From adfc51b1f58e92fb82ec34bd960137e21f5f9f35 Mon Sep 17 00:00:00 2001 From: Mickael ADAM Date: Mon, 15 Dec 2014 14:55:19 +0100 Subject: 436786: [Diagram] Composite diagram shapes shall be refactored https://bugs.eclipse.org/bugs/show_bug.cgi?id=436786 Refactor of: ActivityCompositeEditPart ActivityCompositeEditPartCN BehaviorPortEditPart ClassCompositeEditPart CollaborationCompositeEditPart CollaborationCompositeEditPartCN CollaborationRoleEditPartCN CollaborationUseEditPartCN ComponentCompositeEditPart ComponentCompositeEditPartCN DeviceCompositeEditPart DeviceCompositeEditPartCN DurationObservationEditPart ExecutionEnvironmentCompositeEditPart ExecutionEnvironmentCompositeEditPartCN FunctionBehaviorCompositeEditPart FunctionBehaviorCompositeEditPartCN InformationItemEditPart InteractionCompositeEditPart InteractionCompositeEditPartCN InterfaceCompositeEditPart InterfaceCompositeEditPartCN NodeCompositeEditPart NodeCompositeEditPartCN OpaqueBehaviorCompositeEditPart OpaqueBehaviorCompositeEditPartCN PortEditPart PropertyPartEditPartCN ProtocolStateMachineCompositeEditPart ProtocolStateMachineCompositeEditPartCN StateMachineCompositeEditPart StateMachineCompositeEditPartCN TimeObservationEditPart PrimitiveTypeEditPart SignalEditPartCN PrimitiveTypeEditPartCN SignalEditPart DataTypeEditPart DataTypeEditPartCN EnumerationEditPart EnumerationEditPartCN ClassCompositeEditPartCN InterfaceEditPart InterfaceEditPartCN ParameterEditPart ActorEditPartCN DeploymentSpecificationEditPartCN ArtifactEditPartCN InformationItemEditPartCN ArtifactEditPart ActorEditPart DeploymentSpecificationEditPart LiteralBooleanEditPart LiteralIntegerEditPart LiteralNullEditPart LiteralStringEditPart LiteralUnlimitedNaturalEditPart StringExpressionEditPart OpaqueExpressionEditPart TimeExpressionEditPart ExpressionEditPart DurationEditPart TimeIntervalEditPart DurationIntervalEditPart IntervalEditPart InstanceValueEditPart UseCaseEditPart SignalEventEditPart CallEventEditPart AnyReceiveEventEditPart ChangeEventEditPart TimeEventEditPart UseCaseEditPartCN Change-Id: Iba0dc763d52fe830cb25673d24728b3e52d3e862 Signed-off-by: Mickael ADAM --- .../resources/base.css | 17 + .../META-INF/MANIFEST.MF | 12 +- .../edit/parts/AbstractBehaviorPortEditPart.java | 24 +- .../edit/parts/CustomPropertyPartEditPartCN.java | 81 - .../edit/policies/PropertyLayoutEditPolicy.java | 1 - .../figures/AbstractObservationNodeFigure.java | 1 + .../custom/figures/CollaborationRoleFigure.java | 4 +- .../custom/figures/CollaborationUseFigure.java | 24 +- .../composite/custom/figures/CompositeFigure.java | 4 +- .../figures/DurationObservationNodeFigure.java | 1 + .../custom/figures/InformationItemFigure.java | 4 +- .../custom/figures/TimeObservationNodeFigure.java | 1 + .../model/compositediagram.gmfgen | 1899 ++++++++++- .../plugin.xml | 3506 ++++++++++---------- .../AbstractionAppliedStereotypeEditPart.java | 1635 +++++---- .../edit/parts/AbstractionNameEditPart.java | 1651 +++++---- .../ActivityCompositeCompartmentEditPart.java | 2 + .../ActivityCompositeCompartmentEditPartCN.java | 2 + .../edit/parts/ActivityCompositeEditPart.java | 66 +- .../edit/parts/ActivityCompositeEditPartCN.java | 66 +- .../ActivityCompositeFloatingLabelEditPart.java | 860 +++++ .../ActivityCompositeFloatingLabelEditPartCN.java | 860 +++++ .../edit/parts/ActivityCompositeNameEditPart.java | 2 +- .../parts/ActivityCompositeNameEditPartCN.java | 2 +- .../composite/edit/parts/ActorEditPart.java | 56 +- .../composite/edit/parts/ActorEditPartCN.java | 56 +- .../edit/parts/ActorFloatingLabelEditPart.java | 860 +++++ .../edit/parts/ActorFloatingLabelEditPartCN.java | 860 +++++ .../composite/edit/parts/ActorNameEditPart.java | 2 +- .../composite/edit/parts/ActorNameEditPartCN.java | 2 +- .../edit/parts/AnyReceiveEventEditPart.java | 87 +- .../AnyReceiveEventFloatingLabelEditPart.java | 860 +++++ .../edit/parts/AnyReceiveEventNameEditPart.java | 2 +- .../composite/edit/parts/ArtifactEditPart.java | 56 +- .../composite/edit/parts/ArtifactEditPartCN.java | 56 +- .../edit/parts/ArtifactFloatingLabelEditPart.java | 860 +++++ .../parts/ArtifactFloatingLabelEditPartCN.java | 860 +++++ .../composite/edit/parts/ArtifactNameEditPart.java | 2 +- .../edit/parts/ArtifactNameEditPartCN.java | 2 +- .../composite/edit/parts/BehaviorPortEditPart.java | 77 +- .../parts/BehaviorPortFloatingLabelEditPart.java | 861 +++++ .../composite/edit/parts/CallEventEditPart.java | 87 +- .../edit/parts/CallEventFloatingLabelEditPart.java | 860 +++++ .../edit/parts/CallEventNameEditPart.java | 2 +- .../composite/edit/parts/ChangeEventEditPart.java | 87 +- .../parts/ChangeEventFloatingLabelEditPart.java | 860 +++++ .../edit/parts/ChangeEventNameEditPart.java | 2 +- .../parts/ClassCompositeCompartmentEditPart.java | 2 + .../parts/ClassCompositeCompartmentEditPartCN.java | 2 + .../edit/parts/ClassCompositeEditPart.java | 62 +- .../edit/parts/ClassCompositeEditPartCN.java | 62 +- .../parts/ClassCompositeFloatingLabelEditPart.java | 860 +++++ .../ClassCompositeFloatingLabelEditPartCN.java | 860 +++++ .../edit/parts/ClassCompositeNameEditPart.java | 2 +- .../edit/parts/ClassCompositeNameEditPartCN.java | 2 +- .../CollaborationCompositeCompartmentEditPart.java | 2 + ...ollaborationCompositeCompartmentEditPartCN.java | 2 + .../edit/parts/CollaborationCompositeEditPart.java | 67 +- .../parts/CollaborationCompositeEditPartCN.java | 67 +- ...ollaborationCompositeFloatingLabelEditPart.java | 860 +++++ ...laborationCompositeFloatingLabelEditPartCN.java | 860 +++++ .../parts/CollaborationCompositeNameEditPart.java | 2 +- .../CollaborationCompositeNameEditPartCN.java | 2 +- .../edit/parts/CollaborationRoleEditPartCN.java | 67 +- .../CollaborationRoleFloatingLabelEditPartCN.java | 860 +++++ .../parts/CollaborationRoleNameEditPartCN.java | 2 +- .../edit/parts/CollaborationUseEditPartCN.java | 75 +- .../CollaborationUseFloatingLabelEditPartCN.java | 860 +++++ .../edit/parts/CollaborationUseNameEditPart.java | 2 +- .../composite/edit/parts/CommentBodyEditPart.java | 2 +- .../edit/parts/CommentBodyEditPartCN.java | 2 +- .../composite/edit/parts/CommentEditPart.java | 4 +- .../composite/edit/parts/CommentEditPartCN.java | 4 +- .../ComponentCompositeCompartmentEditPart.java | 2 + .../ComponentCompositeCompartmentEditPartCN.java | 2 + .../edit/parts/ComponentCompositeEditPart.java | 62 +- .../edit/parts/ComponentCompositeEditPartCN.java | 62 +- .../ComponentCompositeFloatingLabelEditPart.java | 860 +++++ .../ComponentCompositeFloatingLabelEditPartCN.java | 860 +++++ .../edit/parts/ComponentCompositeNameEditPart.java | 2 +- .../parts/ComponentCompositeNameEditPartCN.java | 2 +- ...ponentRealizationAppliedStereotypeEditPart.java | 1635 +++++---- .../parts/ComponentRealizationNameEditPart.java | 1651 +++++---- .../parts/ConnectorAppliedStereotypeEditPart.java | 1635 +++++---- .../parts/ConnectorMultiplicitySourceEditPart.java | 1635 +++++---- .../parts/ConnectorMultiplicityTargetEditPart.java | 1635 +++++---- .../edit/parts/ConnectorNameEditPart.java | 1685 +++++----- .../composite/edit/parts/ConstraintEditPart.java | 4 +- .../composite/edit/parts/ConstraintEditPartCN.java | 4 +- .../edit/parts/ConstraintNameEditPart.java | 2 +- .../edit/parts/ConstraintNameEditPartCN.java | 2 +- .../parts/ConstraintSpecificationEditPart.java | 2 +- .../parts/ConstraintSpecificationEditPartCN.java | 2 +- .../DataTypeAttributeCompartmentEditPart.java | 2 + .../DataTypeAttributeCompartmentEditPartCN.java | 2 + .../composite/edit/parts/DataTypeEditPart.java | 67 +- .../composite/edit/parts/DataTypeEditPartCN.java | 67 +- .../edit/parts/DataTypeFloatingLabelEditPart.java | 860 +++++ .../parts/DataTypeFloatingLabelEditPartCN.java | 860 +++++ .../composite/edit/parts/DataTypeNameEditPart.java | 2 +- .../edit/parts/DataTypeNameEditPartCN.java | 2 +- .../DataTypeOperationCompartmentEditPart.java | 2 + .../DataTypeOperationCompartmentEditPartCN.java | 2 + .../parts/DependencyAppliedStereotypeEditPart.java | 1635 +++++---- .../edit/parts/DependencyNameEditPart.java | 1651 +++++---- .../parts/DeploymentAppliedStereotypeEditPart.java | 1635 +++++---- .../edit/parts/DeploymentNameEditPart.java | 1651 +++++---- .../parts/DeploymentSpecificationEditPart.java | 87 +- .../parts/DeploymentSpecificationEditPartCN.java | 87 +- ...ploymentSpecificationFloatingLabelEditPart.java | 860 +++++ ...oymentSpecificationFloatingLabelEditPartCN.java | 860 +++++ .../parts/DeploymentSpecificationNameEditPart.java | 2 +- .../DeploymentSpecificationNameEditPartCN.java | 2 +- .../parts/DeviceCompositeCompartmentEditPart.java | 2 + .../DeviceCompositeCompartmentEditPartCN.java | 2 + .../edit/parts/DeviceCompositeEditPart.java | 62 +- .../edit/parts/DeviceCompositeEditPartCN.java | 62 +- .../DeviceCompositeFloatingLabelEditPart.java | 860 +++++ .../DeviceCompositeFloatingLabelEditPartCN.java | 860 +++++ .../edit/parts/DeviceCompositeNameEditPart.java | 2 +- .../edit/parts/DeviceCompositeNameEditPartCN.java | 2 +- .../edit/parts/DurationConstraintEditPart.java | 4 +- .../edit/parts/DurationConstraintEditPartCN.java | 4 +- .../edit/parts/DurationConstraintNameEditPart.java | 2 +- .../parts/DurationConstraintNameEditPartCN.java | 2 +- .../DurationConstraintSpecificationEditPart.java | 2 +- .../DurationConstraintSpecificationEditPartCN.java | 2 +- .../composite/edit/parts/DurationEditPart.java | 87 +- .../edit/parts/DurationFloatingLabelEditPart.java | 860 +++++ .../edit/parts/DurationIntervalEditPart.java | 87 +- .../DurationIntervalFloatingLabelEditPart.java | 860 +++++ .../edit/parts/DurationIntervalNameEditPart.java | 2 +- .../composite/edit/parts/DurationNameEditPart.java | 2 +- .../edit/parts/DurationObservationEditPart.java | 19 +- .../parts/DurationObservationNameEditPart.java | 6 +- ...DurationObservationStereotypeLabelEditPart.java | 2 + .../composite/edit/parts/EnumerationEditPart.java | 67 +- .../edit/parts/EnumerationEditPartCN.java | 67 +- ...ationEnumerationLiteralCompartmentEditPart.java | 2 + ...ionEnumerationLiteralCompartmentEditPartCN.java | 2 + .../parts/EnumerationFloatingLabelEditPart.java | 860 +++++ .../parts/EnumerationFloatingLabelEditPartCN.java | 860 +++++ .../edit/parts/EnumerationNameEditPart.java | 2 +- .../edit/parts/EnumerationNameEditPartCN.java | 2 +- ...ionEnvironmentCompositeCompartmentEditPart.java | 2 + ...nEnvironmentCompositeCompartmentEditPartCN.java | 2 + .../ExecutionEnvironmentCompositeEditPart.java | 62 +- .../ExecutionEnvironmentCompositeEditPartCN.java | 62 +- ...nEnvironmentCompositeFloatingLabelEditPart.java | 860 +++++ ...nvironmentCompositeFloatingLabelEditPartCN.java | 860 +++++ .../ExecutionEnvironmentCompositeNameEditPart.java | 2 +- ...xecutionEnvironmentCompositeNameEditPartCN.java | 2 +- .../composite/edit/parts/ExpressionEditPart.java | 87 +- .../parts/ExpressionFloatingLabelEditPart.java | 860 +++++ .../edit/parts/ExpressionNameEditPart.java | 2 +- ...nctionBehaviorCompositeCompartmentEditPart.java | 2 + ...tionBehaviorCompositeCompartmentEditPartCN.java | 2 + .../parts/FunctionBehaviorCompositeEditPart.java | 66 +- .../parts/FunctionBehaviorCompositeEditPartCN.java | 66 +- ...tionBehaviorCompositeFloatingLabelEditPart.java | 860 +++++ ...onBehaviorCompositeFloatingLabelEditPartCN.java | 860 +++++ .../FunctionBehaviorCompositeNameEditPart.java | 2 +- .../FunctionBehaviorCompositeNameEditPartCN.java | 2 +- .../GeneralizationAppliedStereotypeEditPart.java | 1635 +++++---- .../InformationFlowAppliedStereotypeEditPart.java | 1635 +++++---- .../InformationFlowConveyedLabelEditPart.java | 1659 +++++---- .../edit/parts/InformationItemEditPart.java | 67 +- .../edit/parts/InformationItemEditPartCN.java | 67 +- .../InformationItemFloatingLabelEditPart.java | 860 +++++ .../InformationItemFloatingLabelEditPartCN.java | 860 +++++ .../edit/parts/InformationItemNameEditPart.java | 2 +- .../edit/parts/InformationItemNameEditPartCN.java | 2 +- .../edit/parts/InstanceValueEditPart.java | 87 +- .../parts/InstanceValueFloatingLabelEditPart.java | 860 +++++ .../edit/parts/InstanceValueNameEditPart.java | 2 +- .../InteractionCompositeCompartmentEditPart.java | 2 + .../InteractionCompositeCompartmentEditPartCN.java | 2 + .../edit/parts/InteractionCompositeEditPart.java | 66 +- .../edit/parts/InteractionCompositeEditPartCN.java | 66 +- .../InteractionCompositeFloatingLabelEditPart.java | 860 +++++ ...nteractionCompositeFloatingLabelEditPartCN.java | 860 +++++ .../parts/InteractionCompositeNameEditPart.java | 2 +- .../parts/InteractionCompositeNameEditPartCN.java | 2 +- .../edit/parts/InteractionConstraintEditPart.java | 4 +- .../parts/InteractionConstraintEditPartCN.java | 4 +- .../parts/InteractionConstraintNameEditPart.java | 2 +- .../parts/InteractionConstraintNameEditPartCN.java | 2 +- ...InteractionConstraintSpecificationEditPart.java | 2 +- ...teractionConstraintSpecificationEditPartCN.java | 2 +- .../composite/edit/parts/InterfaceEditPart.java | 67 +- .../composite/edit/parts/InterfaceEditPartCN.java | 67 +- .../edit/parts/InterfaceFloatingLabelEditPart.java | 860 +++++ .../parts/InterfaceFloatingLabelEditPartCN.java | 860 +++++ .../edit/parts/InterfaceNameEditPart.java | 2 +- .../edit/parts/InterfaceNameEditPartCN.java | 2 +- ...erfaceRealizationAppliedStereotypeEditPart.java | 1635 +++++---- .../parts/InterfaceRealizationNameEditPart.java | 1651 +++++---- .../edit/parts/IntervalConstraintEditPart.java | 4 +- .../edit/parts/IntervalConstraintEditPartCN.java | 4 +- .../edit/parts/IntervalConstraintNameEditPart.java | 2 +- .../parts/IntervalConstraintNameEditPartCN.java | 2 +- .../IntervalConstraintSpecificationEditPart.java | 2 +- .../IntervalConstraintSpecificationEditPartCN.java | 2 +- .../composite/edit/parts/IntervalEditPart.java | 87 +- .../edit/parts/IntervalFloatingLabelEditPart.java | 860 +++++ .../composite/edit/parts/IntervalNameEditPart.java | 2 +- .../edit/parts/LiteralBooleanEditPart.java | 87 +- .../parts/LiteralBooleanFloatingLabelEditPart.java | 860 +++++ .../edit/parts/LiteralBooleanNameEditPart.java | 2 +- .../edit/parts/LiteralIntegerEditPart.java | 87 +- .../parts/LiteralIntegerFloatingLabelEditPart.java | 860 +++++ .../edit/parts/LiteralIntegerNameEditPart.java | 2 +- .../composite/edit/parts/LiteralNullEditPart.java | 87 +- .../parts/LiteralNullFloatingLabelEditPart.java | 860 +++++ .../edit/parts/LiteralNullNameEditPart.java | 2 +- .../edit/parts/LiteralStringEditPart.java | 87 +- .../parts/LiteralStringFloatingLabelEditPart.java | 860 +++++ .../edit/parts/LiteralStringNameEditPart.java | 2 +- .../parts/LiteralUnlimitedNaturalEditPart.java | 87 +- ...teralUnlimitedNaturalFloatingLabelEditPart.java | 860 +++++ .../parts/LiteralUnlimitedNaturalNameEditPart.java | 2 +- .../ManifestationAppliedStereotypeEditPart.java | 1635 +++++---- .../edit/parts/ManifestationNameEditPart.java | 1651 +++++---- .../parts/NodeCompositeCompartmentEditPart.java | 2 + .../parts/NodeCompositeCompartmentEditPartCN.java | 2 + .../edit/parts/NodeCompositeEditPart.java | 62 +- .../edit/parts/NodeCompositeEditPartCN.java | 62 +- .../parts/NodeCompositeFloatingLabelEditPart.java | 860 +++++ .../NodeCompositeFloatingLabelEditPartCN.java | 860 +++++ .../edit/parts/NodeCompositeNameEditPart.java | 2 +- .../edit/parts/NodeCompositeNameEditPartCN.java | 2 +- ...OpaqueBehaviorCompositeCompartmentEditPart.java | 2 + ...aqueBehaviorCompositeCompartmentEditPartCN.java | 2 + .../parts/OpaqueBehaviorCompositeEditPart.java | 66 +- .../parts/OpaqueBehaviorCompositeEditPartCN.java | 66 +- ...aqueBehaviorCompositeFloatingLabelEditPart.java | 860 +++++ ...ueBehaviorCompositeFloatingLabelEditPartCN.java | 860 +++++ .../parts/OpaqueBehaviorCompositeNameEditPart.java | 2 +- .../OpaqueBehaviorCompositeNameEditPartCN.java | 2 +- .../edit/parts/OpaqueExpressionEditPart.java | 87 +- .../OpaqueExpressionFloatingLabelEditPart.java | 860 +++++ .../edit/parts/OpaqueExpressionNameEditPart.java | 2 +- .../parts/ParameterAppliedStereotypeEditPart.java | 2 + .../composite/edit/parts/ParameterEditPart.java | 13 +- .../edit/parts/ParameterNameEditPart.java | 6 +- .../edit/parts/PortAppliedStereotypeEditPart.java | 2 + .../diagram/composite/edit/parts/PortEditPart.java | 13 +- .../composite/edit/parts/PortNameEditPart.java | 6 +- .../edit/parts/PrimitiveTypeEditPart.java | 67 +- .../edit/parts/PrimitiveTypeEditPartCN.java | 67 +- .../parts/PrimitiveTypeFloatingLabelEditPart.java | 860 +++++ .../PrimitiveTypeFloatingLabelEditPartCN.java | 860 +++++ .../edit/parts/PrimitiveTypeNameEditPart.java | 2 +- .../edit/parts/PrimitiveTypeNameEditPartCN.java | 2 +- .../parts/PropertyPartCompartmentEditPartCN.java | 2 + .../edit/parts/PropertyPartEditPartCN.java | 61 +- .../parts/PropertyPartFloatingLabelEditPartCN.java | 860 +++++ .../edit/parts/PropertyPartNameEditPartCN.java | 2 +- ...olStateMachineCompositeCompartmentEditPart.java | 2 + ...StateMachineCompositeCompartmentEditPartCN.java | 2 + .../ProtocolStateMachineCompositeEditPart.java | 66 +- .../ProtocolStateMachineCompositeEditPartCN.java | 66 +- ...StateMachineCompositeFloatingLabelEditPart.java | 860 +++++ ...ateMachineCompositeFloatingLabelEditPartCN.java | 860 +++++ .../ProtocolStateMachineCompositeNameEditPart.java | 2 +- ...rotocolStateMachineCompositeNameEditPartCN.java | 2 +- .../RealizationAppliedStereotypeEditPart.java | 1635 +++++---- .../edit/parts/RealizationNameEditPart.java | 1651 +++++---- .../edit/parts/RepresentationTagLabelEditPart.java | 1653 +++++---- .../RoleBindingAppliedStereotypeEditPart.java | 1635 +++++---- .../edit/parts/RoleBindingRoleNameEditPart.java | 1635 +++++---- .../composite/edit/parts/SignalEditPart.java | 67 +- .../composite/edit/parts/SignalEditPartCN.java | 67 +- .../composite/edit/parts/SignalEventEditPart.java | 87 +- .../parts/SignalEventFloatingLabelEditPart.java | 860 +++++ .../edit/parts/SignalEventNameEditPart.java | 2 +- .../edit/parts/SignalFloatingLabelEditPart.java | 860 +++++ .../edit/parts/SignalFloatingLabelEditPartCN.java | 860 +++++ .../composite/edit/parts/SignalNameEditPart.java | 2 +- .../composite/edit/parts/SignalNameEditPartCN.java | 2 +- .../StateMachineCompositeCompartmentEditPart.java | 2 + ...StateMachineCompositeCompartmentEditPartCN.java | 2 + .../edit/parts/StateMachineCompositeEditPart.java | 66 +- .../parts/StateMachineCompositeEditPartCN.java | 66 +- ...StateMachineCompositeFloatingLabelEditPart.java | 860 +++++ ...ateMachineCompositeFloatingLabelEditPartCN.java | 860 +++++ .../parts/StateMachineCompositeNameEditPart.java | 2 +- .../parts/StateMachineCompositeNameEditPartCN.java | 2 +- .../edit/parts/StringExpressionEditPart.java | 87 +- .../StringExpressionFloatingLabelEditPart.java | 860 +++++ .../edit/parts/StringExpressionNameEditPart.java | 2 +- .../SubstitutionAppliedStereotypeEditPart.java | 1635 +++++---- .../edit/parts/SubstitutionNameEditPart.java | 1651 +++++---- .../edit/parts/TimeConstraintEditPart.java | 4 +- .../edit/parts/TimeConstraintEditPartCN.java | 4 +- .../edit/parts/TimeConstraintNameEditPart.java | 2 +- .../edit/parts/TimeConstraintNameEditPartCN.java | 2 +- .../parts/TimeConstraintSpecificationEditPart.java | 2 +- .../TimeConstraintSpecificationEditPartCN.java | 2 +- .../composite/edit/parts/TimeEventEditPart.java | 87 +- .../edit/parts/TimeEventFloatingLabelEditPart.java | 860 +++++ .../edit/parts/TimeEventNameEditPart.java | 2 +- .../edit/parts/TimeExpressionEditPart.java | 87 +- .../parts/TimeExpressionFloatingLabelEditPart.java | 860 +++++ .../edit/parts/TimeExpressionNameEditPart.java | 2 +- .../composite/edit/parts/TimeIntervalEditPart.java | 87 +- .../parts/TimeIntervalFloatingLabelEditPart.java | 860 +++++ .../edit/parts/TimeIntervalNameEditPart.java | 2 +- .../edit/parts/TimeObservationEditPart.java | 19 +- .../edit/parts/TimeObservationNameEditPart.java | 6 +- .../TimeObservationStereotypeLabelEditPart.java | 2 + .../composite/edit/parts/UMLEditPartFactory.java | 201 ++ .../edit/parts/UsageAppliedStereotypeEditPart.java | 1635 +++++---- .../composite/edit/parts/UsageNameEditPart.java | 1651 +++++---- .../composite/edit/parts/UseCaseEditPart.java | 87 +- .../composite/edit/parts/UseCaseEditPartCN.java | 87 +- .../edit/parts/UseCaseFloatingLabelEditPart.java | 860 +++++ .../edit/parts/UseCaseFloatingLabelEditPartCN.java | 860 +++++ .../composite/edit/parts/UseCaseNameEditPart.java | 2 +- .../edit/parts/UseCaseNameEditPartCN.java | 2 +- ...numerationLiteralItemSemanticEditPolicyCLN.java | 2 +- .../OperationItemSemanticEditPolicyCLN.java | 2 +- .../PropertyItemSemanticEditPolicyCLN.java | 2 +- .../policies/UMLBaseItemSemanticEditPolicy.java | 4 +- .../composite/part/UMLDiagramEditorUtil.java | 2 + .../diagram/composite/part/UMLDiagramUpdater.java | 2 +- .../composite/part/UMLDocumentProvider.java | 3 +- .../composite/part/UMLVisualIDRegistry.java | 205 +- .../composite/providers/UMLParserProvider.java | 2333 ++++++++++--- .../composite/providers/UMLViewProvider.java | 519 ++- .../composite/sheet/UMLPropertySection.java | 2 +- .../TestCompositeDiagramActivityChildNode.java | 8 +- .../TestCompositeDiagramCompositeChildNode.java | 227 +- 333 files changed, 91630 insertions(+), 26335 deletions(-) delete mode 100644 plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/edit/parts/CustomPropertyPartEditPartCN.java create mode 100644 plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ActivityCompositeFloatingLabelEditPart.java create mode 100644 plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ActivityCompositeFloatingLabelEditPartCN.java create mode 100644 plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ActorFloatingLabelEditPart.java create mode 100644 plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ActorFloatingLabelEditPartCN.java create mode 100644 plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/AnyReceiveEventFloatingLabelEditPart.java create mode 100644 plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ArtifactFloatingLabelEditPart.java create mode 100644 plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ArtifactFloatingLabelEditPartCN.java create mode 100644 plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/BehaviorPortFloatingLabelEditPart.java create mode 100644 plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/CallEventFloatingLabelEditPart.java create mode 100644 plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ChangeEventFloatingLabelEditPart.java create mode 100644 plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ClassCompositeFloatingLabelEditPart.java create mode 100644 plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ClassCompositeFloatingLabelEditPartCN.java create mode 100644 plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/CollaborationCompositeFloatingLabelEditPart.java create mode 100644 plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/CollaborationCompositeFloatingLabelEditPartCN.java create mode 100644 plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/CollaborationRoleFloatingLabelEditPartCN.java create mode 100644 plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/CollaborationUseFloatingLabelEditPartCN.java create mode 100644 plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ComponentCompositeFloatingLabelEditPart.java create mode 100644 plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ComponentCompositeFloatingLabelEditPartCN.java create mode 100644 plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DataTypeFloatingLabelEditPart.java create mode 100644 plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DataTypeFloatingLabelEditPartCN.java create mode 100644 plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DeploymentSpecificationFloatingLabelEditPart.java create mode 100644 plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DeploymentSpecificationFloatingLabelEditPartCN.java create mode 100644 plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DeviceCompositeFloatingLabelEditPart.java create mode 100644 plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DeviceCompositeFloatingLabelEditPartCN.java create mode 100644 plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DurationFloatingLabelEditPart.java create mode 100644 plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DurationIntervalFloatingLabelEditPart.java create mode 100644 plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/EnumerationFloatingLabelEditPart.java create mode 100644 plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/EnumerationFloatingLabelEditPartCN.java create mode 100644 plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ExecutionEnvironmentCompositeFloatingLabelEditPart.java create mode 100644 plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ExecutionEnvironmentCompositeFloatingLabelEditPartCN.java create mode 100644 plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ExpressionFloatingLabelEditPart.java create mode 100644 plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/FunctionBehaviorCompositeFloatingLabelEditPart.java create mode 100644 plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/FunctionBehaviorCompositeFloatingLabelEditPartCN.java create mode 100644 plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InformationItemFloatingLabelEditPart.java create mode 100644 plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InformationItemFloatingLabelEditPartCN.java create mode 100644 plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InstanceValueFloatingLabelEditPart.java create mode 100644 plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InteractionCompositeFloatingLabelEditPart.java create mode 100644 plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InteractionCompositeFloatingLabelEditPartCN.java create mode 100644 plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InterfaceFloatingLabelEditPart.java create mode 100644 plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InterfaceFloatingLabelEditPartCN.java create mode 100644 plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/IntervalFloatingLabelEditPart.java create mode 100644 plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/LiteralBooleanFloatingLabelEditPart.java create mode 100644 plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/LiteralIntegerFloatingLabelEditPart.java create mode 100644 plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/LiteralNullFloatingLabelEditPart.java create mode 100644 plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/LiteralStringFloatingLabelEditPart.java create mode 100644 plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/LiteralUnlimitedNaturalFloatingLabelEditPart.java create mode 100644 plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/NodeCompositeFloatingLabelEditPart.java create mode 100644 plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/NodeCompositeFloatingLabelEditPartCN.java create mode 100644 plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/OpaqueBehaviorCompositeFloatingLabelEditPart.java create mode 100644 plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/OpaqueBehaviorCompositeFloatingLabelEditPartCN.java create mode 100644 plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/OpaqueExpressionFloatingLabelEditPart.java create mode 100644 plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/PrimitiveTypeFloatingLabelEditPart.java create mode 100644 plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/PrimitiveTypeFloatingLabelEditPartCN.java create mode 100644 plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/PropertyPartFloatingLabelEditPartCN.java create mode 100644 plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ProtocolStateMachineCompositeFloatingLabelEditPart.java create mode 100644 plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ProtocolStateMachineCompositeFloatingLabelEditPartCN.java create mode 100644 plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/SignalEventFloatingLabelEditPart.java create mode 100644 plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/SignalFloatingLabelEditPart.java create mode 100644 plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/SignalFloatingLabelEditPartCN.java create mode 100644 plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/StateMachineCompositeFloatingLabelEditPart.java create mode 100644 plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/StateMachineCompositeFloatingLabelEditPartCN.java create mode 100644 plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/StringExpressionFloatingLabelEditPart.java create mode 100644 plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/TimeEventFloatingLabelEditPart.java create mode 100644 plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/TimeExpressionFloatingLabelEditPart.java create mode 100644 plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/TimeIntervalFloatingLabelEditPart.java create mode 100644 plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/UseCaseFloatingLabelEditPart.java create mode 100644 plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/UseCaseFloatingLabelEditPartCN.java diff --git a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/resources/base.css b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/resources/base.css index eb32aa78f39..1e1cfcfbbd5 100644 --- a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/resources/base.css +++ b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/resources/base.css @@ -301,4 +301,21 @@ StateMachineDiagram Pseudostate[kind="choice"]{ maintainSymbolRatio:false; } +/*---------- Composite Diagram ---------*/ +CompositeDiagram Property[aggregation="shared"]{ + borderStyle: custom; +} + +CompositeDiagram DurationObservation > Compartment[kind="symbol"], +CompositeDiagram TimeObservation > Compartment[kind="symbol"] +{ + visible:true; +} + +CompositeDiagram DurationObservation > Label, +CompositeDiagram TimeObservation > Label +{ + visible:true; + textAlignment:"Left"; +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/META-INF/MANIFEST.MF b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/META-INF/MANIFEST.MF index a0c85b6ffef..6862cb36431 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/META-INF/MANIFEST.MF +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/META-INF/MANIFEST.MF @@ -20,7 +20,7 @@ Bundle-ActivationPolicy: lazy Bundle-ClassPath: . Bundle-Name: %pluginName Bundle-Localization: plugin -Bundle-RequiredExecutionEnvironment: JavaSE-1.6 +Bundle-RequiredExecutionEnvironment: J2SE-1.5 Require-Bundle: org.eclipse.emf.ecore, org.eclipse.core.runtime, org.eclipse.core.resources, @@ -71,13 +71,11 @@ Require-Bundle: org.eclipse.emf.ecore, org.eclipse.papyrus.infra.viewpoints.policy;bundle-version="1.1.0", org.eclipse.papyrus.infra.viewpoints.configuration;bundle-version="1.1.0", org.eclipse.papyrus.views.properties;bundle-version="1.1.0", - org.eclipse.papyrus.uml.diagram.synchronizeview;bundle-version="1.1.0" + org.eclipse.papyrus.uml.diagram.synchronizeview;bundle-version="1.1.0", + org.eclipse.core.databinding.observable Bundle-Vendor: %providerName Eclipse-LazyStart: true Bundle-Version: 1.1.0.qualifier -Bundle-Activator: org.eclipse.papyrus.uml.diagram.composite.part.UMLDi - agramEditorPlugin +Bundle-Activator: org.eclipse.papyrus.uml.diagram.composite.part.UMLDiagramEditorPlugin Bundle-ManifestVersion: 2 -Bundle-SymbolicName: org.eclipse.papyrus.uml.diagram.composite;singlet - on:=true - +Bundle-SymbolicName: org.eclipse.papyrus.uml.diagram.composite; singleton:=true diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/edit/parts/AbstractBehaviorPortEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/edit/parts/AbstractBehaviorPortEditPart.java index 7b72656ad35..c561ca7a90c 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/edit/parts/AbstractBehaviorPortEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/edit/parts/AbstractBehaviorPortEditPart.java @@ -16,14 +16,14 @@ package org.eclipse.papyrus.uml.diagram.composite.custom.edit.parts; import org.eclipse.gef.DragTracker; import org.eclipse.gef.Request; import org.eclipse.gmf.runtime.notation.View; -import org.eclipse.papyrus.infra.gmfdiag.common.editpart.NodeEditPart; import org.eclipse.papyrus.uml.diagram.common.dragtracker.NoScrollDragEditPartsTrackerEx; +import org.eclipse.papyrus.uml.diagram.common.editparts.RoundedCompartmentEditPart; /** * this is an abstract edit part to prevent the behavior port to got out of the composite * */ -public abstract class AbstractBehaviorPortEditPart extends NodeEditPart { +public abstract class AbstractBehaviorPortEditPart extends RoundedCompartmentEditPart { public AbstractBehaviorPortEditPart(View view) { super(view); } @@ -32,4 +32,24 @@ public abstract class AbstractBehaviorPortEditPart extends NodeEditPart { public DragTracker getDragTracker(Request request) { return new NoScrollDragEditPartsTrackerEx(this); } + + /** + * @see org.eclipse.papyrus.uml.diagram.common.editparts.RoundedCompartmentEditPart#getDefaultCornerHeight() + * + * @return + */ + @Override + protected int getDefaultCornerHeight() { + return 10; + } + + /** + * @see org.eclipse.papyrus.uml.diagram.common.editparts.RoundedCompartmentEditPart#getDefaultCornerWidth() + * + * @return + */ + @Override + protected int getDefaultCornerWidth() { + return 10; + } } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/edit/parts/CustomPropertyPartEditPartCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/edit/parts/CustomPropertyPartEditPartCN.java deleted file mode 100644 index b313a6d0986..00000000000 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/edit/parts/CustomPropertyPartEditPartCN.java +++ /dev/null @@ -1,81 +0,0 @@ -/***************************************************************************** - * Copyright (c) 2009-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: - * Yann Tanguy (CEA LIST) yann.tanguy@cea.fr - Initial API and implementation - * - *****************************************************************************/ -package org.eclipse.papyrus.uml.diagram.composite.custom.edit.parts; - -import org.eclipse.draw2d.Graphics; -import org.eclipse.emf.common.notify.Notification; -import org.eclipse.gmf.runtime.notation.View; -import org.eclipse.papyrus.uml.diagram.common.editparts.NamedElementEditPart; -import org.eclipse.uml2.uml.AggregationKind; -import org.eclipse.uml2.uml.Property; -import org.eclipse.uml2.uml.UMLPackage; - -/** - *
- * This class will be inherited by the GMF generated {@link org.eclipse.papyrus.uml.diagram.composite.edit.parts.PropertyPartEditPartCN}
- * in order to refresh the related figure when when the Property::aggregation eAttribute value
- * changes.
- * 
- */ -public abstract class CustomPropertyPartEditPartCN extends NamedElementEditPart { - - /** - * Constructor - * - * @param view - */ - public CustomPropertyPartEditPartCN(View view) { - super(view); - } - - /** - *
-	 * Calls the figure refresh when a change event is detected on
-	 * UMLPackage.eINSTANCE.getProperty_Aggregation().
-	 *
-	 * {@inheritDoc}
-	 * 
- */ - @Override - protected void handleNotificationEvent(Notification event) { - - if ((resolveSemanticElement() != null) && (resolveSemanticElement().equals(event.getNotifier()))) { - if (UMLPackage.eINSTANCE.getProperty_Aggregation().equals(event.getFeature())) { - refreshVisuals(); - } - } - super.handleNotificationEvent(event); - } - - - /** - *
-	 * Refresh the figure with dashed border when Property aggregation value is SHARED.
-	 * Else set the border style to solid line.
-	 *
-	 * {@inheritDoc}
-	 * 
- */ - @Override - protected void refreshVisuals() { - super.refreshVisuals(); - if ((resolveSemanticElement() != null) && (resolveSemanticElement() instanceof Property)) { - if (((Property) resolveSemanticElement()).getAggregation().equals(AggregationKind.SHARED_LITERAL)) { - getPrimaryShape().setLineStyle(Graphics.LINE_CUSTOM); - } else { - getPrimaryShape().setLineStyle(Graphics.LINE_SOLID); - } - } - } -} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/edit/policies/PropertyLayoutEditPolicy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/edit/policies/PropertyLayoutEditPolicy.java index 5606fd308de..c2326ab23af 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/edit/policies/PropertyLayoutEditPolicy.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/edit/policies/PropertyLayoutEditPolicy.java @@ -13,7 +13,6 @@ *****************************************************************************/ package org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies; -import org.eclipse.papyrus.uml.diagram.composite.custom.edit.parts.CustomPropertyPartEditPartCN; /** diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/figures/AbstractObservationNodeFigure.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/figures/AbstractObservationNodeFigure.java index e15f7f2e495..098cebc0a7a 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/figures/AbstractObservationNodeFigure.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/figures/AbstractObservationNodeFigure.java @@ -29,6 +29,7 @@ import org.eclipse.swt.graphics.Image; /** * Provides stereotype and name management for {@link TimeObservationNodeFigure} and {@link DurationObservationNodeFigure} */ +// To delete public class AbstractObservationNodeFigure extends NodeNamedElementFigure { /** Plug-in ID where UML2 icons can be found */ diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/figures/CollaborationRoleFigure.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/figures/CollaborationRoleFigure.java index f73280e3217..75b0ff0f794 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/figures/CollaborationRoleFigure.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/figures/CollaborationRoleFigure.java @@ -18,14 +18,14 @@ import org.eclipse.draw2d.ImageFigure; import org.eclipse.draw2d.OrderedLayout; import org.eclipse.draw2d.Panel; import org.eclipse.draw2d.ToolbarLayout; -import org.eclipse.papyrus.uml.diagram.common.figure.node.NodeNamedElementFigure; +import org.eclipse.papyrus.uml.diagram.common.figure.node.RoundedCompartmentFigure; import org.eclipse.papyrus.uml.diagram.composite.part.UMLDiagramEditorPlugin; import org.eclipse.swt.graphics.Image; /** * Figure for CollaborationRole (in Composite) representation of ConnectableElement. */ -public class CollaborationRoleFigure extends NodeNamedElementFigure { +public class CollaborationRoleFigure extends RoundedCompartmentFigure { /** * Path of the Arrow image used in the figure. diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/figures/CollaborationUseFigure.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/figures/CollaborationUseFigure.java index 23840842aad..8afe3119ffc 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/figures/CollaborationUseFigure.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/figures/CollaborationUseFigure.java @@ -13,29 +13,27 @@ *****************************************************************************/ package org.eclipse.papyrus.uml.diagram.composite.custom.figures; -import org.eclipse.draw2d.Graphics; -import org.eclipse.draw2d.ToolbarLayout; -import org.eclipse.papyrus.uml.diagram.common.figure.node.NodeNamedElementFigure; +import org.eclipse.papyrus.uml.diagram.common.figure.node.RoundedCompartmentFigure; /** * Figure for CollaborationUse representation. */ -public class CollaborationUseFigure extends NodeNamedElementFigure { +public class CollaborationUseFigure extends RoundedCompartmentFigure { /** * Creates a new CollaborationUseFigure. */ public CollaborationUseFigure() { super(); - - // Use custom dashed line border. - setCustomDash(DEFAULT_CUSTOM_DASH); - setLineStyle(Graphics.LINE_CUSTOM); - - // Set layout (Vertical ToolbarLayout) - ToolbarLayout layout = new ToolbarLayout(); - layout.setHorizontal(false); - setLayoutManager(layout); + // + // // Use custom dashed line border. + // setCustomDash(DEFAULT_CUSTOM_DASH); + // setLineStyle(Graphics.LINE_CUSTOM); + // + // // Set layout (Vertical ToolbarLayout) + // ToolbarLayout layout = new ToolbarLayout(); + // layout.setHorizontal(false); + // setLayoutManager(layout); } } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/figures/CompositeFigure.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/figures/CompositeFigure.java index aa5310857c1..6f15a8f4ac7 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/figures/CompositeFigure.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/figures/CompositeFigure.java @@ -17,12 +17,12 @@ import java.util.ArrayList; import java.util.List; import org.eclipse.draw2d.IFigure; -import org.eclipse.papyrus.uml.diagram.common.figure.node.CompartmentFigure; +import org.eclipse.papyrus.uml.diagram.common.figure.node.RoundedCompartmentFigure; /** * Figure for Composite representation of Class. */ -public class CompositeFigure extends CompartmentFigure { +public class CompositeFigure extends RoundedCompartmentFigure { /** The Internal Structure Compartment */ private final static String COMPOSITE_COMPARTMENT = "compositeCompartment"; diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/figures/DurationObservationNodeFigure.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/figures/DurationObservationNodeFigure.java index 7958899f5ce..a89a73a96e4 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/figures/DurationObservationNodeFigure.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/figures/DurationObservationNodeFigure.java @@ -20,6 +20,7 @@ import org.eclipse.swt.graphics.Image; /** * Figure for DurationObservation */ +// to delete public class DurationObservationNodeFigure extends AbstractObservationNodeFigure { public static final String IMAGE_DURATION = "DurationObservation.gif"; //$NON-NLS-1$ diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/figures/InformationItemFigure.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/figures/InformationItemFigure.java index b3962b02893..25f8e25fa20 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/figures/InformationItemFigure.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/figures/InformationItemFigure.java @@ -16,12 +16,12 @@ package org.eclipse.papyrus.uml.diagram.composite.custom.figures; import java.util.ArrayList; import java.util.List; -import org.eclipse.papyrus.uml.diagram.common.figure.node.CompartmentFigure; +import org.eclipse.papyrus.uml.diagram.common.figure.node.RoundedCompartmentFigure; /** * Figure for Composite representation of InformationItem. */ -public class InformationItemFigure extends CompartmentFigure { +public class InformationItemFigure extends RoundedCompartmentFigure { /** Value of the textual tag added to the figure. */ private static String TAG_LABEL = "Information"; //$NON-NLS-1$ diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/figures/TimeObservationNodeFigure.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/figures/TimeObservationNodeFigure.java index 1636a3a5e59..500a6e6f302 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/figures/TimeObservationNodeFigure.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/figures/TimeObservationNodeFigure.java @@ -20,6 +20,7 @@ import org.eclipse.swt.graphics.Image; /** * Figure for TimeObservation */ +// To delete public class TimeObservationNodeFigure extends AbstractObservationNodeFigure { public static final String IMAGE_OBSERVATION = "TimeObservation.gif"; //$NON-NLS-1$ diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/model/compositediagram.gmfgen b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/model/compositediagram.gmfgen index a7031575b93..1c199db9087 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/model/compositediagram.gmfgen +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/model/compositediagram.gmfgen @@ -59,7 +59,7 @@ xsi:type="gmfgen:NotationType"/> + figureQualifiedClassName="org.eclipse.papyrus.uml.diagram.common.figure.node.RoundedCompartmentFigure"/> + + + + + + + + + @@ -256,6 +284,10 @@ xsi:type="gmfgen:CustomBehaviour" key="org.eclipse.papyrus.uml.diagram.common.editpolicies.ShowHideLabelEditPolicy.SHOW_HIDE_LABEL_ROLE" editPolicyQualifiedClassName="org.eclipse.papyrus.uml.diagram.common.editpolicies.ShowHideLabelEditPolicy"/> + @@ -396,6 +428,10 @@ xsi:type="gmfgen:CustomBehaviour" key="org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY" editPolicyQualifiedClassName="org.eclipse.papyrus.uml.diagram.common.editpolicies.MaskManagedNodeEditPolicy"/> + + + + + + + + + @@ -510,6 +570,26 @@ href="../../../plugin/org.eclipse.uml2.uml/model/UML.genmodel#//uml/NamedElement/name"/> + + + + + + + + figureQualifiedClassName="org.eclipse.papyrus.uml.diagram.common.figure.node.RoundedCompartmentFigure"/> + @@ -582,6 +666,26 @@ href="../../../plugin/org.eclipse.uml2.uml/model/UML.genmodel#//uml/NamedElement/name"/> + + + + + + + + @@ -671,6 +779,26 @@ href="../../../plugin/org.eclipse.uml2.uml/model/UML.genmodel#//uml/NamedElement/name"/> + + + + + + + + @@ -760,6 +892,26 @@ href="../../../plugin/org.eclipse.uml2.uml/model/UML.genmodel#//uml/NamedElement/name"/> + + + + + + + + @@ -849,6 +1005,26 @@ href="../../../plugin/org.eclipse.uml2.uml/model/UML.genmodel#//uml/NamedElement/name"/> + + + + + + + + @@ -938,6 +1118,26 @@ href="../../../plugin/org.eclipse.uml2.uml/model/UML.genmodel#//uml/NamedElement/name"/> + + + + + + + + @@ -1027,6 +1231,26 @@ href="../../../plugin/org.eclipse.uml2.uml/model/UML.genmodel#//uml/NamedElement/name"/> + + + + + + + + @@ -1116,6 +1344,26 @@ href="../../../plugin/org.eclipse.uml2.uml/model/UML.genmodel#//uml/NamedElement/name"/> + + + + + + + + @@ -1209,6 +1461,26 @@ href="../../../plugin/org.eclipse.uml2.uml/model/UML.genmodel#//uml/NamedElement/name"/> + + + + + + + + @@ -1298,6 +1574,26 @@ href="../../../plugin/org.eclipse.uml2.uml/model/UML.genmodel#//uml/NamedElement/name"/> + + + + + + + + @@ -1387,13 +1687,33 @@ href="../../../plugin/org.eclipse.uml2.uml/model/UML.genmodel#//uml/NamedElement/name"/> - - + + + + + + + + + @@ -1480,6 +1804,26 @@ href="../../../plugin/org.eclipse.uml2.uml/model/UML.genmodel#//uml/NamedElement/name"/> + + + + + + + + @@ -1573,6 +1921,26 @@ href="../../../plugin/org.eclipse.uml2.uml/model/UML.genmodel#//uml/NamedElement/name"/> + + + + + + + + @@ -1649,6 +2021,26 @@ href="../../../plugin/org.eclipse.uml2.uml/model/UML.genmodel#//uml/NamedElement/name"/> + + + + + + + + @@ -1720,6 +2116,26 @@ href="../../../plugin/org.eclipse.uml2.uml/model/UML.genmodel#//uml/NamedElement/name"/> + + + + + + + + @@ -1791,6 +2211,26 @@ href="../../../plugin/org.eclipse.uml2.uml/model/UML.genmodel#//uml/NamedElement/name"/> + + + + + + + + @@ -1864,6 +2308,26 @@ href="../../../plugin/org.eclipse.uml2.uml/model/UML.genmodel#//uml/NamedElement/name"/> + + + + + + + + @@ -1936,6 +2404,26 @@ href="../../../plugin/org.eclipse.uml2.uml/model/UML.genmodel#//uml/NamedElement/name"/> + + + + + + + + figureQualifiedClassName="org.eclipse.papyrus.uml.diagram.common.figure.node.RoundedCompartmentFigure"/> + @@ -2003,6 +2495,26 @@ href="../../../plugin/org.eclipse.uml2.uml/model/UML.genmodel#//uml/NamedElement/name"/> + + + + + + + + figureQualifiedClassName="org.eclipse.papyrus.uml.diagram.common.figure.node.RoundedCompartmentFigure"/> + @@ -2066,6 +2582,26 @@ href="../../../plugin/org.eclipse.uml2.uml/model/UML.genmodel#//uml/NamedElement/name"/> + + + + + + + + figureQualifiedClassName="org.eclipse.papyrus.uml.diagram.common.figure.node.RoundedCompartmentFigure"/> + @@ -2133,6 +2673,26 @@ href="../../../plugin/org.eclipse.uml2.uml/model/UML.genmodel#//uml/NamedElement/name"/> + + + + + + + + @@ -2211,6 +2775,26 @@ href="../../../plugin/org.eclipse.uml2.uml/model/UML.genmodel#//uml/NamedElement/name"/> + + + + + + + + @@ -2274,6 +2862,26 @@ href="../../../plugin/org.eclipse.uml2.uml/model/UML.genmodel#//uml/NamedElement/name"/> + + + + + + + + figureQualifiedClassName="org.eclipse.papyrus.uml.diagram.common.figure.node.RoundedCompartmentFigure"/> + @@ -2341,6 +2953,26 @@ href="../../../plugin/org.eclipse.uml2.uml/model/UML.genmodel#//uml/NamedElement/name"/> + + + + + + + + @@ -3037,6 +3673,26 @@ href="../../../plugin/org.eclipse.uml2.uml/model/UML.genmodel#//uml/NamedElement/name"/> + + + + + + + + @@ -3125,6 +3785,26 @@ href="../../../plugin/org.eclipse.uml2.uml/model/UML.genmodel#//uml/NamedElement/name"/> + + + + + + + + @@ -3213,6 +3897,26 @@ href="../../../plugin/org.eclipse.uml2.uml/model/UML.genmodel#//uml/NamedElement/name"/> + + + + + + + + @@ -3301,6 +4009,26 @@ href="../../../plugin/org.eclipse.uml2.uml/model/UML.genmodel#//uml/NamedElement/name"/> + + + + + + + + @@ -3389,6 +4121,26 @@ href="../../../plugin/org.eclipse.uml2.uml/model/UML.genmodel#//uml/NamedElement/name"/> + + + + + + + + @@ -3477,6 +4233,26 @@ href="../../../plugin/org.eclipse.uml2.uml/model/UML.genmodel#//uml/NamedElement/name"/> + + + + + + + + @@ -3569,6 +4349,26 @@ href="../../../plugin/org.eclipse.uml2.uml/model/UML.genmodel#//uml/NamedElement/name"/> + + + + + + + + @@ -3637,22 +4441,42 @@ + visualID="5122" + editPartClassName="DeviceCompositeNameEditPart" + itemSemanticEditPolicyClassName="DeviceCompositeNameItemSemanticEditPolicy" + elementIcon="true"> + + + + + + + + xsi:type="gmfgen:FigureViewmap" + figureQualifiedClassName="org.eclipse.papyrus.infra.gmfdiag.common.figure.node.PapyrusWrappingLabel"/> + viewPattern="" + editorPattern="" + editPattern=""> @@ -3707,6 +4531,10 @@ xsi:type="gmfgen:CustomBehaviour" key=""REMOVE_ORPHAN_VIEW"" editPolicyQualifiedClassName="org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.RemoveOrphanViewPolicy"/> + @@ -3745,6 +4573,26 @@ href="../../../plugin/org.eclipse.uml2.uml/model/UML.genmodel#//uml/NamedElement/name"/> + + + + + + + + @@ -3837,6 +4689,26 @@ href="../../../plugin/org.eclipse.uml2.uml/model/UML.genmodel#//uml/NamedElement/name"/> + + + + + + + + @@ -3929,6 +4805,26 @@ href="../../../plugin/org.eclipse.uml2.uml/model/UML.genmodel#//uml/NamedElement/name"/> + + + + + + + + @@ -4004,6 +4904,26 @@ href="../../../plugin/org.eclipse.uml2.uml/model/UML.genmodel#//uml/NamedElement/name"/> + + + + + + + + @@ -4074,6 +4998,26 @@ href="../../../plugin/org.eclipse.uml2.uml/model/UML.genmodel#//uml/NamedElement/name"/> + + + + + + + + @@ -4144,6 +5092,26 @@ href="../../../plugin/org.eclipse.uml2.uml/model/UML.genmodel#//uml/NamedElement/name"/> + + + + + + + + @@ -4216,6 +5188,26 @@ href="../../../plugin/org.eclipse.uml2.uml/model/UML.genmodel#//uml/NamedElement/name"/> + + + + + + + + @@ -4287,6 +5283,26 @@ href="../../../plugin/org.eclipse.uml2.uml/model/UML.genmodel#//uml/NamedElement/name"/> + + + + + + + + figureQualifiedClassName="org.eclipse.papyrus.uml.diagram.common.figure.node.RoundedCompartmentFigure"/> + @@ -4353,6 +5373,26 @@ href="../../../plugin/org.eclipse.uml2.uml/model/UML.genmodel#//uml/NamedElement/name"/> + + + + + + + + figureQualifiedClassName="org.eclipse.papyrus.uml.diagram.common.figure.node.RoundedCompartmentFigure"/> + @@ -4415,6 +5459,26 @@ href="../../../plugin/org.eclipse.uml2.uml/model/UML.genmodel#//uml/NamedElement/name"/> + + + + + + + + figureQualifiedClassName="org.eclipse.papyrus.uml.diagram.common.figure.node.RoundedCompartmentFigure"/> + @@ -4481,6 +5549,26 @@ href="../../../plugin/org.eclipse.uml2.uml/model/UML.genmodel#//uml/NamedElement/name"/> + + + + + + + + @@ -4551,9 +5643,29 @@ + viewPattern="{0} " + editorPattern="{0}" + editPattern="{0}"> + + + + + + + @@ -4582,6 +5694,10 @@ xsi:type="gmfgen:CustomBehaviour" key="org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeLabelDisplayEditPolicy.STEREOTYPE_LABEL_POLICY" editPolicyQualifiedClassName="org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeNodeLabelDisplayEditPolicy"/> + @@ -4620,6 +5736,26 @@ href="../../../plugin/org.eclipse.uml2.uml/model/UML.genmodel#//uml/NamedElement/name"/> + + + + + + + + figureQualifiedClassName="org.eclipse.papyrus.uml.diagram.common.figure.node.RoundedCompartmentFigure"/> + @@ -4686,6 +5826,26 @@ href="../../../plugin/org.eclipse.uml2.uml/model/UML.genmodel#//uml/NamedElement/name"/> + + + + + + + + figureQualifiedClassName="org.eclipse.papyrus.uml.diagram.common.figure.node.RoundedCompartmentFigure"/> + @@ -4748,6 +5912,26 @@ href="../../../plugin/org.eclipse.uml2.uml/model/UML.genmodel#//uml/NamedElement/name"/> + + + + + + + + figureQualifiedClassName="org.eclipse.papyrus.uml.diagram.common.figure.node.RoundedCompartmentFigure"/> + @@ -4810,6 +5998,26 @@ href="../../../plugin/org.eclipse.uml2.uml/model/UML.genmodel#//uml/NamedElement/name"/> + + + + + + + + figureQualifiedClassName="org.eclipse.papyrus.uml.diagram.common.figure.node.RoundedCompartmentFigure"/> + @@ -4872,6 +6084,26 @@ href="../../../plugin/org.eclipse.uml2.uml/model/UML.genmodel#//uml/NamedElement/name"/> + + + + + + + + figureQualifiedClassName="org.eclipse.papyrus.uml.diagram.common.figure.node.RoundedCompartmentFigure"/> + @@ -4934,6 +6170,26 @@ href="../../../plugin/org.eclipse.uml2.uml/model/UML.genmodel#//uml/NamedElement/name"/> + + + + + + + + figureQualifiedClassName="org.eclipse.papyrus.uml.diagram.common.figure.node.RoundedCompartmentFigure"/> + @@ -4996,6 +6256,26 @@ href="../../../plugin/org.eclipse.uml2.uml/model/UML.genmodel#//uml/NamedElement/name"/> + + + + + + + + figureQualifiedClassName="org.eclipse.papyrus.uml.diagram.common.figure.node.RoundedCompartmentFigure"> + + + figureQualifiedClassName="org.eclipse.papyrus.uml.diagram.common.figure.node.RoundedCompartmentFigure"> + + + figureQualifiedClassName="org.eclipse.papyrus.uml.diagram.common.figure.node.RoundedCompartmentFigure"/> + @@ -5266,6 +6560,26 @@ href="../../../plugin/org.eclipse.uml2.uml/model/UML.genmodel#//uml/NamedElement/name"/> + + + + + + + + figureQualifiedClassName="org.eclipse.papyrus.uml.diagram.common.figure.node.RoundedCompartmentFigure"/> + @@ -5328,6 +6646,26 @@ href="../../../plugin/org.eclipse.uml2.uml/model/UML.genmodel#//uml/NamedElement/name"/> + + + + + + + + figureQualifiedClassName="org.eclipse.papyrus.uml.diagram.common.figure.node.RoundedCompartmentFigure"/> + @@ -5390,6 +6732,26 @@ href="../../../plugin/org.eclipse.uml2.uml/model/UML.genmodel#//uml/NamedElement/name"/> + + + + + + + + figureQualifiedClassName="org.eclipse.papyrus.uml.diagram.common.figure.node.RoundedCompartmentFigure"/> + @@ -5452,6 +6818,26 @@ href="../../../plugin/org.eclipse.uml2.uml/model/UML.genmodel#//uml/NamedElement/name"/> + + + + + + + + figureQualifiedClassName="org.eclipse.papyrus.uml.diagram.common.figure.node.RoundedCompartmentFigure"/> + @@ -5514,6 +6904,26 @@ href="../../../plugin/org.eclipse.uml2.uml/model/UML.genmodel#//uml/NamedElement/name"/> + + + + + + + + figureQualifiedClassName="org.eclipse.papyrus.uml.diagram.common.figure.node.RoundedCompartmentFigure"/> + @@ -5576,6 +6990,26 @@ href="../../../plugin/org.eclipse.uml2.uml/model/UML.genmodel#//uml/NamedElement/name"/> + + + + + + + + figureQualifiedClassName="org.eclipse.papyrus.uml.diagram.common.figure.node.RoundedCompartmentFigure"/> + @@ -5638,6 +7076,26 @@ href="../../../plugin/org.eclipse.uml2.uml/model/UML.genmodel#//uml/NamedElement/name"/> + + + + + + + + figureQualifiedClassName="org.eclipse.papyrus.uml.diagram.common.figure.node.RoundedCompartmentFigure"/> + @@ -5700,6 +7162,26 @@ href="../../../plugin/org.eclipse.uml2.uml/model/UML.genmodel#//uml/NamedElement/name"/> + + + + + + + + figureQualifiedClassName="org.eclipse.papyrus.uml.diagram.common.figure.node.RoundedCompartmentFigure"/> + @@ -5762,6 +7248,26 @@ href="../../../plugin/org.eclipse.uml2.uml/model/UML.genmodel#//uml/NamedElement/name"/> + + + + + + + + figureQualifiedClassName="org.eclipse.papyrus.uml.diagram.common.figure.node.RoundedCompartmentFigure"/> + @@ -5824,6 +7334,26 @@ href="../../../plugin/org.eclipse.uml2.uml/model/UML.genmodel#//uml/NamedElement/name"/> + + + + + + + + figureQualifiedClassName="org.eclipse.papyrus.uml.diagram.common.figure.node.RoundedCompartmentFigure"/> + @@ -5886,6 +7420,26 @@ href="../../../plugin/org.eclipse.uml2.uml/model/UML.genmodel#//uml/NamedElement/name"/> + + + + + + + + figureQualifiedClassName="org.eclipse.papyrus.uml.diagram.common.figure.node.RoundedCompartmentFigure"/> + @@ -5948,6 +7506,26 @@ href="../../../plugin/org.eclipse.uml2.uml/model/UML.genmodel#//uml/NamedElement/name"/> + + + + + + + + figureQualifiedClassName="org.eclipse.papyrus.uml.diagram.common.figure.node.RoundedCompartmentFigure"/> + @@ -6010,6 +7592,26 @@ href="../../../plugin/org.eclipse.uml2.uml/model/UML.genmodel#//uml/NamedElement/name"/> + + + + + + + + figureQualifiedClassName="org.eclipse.papyrus.uml.diagram.common.figure.node.RoundedCompartmentFigure"/> + @@ -6072,6 +7678,26 @@ href="../../../plugin/org.eclipse.uml2.uml/model/UML.genmodel#//uml/NamedElement/name"/> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + version="1.1.0.qualifier"> org.eclipse.draw2d org.eclipse.gmf.runtime.draw2d.ui @@ -9193,7 +10943,7 @@ extensibleViaService="true"> + uses="/0/@diagram/@topLevelNodes.0/@labels.0/@modelFacet /0/@diagram/@topLevelNodes.1/@labels.0/@modelFacet /0/@diagram/@topLevelNodes.2/@labels.0/@modelFacet /0/@diagram/@topLevelNodes.3/@labels.0/@modelFacet /0/@diagram/@topLevelNodes.4/@labels.0/@modelFacet /0/@diagram/@topLevelNodes.5/@labels.0/@modelFacet /0/@diagram/@topLevelNodes.13/@labels.0/@modelFacet /0/@diagram/@childNodes.36/@labelModelFacet /0/@diagram/@topLevelNodes.14/@labels.0/@modelFacet /0/@diagram/@topLevelNodes.15/@labels.0/@modelFacet /0/@diagram/@topLevelNodes.6/@labels.0/@modelFacet /0/@diagram/@topLevelNodes.7/@labels.0/@modelFacet /0/@diagram/@topLevelNodes.8/@labels.0/@modelFacet /0/@diagram/@topLevelNodes.9/@labels.0/@modelFacet /0/@diagram/@childNodes.1/@labels.0/@modelFacet /0/@diagram/@childNodes.3/@labels.0/@modelFacet /0/@diagram/@childNodes.5/@labels.0/@modelFacet /0/@diagram/@childNodes.6/@labels.0/@modelFacet /0/@diagram/@childNodes.7/@labels.0/@modelFacet /0/@diagram/@childNodes.8/@labels.0/@modelFacet /0/@diagram/@childNodes.9/@labels.0/@modelFacet /0/@diagram/@childNodes.10/@labels.0/@modelFacet /0/@diagram/@childNodes.11/@labels.0/@modelFacet /0/@diagram/@childNodes.19/@labels.0/@modelFacet /0/@diagram/@childNodes.20/@labels.0/@modelFacet /0/@diagram/@childNodes.21/@labels.0/@modelFacet /0/@diagram/@childNodes.12/@labels.0/@modelFacet /0/@diagram/@childNodes.13/@labels.0/@modelFacet /0/@diagram/@childNodes.14/@labels.0/@modelFacet /0/@diagram/@childNodes.15/@labels.0/@modelFacet /0/@diagram/@childNodes.17/@labels.0/@modelFacet /0/@diagram/@childNodes.22/@labels.0/@modelFacet /0/@diagram/@childNodes.23/@labels.0/@modelFacet /0/@diagram/@childNodes.24/@labels.0/@modelFacet /0/@diagram/@childNodes.25/@labels.0/@modelFacet /0/@diagram/@childNodes.26/@labels.0/@modelFacet /0/@diagram/@childNodes.27/@labels.0/@modelFacet /0/@diagram/@childNodes.18/@labels.0/@modelFacet /0/@diagram/@childNodes.16/@labels.0/@modelFacet /0/@diagram/@topLevelNodes.10/@labels.0/@modelFacet /0/@diagram/@childNodes.34/@labelModelFacet /0/@diagram/@childNodes.35/@labelModelFacet /0/@diagram/@topLevelNodes.11/@labels.0/@modelFacet /0/@diagram/@topLevelNodes.12/@labels.0/@modelFacet /0/@diagram/@topLevelNodes.16/@labels.0/@modelFacet /0/@diagram/@topLevelNodes.17/@labels.0/@modelFacet /0/@diagram/@topLevelNodes.18/@labels.0/@modelFacet /0/@diagram/@topLevelNodes.19/@labels.0/@modelFacet /0/@diagram/@topLevelNodes.20/@labels.0/@modelFacet /0/@diagram/@topLevelNodes.21/@labels.0/@modelFacet /0/@diagram/@topLevelNodes.22/@labels.0/@modelFacet /0/@diagram/@topLevelNodes.23/@labels.0/@modelFacet /0/@diagram/@topLevelNodes.24/@labels.0/@modelFacet /0/@diagram/@topLevelNodes.25/@labels.0/@modelFacet /0/@diagram/@topLevelNodes.26/@labels.0/@modelFacet /0/@diagram/@topLevelNodes.29/@labels.0/@modelFacet /0/@diagram/@topLevelNodes.30/@labels.0/@modelFacet /0/@diagram/@topLevelNodes.31/@labels.0/@modelFacet /0/@diagram/@topLevelNodes.32/@labels.0/@modelFacet /0/@diagram/@topLevelNodes.33/@labels.0/@modelFacet /0/@diagram/@topLevelNodes.34/@labels.0/@modelFacet /0/@diagram/@topLevelNodes.35/@labels.0/@modelFacet /0/@diagram/@topLevelNodes.36/@labels.0/@modelFacet /0/@diagram/@topLevelNodes.37/@labels.0/@modelFacet /0/@diagram/@topLevelNodes.38/@labels.0/@modelFacet /0/@diagram/@topLevelNodes.39/@labels.0/@modelFacet /0/@diagram/@topLevelNodes.40/@labels.0/@modelFacet /0/@diagram/@topLevelNodes.41/@labels.0/@modelFacet /0/@diagram/@topLevelNodes.42/@labels.0/@modelFacet /0/@diagram/@topLevelNodes.44/@labels.0/@modelFacet /0/@diagram/@topLevelNodes.45/@labels.0/@modelFacet /0/@diagram/@topLevelNodes.46/@labels.0/@modelFacet /0/@diagram/@topLevelNodes.47/@labels.0/@modelFacet /0/@diagram/@topLevelNodes.48/@labels.0/@modelFacet /0/@diagram/@links.4/@labels.0/@modelFacet /0/@diagram/@links.5/@labels.0/@modelFacet /0/@diagram/@links.6/@labels.0/@modelFacet /0/@diagram/@links.7/@labels.0/@modelFacet /0/@diagram/@links.8/@labels.0/@modelFacet /0/@diagram/@links.9/@labels.0/@modelFacet /0/@diagram/@links.10/@labels.0/@modelFacet /0/@diagram/@links.11/@labels.0/@modelFacet /0/@diagram/@links.13/@labels.0/@modelFacet /0/@diagram/@childNodes.4/@labels.0/@modelFacet /0/@diagram/@topLevelNodes.28/@labels.0/@modelFacet /0/@diagram/@topLevelNodes.27/@labels.0/@modelFacet /0/@diagram/@childNodes.2/@labels.0/@modelFacet /0/@diagram/@childNodes.29/@labels.0/@modelFacet /0/@diagram/@childNodes.30/@labels.0/@modelFacet /0/@diagram/@childNodes.31/@labels.0/@modelFacet /0/@diagram/@childNodes.33/@labels.0/@modelFacet /0/@diagram/@childNodes.32/@labels.0/@modelFacet /0/@diagram/@links.14/@labels.1/@modelFacet /0/@diagram/@links.14/@labels.2/@modelFacet /0/@diagram/@links.14/@labels.3/@modelFacet /0/@diagram/@childNodes.0/@labels.0/@modelFacet /0/@diagram/@childNodes.3/@labels.1/@modelFacet /0/@diagram/@childNodes.4/@labels.1/@modelFacet /0/@diagram/@childNodes.5/@labels.1/@modelFacet /0/@diagram/@childNodes.6/@labels.1/@modelFacet /0/@diagram/@childNodes.7/@labels.1/@modelFacet /0/@diagram/@childNodes.8/@labels.1/@modelFacet /0/@diagram/@childNodes.9/@labels.1/@modelFacet /0/@diagram/@childNodes.10/@labels.1/@modelFacet /0/@diagram/@childNodes.11/@labels.1/@modelFacet /0/@diagram/@childNodes.12/@labels.1/@modelFacet /0/@diagram/@childNodes.13/@labels.1/@modelFacet /0/@diagram/@childNodes.14/@labels.1/@modelFacet /0/@diagram/@childNodes.15/@labels.1/@modelFacet /0/@diagram/@childNodes.16/@labels.1/@modelFacet /0/@diagram/@childNodes.17/@labels.1/@modelFacet /0/@diagram/@childNodes.18/@labels.1/@modelFacet /0/@diagram/@childNodes.19/@labels.1/@modelFacet /0/@diagram/@childNodes.20/@labels.1/@modelFacet /0/@diagram/@childNodes.21/@labels.1/@modelFacet /0/@diagram/@childNodes.22/@labels.1/@modelFacet /0/@diagram/@childNodes.23/@labels.1/@modelFacet /0/@diagram/@childNodes.24/@labels.1/@modelFacet /0/@diagram/@childNodes.25/@labels.1/@modelFacet /0/@diagram/@childNodes.26/@labels.1/@modelFacet /0/@diagram/@childNodes.27/@labels.1/@modelFacet /0/@diagram/@topLevelNodes.0/@labels.1/@modelFacet /0/@diagram/@topLevelNodes.1/@labels.1/@modelFacet /0/@diagram/@topLevelNodes.2/@labels.1/@modelFacet /0/@diagram/@topLevelNodes.3/@labels.1/@modelFacet /0/@diagram/@topLevelNodes.4/@labels.1/@modelFacet /0/@diagram/@topLevelNodes.5/@labels.1/@modelFacet /0/@diagram/@topLevelNodes.6/@labels.1/@modelFacet /0/@diagram/@topLevelNodes.7/@labels.1/@modelFacet /0/@diagram/@topLevelNodes.8/@labels.1/@modelFacet /0/@diagram/@topLevelNodes.9/@labels.1/@modelFacet /0/@diagram/@topLevelNodes.10/@labels.1/@modelFacet /0/@diagram/@topLevelNodes.11/@labels.1/@modelFacet /0/@diagram/@topLevelNodes.12/@labels.1/@modelFacet /0/@diagram/@topLevelNodes.13/@labels.1/@modelFacet /0/@diagram/@topLevelNodes.14/@labels.1/@modelFacet /0/@diagram/@topLevelNodes.15/@labels.1/@modelFacet /0/@diagram/@topLevelNodes.16/@labels.1/@modelFacet /0/@diagram/@topLevelNodes.17/@labels.1/@modelFacet /0/@diagram/@topLevelNodes.18/@labels.1/@modelFacet /0/@diagram/@topLevelNodes.19/@labels.1/@modelFacet /0/@diagram/@topLevelNodes.20/@labels.1/@modelFacet /0/@diagram/@topLevelNodes.21/@labels.1/@modelFacet /0/@diagram/@topLevelNodes.22/@labels.1/@modelFacet /0/@diagram/@topLevelNodes.23/@labels.1/@modelFacet /0/@diagram/@topLevelNodes.24/@labels.1/@modelFacet /0/@diagram/@topLevelNodes.25/@labels.1/@modelFacet /0/@diagram/@topLevelNodes.26/@labels.1/@modelFacet /0/@diagram/@topLevelNodes.29/@labels.1/@modelFacet /0/@diagram/@topLevelNodes.30/@labels.1/@modelFacet /0/@diagram/@topLevelNodes.31/@labels.1/@modelFacet /0/@diagram/@topLevelNodes.32/@labels.1/@modelFacet /0/@diagram/@topLevelNodes.33/@labels.1/@modelFacet /0/@diagram/@topLevelNodes.34/@labels.1/@modelFacet /0/@diagram/@topLevelNodes.35/@labels.1/@modelFacet /0/@diagram/@topLevelNodes.36/@labels.1/@modelFacet /0/@diagram/@topLevelNodes.37/@labels.1/@modelFacet /0/@diagram/@topLevelNodes.38/@labels.1/@modelFacet /0/@diagram/@topLevelNodes.39/@labels.1/@modelFacet /0/@diagram/@topLevelNodes.40/@labels.1/@modelFacet /0/@diagram/@topLevelNodes.41/@labels.1/@modelFacet /0/@diagram/@topLevelNodes.42/@labels.1/@modelFacet"/> + superOwnedEditPart="org.eclipse.papyrus.uml.diagram.common.editparts.RoundedCompartmentEditPart"/> - - + superOwnedEditPart="org.eclipse.papyrus.uml.diagram.common.editparts.RoundedCompartmentEditPart"/> + genExternalNodeLabel="/0/@diagram/@topLevelNodes.27/@labels.1 /0/@diagram/@childNodes.1/@labels.1 /0/@diagram/@childNodes.2/@labels.1 /0/@diagram/@topLevelNodes.28/@labels.1"/> + + + + diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/plugin.xml b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/plugin.xml index 2f3ae9f4124..883aea53877 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/plugin.xml +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/plugin.xml @@ -15,22 +15,22 @@ --> - - - - - + + + + + - - - - + + + + @@ -57,77 +57,77 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -153,1153 +153,1153 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -1331,38 +1331,38 @@ id="org.eclipse.papyrus.uml.diagram.composite.createCompositeDiagram" name="Create a new Composite Structure Diagram"> - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + @@ -1547,475 +1547,475 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/AbstractionAppliedStereotypeEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/AbstractionAppliedStereotypeEditPart.java index fa4a0a20bce..314618e9f0e 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/AbstractionAppliedStereotypeEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/AbstractionAppliedStereotypeEditPart.java @@ -1,820 +1,815 @@ -/** - * 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.uml.diagram.composite.edit.parts; - -import java.util.Collections; -import java.util.List; - -import org.eclipse.draw2d.ConnectionLocator; -import org.eclipse.draw2d.IFigure; -import org.eclipse.draw2d.Label; -import org.eclipse.draw2d.geometry.Point; -import org.eclipse.emf.common.notify.Notification; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.transaction.RecordingCommand; -import org.eclipse.emf.transaction.RunnableWithResult; -import org.eclipse.emf.transaction.TransactionalEditingDomain; -import org.eclipse.gef.AccessibleEditPart; -import org.eclipse.gef.EditPolicy; -import org.eclipse.gef.Request; -import org.eclipse.gef.requests.DirectEditRequest; -import org.eclipse.gef.tools.DirectEditManager; -import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; -import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; -import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; -import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; -import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; -import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; -import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; -import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; -import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; -import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; -import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; -import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; -import org.eclipse.gmf.runtime.notation.FontStyle; -import org.eclipse.gmf.runtime.notation.NotationPackage; -import org.eclipse.gmf.runtime.notation.View; -import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.jface.text.contentassist.IContentAssistProcessor; -import org.eclipse.jface.viewers.ICellEditorValidator; -import org.eclipse.jface.window.Window; -import org.eclipse.papyrus.extensionpoints.editors.Activator; -import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; -import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; -import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; -import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; -import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; -import org.eclipse.papyrus.infra.gmfdiag.common.editpart.IControlParserForDirectEdit; -import org.eclipse.papyrus.infra.gmfdiag.common.editpart.PapyrusLabelEditPart; -import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; -import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; -import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.PapyrusLinkLabelDragPolicy; -import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; -import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; -import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; -import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; -import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; -import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; -import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; -import org.eclipse.swt.SWT; -import org.eclipse.swt.accessibility.AccessibleEvent; -import org.eclipse.swt.custom.BusyIndicator; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.FontData; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.widgets.Display; -import org.eclipse.ui.PlatformUI; -import org.eclipse.uml2.uml.Feature; - -/** - * @generated - */ -public class AbstractionAppliedStereotypeEditPart extends PapyrusLabelEditPart implements ITextAwareEditPart, IControlParserForDirectEdit { - - /** - * @generated - */ - public static final int VISUAL_ID = 6020; - - /** - * @generated - */ - private DirectEditManager manager; - - /** - * @generated - */ - private IParser parser; - - /** - * @generated - */ - private List parserElements; - - /** - * @generated - */ - private String defaultText; - - /** - * direct edition mode (default, undefined, registered editor, etc.) - * - * @generated - */ - protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; - - /** - * configuration from a registered edit dialog - * - * @generated - */ - protected IDirectEditorConfiguration configuration; - /** - * @generated - */ - static { - registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.AbstractionAppliedStereotypeEditPart.VISUAL_ID), new Point(0, 30)); - } - - /** - * @generated - */ - public AbstractionAppliedStereotypeEditPart(View view) { - super(view); - } - - /** - * @generated - */ - @Override - protected void createDefaultEditPolicies() { - super.createDefaultEditPolicies(); - installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); - installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); - installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new PapyrusLinkLabelDragPolicy()); - } - - /** - * @generated - */ - @Override - public int getKeyPoint() { - return ConnectionLocator.MIDDLE; - } - - /** - * @generated - */ - protected String getLabelTextHelper(IFigure figure) { - if (figure instanceof WrappingLabel) { - return ((WrappingLabel) figure).getText(); - } else if (figure instanceof ILabelFigure) { - return ((ILabelFigure) figure).getText(); - } else { - return ((Label) figure).getText(); - } - } - - /** - * @generated - */ - protected void setLabelTextHelper(IFigure figure, String text) { - if (figure instanceof WrappingLabel) { - ((WrappingLabel) figure).setText(text); - } else if (figure instanceof ILabelFigure) { - ((ILabelFigure) figure).setText(text); - } else { - ((Label) figure).setText(text); - } - } - - /** - * @generated - */ - protected Image getLabelIconHelper(IFigure figure) { - if (figure instanceof WrappingLabel) { - return ((WrappingLabel) figure).getIcon(); - } else if (figure instanceof ILabelFigure) { - return ((ILabelFigure) figure).getIcon(); - } else { - return ((Label) figure).getIcon(); - } - } - - /** - * @generated - */ - protected void setLabelIconHelper(IFigure figure, Image icon) { - if (figure instanceof WrappingLabel) { - ((WrappingLabel) figure).setIcon(icon); - } else if (figure instanceof ILabelFigure) { - ((ILabelFigure) figure).setIcon(icon); - } else { - ((Label) figure).setIcon(icon); - } - } - - /** - * @generated - */ - public void setLabel(IFigure - figure) { - unregisterVisuals(); - setFigure(figure); - defaultText = getLabelTextHelper(figure); - registerVisuals(); - refreshVisuals(); - } - - /** - * @generated - */ - @Override - protected List getModelChildren() { - return Collections.EMPTY_LIST; - } - - /** - * @generated - */ - @Override - public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { - return null; - } - - /** - * @generated - */ - @Override - public void setParser(IParser parser) { - this.parser = parser; - } - - /** - * @generated - */ - protected EObject getParserElement() { - return resolveSemanticElement(); - } - - /** - * @generated - */ - protected Image getLabelIcon() { - return null; - } - - /** - * @generated - */ - protected String getLabelText() { - String text = null; - EObject parserElement = getParserElement(); - if (parserElement != null && getParser() != null) { - text = getParser().getPrintString( - new EObjectAdapter(parserElement), - getParserOptions().intValue()); - } - if (text == null || text.length() == 0) { - text = defaultText; - } - return text; - } - - /** - * @generated - */ - @Override - public void setLabelText(String text) { - setLabelTextHelper(getFigure(), text); - Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); - if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); - } - Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); - if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); - } - } - - /** - * @generated - */ - @Override - public String getEditText() { - if (getParserElement() == null || getParser() == null) { - return ""; //$NON-NLS-1$ - } - return getParser().getEditString( - new EObjectAdapter(getParserElement()), - getParserOptions().intValue()); - } - - /** - * @generated - */ - protected boolean isEditable() { - return false; - } - - /** - * @generated - */ - @Override - public ICellEditorValidator getEditTextValidator() { - return new ICellEditorValidator() { - - @Override - public String isValid(final Object value) { - if (value instanceof String) { - final EObject element = getParserElement(); - final IParser parser = getParser(); - try { - IParserEditStatus valid = - (IParserEditStatus) getEditingDomain().runExclusive( - new RunnableWithResult.Impl() { - - @Override - public void run() { - setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); - } - }); - return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); - } catch (InterruptedException ie) { - ie.printStackTrace(); - } - } - - // shouldn't get here - return null; - } - }; - } - - /** - * @generated - */ - @Override - public IContentAssistProcessor getCompletionProcessor() { - if (getParserElement() == null || getParser() == null) { - return null; - } - return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); - } - - /** - * @generated - */ - @Override - public ParserOptions getParserOptions() { - return ParserOptions.NONE; - } - - /** - * @generated - */ - @Override - public IParser getParser() { - if (parser == null) { - parser = UMLParserProvider.getParser(UMLElementTypes.Abstraction_4007, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.AbstractionAppliedStereotypeEditPart.VISUAL_ID)); - } - return parser; - } - - /** - * @generated - */ - protected DirectEditManager getManager() { - if (manager == null) { - setManager(new MultilineLabelDirectEditManager(this, - MultilineLabelDirectEditManager.getTextCellEditorClass(this), - UMLEditPartFactory.getTextCellEditorLocator(this))); - } - return manager; - } - - /** - * @generated - */ - protected void setManager(DirectEditManager manager) { - this.manager = manager; - } - - /** - * @generated - */ - protected void performDirectEdit() { - BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { - - @Override - public void run() { - getManager().show(); - } - }); - } - - /** - * @generated - */ - protected void performDirectEdit(Point eventLocation) { - if (getManager() instanceof TextDirectEditManager) { - ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); - } - } - - /** - * @generated - */ - private void performDirectEdit(char initialCharacter) { - if (getManager() instanceof TextDirectEditManager) { - ((TextDirectEditManager) getManager()).show(initialCharacter); - } else { - performDirectEdit(); - } - } - - /** - * @generated - */ - @Override - protected void performDirectEditRequest(Request request) { - - final Request theRequest = request; - - if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { - directEditionMode = getDirectEditionType(); - } - switch (directEditionMode) { - case IDirectEdition.NO_DIRECT_EDITION: - // no direct edition mode => does nothing - return; - case IDirectEdition.EXTENDED_DIRECT_EDITOR: - updateExtendedEditorConfiguration(); - if (configuration == null || configuration.getLanguage() == null) { - // Create default edit manager - setManager(new MultilineLabelDirectEditManager(this, - MultilineLabelDirectEditManager.getTextCellEditorClass(this), - UMLEditPartFactory.getTextCellEditorLocator(this))); - performDefaultDirectEditorEdit(theRequest); - } else { - configuration.preEditAction(resolveSemanticElement()); - Dialog dialog = null; - if (configuration instanceof ICustomDirectEditorConfiguration) { - setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); - initializeDirectEditManager(theRequest); - return; - } else if (configuration instanceof IPopupEditorConfiguration) { - IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); - helper.showEditor(); - return; - } - else if (configuration instanceof IAdvancedEditorConfiguration) { - dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); - } else if (configuration instanceof IDirectEditorConfiguration) { - dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), - configuration); - } else { - return; - } - final Dialog finalDialog = dialog; - - if (Window.OK == dialog.open()) { - TransactionalEditingDomain domain = getEditingDomain(); - RecordingCommand command = new RecordingCommand(domain, "Edit Label") { - - @Override - protected void doExecute() { - configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); - - } - }; - domain.getCommandStack().execute(command); - } - } - break; - case IDirectEdition.DEFAULT_DIRECT_EDITOR: - initializeDirectEditManager(theRequest); - break; - default: - break; - } - } - - /** - * @generated - */ - protected void initializeDirectEditManager(final Request request) { - // initialize the direct edit manager - try { - getEditingDomain().runExclusive(new Runnable() { - @Override - public void run() { - if (isActive() && isEditable()) { - if (request.getExtendedData().get( - RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { - Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); - performDirectEdit(initialChar.charValue()); - } - else { - performDirectEdit(); - } - } - } - }); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - - /** - * @generated - */ - @Override - protected void refreshVisuals() { - super.refreshVisuals(); - refreshLabel(); - refreshFont(); - refreshFontColor(); - refreshUnderline(); - refreshStrikeThrough(); - } - - /** - * @generated - */ - protected void refreshLabel() { - EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); - if (maskLabelPolicy == null) { - maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); - } - if (maskLabelPolicy == null) { - View view = (View) getModel(); - if (view.isVisible()) { - setLabelTextHelper(getFigure(), getLabelText()); - setLabelIconHelper(getFigure(), getLabelIcon()); - } - else { - setLabelTextHelper(getFigure(), ""); //$NON-NLS-1$ - setLabelIconHelper(getFigure(), null); - } - } - Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); - if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); - } - Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); - if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); - } - } - - /** - * @generated - */ - protected void refreshUnderline() { - FontStyle style = - (FontStyle) getFontStyleOwnerView().getStyle( - NotationPackage.eINSTANCE.getFontStyle()); - if (style != null && getFigure() instanceof WrappingLabel) { - ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); - } - if (resolveSemanticElement() instanceof Feature) { - if (((Feature) resolveSemanticElement()).isStatic()) { - ((WrappingLabel) getFigure()).setTextUnderline(true); - } - else { - ((WrappingLabel) getFigure()).setTextUnderline(false); - } - } - } - - /** - * @generated - */ - protected void refreshStrikeThrough() { - FontStyle style = - (FontStyle) getFontStyleOwnerView().getStyle( - NotationPackage.eINSTANCE.getFontStyle()); - if (style != null && getFigure() instanceof WrappingLabel) { - ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); - } - } - - /** - * @generated - */ - @Override - protected void refreshFont() { - FontStyle style = - (FontStyle) getFontStyleOwnerView().getStyle( - NotationPackage.eINSTANCE.getFontStyle()); - if (style != null) { - FontData fontData = new FontData( - style.getFontName(), style.getFontHeight(), - (style.isBold() ? SWT.BOLD : SWT.NORMAL) | - (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); - setFont(fontData); - } - } - - /** - * @generated - */ - @Override - protected void setFontColor(Color color) { - getFigure().setForegroundColor(color); - } - - /** - * @generated - */ - @Override - protected void addSemanticListeners() { - if (getParser() instanceof ISemanticParser) { - EObject element = resolveSemanticElement(); - parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); - for (int i = 0; i < parserElements.size(); i++) { - addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ - } - } else { - super.addSemanticListeners(); - } - } - - /** - * @generated - */ - @Override - protected void removeSemanticListeners() { - if (parserElements != null) { - for (int i = 0; i < parserElements.size(); i++) { - removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ - } - } else { - super.removeSemanticListeners(); - } - } - - /** - * @generated - */ - @Override - protected AccessibleEditPart getAccessibleEditPart() { - if (accessibleEP == null) { - accessibleEP = new AccessibleGraphicalEditPart() { - - @Override - public void getName(AccessibleEvent e) { - e.result = getLabelTextHelper(getFigure()); - } - }; - } - return accessibleEP; - } - - /** - * @generated - */ - private View getFontStyleOwnerView() { - return getPrimaryView(); - } - - /** - * Returns the kind of associated editor for direct edition. - * - * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition - * @generated - */ - public int getDirectEditionType() { - // The label is read-only (defined in GMFGen model) - return IDirectEdition.NO_DIRECT_EDITION; - } - - /** - * Checks if an extended editor is present. - * - * @return true if an extended editor is present. - * @generated - */ - protected boolean checkExtendedEditor() { - if (resolveSemanticElement() != null) { - return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); - } - return false; - } - - /** - * Checks if a default direct edition is available - * - * @return true if a default direct edition is available - * @generated - */ - protected boolean checkDefaultEdition() { - return (getParser() != null); - } - - /** - * Initializes the extended editor configuration - * - * @generated - */ - protected void initExtendedEditorConfiguration() { - if (configuration == null) { - final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); - if (languagePreferred != null && !languagePreferred.equals("")) { - configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); - } else { - configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); - } - } - } - - /** - * Updates the preference configuration - * - * @generated - */ - protected void updateExtendedEditorConfiguration() { - String languagePreferred = Activator.getDefault().getPreferenceStore().getString( - IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); - if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { - configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() - .eClass().getInstanceClassName()); - } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { - configuration = null; - } - } - - /** - * Performs the direct edit usually used by GMF editors. - * - * @param theRequest - * the direct edit request that starts the direct edit system - * @generated - */ - protected void performDefaultDirectEditorEdit(final Request theRequest) { - // initialize the direct edit manager - try { - getEditingDomain().runExclusive(new Runnable() { - - @Override - public void run() { - if (isActive() && isEditable()) { - if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { - Character initialChar = (Character) theRequest.getExtendedData().get( - RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); - performDirectEdit(initialChar.charValue()); - } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { - DirectEditRequest editRequest = (DirectEditRequest) theRequest; - performDirectEdit(editRequest.getLocation()); - } else { - performDirectEdit(); - } - } - } - }); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - - /** - * @generated - */ - @Override - protected void handleNotificationEvent(Notification event) { - Object feature = event.getFeature(); - if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { - Integer c = (Integer) event.getNewValue(); - setFontColor(DiagramColorRegistry.getInstance().getColor(c)); - } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { - refreshUnderline(); - } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { - refreshStrikeThrough(); - } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || - NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || - NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || - NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { - refreshFont(); - } else { - if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { - refreshLabel(); - } - if (getParser() instanceof ISemanticParser) { - ISemanticParser modelParser = - (ISemanticParser) getParser(); - if (modelParser.areSemanticElementsAffected(null, event)) { - removeSemanticListeners(); - if (resolveSemanticElement() != null) { - addSemanticListeners(); - } - refreshLabel(); - } - } - } - - super.handleNotificationEvent(event); - } - - /** - * @generated - */ - @Override - protected IFigure createFigure() { - // Parent should assign one using setLabel() method - return 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.uml.diagram.composite.edit.parts; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.draw2d.ConnectionLocator; +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.Label; +import org.eclipse.draw2d.geometry.Point; +import org.eclipse.emf.common.notify.Notification; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.RunnableWithResult; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gef.AccessibleEditPart; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.Request; +import org.eclipse.gef.requests.DirectEditRequest; +import org.eclipse.gef.tools.DirectEditManager; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; +import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; +import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; +import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; +import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; +import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; +import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; +import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; +import org.eclipse.gmf.runtime.notation.FontStyle; +import org.eclipse.gmf.runtime.notation.NotationPackage; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.gmf.tooling.runtime.edit.policies.DefaultLinkLabelDragPolicy; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.text.contentassist.IContentAssistProcessor; +import org.eclipse.jface.viewers.ICellEditorValidator; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.extensionpoints.editors.Activator; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; +import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; +import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; +import org.eclipse.papyrus.infra.gmfdiag.common.editpart.IControlParserForDirectEdit; +import org.eclipse.papyrus.infra.gmfdiag.common.editpart.PapyrusLabelEditPart; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.PapyrusLinkLabelDragPolicy; +import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; +import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; +import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; +import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; +import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.accessibility.AccessibleEvent; +import org.eclipse.swt.custom.BusyIndicator; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; +import org.eclipse.uml2.uml.Feature; + +/** + * @generated + */ +public class AbstractionAppliedStereotypeEditPart extends PapyrusLabelEditPart implements ITextAwareEditPart, IControlParserForDirectEdit { + + /** + * @generated + */ + public static final int VISUAL_ID = 6020; + + /** + * @generated + */ + private DirectEditManager manager; + + /** + * @generated + */ + private IParser parser; + + /** + * @generated + */ + private List parserElements; + + /** + * @generated + */ + private String defaultText; + + /** + * direct edition mode (default, undefined, registered editor, etc.) + * + * @generated + */ + protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; + + /** + * configuration from a registered edit dialog + * + * @generated + */ + protected IDirectEditorConfiguration configuration; + /** + * @generated + */ + static { + registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.AbstractionAppliedStereotypeEditPart.VISUAL_ID), new Point(0, 30)); + } + + /** + * @generated + */ + public AbstractionAppliedStereotypeEditPart(View view) { + super(view); + } + + /** + * @generated + */ + @Override + protected void createDefaultEditPolicies() { + super.createDefaultEditPolicies(); + installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); + installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new DefaultLinkLabelDragPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new PapyrusLinkLabelDragPolicy()); + } + + /** + * @generated + */ + @Override + public int getKeyPoint() { + return ConnectionLocator.MIDDLE; + } + + /** + * @generated + */ + protected String getLabelTextHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getText(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getText(); + } else { + return ((Label) figure).getText(); + } + } + + /** + * @generated + */ + protected void setLabelTextHelper(IFigure figure, String text) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setText(text); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setText(text); + } else { + ((Label) figure).setText(text); + } + } + + /** + * @generated + */ + protected Image getLabelIconHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getIcon(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getIcon(); + } else { + return ((Label) figure).getIcon(); + } + } + + /** + * @generated + */ + protected void setLabelIconHelper(IFigure figure, Image icon) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setIcon(icon); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setIcon(icon); + } else { + ((Label) figure).setIcon(icon); + } + } + + /** + * @generated + */ + public void setLabel(IFigure + figure) { + unregisterVisuals(); + setFigure(figure); + defaultText = getLabelTextHelper(figure); + registerVisuals(); + refreshVisuals(); + } + + /** + * @generated + */ + @Override + protected List getModelChildren() { + return Collections.EMPTY_LIST; + } + + /** + * @generated + */ + @Override + public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { + return null; + } + + /** + * @generated + */ + @Override + public void setParser(IParser parser) { + this.parser = parser; + } + + /** + * @generated + */ + protected EObject getParserElement() { + return resolveSemanticElement(); + } + + /** + * @generated + */ + protected Image getLabelIcon() { + return null; + } + + /** + * @generated + */ + protected String getLabelText() { + String text = null; + EObject parserElement = getParserElement(); + if (parserElement != null && getParser() != null) { + text = getParser().getPrintString( + new EObjectAdapter(parserElement), + getParserOptions().intValue()); + } + if (text == null || text.length() == 0) { + text = defaultText; + } + return text; + } + + /** + * @generated + */ + @Override + public void setLabelText(String text) { + setLabelTextHelper(getFigure(), text); + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + @Override + public String getEditText() { + if (getParserElement() == null || getParser() == null) { + return ""; //$NON-NLS-1$ + } + return getParser().getEditString( + new EObjectAdapter(getParserElement()), + getParserOptions().intValue()); + } + + /** + * @generated + */ + protected boolean isEditable() { + return false; + } + + /** + * @generated + */ + @Override + public ICellEditorValidator getEditTextValidator() { + return new ICellEditorValidator() { + + @Override + public String isValid(final Object value) { + if (value instanceof String) { + final EObject element = getParserElement(); + final IParser parser = getParser(); + try { + IParserEditStatus valid = + (IParserEditStatus) getEditingDomain().runExclusive( + new RunnableWithResult.Impl() { + + @Override + public void run() { + setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); + } + }); + return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); + } catch (InterruptedException ie) { + ie.printStackTrace(); + } + } + + // shouldn't get here + return null; + } + }; + } + + /** + * @generated + */ + @Override + public IContentAssistProcessor getCompletionProcessor() { + if (getParserElement() == null || getParser() == null) { + return null; + } + return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); + } + + /** + * @generated + */ + @Override + public ParserOptions getParserOptions() { + return ParserOptions.NONE; + } + + /** + * @generated + */ + @Override + public IParser getParser() { + if (parser == null) { + parser = UMLParserProvider.getParser(UMLElementTypes.Abstraction_4007, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.AbstractionAppliedStereotypeEditPart.VISUAL_ID)); + } + return parser; + } + + /** + * @generated + */ + protected DirectEditManager getManager() { + if (manager == null) { + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + } + return manager; + } + + /** + * @generated + */ + protected void setManager(DirectEditManager manager) { + this.manager = manager; + } + + /** + * @generated + */ + protected void performDirectEdit() { + BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { + + @Override + public void run() { + getManager().show(); + } + }); + } + + /** + * @generated + */ + protected void performDirectEdit(Point eventLocation) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); + } + } + + /** + * @generated + */ + private void performDirectEdit(char initialCharacter) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(initialCharacter); + } else { + performDirectEdit(); + } + } + + /** + * @generated + */ + @Override + protected void performDirectEditRequest(Request request) { + + final Request theRequest = request; + + if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { + directEditionMode = getDirectEditionType(); + } + switch (directEditionMode) { + case IDirectEdition.NO_DIRECT_EDITION: + // no direct edition mode => does nothing + return; + case IDirectEdition.EXTENDED_DIRECT_EDITOR: + updateExtendedEditorConfiguration(); + if (configuration == null || configuration.getLanguage() == null) { + // Create default edit manager + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + performDefaultDirectEditorEdit(theRequest); + } else { + configuration.preEditAction(resolveSemanticElement()); + Dialog dialog = null; + if (configuration instanceof ICustomDirectEditorConfiguration) { + setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); + initializeDirectEditManager(theRequest); + return; + } else if (configuration instanceof IPopupEditorConfiguration) { + IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); + helper.showEditor(); + return; + } + else if (configuration instanceof IAdvancedEditorConfiguration) { + dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); + } else if (configuration instanceof IDirectEditorConfiguration) { + dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), + configuration); + } else { + return; + } + final Dialog finalDialog = dialog; + + if (Window.OK == dialog.open()) { + TransactionalEditingDomain domain = getEditingDomain(); + RecordingCommand command = new RecordingCommand(domain, "Edit Label") { + + @Override + protected void doExecute() { + configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); + + } + }; + domain.getCommandStack().execute(command); + } + } + break; + case IDirectEdition.DEFAULT_DIRECT_EDITOR: + initializeDirectEditManager(theRequest); + break; + default: + break; + } + } + + /** + * @generated + */ + protected void initializeDirectEditManager(final Request request) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + @Override + public void run() { + if (isActive() && isEditable()) { + if (request.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } + else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void refreshVisuals() { + super.refreshVisuals(); + refreshLabel(); + refreshFont(); + refreshFontColor(); + refreshUnderline(); + refreshStrikeThrough(); + } + + /** + * @generated + */ + protected void refreshLabel() { + EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); + if (maskLabelPolicy == null) { + maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); + } + if (maskLabelPolicy == null) { + setLabelTextHelper(getFigure(), getLabelText()); + setLabelIconHelper(getFigure(), getLabelIcon()); + } + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + protected void refreshUnderline() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); + } + if (resolveSemanticElement() instanceof Feature) { + if (((Feature) resolveSemanticElement()).isStatic()) { + ((WrappingLabel) getFigure()).setTextUnderline(true); + } + else { + ((WrappingLabel) getFigure()).setTextUnderline(false); + } + } + } + + /** + * @generated + */ + protected void refreshStrikeThrough() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); + } + } + + /** + * @generated + */ + @Override + protected void refreshFont() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null) { + FontData fontData = new FontData( + style.getFontName(), style.getFontHeight(), + (style.isBold() ? SWT.BOLD : SWT.NORMAL) | + (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); + setFont(fontData); + } + } + + /** + * @generated + */ + @Override + protected void setFontColor(Color color) { + getFigure().setForegroundColor(color); + } + + /** + * @generated + */ + @Override + protected void addSemanticListeners() { + if (getParser() instanceof ISemanticParser) { + EObject element = resolveSemanticElement(); + parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); + for (int i = 0; i < parserElements.size(); i++) { + addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ + } + } else { + super.addSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected void removeSemanticListeners() { + if (parserElements != null) { + for (int i = 0; i < parserElements.size(); i++) { + removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ + } + } else { + super.removeSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected AccessibleEditPart getAccessibleEditPart() { + if (accessibleEP == null) { + accessibleEP = new AccessibleGraphicalEditPart() { + + @Override + public void getName(AccessibleEvent e) { + e.result = getLabelTextHelper(getFigure()); + } + }; + } + return accessibleEP; + } + + /** + * @generated + */ + private View getFontStyleOwnerView() { + return getPrimaryView(); + } + + /** + * Returns the kind of associated editor for direct edition. + * + * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition + * @generated + */ + public int getDirectEditionType() { + // The label is read-only (defined in GMFGen model) + return IDirectEdition.NO_DIRECT_EDITION; + } + + /** + * Checks if an extended editor is present. + * + * @return true if an extended editor is present. + * @generated + */ + protected boolean checkExtendedEditor() { + if (resolveSemanticElement() != null) { + return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); + } + return false; + } + + /** + * Checks if a default direct edition is available + * + * @return true if a default direct edition is available + * @generated + */ + protected boolean checkDefaultEdition() { + return (getParser() != null); + } + + /** + * Initializes the extended editor configuration + * + * @generated + */ + protected void initExtendedEditorConfiguration() { + if (configuration == null) { + final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("")) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); + } else { + configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); + } + } + } + + /** + * Updates the preference configuration + * + * @generated + */ + protected void updateExtendedEditorConfiguration() { + String languagePreferred = Activator.getDefault().getPreferenceStore().getString( + IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() + .eClass().getInstanceClassName()); + } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { + configuration = null; + } + } + + /** + * Performs the direct edit usually used by GMF editors. + * + * @param theRequest + * the direct edit request that starts the direct edit system + * @generated + */ + protected void performDefaultDirectEditorEdit(final Request theRequest) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + + @Override + public void run() { + if (isActive() && isEditable()) { + if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) theRequest.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { + DirectEditRequest editRequest = (DirectEditRequest) theRequest; + performDirectEdit(editRequest.getLocation()); + } else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void handleNotificationEvent(Notification event) { + Object feature = event.getFeature(); + if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { + Integer c = (Integer) event.getNewValue(); + setFontColor(DiagramColorRegistry.getInstance().getColor(c)); + } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { + refreshUnderline(); + } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { + refreshStrikeThrough(); + } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { + refreshFont(); + } else { + if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { + refreshLabel(); + } + if (getParser() instanceof ISemanticParser) { + ISemanticParser modelParser = + (ISemanticParser) getParser(); + if (modelParser.areSemanticElementsAffected(null, event)) { + removeSemanticListeners(); + if (resolveSemanticElement() != null) { + addSemanticListeners(); + } + refreshLabel(); + } + } + } + + super.handleNotificationEvent(event); + } + + /** + * @generated + */ + @Override + protected IFigure createFigure() { + // Parent should assign one using setLabel() method + return null; + } +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/AbstractionNameEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/AbstractionNameEditPart.java index 60669d536e4..ea2e4760660 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/AbstractionNameEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/AbstractionNameEditPart.java @@ -1,828 +1,823 @@ -/** - * 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.uml.diagram.composite.edit.parts; - -import java.util.Collections; -import java.util.List; - -import org.eclipse.draw2d.ConnectionLocator; -import org.eclipse.draw2d.IFigure; -import org.eclipse.draw2d.Label; -import org.eclipse.draw2d.geometry.Point; -import org.eclipse.emf.common.notify.Notification; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.transaction.RecordingCommand; -import org.eclipse.emf.transaction.RunnableWithResult; -import org.eclipse.emf.transaction.TransactionalEditingDomain; -import org.eclipse.gef.AccessibleEditPart; -import org.eclipse.gef.EditPolicy; -import org.eclipse.gef.Request; -import org.eclipse.gef.requests.DirectEditRequest; -import org.eclipse.gef.tools.DirectEditManager; -import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; -import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; -import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; -import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; -import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; -import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; -import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; -import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; -import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; -import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; -import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; -import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; -import org.eclipse.gmf.runtime.notation.FontStyle; -import org.eclipse.gmf.runtime.notation.NotationPackage; -import org.eclipse.gmf.runtime.notation.View; -import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.jface.text.contentassist.IContentAssistProcessor; -import org.eclipse.jface.viewers.ICellEditorValidator; -import org.eclipse.jface.window.Window; -import org.eclipse.papyrus.extensionpoints.editors.Activator; -import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; -import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; -import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; -import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; -import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; -import org.eclipse.papyrus.infra.gmfdiag.common.editpart.IControlParserForDirectEdit; -import org.eclipse.papyrus.infra.gmfdiag.common.editpart.PapyrusLabelEditPart; -import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; -import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; -import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.PapyrusLinkLabelDragPolicy; -import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; -import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; -import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; -import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; -import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; -import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; -import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; -import org.eclipse.swt.SWT; -import org.eclipse.swt.accessibility.AccessibleEvent; -import org.eclipse.swt.custom.BusyIndicator; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.FontData; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.widgets.Display; -import org.eclipse.ui.PlatformUI; -import org.eclipse.uml2.uml.Feature; - -/** - * @generated - */ -public class AbstractionNameEditPart extends PapyrusLabelEditPart implements ITextAwareEditPart, IControlParserForDirectEdit { - - /** - * @generated - */ - public static final int VISUAL_ID = 6006; - - /** - * @generated - */ - private DirectEditManager manager; - - /** - * @generated - */ - private IParser parser; - - /** - * @generated - */ - private List parserElements; - - /** - * @generated - */ - private String defaultText; - - /** - * direct edition mode (default, undefined, registered editor, etc.) - * - * @generated - */ - protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; - - /** - * configuration from a registered edit dialog - * - * @generated - */ - protected IDirectEditorConfiguration configuration; - /** - * @generated - */ - static { - registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.AbstractionNameEditPart.VISUAL_ID), new Point(0, 60)); - } - - /** - * @generated - */ - public AbstractionNameEditPart(View view) { - super(view); - } - - /** - * @generated - */ - @Override - protected void createDefaultEditPolicies() { - super.createDefaultEditPolicies(); - installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); - installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); - installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new PapyrusLinkLabelDragPolicy()); - } - - /** - * @generated - */ - @Override - public int getKeyPoint() { - return ConnectionLocator.MIDDLE; - } - - /** - * @generated - */ - protected String getLabelTextHelper(IFigure figure) { - if (figure instanceof WrappingLabel) { - return ((WrappingLabel) figure).getText(); - } else if (figure instanceof ILabelFigure) { - return ((ILabelFigure) figure).getText(); - } else { - return ((Label) figure).getText(); - } - } - - /** - * @generated - */ - protected void setLabelTextHelper(IFigure figure, String text) { - if (figure instanceof WrappingLabel) { - ((WrappingLabel) figure).setText(text); - } else if (figure instanceof ILabelFigure) { - ((ILabelFigure) figure).setText(text); - } else { - ((Label) figure).setText(text); - } - } - - /** - * @generated - */ - protected Image getLabelIconHelper(IFigure figure) { - if (figure instanceof WrappingLabel) { - return ((WrappingLabel) figure).getIcon(); - } else if (figure instanceof ILabelFigure) { - return ((ILabelFigure) figure).getIcon(); - } else { - return ((Label) figure).getIcon(); - } - } - - /** - * @generated - */ - protected void setLabelIconHelper(IFigure figure, Image icon) { - if (figure instanceof WrappingLabel) { - ((WrappingLabel) figure).setIcon(icon); - } else if (figure instanceof ILabelFigure) { - ((ILabelFigure) figure).setIcon(icon); - } else { - ((Label) figure).setIcon(icon); - } - } - - /** - * @generated - */ - public void setLabel(IFigure - figure) { - unregisterVisuals(); - setFigure(figure); - defaultText = getLabelTextHelper(figure); - registerVisuals(); - refreshVisuals(); - } - - /** - * @generated - */ - @Override - protected List getModelChildren() { - return Collections.EMPTY_LIST; - } - - /** - * @generated - */ - @Override - public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { - return null; - } - - /** - * @generated - */ - @Override - public void setParser(IParser parser) { - this.parser = parser; - } - - /** - * @generated - */ - protected EObject getParserElement() { - return resolveSemanticElement(); - } - - /** - * @generated - */ - protected Image getLabelIcon() { - return null; - } - - /** - * @generated - */ - protected String getLabelText() { - String text = null; - EObject parserElement = getParserElement(); - if (parserElement != null && getParser() != null) { - text = getParser().getPrintString( - new EObjectAdapter(parserElement), - getParserOptions().intValue()); - } - if (text == null || text.length() == 0) { - text = defaultText; - } - return text; - } - - /** - * @generated - */ - @Override - public void setLabelText(String text) { - setLabelTextHelper(getFigure(), text); - Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); - if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); - } - Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); - if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); - } - } - - /** - * @generated - */ - @Override - public String getEditText() { - if (getParserElement() == null || getParser() == null) { - return ""; //$NON-NLS-1$ - } - return getParser().getEditString( - new EObjectAdapter(getParserElement()), - getParserOptions().intValue()); - } - - /** - * @generated - */ - protected boolean isEditable() { - return getParser() != null; - } - - /** - * @generated - */ - @Override - public ICellEditorValidator getEditTextValidator() { - return new ICellEditorValidator() { - - @Override - public String isValid(final Object value) { - if (value instanceof String) { - final EObject element = getParserElement(); - final IParser parser = getParser(); - try { - IParserEditStatus valid = - (IParserEditStatus) getEditingDomain().runExclusive( - new RunnableWithResult.Impl() { - - @Override - public void run() { - setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); - } - }); - return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); - } catch (InterruptedException ie) { - ie.printStackTrace(); - } - } - - // shouldn't get here - return null; - } - }; - } - - /** - * @generated - */ - @Override - public IContentAssistProcessor getCompletionProcessor() { - if (getParserElement() == null || getParser() == null) { - return null; - } - return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); - } - - /** - * @generated - */ - @Override - public ParserOptions getParserOptions() { - return ParserOptions.NONE; - } - - /** - * @generated - */ - @Override - public IParser getParser() { - if (parser == null) { - parser = UMLParserProvider.getParser(UMLElementTypes.Abstraction_4007, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.AbstractionNameEditPart.VISUAL_ID)); - } - return parser; - } - - /** - * @generated - */ - protected DirectEditManager getManager() { - if (manager == null) { - setManager(new MultilineLabelDirectEditManager(this, - MultilineLabelDirectEditManager.getTextCellEditorClass(this), - UMLEditPartFactory.getTextCellEditorLocator(this))); - } - return manager; - } - - /** - * @generated - */ - protected void setManager(DirectEditManager manager) { - this.manager = manager; - } - - /** - * @generated - */ - protected void performDirectEdit() { - BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { - - @Override - public void run() { - getManager().show(); - } - }); - } - - /** - * @generated - */ - protected void performDirectEdit(Point eventLocation) { - if (getManager() instanceof TextDirectEditManager) { - ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); - } - } - - /** - * @generated - */ - private void performDirectEdit(char initialCharacter) { - if (getManager() instanceof TextDirectEditManager) { - ((TextDirectEditManager) getManager()).show(initialCharacter); - } else { - performDirectEdit(); - } - } - - /** - * @generated - */ - @Override - protected void performDirectEditRequest(Request request) { - - final Request theRequest = request; - - if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { - directEditionMode = getDirectEditionType(); - } - switch (directEditionMode) { - case IDirectEdition.NO_DIRECT_EDITION: - // no direct edition mode => does nothing - return; - case IDirectEdition.EXTENDED_DIRECT_EDITOR: - updateExtendedEditorConfiguration(); - if (configuration == null || configuration.getLanguage() == null) { - // Create default edit manager - setManager(new MultilineLabelDirectEditManager(this, - MultilineLabelDirectEditManager.getTextCellEditorClass(this), - UMLEditPartFactory.getTextCellEditorLocator(this))); - performDefaultDirectEditorEdit(theRequest); - } else { - configuration.preEditAction(resolveSemanticElement()); - Dialog dialog = null; - if (configuration instanceof ICustomDirectEditorConfiguration) { - setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); - initializeDirectEditManager(theRequest); - return; - } else if (configuration instanceof IPopupEditorConfiguration) { - IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); - helper.showEditor(); - return; - } - else if (configuration instanceof IAdvancedEditorConfiguration) { - dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); - } else if (configuration instanceof IDirectEditorConfiguration) { - dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), - configuration); - } else { - return; - } - final Dialog finalDialog = dialog; - - if (Window.OK == dialog.open()) { - TransactionalEditingDomain domain = getEditingDomain(); - RecordingCommand command = new RecordingCommand(domain, "Edit Label") { - - @Override - protected void doExecute() { - configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); - - } - }; - domain.getCommandStack().execute(command); - } - } - break; - case IDirectEdition.DEFAULT_DIRECT_EDITOR: - initializeDirectEditManager(theRequest); - break; - default: - break; - } - } - - /** - * @generated - */ - protected void initializeDirectEditManager(final Request request) { - // initialize the direct edit manager - try { - getEditingDomain().runExclusive(new Runnable() { - @Override - public void run() { - if (isActive() && isEditable()) { - if (request.getExtendedData().get( - RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { - Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); - performDirectEdit(initialChar.charValue()); - } - else { - performDirectEdit(); - } - } - } - }); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - - /** - * @generated - */ - @Override - protected void refreshVisuals() { - super.refreshVisuals(); - refreshLabel(); - refreshFont(); - refreshFontColor(); - refreshUnderline(); - refreshStrikeThrough(); - } - - /** - * @generated - */ - protected void refreshLabel() { - EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); - if (maskLabelPolicy == null) { - maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); - } - if (maskLabelPolicy == null) { - View view = (View) getModel(); - if (view.isVisible()) { - setLabelTextHelper(getFigure(), getLabelText()); - setLabelIconHelper(getFigure(), getLabelIcon()); - } - else { - setLabelTextHelper(getFigure(), ""); //$NON-NLS-1$ - setLabelIconHelper(getFigure(), null); - } - } - Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); - if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); - } - Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); - if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); - } - } - - /** - * @generated - */ - protected void refreshUnderline() { - FontStyle style = - (FontStyle) getFontStyleOwnerView().getStyle( - NotationPackage.eINSTANCE.getFontStyle()); - if (style != null && getFigure() instanceof WrappingLabel) { - ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); - } - if (resolveSemanticElement() instanceof Feature) { - if (((Feature) resolveSemanticElement()).isStatic()) { - ((WrappingLabel) getFigure()).setTextUnderline(true); - } - else { - ((WrappingLabel) getFigure()).setTextUnderline(false); - } - } - } - - /** - * @generated - */ - protected void refreshStrikeThrough() { - FontStyle style = - (FontStyle) getFontStyleOwnerView().getStyle( - NotationPackage.eINSTANCE.getFontStyle()); - if (style != null && getFigure() instanceof WrappingLabel) { - ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); - } - } - - /** - * @generated - */ - @Override - protected void refreshFont() { - FontStyle style = - (FontStyle) getFontStyleOwnerView().getStyle( - NotationPackage.eINSTANCE.getFontStyle()); - if (style != null) { - FontData fontData = new FontData( - style.getFontName(), style.getFontHeight(), - (style.isBold() ? SWT.BOLD : SWT.NORMAL) | - (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); - setFont(fontData); - } - } - - /** - * @generated - */ - @Override - protected void setFontColor(Color color) { - getFigure().setForegroundColor(color); - } - - /** - * @generated - */ - @Override - protected void addSemanticListeners() { - if (getParser() instanceof ISemanticParser) { - EObject element = resolveSemanticElement(); - parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); - for (int i = 0; i < parserElements.size(); i++) { - addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ - } - } else { - super.addSemanticListeners(); - } - } - - /** - * @generated - */ - @Override - protected void removeSemanticListeners() { - if (parserElements != null) { - for (int i = 0; i < parserElements.size(); i++) { - removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ - } - } else { - super.removeSemanticListeners(); - } - } - - /** - * @generated - */ - @Override - protected AccessibleEditPart getAccessibleEditPart() { - if (accessibleEP == null) { - accessibleEP = new AccessibleGraphicalEditPart() { - - @Override - public void getName(AccessibleEvent e) { - e.result = getLabelTextHelper(getFigure()); - } - }; - } - return accessibleEP; - } - - /** - * @generated - */ - private View getFontStyleOwnerView() { - return getPrimaryView(); - } - - /** - * Returns the kind of associated editor for direct edition. - * - * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition - * @generated - */ - public int getDirectEditionType() { - if (checkExtendedEditor()) { - initExtendedEditorConfiguration(); - return IDirectEdition.EXTENDED_DIRECT_EDITOR; - } - if (checkDefaultEdition()) { - return IDirectEdition.DEFAULT_DIRECT_EDITOR; - } - - // not a named element. no specific editor => do nothing - return IDirectEdition.NO_DIRECT_EDITION; - } - - /** - * Checks if an extended editor is present. - * - * @return true if an extended editor is present. - * @generated - */ - protected boolean checkExtendedEditor() { - if (resolveSemanticElement() != null) { - return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); - } - return false; - } - - /** - * Checks if a default direct edition is available - * - * @return true if a default direct edition is available - * @generated - */ - protected boolean checkDefaultEdition() { - return (getParser() != null); - } - - /** - * Initializes the extended editor configuration - * - * @generated - */ - protected void initExtendedEditorConfiguration() { - if (configuration == null) { - final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); - if (languagePreferred != null && !languagePreferred.equals("")) { - configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); - } else { - configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); - } - } - } - - /** - * Updates the preference configuration - * - * @generated - */ - protected void updateExtendedEditorConfiguration() { - String languagePreferred = Activator.getDefault().getPreferenceStore().getString( - IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); - if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { - configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() - .eClass().getInstanceClassName()); - } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { - configuration = null; - } - } - - /** - * Performs the direct edit usually used by GMF editors. - * - * @param theRequest - * the direct edit request that starts the direct edit system - * @generated - */ - protected void performDefaultDirectEditorEdit(final Request theRequest) { - // initialize the direct edit manager - try { - getEditingDomain().runExclusive(new Runnable() { - - @Override - public void run() { - if (isActive() && isEditable()) { - if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { - Character initialChar = (Character) theRequest.getExtendedData().get( - RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); - performDirectEdit(initialChar.charValue()); - } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { - DirectEditRequest editRequest = (DirectEditRequest) theRequest; - performDirectEdit(editRequest.getLocation()); - } else { - performDirectEdit(); - } - } - } - }); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - - /** - * @generated - */ - @Override - protected void handleNotificationEvent(Notification event) { - Object feature = event.getFeature(); - if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { - Integer c = (Integer) event.getNewValue(); - setFontColor(DiagramColorRegistry.getInstance().getColor(c)); - } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { - refreshUnderline(); - } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { - refreshStrikeThrough(); - } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || - NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || - NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || - NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { - refreshFont(); - } else { - if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { - refreshLabel(); - } - if (getParser() instanceof ISemanticParser) { - ISemanticParser modelParser = - (ISemanticParser) getParser(); - if (modelParser.areSemanticElementsAffected(null, event)) { - removeSemanticListeners(); - if (resolveSemanticElement() != null) { - addSemanticListeners(); - } - refreshLabel(); - } - } - } - - super.handleNotificationEvent(event); - } - - /** - * @generated - */ - @Override - protected IFigure createFigure() { - // Parent should assign one using setLabel() method - return 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.uml.diagram.composite.edit.parts; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.draw2d.ConnectionLocator; +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.Label; +import org.eclipse.draw2d.geometry.Point; +import org.eclipse.emf.common.notify.Notification; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.RunnableWithResult; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gef.AccessibleEditPart; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.Request; +import org.eclipse.gef.requests.DirectEditRequest; +import org.eclipse.gef.tools.DirectEditManager; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; +import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; +import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; +import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; +import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; +import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; +import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; +import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; +import org.eclipse.gmf.runtime.notation.FontStyle; +import org.eclipse.gmf.runtime.notation.NotationPackage; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.gmf.tooling.runtime.edit.policies.DefaultLinkLabelDragPolicy; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.text.contentassist.IContentAssistProcessor; +import org.eclipse.jface.viewers.ICellEditorValidator; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.extensionpoints.editors.Activator; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; +import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; +import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; +import org.eclipse.papyrus.infra.gmfdiag.common.editpart.IControlParserForDirectEdit; +import org.eclipse.papyrus.infra.gmfdiag.common.editpart.PapyrusLabelEditPart; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.PapyrusLinkLabelDragPolicy; +import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; +import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; +import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; +import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; +import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.accessibility.AccessibleEvent; +import org.eclipse.swt.custom.BusyIndicator; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; +import org.eclipse.uml2.uml.Feature; + +/** + * @generated + */ +public class AbstractionNameEditPart extends PapyrusLabelEditPart implements ITextAwareEditPart, IControlParserForDirectEdit { + + /** + * @generated + */ + public static final int VISUAL_ID = 6006; + + /** + * @generated + */ + private DirectEditManager manager; + + /** + * @generated + */ + private IParser parser; + + /** + * @generated + */ + private List parserElements; + + /** + * @generated + */ + private String defaultText; + + /** + * direct edition mode (default, undefined, registered editor, etc.) + * + * @generated + */ + protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; + + /** + * configuration from a registered edit dialog + * + * @generated + */ + protected IDirectEditorConfiguration configuration; + /** + * @generated + */ + static { + registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.AbstractionNameEditPart.VISUAL_ID), new Point(0, 60)); + } + + /** + * @generated + */ + public AbstractionNameEditPart(View view) { + super(view); + } + + /** + * @generated + */ + @Override + protected void createDefaultEditPolicies() { + super.createDefaultEditPolicies(); + installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); + installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new DefaultLinkLabelDragPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new PapyrusLinkLabelDragPolicy()); + } + + /** + * @generated + */ + @Override + public int getKeyPoint() { + return ConnectionLocator.MIDDLE; + } + + /** + * @generated + */ + protected String getLabelTextHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getText(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getText(); + } else { + return ((Label) figure).getText(); + } + } + + /** + * @generated + */ + protected void setLabelTextHelper(IFigure figure, String text) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setText(text); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setText(text); + } else { + ((Label) figure).setText(text); + } + } + + /** + * @generated + */ + protected Image getLabelIconHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getIcon(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getIcon(); + } else { + return ((Label) figure).getIcon(); + } + } + + /** + * @generated + */ + protected void setLabelIconHelper(IFigure figure, Image icon) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setIcon(icon); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setIcon(icon); + } else { + ((Label) figure).setIcon(icon); + } + } + + /** + * @generated + */ + public void setLabel(IFigure + figure) { + unregisterVisuals(); + setFigure(figure); + defaultText = getLabelTextHelper(figure); + registerVisuals(); + refreshVisuals(); + } + + /** + * @generated + */ + @Override + protected List getModelChildren() { + return Collections.EMPTY_LIST; + } + + /** + * @generated + */ + @Override + public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { + return null; + } + + /** + * @generated + */ + @Override + public void setParser(IParser parser) { + this.parser = parser; + } + + /** + * @generated + */ + protected EObject getParserElement() { + return resolveSemanticElement(); + } + + /** + * @generated + */ + protected Image getLabelIcon() { + return null; + } + + /** + * @generated + */ + protected String getLabelText() { + String text = null; + EObject parserElement = getParserElement(); + if (parserElement != null && getParser() != null) { + text = getParser().getPrintString( + new EObjectAdapter(parserElement), + getParserOptions().intValue()); + } + if (text == null || text.length() == 0) { + text = defaultText; + } + return text; + } + + /** + * @generated + */ + @Override + public void setLabelText(String text) { + setLabelTextHelper(getFigure(), text); + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + @Override + public String getEditText() { + if (getParserElement() == null || getParser() == null) { + return ""; //$NON-NLS-1$ + } + return getParser().getEditString( + new EObjectAdapter(getParserElement()), + getParserOptions().intValue()); + } + + /** + * @generated + */ + protected boolean isEditable() { + return getParser() != null; + } + + /** + * @generated + */ + @Override + public ICellEditorValidator getEditTextValidator() { + return new ICellEditorValidator() { + + @Override + public String isValid(final Object value) { + if (value instanceof String) { + final EObject element = getParserElement(); + final IParser parser = getParser(); + try { + IParserEditStatus valid = + (IParserEditStatus) getEditingDomain().runExclusive( + new RunnableWithResult.Impl() { + + @Override + public void run() { + setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); + } + }); + return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); + } catch (InterruptedException ie) { + ie.printStackTrace(); + } + } + + // shouldn't get here + return null; + } + }; + } + + /** + * @generated + */ + @Override + public IContentAssistProcessor getCompletionProcessor() { + if (getParserElement() == null || getParser() == null) { + return null; + } + return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); + } + + /** + * @generated + */ + @Override + public ParserOptions getParserOptions() { + return ParserOptions.NONE; + } + + /** + * @generated + */ + @Override + public IParser getParser() { + if (parser == null) { + parser = UMLParserProvider.getParser(UMLElementTypes.Abstraction_4007, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.AbstractionNameEditPart.VISUAL_ID)); + } + return parser; + } + + /** + * @generated + */ + protected DirectEditManager getManager() { + if (manager == null) { + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + } + return manager; + } + + /** + * @generated + */ + protected void setManager(DirectEditManager manager) { + this.manager = manager; + } + + /** + * @generated + */ + protected void performDirectEdit() { + BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { + + @Override + public void run() { + getManager().show(); + } + }); + } + + /** + * @generated + */ + protected void performDirectEdit(Point eventLocation) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); + } + } + + /** + * @generated + */ + private void performDirectEdit(char initialCharacter) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(initialCharacter); + } else { + performDirectEdit(); + } + } + + /** + * @generated + */ + @Override + protected void performDirectEditRequest(Request request) { + + final Request theRequest = request; + + if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { + directEditionMode = getDirectEditionType(); + } + switch (directEditionMode) { + case IDirectEdition.NO_DIRECT_EDITION: + // no direct edition mode => does nothing + return; + case IDirectEdition.EXTENDED_DIRECT_EDITOR: + updateExtendedEditorConfiguration(); + if (configuration == null || configuration.getLanguage() == null) { + // Create default edit manager + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + performDefaultDirectEditorEdit(theRequest); + } else { + configuration.preEditAction(resolveSemanticElement()); + Dialog dialog = null; + if (configuration instanceof ICustomDirectEditorConfiguration) { + setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); + initializeDirectEditManager(theRequest); + return; + } else if (configuration instanceof IPopupEditorConfiguration) { + IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); + helper.showEditor(); + return; + } + else if (configuration instanceof IAdvancedEditorConfiguration) { + dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); + } else if (configuration instanceof IDirectEditorConfiguration) { + dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), + configuration); + } else { + return; + } + final Dialog finalDialog = dialog; + + if (Window.OK == dialog.open()) { + TransactionalEditingDomain domain = getEditingDomain(); + RecordingCommand command = new RecordingCommand(domain, "Edit Label") { + + @Override + protected void doExecute() { + configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); + + } + }; + domain.getCommandStack().execute(command); + } + } + break; + case IDirectEdition.DEFAULT_DIRECT_EDITOR: + initializeDirectEditManager(theRequest); + break; + default: + break; + } + } + + /** + * @generated + */ + protected void initializeDirectEditManager(final Request request) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + @Override + public void run() { + if (isActive() && isEditable()) { + if (request.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } + else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void refreshVisuals() { + super.refreshVisuals(); + refreshLabel(); + refreshFont(); + refreshFontColor(); + refreshUnderline(); + refreshStrikeThrough(); + } + + /** + * @generated + */ + protected void refreshLabel() { + EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); + if (maskLabelPolicy == null) { + maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); + } + if (maskLabelPolicy == null) { + setLabelTextHelper(getFigure(), getLabelText()); + setLabelIconHelper(getFigure(), getLabelIcon()); + } + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + protected void refreshUnderline() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); + } + if (resolveSemanticElement() instanceof Feature) { + if (((Feature) resolveSemanticElement()).isStatic()) { + ((WrappingLabel) getFigure()).setTextUnderline(true); + } + else { + ((WrappingLabel) getFigure()).setTextUnderline(false); + } + } + } + + /** + * @generated + */ + protected void refreshStrikeThrough() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); + } + } + + /** + * @generated + */ + @Override + protected void refreshFont() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null) { + FontData fontData = new FontData( + style.getFontName(), style.getFontHeight(), + (style.isBold() ? SWT.BOLD : SWT.NORMAL) | + (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); + setFont(fontData); + } + } + + /** + * @generated + */ + @Override + protected void setFontColor(Color color) { + getFigure().setForegroundColor(color); + } + + /** + * @generated + */ + @Override + protected void addSemanticListeners() { + if (getParser() instanceof ISemanticParser) { + EObject element = resolveSemanticElement(); + parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); + for (int i = 0; i < parserElements.size(); i++) { + addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ + } + } else { + super.addSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected void removeSemanticListeners() { + if (parserElements != null) { + for (int i = 0; i < parserElements.size(); i++) { + removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ + } + } else { + super.removeSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected AccessibleEditPart getAccessibleEditPart() { + if (accessibleEP == null) { + accessibleEP = new AccessibleGraphicalEditPart() { + + @Override + public void getName(AccessibleEvent e) { + e.result = getLabelTextHelper(getFigure()); + } + }; + } + return accessibleEP; + } + + /** + * @generated + */ + private View getFontStyleOwnerView() { + return getPrimaryView(); + } + + /** + * Returns the kind of associated editor for direct edition. + * + * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition + * @generated + */ + public int getDirectEditionType() { + if (checkExtendedEditor()) { + initExtendedEditorConfiguration(); + return IDirectEdition.EXTENDED_DIRECT_EDITOR; + } + if (checkDefaultEdition()) { + return IDirectEdition.DEFAULT_DIRECT_EDITOR; + } + + // not a named element. no specific editor => do nothing + return IDirectEdition.NO_DIRECT_EDITION; + } + + /** + * Checks if an extended editor is present. + * + * @return true if an extended editor is present. + * @generated + */ + protected boolean checkExtendedEditor() { + if (resolveSemanticElement() != null) { + return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); + } + return false; + } + + /** + * Checks if a default direct edition is available + * + * @return true if a default direct edition is available + * @generated + */ + protected boolean checkDefaultEdition() { + return (getParser() != null); + } + + /** + * Initializes the extended editor configuration + * + * @generated + */ + protected void initExtendedEditorConfiguration() { + if (configuration == null) { + final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("")) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); + } else { + configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); + } + } + } + + /** + * Updates the preference configuration + * + * @generated + */ + protected void updateExtendedEditorConfiguration() { + String languagePreferred = Activator.getDefault().getPreferenceStore().getString( + IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() + .eClass().getInstanceClassName()); + } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { + configuration = null; + } + } + + /** + * Performs the direct edit usually used by GMF editors. + * + * @param theRequest + * the direct edit request that starts the direct edit system + * @generated + */ + protected void performDefaultDirectEditorEdit(final Request theRequest) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + + @Override + public void run() { + if (isActive() && isEditable()) { + if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) theRequest.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { + DirectEditRequest editRequest = (DirectEditRequest) theRequest; + performDirectEdit(editRequest.getLocation()); + } else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void handleNotificationEvent(Notification event) { + Object feature = event.getFeature(); + if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { + Integer c = (Integer) event.getNewValue(); + setFontColor(DiagramColorRegistry.getInstance().getColor(c)); + } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { + refreshUnderline(); + } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { + refreshStrikeThrough(); + } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { + refreshFont(); + } else { + if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { + refreshLabel(); + } + if (getParser() instanceof ISemanticParser) { + ISemanticParser modelParser = + (ISemanticParser) getParser(); + if (modelParser.areSemanticElementsAffected(null, event)) { + removeSemanticListeners(); + if (resolveSemanticElement() != null) { + addSemanticListeners(); + } + refreshLabel(); + } + } + } + + super.handleNotificationEvent(event); + } + + /** + * @generated + */ + @Override + protected IFigure createFigure() { + // Parent should assign one using setLabel() method + return null; + } +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ActivityCompositeCompartmentEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ActivityCompositeCompartmentEditPart.java index 46b5c4b6638..971d41d8b87 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ActivityCompositeCompartmentEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ActivityCompositeCompartmentEditPart.java @@ -26,6 +26,7 @@ import org.eclipse.gmf.runtime.diagram.ui.editpolicies.ResizableCompartmentEditP import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.BorderDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.CustomContainerEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.DuplicatePasteEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.PapyrusCreationEditPolicy; @@ -75,6 +76,7 @@ public class ActivityCompositeCompartmentEditPart extends ShapeCompartmentEditPa installEditPolicy(EditPolicy.GRAPHICAL_NODE_ROLE, new CustomContainerEditPolicy()); installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, new CustomDiagramDragDropEditPolicy()); installEditPolicy(EditPolicyRoles.CREATION_ROLE, new PortInCompartmentCreationEditPolicy()); + installEditPolicy(BorderDisplayEditPolicy.BORDER_DISPLAY_EDITPOLICY, new BorderDisplayEditPolicy()); } /** diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ActivityCompositeCompartmentEditPartCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ActivityCompositeCompartmentEditPartCN.java index 1b399c6f938..ec5cb4a067e 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ActivityCompositeCompartmentEditPartCN.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ActivityCompositeCompartmentEditPartCN.java @@ -26,6 +26,7 @@ import org.eclipse.gmf.runtime.diagram.ui.editpolicies.ResizableCompartmentEditP import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.BorderDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.CustomContainerEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.DuplicatePasteEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.PapyrusCreationEditPolicy; @@ -75,6 +76,7 @@ public class ActivityCompositeCompartmentEditPartCN extends ShapeCompartmentEdit installEditPolicy(EditPolicy.GRAPHICAL_NODE_ROLE, new CustomContainerEditPolicy()); installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, new CustomDiagramDragDropEditPolicy()); installEditPolicy(EditPolicyRoles.CREATION_ROLE, new PortInCompartmentCreationEditPolicy()); + installEditPolicy(BorderDisplayEditPolicy.BORDER_DISPLAY_EDITPOLICY, new BorderDisplayEditPolicy()); } /** diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ActivityCompositeEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ActivityCompositeEditPart.java index c43819f8769..4afa7a0c9f9 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ActivityCompositeEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ActivityCompositeEditPart.java @@ -11,28 +11,37 @@ */ package org.eclipse.papyrus.uml.diagram.composite.edit.parts; +import java.util.Collections; +import java.util.List; + import org.eclipse.draw2d.IFigure; import org.eclipse.draw2d.PositionConstants; import org.eclipse.emf.common.notify.Notification; import org.eclipse.gef.EditPart; import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.GraphicalEditPart; 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.handles.MoveHandle; import org.eclipse.gef.requests.CreateRequest; import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.BorderItemSelectionEditPolicy; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.DragDropEditPolicy; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles; import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; -import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure; import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure; +import org.eclipse.gmf.runtime.notation.Edge; +import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.GetChildLayoutEditPolicy; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.IPapyrusNodeFigure; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.RoundedRectangleNodePlateFigure; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.SelectableBorderedNodeFigure; -import org.eclipse.papyrus.uml.diagram.common.editparts.NamedElementEditPart; +import org.eclipse.papyrus.uml.diagram.common.editparts.RoundedCompartmentEditPart; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AffixedNodeAlignmentEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeNodeLabelDisplayEditPolicy; @@ -41,11 +50,11 @@ import org.eclipse.papyrus.uml.diagram.common.editpolicies.PapyrusCreationEditPo import org.eclipse.papyrus.uml.diagram.common.editpolicies.QualifiedNameDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.ShowHideClassifierContentsEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.ShowHideCompartmentEditPolicy; +import org.eclipse.papyrus.uml.diagram.common.locator.RoundedRectangleLabelPositionLocator; import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.BehaviorLayoutEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.CustomDiagramDragDropEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.RemoveOrphanViewPolicy; import org.eclipse.papyrus.uml.diagram.composite.custom.figures.ActivityCompositeFigure; -import org.eclipse.papyrus.uml.diagram.composite.custom.locators.PortPositionLocator; import org.eclipse.papyrus.uml.diagram.composite.edit.policies.ActivityCompositeItemSemanticEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; import org.eclipse.swt.graphics.Color; @@ -53,7 +62,7 @@ import org.eclipse.swt.graphics.Color; /** * @generated */ -public class ActivityCompositeEditPart extends NamedElementEditPart { +public class ActivityCompositeEditPart extends RoundedCompartmentEditPart { /** * @generated @@ -95,6 +104,7 @@ public class ActivityCompositeEditPart extends NamedElementEditPart { installEditPolicy(ShowHideCompartmentEditPolicy.SHOW_HIDE_COMPARTMENT_POLICY, new ShowHideCompartmentEditPolicy()); installEditPolicy(AffixedNodeAlignmentEditPolicy.AFFIXED_CHILD_ALIGNMENT_ROLE, new AffixedNodeAlignmentEditPolicy()); installEditPolicy("REMOVE_ORPHAN_VIEW", new RemoveOrphanViewPolicy()); //$NON-NLS-1$ + installEditPolicy(EditPolicy.LAYOUT_ROLE, new GetChildLayoutEditPolicy()); // XXX need an SCR to runtime to have another abstract superclass that would let children add reasonable editpolicies // removeEditPolicy(org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles.CONNECTION_HANDLES_ROLE); } @@ -109,6 +119,17 @@ public class ActivityCompositeEditPart extends NamedElementEditPart { protected EditPolicy createChildEditPolicy(EditPart child) { View childView = (View) child.getModel(); switch (UMLVisualIDRegistry.getVisualID(childView)) { + case ActivityCompositeFloatingLabelEditPart.VISUAL_ID: + return new BorderItemSelectionEditPolicy() { + + @Override + protected List createSelectionHandles() { + MoveHandle mh = new MoveHandle((GraphicalEditPart) getHost()); + mh.setBorder(null); + return Collections.singletonList(mh); + } + } + ; case PortEditPart.VISUAL_ID: case ParameterEditPart.VISUAL_ID: return new BorderItemResizableEditPolicy(); @@ -140,6 +161,19 @@ public class ActivityCompositeEditPart extends NamedElementEditPart { **/ @Override protected void handleNotificationEvent(Notification event) { + /* + * when a node have external node labels, the methods refreshChildren() remove the EditPart corresponding to the Label from the EditPart + * Registry. After that, we can't reset the visibility to true (using the Show/Hide Label Action)! + */ + if (NotationPackage.eINSTANCE.getView_Visible().equals(event.getFeature())) { + Object notifier = event.getNotifier(); + List modelChildren = ((View) getModel()).getChildren(); + if (!(notifier instanceof Edge)) { + if (modelChildren.contains(event.getNotifier())) { + return; + } + } + } super.handleNotificationEvent(event); } @@ -181,9 +215,9 @@ public class ActivityCompositeEditPart extends NamedElementEditPart { - //Papyrus Gencode :Affixed Port locator + // Papyrus Gencode :Affixed Port locator if (childEditPart instanceof PortEditPart) { - IBorderItemLocator locator = new PortPositionLocator(getMainFigure(), PositionConstants.NONE); + IBorderItemLocator locator = new org.eclipse.papyrus.uml.diagram.common.locator.PortPositionLocator(getMainFigure(), PositionConstants.NONE); getBorderedFigure().getBorderItemContainer().add(((PortEditPart) childEditPart).getFigure(), locator); return true; } @@ -191,9 +225,9 @@ public class ActivityCompositeEditPart extends NamedElementEditPart { - //Papyrus Gencode :Affixed Port locator + // Papyrus Gencode :Affixed Port locator if (childEditPart instanceof ParameterEditPart) { - IBorderItemLocator locator = new PortPositionLocator(getMainFigure(), PositionConstants.NONE); + IBorderItemLocator locator = new org.eclipse.papyrus.uml.diagram.common.locator.PortPositionLocator(getMainFigure(), PositionConstants.NONE); getBorderedFigure().getBorderItemContainer().add(((ParameterEditPart) childEditPart).getFigure(), locator); return true; } @@ -261,12 +295,26 @@ public class ActivityCompositeEditPart extends NamedElementEditPart { return getContentPane(); } + /** + * @generated + */ + @Override + protected void addBorderItem(IFigure borderItemContainer, IBorderItemEditPart borderItemEditPart) { + if (borderItemEditPart instanceof ActivityCompositeFloatingLabelEditPart) { + IBorderItemLocator locator = new RoundedRectangleLabelPositionLocator(getMainFigure()); + borderItemContainer.add(borderItemEditPart.getFigure(), locator); + } else + { + super.addBorderItem(borderItemContainer, borderItemEditPart); + } + } + /** * @generated */ @Override protected NodeFigure createNodePlate() { - DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(40, 40); + RoundedRectangleNodePlateFigure result = new RoundedRectangleNodePlateFigure(40, 40); return result; } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ActivityCompositeEditPartCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ActivityCompositeEditPartCN.java index b06c0a325ec..a6559d9f790 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ActivityCompositeEditPartCN.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ActivityCompositeEditPartCN.java @@ -11,28 +11,37 @@ */ package org.eclipse.papyrus.uml.diagram.composite.edit.parts; +import java.util.Collections; +import java.util.List; + import org.eclipse.draw2d.IFigure; import org.eclipse.draw2d.PositionConstants; import org.eclipse.emf.common.notify.Notification; import org.eclipse.gef.EditPart; import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.GraphicalEditPart; 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.handles.MoveHandle; import org.eclipse.gef.requests.CreateRequest; import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.BorderItemSelectionEditPolicy; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.DragDropEditPolicy; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles; import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; -import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure; import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure; +import org.eclipse.gmf.runtime.notation.Edge; +import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.GetChildLayoutEditPolicy; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.IPapyrusNodeFigure; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.RoundedRectangleNodePlateFigure; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.SelectableBorderedNodeFigure; -import org.eclipse.papyrus.uml.diagram.common.editparts.NamedElementEditPart; +import org.eclipse.papyrus.uml.diagram.common.editparts.RoundedCompartmentEditPart; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AffixedNodeAlignmentEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeNodeLabelDisplayEditPolicy; @@ -41,11 +50,11 @@ import org.eclipse.papyrus.uml.diagram.common.editpolicies.PapyrusCreationEditPo import org.eclipse.papyrus.uml.diagram.common.editpolicies.QualifiedNameDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.ShowHideClassifierContentsEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.ShowHideCompartmentEditPolicy; +import org.eclipse.papyrus.uml.diagram.common.locator.RoundedRectangleLabelPositionLocator; import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.BehaviorLayoutEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.CustomDiagramDragDropEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.RemoveOrphanViewPolicy; import org.eclipse.papyrus.uml.diagram.composite.custom.figures.ActivityCompositeFigure; -import org.eclipse.papyrus.uml.diagram.composite.custom.locators.PortPositionLocator; import org.eclipse.papyrus.uml.diagram.composite.edit.policies.ActivityCompositeItemSemanticEditPolicyCN; import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; import org.eclipse.swt.graphics.Color; @@ -53,7 +62,7 @@ import org.eclipse.swt.graphics.Color; /** * @generated */ -public class ActivityCompositeEditPartCN extends NamedElementEditPart { +public class ActivityCompositeEditPartCN extends RoundedCompartmentEditPart { /** * @generated @@ -95,6 +104,7 @@ public class ActivityCompositeEditPartCN extends NamedElementEditPart { installEditPolicy(ShowHideCompartmentEditPolicy.SHOW_HIDE_COMPARTMENT_POLICY, new ShowHideCompartmentEditPolicy()); installEditPolicy(AffixedNodeAlignmentEditPolicy.AFFIXED_CHILD_ALIGNMENT_ROLE, new AffixedNodeAlignmentEditPolicy()); installEditPolicy("REMOVE_ORPHAN_VIEW", new RemoveOrphanViewPolicy()); //$NON-NLS-1$ + installEditPolicy(EditPolicy.LAYOUT_ROLE, new GetChildLayoutEditPolicy()); // XXX need an SCR to runtime to have another abstract superclass that would let children add reasonable editpolicies // removeEditPolicy(org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles.CONNECTION_HANDLES_ROLE); } @@ -109,6 +119,17 @@ public class ActivityCompositeEditPartCN extends NamedElementEditPart { protected EditPolicy createChildEditPolicy(EditPart child) { View childView = (View) child.getModel(); switch (UMLVisualIDRegistry.getVisualID(childView)) { + case ActivityCompositeFloatingLabelEditPartCN.VISUAL_ID: + return new BorderItemSelectionEditPolicy() { + + @Override + protected List createSelectionHandles() { + MoveHandle mh = new MoveHandle((GraphicalEditPart) getHost()); + mh.setBorder(null); + return Collections.singletonList(mh); + } + } + ; case PortEditPart.VISUAL_ID: case ParameterEditPart.VISUAL_ID: return new BorderItemResizableEditPolicy(); @@ -140,6 +161,19 @@ public class ActivityCompositeEditPartCN extends NamedElementEditPart { **/ @Override protected void handleNotificationEvent(Notification event) { + /* + * when a node have external node labels, the methods refreshChildren() remove the EditPart corresponding to the Label from the EditPart + * Registry. After that, we can't reset the visibility to true (using the Show/Hide Label Action)! + */ + if (NotationPackage.eINSTANCE.getView_Visible().equals(event.getFeature())) { + Object notifier = event.getNotifier(); + List modelChildren = ((View) getModel()).getChildren(); + if (!(notifier instanceof Edge)) { + if (modelChildren.contains(event.getNotifier())) { + return; + } + } + } super.handleNotificationEvent(event); } @@ -181,9 +215,9 @@ public class ActivityCompositeEditPartCN extends NamedElementEditPart { - //Papyrus Gencode :Affixed Port locator + // Papyrus Gencode :Affixed Port locator if (childEditPart instanceof PortEditPart) { - IBorderItemLocator locator = new PortPositionLocator(getMainFigure(), PositionConstants.NONE); + IBorderItemLocator locator = new org.eclipse.papyrus.uml.diagram.common.locator.PortPositionLocator(getMainFigure(), PositionConstants.NONE); getBorderedFigure().getBorderItemContainer().add(((PortEditPart) childEditPart).getFigure(), locator); return true; } @@ -191,9 +225,9 @@ public class ActivityCompositeEditPartCN extends NamedElementEditPart { - //Papyrus Gencode :Affixed Port locator + // Papyrus Gencode :Affixed Port locator if (childEditPart instanceof ParameterEditPart) { - IBorderItemLocator locator = new PortPositionLocator(getMainFigure(), PositionConstants.NONE); + IBorderItemLocator locator = new org.eclipse.papyrus.uml.diagram.common.locator.PortPositionLocator(getMainFigure(), PositionConstants.NONE); getBorderedFigure().getBorderItemContainer().add(((ParameterEditPart) childEditPart).getFigure(), locator); return true; } @@ -261,12 +295,26 @@ public class ActivityCompositeEditPartCN extends NamedElementEditPart { return getContentPane(); } + /** + * @generated + */ + @Override + protected void addBorderItem(IFigure borderItemContainer, IBorderItemEditPart borderItemEditPart) { + if (borderItemEditPart instanceof ActivityCompositeFloatingLabelEditPartCN) { + IBorderItemLocator locator = new RoundedRectangleLabelPositionLocator(getMainFigure()); + borderItemContainer.add(borderItemEditPart.getFigure(), locator); + } else + { + super.addBorderItem(borderItemContainer, borderItemEditPart); + } + } + /** * @generated */ @Override protected NodeFigure createNodePlate() { - DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(40, 40); + RoundedRectangleNodePlateFigure result = new RoundedRectangleNodePlateFigure(40, 40); return result; } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ActivityCompositeFloatingLabelEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ActivityCompositeFloatingLabelEditPart.java new file mode 100644 index 00000000000..e4cd2e78044 --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ActivityCompositeFloatingLabelEditPart.java @@ -0,0 +1,860 @@ +/** + * 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.uml.diagram.composite.edit.parts; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.Label; +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.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.RunnableWithResult; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gef.AccessibleEditPart; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.Request; +import org.eclipse.gef.requests.DirectEditRequest; +import org.eclipse.gef.tools.DirectEditManager; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; +import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; +import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; +import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; +import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; +import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; +import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; +import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; +import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; +import org.eclipse.gmf.runtime.notation.FontStyle; +import org.eclipse.gmf.runtime.notation.NotationPackage; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.text.contentassist.IContentAssistProcessor; +import org.eclipse.jface.viewers.ICellEditorValidator; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.extensionpoints.editors.Activator; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; +import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; +import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.ExternalLabelPrimaryDragRoleEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.PapyrusWrappingLabel; +import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; +import org.eclipse.papyrus.uml.diagram.common.editparts.FloatingLabelEditPart; +import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; +import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; +import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; +import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.accessibility.AccessibleEvent; +import org.eclipse.swt.custom.BusyIndicator; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; +import org.eclipse.uml2.uml.Feature; + +/** + * @generated + */ +public class ActivityCompositeFloatingLabelEditPart extends FloatingLabelEditPart + implements ITextAwareEditPart, IBorderItemEditPart +{ + + /** + * @generated + */ + public static final int VISUAL_ID = 6079; + + /** + * @generated + */ + private DirectEditManager manager; + + /** + * @generated + */ + private IParser parser; + + /** + * @generated + */ + private List parserElements; + + /** + * @generated + */ + private String defaultText; + + /** + * direct edition mode (default, undefined, registered editor, etc.) + * + * @generated + */ + protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; + + /** + * configuration from a registered edit dialog + * + * @generated + */ + protected IDirectEditorConfiguration configuration; + + + /** + * @generated + */ + static { + registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.ActivityCompositeFloatingLabelEditPart.VISUAL_ID), new Point(0, 0)); + } + + /** + * @generated + */ + public ActivityCompositeFloatingLabelEditPart(View view) { + super(view); + } + + /** + * @generated + */ + @Override + protected void createDefaultEditPolicies() { + super.createDefaultEditPolicies(); + installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); + installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ExternalLabelPrimaryDragRoleEditPolicy()); + } + + /** + * @generated + */ + @Override + public IBorderItemLocator getBorderItemLocator() { + IFigure parentFigure = getFigure().getParent(); + if (parentFigure != null && parentFigure.getLayoutManager() != null) { + Object constraint = parentFigure.getLayoutManager().getConstraint(getFigure()); + return (IBorderItemLocator) constraint; + } + return null; + } + + /** + * @generated + */ + @Override + public void refreshBounds() { + int x = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_X())).intValue(); + int y = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_Y())).intValue(); + int width = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Width())).intValue(); + int height = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Height())).intValue(); + getBorderItemLocator().setConstraint(new Rectangle(x, y, width, height)); + } + + + /** + * @generated + */ + protected String getLabelTextHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getText(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getText(); + } else { + return ((Label) figure).getText(); + } + } + + /** + * @generated + */ + protected void setLabelTextHelper(IFigure figure, String text) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setText(text); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setText(text); + } else { + ((Label) figure).setText(text); + } + } + + /** + * @generated + */ + protected Image getLabelIconHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getIcon(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getIcon(); + } else { + return ((Label) figure).getIcon(); + } + } + + /** + * @generated + */ + protected void setLabelIconHelper(IFigure figure, Image icon) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setIcon(icon); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setIcon(icon); + } else { + ((Label) figure).setIcon(icon); + } + } + + /** + * @generated + */ + public void setLabel(IFigure + figure) { + unregisterVisuals(); + setFigure(figure); + defaultText = getLabelTextHelper(figure); + registerVisuals(); + refreshVisuals(); + } + + /** + * @generated + */ + @Override + protected List getModelChildren() { + return Collections.EMPTY_LIST; + } + + /** + * @generated + */ + @Override + public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { + return null; + } + + /** + * @generated + */ + public void setParser(IParser parser) { + this.parser = parser; + } + + /** + * @generated + */ + protected EObject getParserElement() { + return resolveSemanticElement(); + } + + /** + * @generated + */ + protected Image getLabelIcon() { + return null; + } + + /** + * @generated + */ + protected String getLabelText() { + String text = null; + EObject parserElement = getParserElement(); + if (parserElement != null && getParser() != null) { + text = getParser().getPrintString( + new EObjectAdapter(parserElement), + getParserOptions().intValue()); + } + if (text == null || text.length() == 0) { + text = defaultText; + } + return text; + } + + /** + * @generated + */ + @Override + public void setLabelText(String text) { + setLabelTextHelper(getFigure(), text); + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + @Override + public String getEditText() { + if (getParserElement() == null || getParser() == null) { + return ""; //$NON-NLS-1$ + } + return getParser().getEditString( + new EObjectAdapter(getParserElement()), + getParserOptions().intValue()); + } + + /** + * @generated + */ + protected boolean isEditable() { + return getParser() != null; + } + + /** + * @generated + */ + @Override + public ICellEditorValidator getEditTextValidator() { + return new ICellEditorValidator() { + + @Override + public String isValid(final Object value) { + if (value instanceof String) { + final EObject element = getParserElement(); + final IParser parser = getParser(); + try { + IParserEditStatus valid = + (IParserEditStatus) getEditingDomain().runExclusive( + new RunnableWithResult.Impl() { + + @Override + public void run() { + setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); + } + }); + return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); + } catch (InterruptedException ie) { + ie.printStackTrace(); + } + } + + // shouldn't get here + return null; + } + }; + } + + /** + * @generated + */ + @Override + public IContentAssistProcessor getCompletionProcessor() { + if (getParserElement() == null || getParser() == null) { + return null; + } + return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); + } + + /** + * @generated + */ + @Override + public ParserOptions getParserOptions() { + return ParserOptions.NONE; + } + + /** + * @generated + */ + @Override + public IParser getParser() { + if (parser == null) { + parser = UMLParserProvider.getParser(UMLElementTypes.Activity_2060, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.ActivityCompositeFloatingLabelEditPart.VISUAL_ID)); + } + return parser; + } + + /** + * @generated + */ + protected DirectEditManager getManager() { + if (manager == null) { + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + } + return manager; + } + + /** + * @generated + */ + protected void setManager(DirectEditManager manager) { + this.manager = manager; + } + + /** + * @generated + */ + protected void performDirectEdit() { + BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { + + @Override + public void run() { + getManager().show(); + } + }); + } + + /** + * @generated + */ + protected void performDirectEdit(Point eventLocation) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); + } + } + + /** + * @generated + */ + private void performDirectEdit(char initialCharacter) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(initialCharacter); + } else { + performDirectEdit(); + } + } + + /** + * @generated + */ + @Override + protected void performDirectEditRequest(Request request) { + + final Request theRequest = request; + + if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { + directEditionMode = getDirectEditionType(); + } + switch (directEditionMode) { + case IDirectEdition.NO_DIRECT_EDITION: + // no direct edition mode => does nothing + return; + case IDirectEdition.EXTENDED_DIRECT_EDITOR: + updateExtendedEditorConfiguration(); + if (configuration == null || configuration.getLanguage() == null) { + // Create default edit manager + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + performDefaultDirectEditorEdit(theRequest); + } else { + configuration.preEditAction(resolveSemanticElement()); + Dialog dialog = null; + if (configuration instanceof ICustomDirectEditorConfiguration) { + setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); + initializeDirectEditManager(theRequest); + return; + } else if (configuration instanceof IPopupEditorConfiguration) { + IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); + helper.showEditor(); + return; + } + else if (configuration instanceof IAdvancedEditorConfiguration) { + dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); + } else if (configuration instanceof IDirectEditorConfiguration) { + dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), + configuration); + } else { + return; + } + final Dialog finalDialog = dialog; + + if (Window.OK == dialog.open()) { + TransactionalEditingDomain domain = getEditingDomain(); + RecordingCommand command = new RecordingCommand(domain, "Edit Label") { + + @Override + protected void doExecute() { + configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); + + } + }; + domain.getCommandStack().execute(command); + } + } + break; + case IDirectEdition.DEFAULT_DIRECT_EDITOR: + initializeDirectEditManager(theRequest); + break; + default: + break; + } + } + + /** + * @generated + */ + protected void initializeDirectEditManager(final Request request) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + @Override + public void run() { + if (isActive() && isEditable()) { + if (request.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } + else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void refreshVisuals() { + super.refreshVisuals(); + refreshLabel(); + refreshFont(); + refreshFontColor(); + refreshUnderline(); + refreshStrikeThrough(); + } + + /** + * @generated + */ + protected void refreshLabel() { + EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); + if (maskLabelPolicy == null) { + maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); + } + if (maskLabelPolicy == null) { + View view = (View) getModel(); + if (view.isVisible()) { + setLabelTextHelper(getFigure(), getLabelText()); + setLabelIconHelper(getFigure(), getLabelIcon()); + } + else { + setLabelTextHelper(getFigure(), ""); //$NON-NLS-1$ + setLabelIconHelper(getFigure(), null); + } + } + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + protected void refreshUnderline() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); + } + if (resolveSemanticElement() instanceof Feature) { + if (((Feature) resolveSemanticElement()).isStatic()) { + ((WrappingLabel) getFigure()).setTextUnderline(true); + } + else { + ((WrappingLabel) getFigure()).setTextUnderline(false); + } + } + } + + /** + * @generated + */ + protected void refreshStrikeThrough() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); + } + } + + /** + * @generated + */ + @Override + protected void refreshFont() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null) { + FontData fontData = new FontData( + style.getFontName(), style.getFontHeight(), + (style.isBold() ? SWT.BOLD : SWT.NORMAL) | + (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); + setFont(fontData); + } + } + + /** + * @generated + */ + @Override + protected void setFontColor(Color color) { + getFigure().setForegroundColor(color); + } + + /** + * @generated + */ + @Override + protected void addSemanticListeners() { + if (getParser() instanceof ISemanticParser) { + EObject element = resolveSemanticElement(); + parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); + for (int i = 0; i < parserElements.size(); i++) { + addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ + } + } else { + super.addSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected void removeSemanticListeners() { + if (parserElements != null) { + for (int i = 0; i < parserElements.size(); i++) { + removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ + } + } else { + super.removeSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected AccessibleEditPart getAccessibleEditPart() { + if (accessibleEP == null) { + accessibleEP = new AccessibleGraphicalEditPart() { + + @Override + public void getName(AccessibleEvent e) { + e.result = getLabelTextHelper(getFigure()); + } + }; + } + return accessibleEP; + } + + /** + * @generated + */ + private View getFontStyleOwnerView() { + return getPrimaryView(); + } + + /** + * Returns the kind of associated editor for direct edition. + * + * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition + * @generated + */ + public int getDirectEditionType() { + if (checkExtendedEditor()) { + initExtendedEditorConfiguration(); + return IDirectEdition.EXTENDED_DIRECT_EDITOR; + } + if (checkDefaultEdition()) { + return IDirectEdition.DEFAULT_DIRECT_EDITOR; + } + + // not a named element. no specific editor => do nothing + return IDirectEdition.NO_DIRECT_EDITION; + } + + /** + * Checks if an extended editor is present. + * + * @return true if an extended editor is present. + * @generated + */ + protected boolean checkExtendedEditor() { + if (resolveSemanticElement() != null) { + return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); + } + return false; + } + + /** + * Checks if a default direct edition is available + * + * @return true if a default direct edition is available + * @generated + */ + protected boolean checkDefaultEdition() { + return (getParser() != null); + } + + /** + * Initializes the extended editor configuration + * + * @generated + */ + protected void initExtendedEditorConfiguration() { + if (configuration == null) { + final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("")) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); + } else { + configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); + } + } + } + + /** + * Updates the preference configuration + * + * @generated + */ + protected void updateExtendedEditorConfiguration() { + String languagePreferred = Activator.getDefault().getPreferenceStore().getString( + IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() + .eClass().getInstanceClassName()); + } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { + configuration = null; + } + } + + /** + * Performs the direct edit usually used by GMF editors. + * + * @param theRequest + * the direct edit request that starts the direct edit system + * @generated + */ + protected void performDefaultDirectEditorEdit(final Request theRequest) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + + @Override + public void run() { + if (isActive() && isEditable()) { + if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) theRequest.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { + DirectEditRequest editRequest = (DirectEditRequest) theRequest; + performDirectEdit(editRequest.getLocation()); + } else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + + /** + * @generated + */ + @Override + protected void handleNotificationEvent(Notification event) { + Object feature = event.getFeature(); + if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { + Integer c = (Integer) event.getNewValue(); + setFontColor(DiagramColorRegistry.getInstance().getColor(c)); + } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { + refreshUnderline(); + } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { + refreshStrikeThrough(); + } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { + refreshFont(); + } else { + if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { + refreshLabel(); + } + if (getParser() instanceof ISemanticParser) { + ISemanticParser modelParser = + (ISemanticParser) getParser(); + if (modelParser.areSemanticElementsAffected(null, event)) { + removeSemanticListeners(); + if (resolveSemanticElement() != null) { + addSemanticListeners(); + } + refreshLabel(); + } + } + } + super.handleNotificationEvent(event); + } + + /** + * @generated + */ + @Override + protected IFigure createFigure() { + IFigure label = createFigurePrim(); + defaultText = getLabelTextHelper(label); + return label; + } + + /** + * @generated + */ + protected IFigure createFigurePrim() { + return new PapyrusWrappingLabel(); + } + +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ActivityCompositeFloatingLabelEditPartCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ActivityCompositeFloatingLabelEditPartCN.java new file mode 100644 index 00000000000..f44da5f3778 --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ActivityCompositeFloatingLabelEditPartCN.java @@ -0,0 +1,860 @@ +/** + * 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.uml.diagram.composite.edit.parts; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.Label; +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.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.RunnableWithResult; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gef.AccessibleEditPart; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.Request; +import org.eclipse.gef.requests.DirectEditRequest; +import org.eclipse.gef.tools.DirectEditManager; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; +import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; +import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; +import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; +import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; +import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; +import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; +import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; +import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; +import org.eclipse.gmf.runtime.notation.FontStyle; +import org.eclipse.gmf.runtime.notation.NotationPackage; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.text.contentassist.IContentAssistProcessor; +import org.eclipse.jface.viewers.ICellEditorValidator; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.extensionpoints.editors.Activator; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; +import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; +import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.ExternalLabelPrimaryDragRoleEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.PapyrusWrappingLabel; +import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; +import org.eclipse.papyrus.uml.diagram.common.editparts.FloatingLabelEditPart; +import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; +import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; +import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; +import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.accessibility.AccessibleEvent; +import org.eclipse.swt.custom.BusyIndicator; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; +import org.eclipse.uml2.uml.Feature; + +/** + * @generated + */ +public class ActivityCompositeFloatingLabelEditPartCN extends FloatingLabelEditPart + implements ITextAwareEditPart, IBorderItemEditPart +{ + + /** + * @generated + */ + public static final int VISUAL_ID = 6057; + + /** + * @generated + */ + private DirectEditManager manager; + + /** + * @generated + */ + private IParser parser; + + /** + * @generated + */ + private List parserElements; + + /** + * @generated + */ + private String defaultText; + + /** + * direct edition mode (default, undefined, registered editor, etc.) + * + * @generated + */ + protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; + + /** + * configuration from a registered edit dialog + * + * @generated + */ + protected IDirectEditorConfiguration configuration; + + + /** + * @generated + */ + static { + registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.ActivityCompositeFloatingLabelEditPartCN.VISUAL_ID), new Point(0, 0)); + } + + /** + * @generated + */ + public ActivityCompositeFloatingLabelEditPartCN(View view) { + super(view); + } + + /** + * @generated + */ + @Override + protected void createDefaultEditPolicies() { + super.createDefaultEditPolicies(); + installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); + installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ExternalLabelPrimaryDragRoleEditPolicy()); + } + + /** + * @generated + */ + @Override + public IBorderItemLocator getBorderItemLocator() { + IFigure parentFigure = getFigure().getParent(); + if (parentFigure != null && parentFigure.getLayoutManager() != null) { + Object constraint = parentFigure.getLayoutManager().getConstraint(getFigure()); + return (IBorderItemLocator) constraint; + } + return null; + } + + /** + * @generated + */ + @Override + public void refreshBounds() { + int x = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_X())).intValue(); + int y = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_Y())).intValue(); + int width = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Width())).intValue(); + int height = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Height())).intValue(); + getBorderItemLocator().setConstraint(new Rectangle(x, y, width, height)); + } + + + /** + * @generated + */ + protected String getLabelTextHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getText(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getText(); + } else { + return ((Label) figure).getText(); + } + } + + /** + * @generated + */ + protected void setLabelTextHelper(IFigure figure, String text) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setText(text); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setText(text); + } else { + ((Label) figure).setText(text); + } + } + + /** + * @generated + */ + protected Image getLabelIconHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getIcon(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getIcon(); + } else { + return ((Label) figure).getIcon(); + } + } + + /** + * @generated + */ + protected void setLabelIconHelper(IFigure figure, Image icon) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setIcon(icon); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setIcon(icon); + } else { + ((Label) figure).setIcon(icon); + } + } + + /** + * @generated + */ + public void setLabel(IFigure + figure) { + unregisterVisuals(); + setFigure(figure); + defaultText = getLabelTextHelper(figure); + registerVisuals(); + refreshVisuals(); + } + + /** + * @generated + */ + @Override + protected List getModelChildren() { + return Collections.EMPTY_LIST; + } + + /** + * @generated + */ + @Override + public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { + return null; + } + + /** + * @generated + */ + public void setParser(IParser parser) { + this.parser = parser; + } + + /** + * @generated + */ + protected EObject getParserElement() { + return resolveSemanticElement(); + } + + /** + * @generated + */ + protected Image getLabelIcon() { + return null; + } + + /** + * @generated + */ + protected String getLabelText() { + String text = null; + EObject parserElement = getParserElement(); + if (parserElement != null && getParser() != null) { + text = getParser().getPrintString( + new EObjectAdapter(parserElement), + getParserOptions().intValue()); + } + if (text == null || text.length() == 0) { + text = defaultText; + } + return text; + } + + /** + * @generated + */ + @Override + public void setLabelText(String text) { + setLabelTextHelper(getFigure(), text); + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + @Override + public String getEditText() { + if (getParserElement() == null || getParser() == null) { + return ""; //$NON-NLS-1$ + } + return getParser().getEditString( + new EObjectAdapter(getParserElement()), + getParserOptions().intValue()); + } + + /** + * @generated + */ + protected boolean isEditable() { + return getParser() != null; + } + + /** + * @generated + */ + @Override + public ICellEditorValidator getEditTextValidator() { + return new ICellEditorValidator() { + + @Override + public String isValid(final Object value) { + if (value instanceof String) { + final EObject element = getParserElement(); + final IParser parser = getParser(); + try { + IParserEditStatus valid = + (IParserEditStatus) getEditingDomain().runExclusive( + new RunnableWithResult.Impl() { + + @Override + public void run() { + setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); + } + }); + return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); + } catch (InterruptedException ie) { + ie.printStackTrace(); + } + } + + // shouldn't get here + return null; + } + }; + } + + /** + * @generated + */ + @Override + public IContentAssistProcessor getCompletionProcessor() { + if (getParserElement() == null || getParser() == null) { + return null; + } + return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); + } + + /** + * @generated + */ + @Override + public ParserOptions getParserOptions() { + return ParserOptions.NONE; + } + + /** + * @generated + */ + @Override + public IParser getParser() { + if (parser == null) { + parser = UMLParserProvider.getParser(UMLElementTypes.Activity_3072, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.ActivityCompositeFloatingLabelEditPartCN.VISUAL_ID)); + } + return parser; + } + + /** + * @generated + */ + protected DirectEditManager getManager() { + if (manager == null) { + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + } + return manager; + } + + /** + * @generated + */ + protected void setManager(DirectEditManager manager) { + this.manager = manager; + } + + /** + * @generated + */ + protected void performDirectEdit() { + BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { + + @Override + public void run() { + getManager().show(); + } + }); + } + + /** + * @generated + */ + protected void performDirectEdit(Point eventLocation) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); + } + } + + /** + * @generated + */ + private void performDirectEdit(char initialCharacter) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(initialCharacter); + } else { + performDirectEdit(); + } + } + + /** + * @generated + */ + @Override + protected void performDirectEditRequest(Request request) { + + final Request theRequest = request; + + if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { + directEditionMode = getDirectEditionType(); + } + switch (directEditionMode) { + case IDirectEdition.NO_DIRECT_EDITION: + // no direct edition mode => does nothing + return; + case IDirectEdition.EXTENDED_DIRECT_EDITOR: + updateExtendedEditorConfiguration(); + if (configuration == null || configuration.getLanguage() == null) { + // Create default edit manager + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + performDefaultDirectEditorEdit(theRequest); + } else { + configuration.preEditAction(resolveSemanticElement()); + Dialog dialog = null; + if (configuration instanceof ICustomDirectEditorConfiguration) { + setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); + initializeDirectEditManager(theRequest); + return; + } else if (configuration instanceof IPopupEditorConfiguration) { + IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); + helper.showEditor(); + return; + } + else if (configuration instanceof IAdvancedEditorConfiguration) { + dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); + } else if (configuration instanceof IDirectEditorConfiguration) { + dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), + configuration); + } else { + return; + } + final Dialog finalDialog = dialog; + + if (Window.OK == dialog.open()) { + TransactionalEditingDomain domain = getEditingDomain(); + RecordingCommand command = new RecordingCommand(domain, "Edit Label") { + + @Override + protected void doExecute() { + configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); + + } + }; + domain.getCommandStack().execute(command); + } + } + break; + case IDirectEdition.DEFAULT_DIRECT_EDITOR: + initializeDirectEditManager(theRequest); + break; + default: + break; + } + } + + /** + * @generated + */ + protected void initializeDirectEditManager(final Request request) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + @Override + public void run() { + if (isActive() && isEditable()) { + if (request.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } + else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void refreshVisuals() { + super.refreshVisuals(); + refreshLabel(); + refreshFont(); + refreshFontColor(); + refreshUnderline(); + refreshStrikeThrough(); + } + + /** + * @generated + */ + protected void refreshLabel() { + EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); + if (maskLabelPolicy == null) { + maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); + } + if (maskLabelPolicy == null) { + View view = (View) getModel(); + if (view.isVisible()) { + setLabelTextHelper(getFigure(), getLabelText()); + setLabelIconHelper(getFigure(), getLabelIcon()); + } + else { + setLabelTextHelper(getFigure(), ""); //$NON-NLS-1$ + setLabelIconHelper(getFigure(), null); + } + } + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + protected void refreshUnderline() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); + } + if (resolveSemanticElement() instanceof Feature) { + if (((Feature) resolveSemanticElement()).isStatic()) { + ((WrappingLabel) getFigure()).setTextUnderline(true); + } + else { + ((WrappingLabel) getFigure()).setTextUnderline(false); + } + } + } + + /** + * @generated + */ + protected void refreshStrikeThrough() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); + } + } + + /** + * @generated + */ + @Override + protected void refreshFont() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null) { + FontData fontData = new FontData( + style.getFontName(), style.getFontHeight(), + (style.isBold() ? SWT.BOLD : SWT.NORMAL) | + (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); + setFont(fontData); + } + } + + /** + * @generated + */ + @Override + protected void setFontColor(Color color) { + getFigure().setForegroundColor(color); + } + + /** + * @generated + */ + @Override + protected void addSemanticListeners() { + if (getParser() instanceof ISemanticParser) { + EObject element = resolveSemanticElement(); + parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); + for (int i = 0; i < parserElements.size(); i++) { + addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ + } + } else { + super.addSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected void removeSemanticListeners() { + if (parserElements != null) { + for (int i = 0; i < parserElements.size(); i++) { + removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ + } + } else { + super.removeSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected AccessibleEditPart getAccessibleEditPart() { + if (accessibleEP == null) { + accessibleEP = new AccessibleGraphicalEditPart() { + + @Override + public void getName(AccessibleEvent e) { + e.result = getLabelTextHelper(getFigure()); + } + }; + } + return accessibleEP; + } + + /** + * @generated + */ + private View getFontStyleOwnerView() { + return getPrimaryView(); + } + + /** + * Returns the kind of associated editor for direct edition. + * + * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition + * @generated + */ + public int getDirectEditionType() { + if (checkExtendedEditor()) { + initExtendedEditorConfiguration(); + return IDirectEdition.EXTENDED_DIRECT_EDITOR; + } + if (checkDefaultEdition()) { + return IDirectEdition.DEFAULT_DIRECT_EDITOR; + } + + // not a named element. no specific editor => do nothing + return IDirectEdition.NO_DIRECT_EDITION; + } + + /** + * Checks if an extended editor is present. + * + * @return true if an extended editor is present. + * @generated + */ + protected boolean checkExtendedEditor() { + if (resolveSemanticElement() != null) { + return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); + } + return false; + } + + /** + * Checks if a default direct edition is available + * + * @return true if a default direct edition is available + * @generated + */ + protected boolean checkDefaultEdition() { + return (getParser() != null); + } + + /** + * Initializes the extended editor configuration + * + * @generated + */ + protected void initExtendedEditorConfiguration() { + if (configuration == null) { + final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("")) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); + } else { + configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); + } + } + } + + /** + * Updates the preference configuration + * + * @generated + */ + protected void updateExtendedEditorConfiguration() { + String languagePreferred = Activator.getDefault().getPreferenceStore().getString( + IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() + .eClass().getInstanceClassName()); + } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { + configuration = null; + } + } + + /** + * Performs the direct edit usually used by GMF editors. + * + * @param theRequest + * the direct edit request that starts the direct edit system + * @generated + */ + protected void performDefaultDirectEditorEdit(final Request theRequest) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + + @Override + public void run() { + if (isActive() && isEditable()) { + if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) theRequest.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { + DirectEditRequest editRequest = (DirectEditRequest) theRequest; + performDirectEdit(editRequest.getLocation()); + } else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + + /** + * @generated + */ + @Override + protected void handleNotificationEvent(Notification event) { + Object feature = event.getFeature(); + if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { + Integer c = (Integer) event.getNewValue(); + setFontColor(DiagramColorRegistry.getInstance().getColor(c)); + } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { + refreshUnderline(); + } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { + refreshStrikeThrough(); + } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { + refreshFont(); + } else { + if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { + refreshLabel(); + } + if (getParser() instanceof ISemanticParser) { + ISemanticParser modelParser = + (ISemanticParser) getParser(); + if (modelParser.areSemanticElementsAffected(null, event)) { + removeSemanticListeners(); + if (resolveSemanticElement() != null) { + addSemanticListeners(); + } + refreshLabel(); + } + } + } + super.handleNotificationEvent(event); + } + + /** + * @generated + */ + @Override + protected IFigure createFigure() { + IFigure label = createFigurePrim(); + defaultText = getLabelTextHelper(label); + return label; + } + + /** + * @generated + */ + protected IFigure createFigurePrim() { + return new PapyrusWrappingLabel(); + } + +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ActivityCompositeNameEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ActivityCompositeNameEditPart.java index 70690b25716..1ee60ee95bc 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ActivityCompositeNameEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ActivityCompositeNameEditPart.java @@ -864,7 +864,7 @@ public class ActivityCompositeNameEditPart extends PapyrusCompartmentEditPart im * @generated */ protected void addOwnerElementListeners() { - addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); + addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ActivityCompositeNameEditPartCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ActivityCompositeNameEditPartCN.java index 15430f4d634..dd942996947 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ActivityCompositeNameEditPartCN.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ActivityCompositeNameEditPartCN.java @@ -864,7 +864,7 @@ public class ActivityCompositeNameEditPartCN extends PapyrusCompartmentEditPart * @generated */ protected void addOwnerElementListeners() { - addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); + addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ActorEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ActorEditPart.java index 8cebbfc4443..42ae9548ad5 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ActorEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ActorEditPart.java @@ -11,27 +11,37 @@ */ package org.eclipse.papyrus.uml.diagram.composite.edit.parts; +import java.util.Collections; +import java.util.List; + import org.eclipse.draw2d.IFigure; import org.eclipse.gef.EditPart; import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.GraphicalEditPart; 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.handles.MoveHandle; import org.eclipse.gef.requests.CreateRequest; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.BorderItemSelectionEditPolicy; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles; +import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; -import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure; import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure; import org.eclipse.gmf.runtime.notation.View; import org.eclipse.papyrus.infra.gmfdiag.common.editpart.NodeEditPart; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.GetChildLayoutEditPolicy; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.IPapyrusNodeFigure; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.RoundedRectangleNodePlateFigure; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.SelectableBorderedNodeFigure; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeNodeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.QualifiedNameDisplayEditPolicy; -import org.eclipse.papyrus.uml.diagram.common.figure.node.NodeNamedElementFigure; +import org.eclipse.papyrus.uml.diagram.common.figure.node.RoundedCompartmentFigure; +import org.eclipse.papyrus.uml.diagram.common.locator.RoundedRectangleLabelPositionLocator; import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.CustomGraphicalNodeEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.edit.policies.ActorItemSemanticEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; @@ -75,6 +85,7 @@ public class ActorEditPart extends NodeEditPart { installEditPolicy(QualifiedNameDisplayEditPolicy.QUALIFIED_NAME_POLICY, new QualifiedNameDisplayEditPolicy()); installEditPolicy(AppliedStereotypeLabelDisplayEditPolicy.STEREOTYPE_LABEL_POLICY, new AppliedStereotypeNodeLabelDisplayEditPolicy()); installEditPolicy(EditPolicy.GRAPHICAL_NODE_ROLE, new CustomGraphicalNodeEditPolicy()); + installEditPolicy(EditPolicy.LAYOUT_ROLE, new GetChildLayoutEditPolicy()); // XXX need an SCR to runtime to have another abstract superclass that would let children add reasonable editpolicies // removeEditPolicy(org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles.CONNECTION_HANDLES_ROLE); } @@ -87,6 +98,20 @@ public class ActorEditPart extends NodeEditPart { @Override protected EditPolicy createChildEditPolicy(EditPart child) { + View childView = (View) child.getModel(); + switch (UMLVisualIDRegistry.getVisualID(childView)) { + case ActorFloatingLabelEditPart.VISUAL_ID: + return new BorderItemSelectionEditPolicy() { + + @Override + protected List createSelectionHandles() { + MoveHandle mh = new MoveHandle((GraphicalEditPart) getHost()); + mh.setBorder(null); + return Collections.singletonList(mh); + } + } + ; + } EditPolicy result = child.getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); if (result == null) { result = new NonResizableEditPolicy(); @@ -112,7 +137,7 @@ public class ActorEditPart extends NodeEditPart { */ @Override protected IFigure createNodeShape() { - return primaryShape = new NodeNamedElementFigure(); + return primaryShape = new RoundedCompartmentFigure(); } /** @@ -121,8 +146,8 @@ public class ActorEditPart extends NodeEditPart { * @generated */ @Override - public NodeNamedElementFigure getPrimaryShape() { - return (NodeNamedElementFigure) primaryShape; + public RoundedCompartmentFigure getPrimaryShape() { + return (RoundedCompartmentFigure) primaryShape; } /** @@ -175,15 +200,32 @@ public class ActorEditPart extends NodeEditPart { */ @Override protected IFigure getContentPaneFor(IGraphicalEditPart editPart) { + if (editPart instanceof IBorderItemEditPart) { + return getBorderedFigure().getBorderItemContainer(); + } return getContentPane(); } + /** + * @generated + */ + @Override + protected void addBorderItem(IFigure borderItemContainer, IBorderItemEditPart borderItemEditPart) { + if (borderItemEditPart instanceof ActorFloatingLabelEditPart) { + IBorderItemLocator locator = new RoundedRectangleLabelPositionLocator(getMainFigure()); + borderItemContainer.add(borderItemEditPart.getFigure(), locator); + } else + { + super.addBorderItem(borderItemContainer, borderItemEditPart); + } + } + /** * @generated */ @Override protected NodeFigure createNodePlate() { - DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(40, 40); + RoundedRectangleNodePlateFigure result = new RoundedRectangleNodePlateFigure(40, 40); return result; } @@ -196,7 +238,7 @@ public class ActorEditPart extends NodeEditPart { * @generated */ @Override - protected NodeFigure createNodeFigure() { + protected NodeFigure createMainFigure() { return new SelectableBorderedNodeFigure(createMainFigureWithSVG()); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ActorEditPartCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ActorEditPartCN.java index 00b8a66b849..7d1f5c3a79c 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ActorEditPartCN.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ActorEditPartCN.java @@ -11,27 +11,37 @@ */ package org.eclipse.papyrus.uml.diagram.composite.edit.parts; +import java.util.Collections; +import java.util.List; + import org.eclipse.draw2d.IFigure; import org.eclipse.gef.EditPart; import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.GraphicalEditPart; 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.handles.MoveHandle; import org.eclipse.gef.requests.CreateRequest; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.BorderItemSelectionEditPolicy; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles; +import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; -import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure; import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure; import org.eclipse.gmf.runtime.notation.View; import org.eclipse.papyrus.infra.gmfdiag.common.editpart.NodeEditPart; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.GetChildLayoutEditPolicy; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.IPapyrusNodeFigure; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.RoundedRectangleNodePlateFigure; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.SelectableBorderedNodeFigure; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeNodeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.QualifiedNameDisplayEditPolicy; -import org.eclipse.papyrus.uml.diagram.common.figure.node.NodeNamedElementFigure; +import org.eclipse.papyrus.uml.diagram.common.figure.node.RoundedCompartmentFigure; +import org.eclipse.papyrus.uml.diagram.common.locator.RoundedRectangleLabelPositionLocator; import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.CustomGraphicalNodeEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.edit.policies.ActorItemSemanticEditPolicyCN; import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; @@ -75,6 +85,7 @@ public class ActorEditPartCN extends NodeEditPart { installEditPolicy(QualifiedNameDisplayEditPolicy.QUALIFIED_NAME_POLICY, new QualifiedNameDisplayEditPolicy()); installEditPolicy(AppliedStereotypeLabelDisplayEditPolicy.STEREOTYPE_LABEL_POLICY, new AppliedStereotypeNodeLabelDisplayEditPolicy()); installEditPolicy(EditPolicy.GRAPHICAL_NODE_ROLE, new CustomGraphicalNodeEditPolicy()); + installEditPolicy(EditPolicy.LAYOUT_ROLE, new GetChildLayoutEditPolicy()); // XXX need an SCR to runtime to have another abstract superclass that would let children add reasonable editpolicies // removeEditPolicy(org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles.CONNECTION_HANDLES_ROLE); } @@ -87,6 +98,20 @@ public class ActorEditPartCN extends NodeEditPart { @Override protected EditPolicy createChildEditPolicy(EditPart child) { + View childView = (View) child.getModel(); + switch (UMLVisualIDRegistry.getVisualID(childView)) { + case ActorFloatingLabelEditPartCN.VISUAL_ID: + return new BorderItemSelectionEditPolicy() { + + @Override + protected List createSelectionHandles() { + MoveHandle mh = new MoveHandle((GraphicalEditPart) getHost()); + mh.setBorder(null); + return Collections.singletonList(mh); + } + } + ; + } EditPolicy result = child.getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); if (result == null) { result = new NonResizableEditPolicy(); @@ -112,7 +137,7 @@ public class ActorEditPartCN extends NodeEditPart { */ @Override protected IFigure createNodeShape() { - return primaryShape = new NodeNamedElementFigure(); + return primaryShape = new RoundedCompartmentFigure(); } /** @@ -121,8 +146,8 @@ public class ActorEditPartCN extends NodeEditPart { * @generated */ @Override - public NodeNamedElementFigure getPrimaryShape() { - return (NodeNamedElementFigure) primaryShape; + public RoundedCompartmentFigure getPrimaryShape() { + return (RoundedCompartmentFigure) primaryShape; } /** @@ -175,15 +200,32 @@ public class ActorEditPartCN extends NodeEditPart { */ @Override protected IFigure getContentPaneFor(IGraphicalEditPart editPart) { + if (editPart instanceof IBorderItemEditPart) { + return getBorderedFigure().getBorderItemContainer(); + } return getContentPane(); } + /** + * @generated + */ + @Override + protected void addBorderItem(IFigure borderItemContainer, IBorderItemEditPart borderItemEditPart) { + if (borderItemEditPart instanceof ActorFloatingLabelEditPartCN) { + IBorderItemLocator locator = new RoundedRectangleLabelPositionLocator(getMainFigure()); + borderItemContainer.add(borderItemEditPart.getFigure(), locator); + } else + { + super.addBorderItem(borderItemContainer, borderItemEditPart); + } + } + /** * @generated */ @Override protected NodeFigure createNodePlate() { - DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(40, 40); + RoundedRectangleNodePlateFigure result = new RoundedRectangleNodePlateFigure(40, 40); return result; } @@ -196,7 +238,7 @@ public class ActorEditPartCN extends NodeEditPart { * @generated */ @Override - protected NodeFigure createNodeFigure() { + protected NodeFigure createMainFigure() { return new SelectableBorderedNodeFigure(createMainFigureWithSVG()); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ActorFloatingLabelEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ActorFloatingLabelEditPart.java new file mode 100644 index 00000000000..f48315b4107 --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ActorFloatingLabelEditPart.java @@ -0,0 +1,860 @@ +/** + * 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.uml.diagram.composite.edit.parts; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.Label; +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.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.RunnableWithResult; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gef.AccessibleEditPart; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.Request; +import org.eclipse.gef.requests.DirectEditRequest; +import org.eclipse.gef.tools.DirectEditManager; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; +import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; +import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; +import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; +import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; +import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; +import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; +import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; +import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; +import org.eclipse.gmf.runtime.notation.FontStyle; +import org.eclipse.gmf.runtime.notation.NotationPackage; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.text.contentassist.IContentAssistProcessor; +import org.eclipse.jface.viewers.ICellEditorValidator; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.extensionpoints.editors.Activator; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; +import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; +import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.ExternalLabelPrimaryDragRoleEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.PapyrusWrappingLabel; +import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; +import org.eclipse.papyrus.uml.diagram.common.editparts.FloatingLabelEditPart; +import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; +import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; +import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; +import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.accessibility.AccessibleEvent; +import org.eclipse.swt.custom.BusyIndicator; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; +import org.eclipse.uml2.uml.Feature; + +/** + * @generated + */ +public class ActorFloatingLabelEditPart extends FloatingLabelEditPart + implements ITextAwareEditPart, IBorderItemEditPart +{ + + /** + * @generated + */ + public static final int VISUAL_ID = 6095; + + /** + * @generated + */ + private DirectEditManager manager; + + /** + * @generated + */ + private IParser parser; + + /** + * @generated + */ + private List parserElements; + + /** + * @generated + */ + private String defaultText; + + /** + * direct edition mode (default, undefined, registered editor, etc.) + * + * @generated + */ + protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; + + /** + * configuration from a registered edit dialog + * + * @generated + */ + protected IDirectEditorConfiguration configuration; + + + /** + * @generated + */ + static { + registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.ActorFloatingLabelEditPart.VISUAL_ID), new Point(0, 0)); + } + + /** + * @generated + */ + public ActorFloatingLabelEditPart(View view) { + super(view); + } + + /** + * @generated + */ + @Override + protected void createDefaultEditPolicies() { + super.createDefaultEditPolicies(); + installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); + installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ExternalLabelPrimaryDragRoleEditPolicy()); + } + + /** + * @generated + */ + @Override + public IBorderItemLocator getBorderItemLocator() { + IFigure parentFigure = getFigure().getParent(); + if (parentFigure != null && parentFigure.getLayoutManager() != null) { + Object constraint = parentFigure.getLayoutManager().getConstraint(getFigure()); + return (IBorderItemLocator) constraint; + } + return null; + } + + /** + * @generated + */ + @Override + public void refreshBounds() { + int x = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_X())).intValue(); + int y = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_Y())).intValue(); + int width = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Width())).intValue(); + int height = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Height())).intValue(); + getBorderItemLocator().setConstraint(new Rectangle(x, y, width, height)); + } + + + /** + * @generated + */ + protected String getLabelTextHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getText(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getText(); + } else { + return ((Label) figure).getText(); + } + } + + /** + * @generated + */ + protected void setLabelTextHelper(IFigure figure, String text) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setText(text); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setText(text); + } else { + ((Label) figure).setText(text); + } + } + + /** + * @generated + */ + protected Image getLabelIconHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getIcon(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getIcon(); + } else { + return ((Label) figure).getIcon(); + } + } + + /** + * @generated + */ + protected void setLabelIconHelper(IFigure figure, Image icon) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setIcon(icon); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setIcon(icon); + } else { + ((Label) figure).setIcon(icon); + } + } + + /** + * @generated + */ + public void setLabel(IFigure + figure) { + unregisterVisuals(); + setFigure(figure); + defaultText = getLabelTextHelper(figure); + registerVisuals(); + refreshVisuals(); + } + + /** + * @generated + */ + @Override + protected List getModelChildren() { + return Collections.EMPTY_LIST; + } + + /** + * @generated + */ + @Override + public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { + return null; + } + + /** + * @generated + */ + public void setParser(IParser parser) { + this.parser = parser; + } + + /** + * @generated + */ + protected EObject getParserElement() { + return resolveSemanticElement(); + } + + /** + * @generated + */ + protected Image getLabelIcon() { + return null; + } + + /** + * @generated + */ + protected String getLabelText() { + String text = null; + EObject parserElement = getParserElement(); + if (parserElement != null && getParser() != null) { + text = getParser().getPrintString( + new EObjectAdapter(parserElement), + getParserOptions().intValue()); + } + if (text == null || text.length() == 0) { + text = defaultText; + } + return text; + } + + /** + * @generated + */ + @Override + public void setLabelText(String text) { + setLabelTextHelper(getFigure(), text); + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + @Override + public String getEditText() { + if (getParserElement() == null || getParser() == null) { + return ""; //$NON-NLS-1$ + } + return getParser().getEditString( + new EObjectAdapter(getParserElement()), + getParserOptions().intValue()); + } + + /** + * @generated + */ + protected boolean isEditable() { + return getParser() != null; + } + + /** + * @generated + */ + @Override + public ICellEditorValidator getEditTextValidator() { + return new ICellEditorValidator() { + + @Override + public String isValid(final Object value) { + if (value instanceof String) { + final EObject element = getParserElement(); + final IParser parser = getParser(); + try { + IParserEditStatus valid = + (IParserEditStatus) getEditingDomain().runExclusive( + new RunnableWithResult.Impl() { + + @Override + public void run() { + setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); + } + }); + return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); + } catch (InterruptedException ie) { + ie.printStackTrace(); + } + } + + // shouldn't get here + return null; + } + }; + } + + /** + * @generated + */ + @Override + public IContentAssistProcessor getCompletionProcessor() { + if (getParserElement() == null || getParser() == null) { + return null; + } + return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); + } + + /** + * @generated + */ + @Override + public ParserOptions getParserOptions() { + return ParserOptions.NONE; + } + + /** + * @generated + */ + @Override + public IParser getParser() { + if (parser == null) { + parser = UMLParserProvider.getParser(UMLElementTypes.Actor_2077, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.ActorFloatingLabelEditPart.VISUAL_ID)); + } + return parser; + } + + /** + * @generated + */ + protected DirectEditManager getManager() { + if (manager == null) { + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + } + return manager; + } + + /** + * @generated + */ + protected void setManager(DirectEditManager manager) { + this.manager = manager; + } + + /** + * @generated + */ + protected void performDirectEdit() { + BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { + + @Override + public void run() { + getManager().show(); + } + }); + } + + /** + * @generated + */ + protected void performDirectEdit(Point eventLocation) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); + } + } + + /** + * @generated + */ + private void performDirectEdit(char initialCharacter) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(initialCharacter); + } else { + performDirectEdit(); + } + } + + /** + * @generated + */ + @Override + protected void performDirectEditRequest(Request request) { + + final Request theRequest = request; + + if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { + directEditionMode = getDirectEditionType(); + } + switch (directEditionMode) { + case IDirectEdition.NO_DIRECT_EDITION: + // no direct edition mode => does nothing + return; + case IDirectEdition.EXTENDED_DIRECT_EDITOR: + updateExtendedEditorConfiguration(); + if (configuration == null || configuration.getLanguage() == null) { + // Create default edit manager + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + performDefaultDirectEditorEdit(theRequest); + } else { + configuration.preEditAction(resolveSemanticElement()); + Dialog dialog = null; + if (configuration instanceof ICustomDirectEditorConfiguration) { + setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); + initializeDirectEditManager(theRequest); + return; + } else if (configuration instanceof IPopupEditorConfiguration) { + IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); + helper.showEditor(); + return; + } + else if (configuration instanceof IAdvancedEditorConfiguration) { + dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); + } else if (configuration instanceof IDirectEditorConfiguration) { + dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), + configuration); + } else { + return; + } + final Dialog finalDialog = dialog; + + if (Window.OK == dialog.open()) { + TransactionalEditingDomain domain = getEditingDomain(); + RecordingCommand command = new RecordingCommand(domain, "Edit Label") { + + @Override + protected void doExecute() { + configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); + + } + }; + domain.getCommandStack().execute(command); + } + } + break; + case IDirectEdition.DEFAULT_DIRECT_EDITOR: + initializeDirectEditManager(theRequest); + break; + default: + break; + } + } + + /** + * @generated + */ + protected void initializeDirectEditManager(final Request request) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + @Override + public void run() { + if (isActive() && isEditable()) { + if (request.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } + else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void refreshVisuals() { + super.refreshVisuals(); + refreshLabel(); + refreshFont(); + refreshFontColor(); + refreshUnderline(); + refreshStrikeThrough(); + } + + /** + * @generated + */ + protected void refreshLabel() { + EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); + if (maskLabelPolicy == null) { + maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); + } + if (maskLabelPolicy == null) { + View view = (View) getModel(); + if (view.isVisible()) { + setLabelTextHelper(getFigure(), getLabelText()); + setLabelIconHelper(getFigure(), getLabelIcon()); + } + else { + setLabelTextHelper(getFigure(), ""); //$NON-NLS-1$ + setLabelIconHelper(getFigure(), null); + } + } + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + protected void refreshUnderline() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); + } + if (resolveSemanticElement() instanceof Feature) { + if (((Feature) resolveSemanticElement()).isStatic()) { + ((WrappingLabel) getFigure()).setTextUnderline(true); + } + else { + ((WrappingLabel) getFigure()).setTextUnderline(false); + } + } + } + + /** + * @generated + */ + protected void refreshStrikeThrough() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); + } + } + + /** + * @generated + */ + @Override + protected void refreshFont() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null) { + FontData fontData = new FontData( + style.getFontName(), style.getFontHeight(), + (style.isBold() ? SWT.BOLD : SWT.NORMAL) | + (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); + setFont(fontData); + } + } + + /** + * @generated + */ + @Override + protected void setFontColor(Color color) { + getFigure().setForegroundColor(color); + } + + /** + * @generated + */ + @Override + protected void addSemanticListeners() { + if (getParser() instanceof ISemanticParser) { + EObject element = resolveSemanticElement(); + parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); + for (int i = 0; i < parserElements.size(); i++) { + addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ + } + } else { + super.addSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected void removeSemanticListeners() { + if (parserElements != null) { + for (int i = 0; i < parserElements.size(); i++) { + removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ + } + } else { + super.removeSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected AccessibleEditPart getAccessibleEditPart() { + if (accessibleEP == null) { + accessibleEP = new AccessibleGraphicalEditPart() { + + @Override + public void getName(AccessibleEvent e) { + e.result = getLabelTextHelper(getFigure()); + } + }; + } + return accessibleEP; + } + + /** + * @generated + */ + private View getFontStyleOwnerView() { + return getPrimaryView(); + } + + /** + * Returns the kind of associated editor for direct edition. + * + * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition + * @generated + */ + public int getDirectEditionType() { + if (checkExtendedEditor()) { + initExtendedEditorConfiguration(); + return IDirectEdition.EXTENDED_DIRECT_EDITOR; + } + if (checkDefaultEdition()) { + return IDirectEdition.DEFAULT_DIRECT_EDITOR; + } + + // not a named element. no specific editor => do nothing + return IDirectEdition.NO_DIRECT_EDITION; + } + + /** + * Checks if an extended editor is present. + * + * @return true if an extended editor is present. + * @generated + */ + protected boolean checkExtendedEditor() { + if (resolveSemanticElement() != null) { + return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); + } + return false; + } + + /** + * Checks if a default direct edition is available + * + * @return true if a default direct edition is available + * @generated + */ + protected boolean checkDefaultEdition() { + return (getParser() != null); + } + + /** + * Initializes the extended editor configuration + * + * @generated + */ + protected void initExtendedEditorConfiguration() { + if (configuration == null) { + final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("")) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); + } else { + configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); + } + } + } + + /** + * Updates the preference configuration + * + * @generated + */ + protected void updateExtendedEditorConfiguration() { + String languagePreferred = Activator.getDefault().getPreferenceStore().getString( + IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() + .eClass().getInstanceClassName()); + } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { + configuration = null; + } + } + + /** + * Performs the direct edit usually used by GMF editors. + * + * @param theRequest + * the direct edit request that starts the direct edit system + * @generated + */ + protected void performDefaultDirectEditorEdit(final Request theRequest) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + + @Override + public void run() { + if (isActive() && isEditable()) { + if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) theRequest.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { + DirectEditRequest editRequest = (DirectEditRequest) theRequest; + performDirectEdit(editRequest.getLocation()); + } else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + + /** + * @generated + */ + @Override + protected void handleNotificationEvent(Notification event) { + Object feature = event.getFeature(); + if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { + Integer c = (Integer) event.getNewValue(); + setFontColor(DiagramColorRegistry.getInstance().getColor(c)); + } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { + refreshUnderline(); + } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { + refreshStrikeThrough(); + } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { + refreshFont(); + } else { + if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { + refreshLabel(); + } + if (getParser() instanceof ISemanticParser) { + ISemanticParser modelParser = + (ISemanticParser) getParser(); + if (modelParser.areSemanticElementsAffected(null, event)) { + removeSemanticListeners(); + if (resolveSemanticElement() != null) { + addSemanticListeners(); + } + refreshLabel(); + } + } + } + super.handleNotificationEvent(event); + } + + /** + * @generated + */ + @Override + protected IFigure createFigure() { + IFigure label = createFigurePrim(); + defaultText = getLabelTextHelper(label); + return label; + } + + /** + * @generated + */ + protected IFigure createFigurePrim() { + return new PapyrusWrappingLabel(); + } + +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ActorFloatingLabelEditPartCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ActorFloatingLabelEditPartCN.java new file mode 100644 index 00000000000..e418c8c6ce8 --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ActorFloatingLabelEditPartCN.java @@ -0,0 +1,860 @@ +/** + * 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.uml.diagram.composite.edit.parts; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.Label; +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.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.RunnableWithResult; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gef.AccessibleEditPart; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.Request; +import org.eclipse.gef.requests.DirectEditRequest; +import org.eclipse.gef.tools.DirectEditManager; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; +import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; +import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; +import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; +import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; +import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; +import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; +import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; +import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; +import org.eclipse.gmf.runtime.notation.FontStyle; +import org.eclipse.gmf.runtime.notation.NotationPackage; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.text.contentassist.IContentAssistProcessor; +import org.eclipse.jface.viewers.ICellEditorValidator; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.extensionpoints.editors.Activator; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; +import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; +import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.ExternalLabelPrimaryDragRoleEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.PapyrusWrappingLabel; +import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; +import org.eclipse.papyrus.uml.diagram.common.editparts.FloatingLabelEditPart; +import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; +import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; +import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; +import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.accessibility.AccessibleEvent; +import org.eclipse.swt.custom.BusyIndicator; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; +import org.eclipse.uml2.uml.Feature; + +/** + * @generated + */ +public class ActorFloatingLabelEditPartCN extends FloatingLabelEditPart + implements ITextAwareEditPart, IBorderItemEditPart +{ + + /** + * @generated + */ + public static final int VISUAL_ID = 6073; + + /** + * @generated + */ + private DirectEditManager manager; + + /** + * @generated + */ + private IParser parser; + + /** + * @generated + */ + private List parserElements; + + /** + * @generated + */ + private String defaultText; + + /** + * direct edition mode (default, undefined, registered editor, etc.) + * + * @generated + */ + protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; + + /** + * configuration from a registered edit dialog + * + * @generated + */ + protected IDirectEditorConfiguration configuration; + + + /** + * @generated + */ + static { + registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.ActorFloatingLabelEditPartCN.VISUAL_ID), new Point(0, 0)); + } + + /** + * @generated + */ + public ActorFloatingLabelEditPartCN(View view) { + super(view); + } + + /** + * @generated + */ + @Override + protected void createDefaultEditPolicies() { + super.createDefaultEditPolicies(); + installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); + installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ExternalLabelPrimaryDragRoleEditPolicy()); + } + + /** + * @generated + */ + @Override + public IBorderItemLocator getBorderItemLocator() { + IFigure parentFigure = getFigure().getParent(); + if (parentFigure != null && parentFigure.getLayoutManager() != null) { + Object constraint = parentFigure.getLayoutManager().getConstraint(getFigure()); + return (IBorderItemLocator) constraint; + } + return null; + } + + /** + * @generated + */ + @Override + public void refreshBounds() { + int x = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_X())).intValue(); + int y = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_Y())).intValue(); + int width = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Width())).intValue(); + int height = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Height())).intValue(); + getBorderItemLocator().setConstraint(new Rectangle(x, y, width, height)); + } + + + /** + * @generated + */ + protected String getLabelTextHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getText(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getText(); + } else { + return ((Label) figure).getText(); + } + } + + /** + * @generated + */ + protected void setLabelTextHelper(IFigure figure, String text) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setText(text); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setText(text); + } else { + ((Label) figure).setText(text); + } + } + + /** + * @generated + */ + protected Image getLabelIconHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getIcon(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getIcon(); + } else { + return ((Label) figure).getIcon(); + } + } + + /** + * @generated + */ + protected void setLabelIconHelper(IFigure figure, Image icon) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setIcon(icon); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setIcon(icon); + } else { + ((Label) figure).setIcon(icon); + } + } + + /** + * @generated + */ + public void setLabel(IFigure + figure) { + unregisterVisuals(); + setFigure(figure); + defaultText = getLabelTextHelper(figure); + registerVisuals(); + refreshVisuals(); + } + + /** + * @generated + */ + @Override + protected List getModelChildren() { + return Collections.EMPTY_LIST; + } + + /** + * @generated + */ + @Override + public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { + return null; + } + + /** + * @generated + */ + public void setParser(IParser parser) { + this.parser = parser; + } + + /** + * @generated + */ + protected EObject getParserElement() { + return resolveSemanticElement(); + } + + /** + * @generated + */ + protected Image getLabelIcon() { + return null; + } + + /** + * @generated + */ + protected String getLabelText() { + String text = null; + EObject parserElement = getParserElement(); + if (parserElement != null && getParser() != null) { + text = getParser().getPrintString( + new EObjectAdapter(parserElement), + getParserOptions().intValue()); + } + if (text == null || text.length() == 0) { + text = defaultText; + } + return text; + } + + /** + * @generated + */ + @Override + public void setLabelText(String text) { + setLabelTextHelper(getFigure(), text); + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + @Override + public String getEditText() { + if (getParserElement() == null || getParser() == null) { + return ""; //$NON-NLS-1$ + } + return getParser().getEditString( + new EObjectAdapter(getParserElement()), + getParserOptions().intValue()); + } + + /** + * @generated + */ + protected boolean isEditable() { + return getParser() != null; + } + + /** + * @generated + */ + @Override + public ICellEditorValidator getEditTextValidator() { + return new ICellEditorValidator() { + + @Override + public String isValid(final Object value) { + if (value instanceof String) { + final EObject element = getParserElement(); + final IParser parser = getParser(); + try { + IParserEditStatus valid = + (IParserEditStatus) getEditingDomain().runExclusive( + new RunnableWithResult.Impl() { + + @Override + public void run() { + setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); + } + }); + return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); + } catch (InterruptedException ie) { + ie.printStackTrace(); + } + } + + // shouldn't get here + return null; + } + }; + } + + /** + * @generated + */ + @Override + public IContentAssistProcessor getCompletionProcessor() { + if (getParserElement() == null || getParser() == null) { + return null; + } + return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); + } + + /** + * @generated + */ + @Override + public ParserOptions getParserOptions() { + return ParserOptions.NONE; + } + + /** + * @generated + */ + @Override + public IParser getParser() { + if (parser == null) { + parser = UMLParserProvider.getParser(UMLElementTypes.Actor_3091, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.ActorFloatingLabelEditPartCN.VISUAL_ID)); + } + return parser; + } + + /** + * @generated + */ + protected DirectEditManager getManager() { + if (manager == null) { + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + } + return manager; + } + + /** + * @generated + */ + protected void setManager(DirectEditManager manager) { + this.manager = manager; + } + + /** + * @generated + */ + protected void performDirectEdit() { + BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { + + @Override + public void run() { + getManager().show(); + } + }); + } + + /** + * @generated + */ + protected void performDirectEdit(Point eventLocation) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); + } + } + + /** + * @generated + */ + private void performDirectEdit(char initialCharacter) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(initialCharacter); + } else { + performDirectEdit(); + } + } + + /** + * @generated + */ + @Override + protected void performDirectEditRequest(Request request) { + + final Request theRequest = request; + + if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { + directEditionMode = getDirectEditionType(); + } + switch (directEditionMode) { + case IDirectEdition.NO_DIRECT_EDITION: + // no direct edition mode => does nothing + return; + case IDirectEdition.EXTENDED_DIRECT_EDITOR: + updateExtendedEditorConfiguration(); + if (configuration == null || configuration.getLanguage() == null) { + // Create default edit manager + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + performDefaultDirectEditorEdit(theRequest); + } else { + configuration.preEditAction(resolveSemanticElement()); + Dialog dialog = null; + if (configuration instanceof ICustomDirectEditorConfiguration) { + setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); + initializeDirectEditManager(theRequest); + return; + } else if (configuration instanceof IPopupEditorConfiguration) { + IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); + helper.showEditor(); + return; + } + else if (configuration instanceof IAdvancedEditorConfiguration) { + dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); + } else if (configuration instanceof IDirectEditorConfiguration) { + dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), + configuration); + } else { + return; + } + final Dialog finalDialog = dialog; + + if (Window.OK == dialog.open()) { + TransactionalEditingDomain domain = getEditingDomain(); + RecordingCommand command = new RecordingCommand(domain, "Edit Label") { + + @Override + protected void doExecute() { + configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); + + } + }; + domain.getCommandStack().execute(command); + } + } + break; + case IDirectEdition.DEFAULT_DIRECT_EDITOR: + initializeDirectEditManager(theRequest); + break; + default: + break; + } + } + + /** + * @generated + */ + protected void initializeDirectEditManager(final Request request) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + @Override + public void run() { + if (isActive() && isEditable()) { + if (request.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } + else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void refreshVisuals() { + super.refreshVisuals(); + refreshLabel(); + refreshFont(); + refreshFontColor(); + refreshUnderline(); + refreshStrikeThrough(); + } + + /** + * @generated + */ + protected void refreshLabel() { + EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); + if (maskLabelPolicy == null) { + maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); + } + if (maskLabelPolicy == null) { + View view = (View) getModel(); + if (view.isVisible()) { + setLabelTextHelper(getFigure(), getLabelText()); + setLabelIconHelper(getFigure(), getLabelIcon()); + } + else { + setLabelTextHelper(getFigure(), ""); //$NON-NLS-1$ + setLabelIconHelper(getFigure(), null); + } + } + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + protected void refreshUnderline() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); + } + if (resolveSemanticElement() instanceof Feature) { + if (((Feature) resolveSemanticElement()).isStatic()) { + ((WrappingLabel) getFigure()).setTextUnderline(true); + } + else { + ((WrappingLabel) getFigure()).setTextUnderline(false); + } + } + } + + /** + * @generated + */ + protected void refreshStrikeThrough() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); + } + } + + /** + * @generated + */ + @Override + protected void refreshFont() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null) { + FontData fontData = new FontData( + style.getFontName(), style.getFontHeight(), + (style.isBold() ? SWT.BOLD : SWT.NORMAL) | + (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); + setFont(fontData); + } + } + + /** + * @generated + */ + @Override + protected void setFontColor(Color color) { + getFigure().setForegroundColor(color); + } + + /** + * @generated + */ + @Override + protected void addSemanticListeners() { + if (getParser() instanceof ISemanticParser) { + EObject element = resolveSemanticElement(); + parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); + for (int i = 0; i < parserElements.size(); i++) { + addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ + } + } else { + super.addSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected void removeSemanticListeners() { + if (parserElements != null) { + for (int i = 0; i < parserElements.size(); i++) { + removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ + } + } else { + super.removeSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected AccessibleEditPart getAccessibleEditPart() { + if (accessibleEP == null) { + accessibleEP = new AccessibleGraphicalEditPart() { + + @Override + public void getName(AccessibleEvent e) { + e.result = getLabelTextHelper(getFigure()); + } + }; + } + return accessibleEP; + } + + /** + * @generated + */ + private View getFontStyleOwnerView() { + return getPrimaryView(); + } + + /** + * Returns the kind of associated editor for direct edition. + * + * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition + * @generated + */ + public int getDirectEditionType() { + if (checkExtendedEditor()) { + initExtendedEditorConfiguration(); + return IDirectEdition.EXTENDED_DIRECT_EDITOR; + } + if (checkDefaultEdition()) { + return IDirectEdition.DEFAULT_DIRECT_EDITOR; + } + + // not a named element. no specific editor => do nothing + return IDirectEdition.NO_DIRECT_EDITION; + } + + /** + * Checks if an extended editor is present. + * + * @return true if an extended editor is present. + * @generated + */ + protected boolean checkExtendedEditor() { + if (resolveSemanticElement() != null) { + return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); + } + return false; + } + + /** + * Checks if a default direct edition is available + * + * @return true if a default direct edition is available + * @generated + */ + protected boolean checkDefaultEdition() { + return (getParser() != null); + } + + /** + * Initializes the extended editor configuration + * + * @generated + */ + protected void initExtendedEditorConfiguration() { + if (configuration == null) { + final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("")) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); + } else { + configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); + } + } + } + + /** + * Updates the preference configuration + * + * @generated + */ + protected void updateExtendedEditorConfiguration() { + String languagePreferred = Activator.getDefault().getPreferenceStore().getString( + IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() + .eClass().getInstanceClassName()); + } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { + configuration = null; + } + } + + /** + * Performs the direct edit usually used by GMF editors. + * + * @param theRequest + * the direct edit request that starts the direct edit system + * @generated + */ + protected void performDefaultDirectEditorEdit(final Request theRequest) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + + @Override + public void run() { + if (isActive() && isEditable()) { + if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) theRequest.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { + DirectEditRequest editRequest = (DirectEditRequest) theRequest; + performDirectEdit(editRequest.getLocation()); + } else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + + /** + * @generated + */ + @Override + protected void handleNotificationEvent(Notification event) { + Object feature = event.getFeature(); + if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { + Integer c = (Integer) event.getNewValue(); + setFontColor(DiagramColorRegistry.getInstance().getColor(c)); + } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { + refreshUnderline(); + } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { + refreshStrikeThrough(); + } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { + refreshFont(); + } else { + if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { + refreshLabel(); + } + if (getParser() instanceof ISemanticParser) { + ISemanticParser modelParser = + (ISemanticParser) getParser(); + if (modelParser.areSemanticElementsAffected(null, event)) { + removeSemanticListeners(); + if (resolveSemanticElement() != null) { + addSemanticListeners(); + } + refreshLabel(); + } + } + } + super.handleNotificationEvent(event); + } + + /** + * @generated + */ + @Override + protected IFigure createFigure() { + IFigure label = createFigurePrim(); + defaultText = getLabelTextHelper(label); + return label; + } + + /** + * @generated + */ + protected IFigure createFigurePrim() { + return new PapyrusWrappingLabel(); + } + +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ActorNameEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ActorNameEditPart.java index f9c4061bd48..3709db6bd9d 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ActorNameEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ActorNameEditPart.java @@ -864,7 +864,7 @@ public class ActorNameEditPart extends PapyrusCompartmentEditPart implements ITe * @generated */ protected void addOwnerElementListeners() { - addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); + addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ActorNameEditPartCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ActorNameEditPartCN.java index 6f1e91adf7d..8cbcce3439e 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ActorNameEditPartCN.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ActorNameEditPartCN.java @@ -864,7 +864,7 @@ public class ActorNameEditPartCN extends PapyrusCompartmentEditPart implements I * @generated */ protected void addOwnerElementListeners() { - addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); + addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/AnyReceiveEventEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/AnyReceiveEventEditPart.java index f5b6f7c8694..c2c5febfe63 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/AnyReceiveEventEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/AnyReceiveEventEditPart.java @@ -11,27 +11,40 @@ */ package org.eclipse.papyrus.uml.diagram.composite.edit.parts; +import java.util.Collections; +import java.util.List; + import org.eclipse.draw2d.IFigure; +import org.eclipse.emf.common.notify.Notification; import org.eclipse.gef.EditPart; import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.GraphicalEditPart; 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.handles.MoveHandle; import org.eclipse.gef.requests.CreateRequest; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.BorderItemSelectionEditPolicy; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles; +import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; -import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure; import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure; +import org.eclipse.gmf.runtime.notation.Edge; +import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.gmf.runtime.notation.View; -import org.eclipse.papyrus.infra.gmfdiag.common.editpart.NodeEditPart; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.GetChildLayoutEditPolicy; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.IPapyrusNodeFigure; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.RoundedRectangleNodePlateFigure; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.SelectableBorderedNodeFigure; +import org.eclipse.papyrus.uml.diagram.common.editparts.RoundedCompartmentEditPart; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeNodeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.QualifiedNameDisplayEditPolicy; -import org.eclipse.papyrus.uml.diagram.common.figure.node.NodeNamedElementFigure; +import org.eclipse.papyrus.uml.diagram.common.figure.node.RoundedCompartmentFigure; +import org.eclipse.papyrus.uml.diagram.common.locator.RoundedRectangleLabelPositionLocator; import org.eclipse.papyrus.uml.diagram.composite.edit.policies.AnyReceiveEventItemSemanticEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; import org.eclipse.swt.graphics.Color; @@ -39,7 +52,7 @@ import org.eclipse.swt.graphics.Color; /** * @generated */ -public class AnyReceiveEventEditPart extends NodeEditPart { +public class AnyReceiveEventEditPart extends RoundedCompartmentEditPart { /** * @generated @@ -73,6 +86,7 @@ public class AnyReceiveEventEditPart extends NodeEditPart { installEditPolicy(EditPolicy.LAYOUT_ROLE, createLayoutEditPolicy()); installEditPolicy(QualifiedNameDisplayEditPolicy.QUALIFIED_NAME_POLICY, new QualifiedNameDisplayEditPolicy()); installEditPolicy(AppliedStereotypeLabelDisplayEditPolicy.STEREOTYPE_LABEL_POLICY, new AppliedStereotypeNodeLabelDisplayEditPolicy()); + installEditPolicy(EditPolicy.LAYOUT_ROLE, new GetChildLayoutEditPolicy()); // XXX need an SCR to runtime to have another abstract superclass that would let children add reasonable editpolicies // removeEditPolicy(org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles.CONNECTION_HANDLES_ROLE); } @@ -85,6 +99,20 @@ public class AnyReceiveEventEditPart extends NodeEditPart { @Override protected EditPolicy createChildEditPolicy(EditPart child) { + View childView = (View) child.getModel(); + switch (UMLVisualIDRegistry.getVisualID(childView)) { + case AnyReceiveEventFloatingLabelEditPart.VISUAL_ID: + return new BorderItemSelectionEditPolicy() { + + @Override + protected List createSelectionHandles() { + MoveHandle mh = new MoveHandle((GraphicalEditPart) getHost()); + mh.setBorder(null); + return Collections.singletonList(mh); + } + } + ; + } EditPolicy result = child.getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); if (result == null) { result = new NonResizableEditPolicy(); @@ -105,12 +133,36 @@ public class AnyReceiveEventEditPart extends NodeEditPart { return lep; } + /** + * Papyrus codeGen + * + * @generated + **/ + @Override + protected void handleNotificationEvent(Notification event) { + /* + * when a node have external node labels, the methods refreshChildren() remove the EditPart corresponding to the Label from the EditPart + * Registry. After that, we can't reset the visibility to true (using the Show/Hide Label Action)! + */ + if (NotationPackage.eINSTANCE.getView_Visible().equals(event.getFeature())) { + Object notifier = event.getNotifier(); + List modelChildren = ((View) getModel()).getChildren(); + if (!(notifier instanceof Edge)) { + if (modelChildren.contains(event.getNotifier())) { + return; + } + } + } + super.handleNotificationEvent(event); + + } + /** * @generated */ @Override protected IFigure createNodeShape() { - return primaryShape = new NodeNamedElementFigure(); + return primaryShape = new RoundedCompartmentFigure(); } /** @@ -119,8 +171,8 @@ public class AnyReceiveEventEditPart extends NodeEditPart { * @generated */ @Override - public NodeNamedElementFigure getPrimaryShape() { - return (NodeNamedElementFigure) primaryShape; + public RoundedCompartmentFigure getPrimaryShape() { + return (RoundedCompartmentFigure) primaryShape; } /** @@ -173,15 +225,32 @@ public class AnyReceiveEventEditPart extends NodeEditPart { */ @Override protected IFigure getContentPaneFor(IGraphicalEditPart editPart) { + if (editPart instanceof IBorderItemEditPart) { + return getBorderedFigure().getBorderItemContainer(); + } return getContentPane(); } + /** + * @generated + */ + @Override + protected void addBorderItem(IFigure borderItemContainer, IBorderItemEditPart borderItemEditPart) { + if (borderItemEditPart instanceof AnyReceiveEventFloatingLabelEditPart) { + IBorderItemLocator locator = new RoundedRectangleLabelPositionLocator(getMainFigure()); + borderItemContainer.add(borderItemEditPart.getFigure(), locator); + } else + { + super.addBorderItem(borderItemContainer, borderItemEditPart); + } + } + /** * @generated */ @Override protected NodeFigure createNodePlate() { - DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(40, 40); + RoundedRectangleNodePlateFigure result = new RoundedRectangleNodePlateFigure(40, 40); return result; } @@ -194,7 +263,7 @@ public class AnyReceiveEventEditPart extends NodeEditPart { * @generated */ @Override - protected NodeFigure createNodeFigure() { + protected NodeFigure createMainFigure() { return new SelectableBorderedNodeFigure(createMainFigureWithSVG()); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/AnyReceiveEventFloatingLabelEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/AnyReceiveEventFloatingLabelEditPart.java new file mode 100644 index 00000000000..6085d59ef36 --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/AnyReceiveEventFloatingLabelEditPart.java @@ -0,0 +1,860 @@ +/** + * 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.uml.diagram.composite.edit.parts; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.Label; +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.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.RunnableWithResult; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gef.AccessibleEditPart; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.Request; +import org.eclipse.gef.requests.DirectEditRequest; +import org.eclipse.gef.tools.DirectEditManager; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; +import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; +import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; +import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; +import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; +import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; +import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; +import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; +import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; +import org.eclipse.gmf.runtime.notation.FontStyle; +import org.eclipse.gmf.runtime.notation.NotationPackage; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.text.contentassist.IContentAssistProcessor; +import org.eclipse.jface.viewers.ICellEditorValidator; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.extensionpoints.editors.Activator; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; +import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; +import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.ExternalLabelPrimaryDragRoleEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.PapyrusWrappingLabel; +import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; +import org.eclipse.papyrus.uml.diagram.common.editparts.FloatingLabelEditPart; +import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; +import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; +import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; +import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.accessibility.AccessibleEvent; +import org.eclipse.swt.custom.BusyIndicator; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; +import org.eclipse.uml2.uml.Feature; + +/** + * @generated + */ +public class AnyReceiveEventFloatingLabelEditPart extends FloatingLabelEditPart + implements ITextAwareEditPart, IBorderItemEditPart +{ + + /** + * @generated + */ + public static final int VISUAL_ID = 6103; + + /** + * @generated + */ + private DirectEditManager manager; + + /** + * @generated + */ + private IParser parser; + + /** + * @generated + */ + private List parserElements; + + /** + * @generated + */ + private String defaultText; + + /** + * direct edition mode (default, undefined, registered editor, etc.) + * + * @generated + */ + protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; + + /** + * configuration from a registered edit dialog + * + * @generated + */ + protected IDirectEditorConfiguration configuration; + + + /** + * @generated + */ + static { + registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.AnyReceiveEventFloatingLabelEditPart.VISUAL_ID), new Point(0, 0)); + } + + /** + * @generated + */ + public AnyReceiveEventFloatingLabelEditPart(View view) { + super(view); + } + + /** + * @generated + */ + @Override + protected void createDefaultEditPolicies() { + super.createDefaultEditPolicies(); + installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); + installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ExternalLabelPrimaryDragRoleEditPolicy()); + } + + /** + * @generated + */ + @Override + public IBorderItemLocator getBorderItemLocator() { + IFigure parentFigure = getFigure().getParent(); + if (parentFigure != null && parentFigure.getLayoutManager() != null) { + Object constraint = parentFigure.getLayoutManager().getConstraint(getFigure()); + return (IBorderItemLocator) constraint; + } + return null; + } + + /** + * @generated + */ + @Override + public void refreshBounds() { + int x = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_X())).intValue(); + int y = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_Y())).intValue(); + int width = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Width())).intValue(); + int height = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Height())).intValue(); + getBorderItemLocator().setConstraint(new Rectangle(x, y, width, height)); + } + + + /** + * @generated + */ + protected String getLabelTextHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getText(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getText(); + } else { + return ((Label) figure).getText(); + } + } + + /** + * @generated + */ + protected void setLabelTextHelper(IFigure figure, String text) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setText(text); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setText(text); + } else { + ((Label) figure).setText(text); + } + } + + /** + * @generated + */ + protected Image getLabelIconHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getIcon(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getIcon(); + } else { + return ((Label) figure).getIcon(); + } + } + + /** + * @generated + */ + protected void setLabelIconHelper(IFigure figure, Image icon) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setIcon(icon); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setIcon(icon); + } else { + ((Label) figure).setIcon(icon); + } + } + + /** + * @generated + */ + public void setLabel(IFigure + figure) { + unregisterVisuals(); + setFigure(figure); + defaultText = getLabelTextHelper(figure); + registerVisuals(); + refreshVisuals(); + } + + /** + * @generated + */ + @Override + protected List getModelChildren() { + return Collections.EMPTY_LIST; + } + + /** + * @generated + */ + @Override + public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { + return null; + } + + /** + * @generated + */ + public void setParser(IParser parser) { + this.parser = parser; + } + + /** + * @generated + */ + protected EObject getParserElement() { + return resolveSemanticElement(); + } + + /** + * @generated + */ + protected Image getLabelIcon() { + return null; + } + + /** + * @generated + */ + protected String getLabelText() { + String text = null; + EObject parserElement = getParserElement(); + if (parserElement != null && getParser() != null) { + text = getParser().getPrintString( + new EObjectAdapter(parserElement), + getParserOptions().intValue()); + } + if (text == null || text.length() == 0) { + text = defaultText; + } + return text; + } + + /** + * @generated + */ + @Override + public void setLabelText(String text) { + setLabelTextHelper(getFigure(), text); + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + @Override + public String getEditText() { + if (getParserElement() == null || getParser() == null) { + return ""; //$NON-NLS-1$ + } + return getParser().getEditString( + new EObjectAdapter(getParserElement()), + getParserOptions().intValue()); + } + + /** + * @generated + */ + protected boolean isEditable() { + return getParser() != null; + } + + /** + * @generated + */ + @Override + public ICellEditorValidator getEditTextValidator() { + return new ICellEditorValidator() { + + @Override + public String isValid(final Object value) { + if (value instanceof String) { + final EObject element = getParserElement(); + final IParser parser = getParser(); + try { + IParserEditStatus valid = + (IParserEditStatus) getEditingDomain().runExclusive( + new RunnableWithResult.Impl() { + + @Override + public void run() { + setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); + } + }); + return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); + } catch (InterruptedException ie) { + ie.printStackTrace(); + } + } + + // shouldn't get here + return null; + } + }; + } + + /** + * @generated + */ + @Override + public IContentAssistProcessor getCompletionProcessor() { + if (getParserElement() == null || getParser() == null) { + return null; + } + return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); + } + + /** + * @generated + */ + @Override + public ParserOptions getParserOptions() { + return ParserOptions.NONE; + } + + /** + * @generated + */ + @Override + public IParser getParser() { + if (parser == null) { + parser = UMLParserProvider.getParser(UMLElementTypes.AnyReceiveEvent_2085, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.AnyReceiveEventFloatingLabelEditPart.VISUAL_ID)); + } + return parser; + } + + /** + * @generated + */ + protected DirectEditManager getManager() { + if (manager == null) { + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + } + return manager; + } + + /** + * @generated + */ + protected void setManager(DirectEditManager manager) { + this.manager = manager; + } + + /** + * @generated + */ + protected void performDirectEdit() { + BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { + + @Override + public void run() { + getManager().show(); + } + }); + } + + /** + * @generated + */ + protected void performDirectEdit(Point eventLocation) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); + } + } + + /** + * @generated + */ + private void performDirectEdit(char initialCharacter) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(initialCharacter); + } else { + performDirectEdit(); + } + } + + /** + * @generated + */ + @Override + protected void performDirectEditRequest(Request request) { + + final Request theRequest = request; + + if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { + directEditionMode = getDirectEditionType(); + } + switch (directEditionMode) { + case IDirectEdition.NO_DIRECT_EDITION: + // no direct edition mode => does nothing + return; + case IDirectEdition.EXTENDED_DIRECT_EDITOR: + updateExtendedEditorConfiguration(); + if (configuration == null || configuration.getLanguage() == null) { + // Create default edit manager + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + performDefaultDirectEditorEdit(theRequest); + } else { + configuration.preEditAction(resolveSemanticElement()); + Dialog dialog = null; + if (configuration instanceof ICustomDirectEditorConfiguration) { + setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); + initializeDirectEditManager(theRequest); + return; + } else if (configuration instanceof IPopupEditorConfiguration) { + IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); + helper.showEditor(); + return; + } + else if (configuration instanceof IAdvancedEditorConfiguration) { + dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); + } else if (configuration instanceof IDirectEditorConfiguration) { + dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), + configuration); + } else { + return; + } + final Dialog finalDialog = dialog; + + if (Window.OK == dialog.open()) { + TransactionalEditingDomain domain = getEditingDomain(); + RecordingCommand command = new RecordingCommand(domain, "Edit Label") { + + @Override + protected void doExecute() { + configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); + + } + }; + domain.getCommandStack().execute(command); + } + } + break; + case IDirectEdition.DEFAULT_DIRECT_EDITOR: + initializeDirectEditManager(theRequest); + break; + default: + break; + } + } + + /** + * @generated + */ + protected void initializeDirectEditManager(final Request request) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + @Override + public void run() { + if (isActive() && isEditable()) { + if (request.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } + else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void refreshVisuals() { + super.refreshVisuals(); + refreshLabel(); + refreshFont(); + refreshFontColor(); + refreshUnderline(); + refreshStrikeThrough(); + } + + /** + * @generated + */ + protected void refreshLabel() { + EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); + if (maskLabelPolicy == null) { + maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); + } + if (maskLabelPolicy == null) { + View view = (View) getModel(); + if (view.isVisible()) { + setLabelTextHelper(getFigure(), getLabelText()); + setLabelIconHelper(getFigure(), getLabelIcon()); + } + else { + setLabelTextHelper(getFigure(), ""); //$NON-NLS-1$ + setLabelIconHelper(getFigure(), null); + } + } + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + protected void refreshUnderline() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); + } + if (resolveSemanticElement() instanceof Feature) { + if (((Feature) resolveSemanticElement()).isStatic()) { + ((WrappingLabel) getFigure()).setTextUnderline(true); + } + else { + ((WrappingLabel) getFigure()).setTextUnderline(false); + } + } + } + + /** + * @generated + */ + protected void refreshStrikeThrough() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); + } + } + + /** + * @generated + */ + @Override + protected void refreshFont() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null) { + FontData fontData = new FontData( + style.getFontName(), style.getFontHeight(), + (style.isBold() ? SWT.BOLD : SWT.NORMAL) | + (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); + setFont(fontData); + } + } + + /** + * @generated + */ + @Override + protected void setFontColor(Color color) { + getFigure().setForegroundColor(color); + } + + /** + * @generated + */ + @Override + protected void addSemanticListeners() { + if (getParser() instanceof ISemanticParser) { + EObject element = resolveSemanticElement(); + parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); + for (int i = 0; i < parserElements.size(); i++) { + addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ + } + } else { + super.addSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected void removeSemanticListeners() { + if (parserElements != null) { + for (int i = 0; i < parserElements.size(); i++) { + removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ + } + } else { + super.removeSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected AccessibleEditPart getAccessibleEditPart() { + if (accessibleEP == null) { + accessibleEP = new AccessibleGraphicalEditPart() { + + @Override + public void getName(AccessibleEvent e) { + e.result = getLabelTextHelper(getFigure()); + } + }; + } + return accessibleEP; + } + + /** + * @generated + */ + private View getFontStyleOwnerView() { + return getPrimaryView(); + } + + /** + * Returns the kind of associated editor for direct edition. + * + * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition + * @generated + */ + public int getDirectEditionType() { + if (checkExtendedEditor()) { + initExtendedEditorConfiguration(); + return IDirectEdition.EXTENDED_DIRECT_EDITOR; + } + if (checkDefaultEdition()) { + return IDirectEdition.DEFAULT_DIRECT_EDITOR; + } + + // not a named element. no specific editor => do nothing + return IDirectEdition.NO_DIRECT_EDITION; + } + + /** + * Checks if an extended editor is present. + * + * @return true if an extended editor is present. + * @generated + */ + protected boolean checkExtendedEditor() { + if (resolveSemanticElement() != null) { + return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); + } + return false; + } + + /** + * Checks if a default direct edition is available + * + * @return true if a default direct edition is available + * @generated + */ + protected boolean checkDefaultEdition() { + return (getParser() != null); + } + + /** + * Initializes the extended editor configuration + * + * @generated + */ + protected void initExtendedEditorConfiguration() { + if (configuration == null) { + final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("")) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); + } else { + configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); + } + } + } + + /** + * Updates the preference configuration + * + * @generated + */ + protected void updateExtendedEditorConfiguration() { + String languagePreferred = Activator.getDefault().getPreferenceStore().getString( + IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() + .eClass().getInstanceClassName()); + } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { + configuration = null; + } + } + + /** + * Performs the direct edit usually used by GMF editors. + * + * @param theRequest + * the direct edit request that starts the direct edit system + * @generated + */ + protected void performDefaultDirectEditorEdit(final Request theRequest) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + + @Override + public void run() { + if (isActive() && isEditable()) { + if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) theRequest.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { + DirectEditRequest editRequest = (DirectEditRequest) theRequest; + performDirectEdit(editRequest.getLocation()); + } else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + + /** + * @generated + */ + @Override + protected void handleNotificationEvent(Notification event) { + Object feature = event.getFeature(); + if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { + Integer c = (Integer) event.getNewValue(); + setFontColor(DiagramColorRegistry.getInstance().getColor(c)); + } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { + refreshUnderline(); + } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { + refreshStrikeThrough(); + } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { + refreshFont(); + } else { + if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { + refreshLabel(); + } + if (getParser() instanceof ISemanticParser) { + ISemanticParser modelParser = + (ISemanticParser) getParser(); + if (modelParser.areSemanticElementsAffected(null, event)) { + removeSemanticListeners(); + if (resolveSemanticElement() != null) { + addSemanticListeners(); + } + refreshLabel(); + } + } + } + super.handleNotificationEvent(event); + } + + /** + * @generated + */ + @Override + protected IFigure createFigure() { + IFigure label = createFigurePrim(); + defaultText = getLabelTextHelper(label); + return label; + } + + /** + * @generated + */ + protected IFigure createFigurePrim() { + return new PapyrusWrappingLabel(); + } + +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/AnyReceiveEventNameEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/AnyReceiveEventNameEditPart.java index bacec8cea8a..2e18338d8ac 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/AnyReceiveEventNameEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/AnyReceiveEventNameEditPart.java @@ -864,7 +864,7 @@ public class AnyReceiveEventNameEditPart extends PapyrusCompartmentEditPart impl * @generated */ protected void addOwnerElementListeners() { - addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); + addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ArtifactEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ArtifactEditPart.java index 31551aa9ec1..9189f903456 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ArtifactEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ArtifactEditPart.java @@ -11,27 +11,37 @@ */ package org.eclipse.papyrus.uml.diagram.composite.edit.parts; +import java.util.Collections; +import java.util.List; + import org.eclipse.draw2d.IFigure; import org.eclipse.gef.EditPart; import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.GraphicalEditPart; 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.handles.MoveHandle; import org.eclipse.gef.requests.CreateRequest; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.BorderItemSelectionEditPolicy; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles; +import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; -import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure; import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure; import org.eclipse.gmf.runtime.notation.View; import org.eclipse.papyrus.infra.gmfdiag.common.editpart.NodeEditPart; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.GetChildLayoutEditPolicy; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.IPapyrusNodeFigure; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.RoundedRectangleNodePlateFigure; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.SelectableBorderedNodeFigure; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeNodeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.QualifiedNameDisplayEditPolicy; -import org.eclipse.papyrus.uml.diagram.common.figure.node.NodeNamedElementFigure; +import org.eclipse.papyrus.uml.diagram.common.figure.node.RoundedCompartmentFigure; +import org.eclipse.papyrus.uml.diagram.common.locator.RoundedRectangleLabelPositionLocator; import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.CustomGraphicalNodeEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.edit.policies.ArtifactItemSemanticEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; @@ -75,6 +85,7 @@ public class ArtifactEditPart extends NodeEditPart { installEditPolicy(QualifiedNameDisplayEditPolicy.QUALIFIED_NAME_POLICY, new QualifiedNameDisplayEditPolicy()); installEditPolicy(AppliedStereotypeLabelDisplayEditPolicy.STEREOTYPE_LABEL_POLICY, new AppliedStereotypeNodeLabelDisplayEditPolicy()); installEditPolicy(EditPolicy.GRAPHICAL_NODE_ROLE, new CustomGraphicalNodeEditPolicy()); + installEditPolicy(EditPolicy.LAYOUT_ROLE, new GetChildLayoutEditPolicy()); // XXX need an SCR to runtime to have another abstract superclass that would let children add reasonable editpolicies // removeEditPolicy(org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles.CONNECTION_HANDLES_ROLE); } @@ -87,6 +98,20 @@ public class ArtifactEditPart extends NodeEditPart { @Override protected EditPolicy createChildEditPolicy(EditPart child) { + View childView = (View) child.getModel(); + switch (UMLVisualIDRegistry.getVisualID(childView)) { + case ArtifactFloatingLabelEditPart.VISUAL_ID: + return new BorderItemSelectionEditPolicy() { + + @Override + protected List createSelectionHandles() { + MoveHandle mh = new MoveHandle((GraphicalEditPart) getHost()); + mh.setBorder(null); + return Collections.singletonList(mh); + } + } + ; + } EditPolicy result = child.getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); if (result == null) { result = new NonResizableEditPolicy(); @@ -112,7 +137,7 @@ public class ArtifactEditPart extends NodeEditPart { */ @Override protected IFigure createNodeShape() { - return primaryShape = new NodeNamedElementFigure(); + return primaryShape = new RoundedCompartmentFigure(); } /** @@ -121,8 +146,8 @@ public class ArtifactEditPart extends NodeEditPart { * @generated */ @Override - public NodeNamedElementFigure getPrimaryShape() { - return (NodeNamedElementFigure) primaryShape; + public RoundedCompartmentFigure getPrimaryShape() { + return (RoundedCompartmentFigure) primaryShape; } /** @@ -175,15 +200,32 @@ public class ArtifactEditPart extends NodeEditPart { */ @Override protected IFigure getContentPaneFor(IGraphicalEditPart editPart) { + if (editPart instanceof IBorderItemEditPart) { + return getBorderedFigure().getBorderItemContainer(); + } return getContentPane(); } + /** + * @generated + */ + @Override + protected void addBorderItem(IFigure borderItemContainer, IBorderItemEditPart borderItemEditPart) { + if (borderItemEditPart instanceof ArtifactFloatingLabelEditPart) { + IBorderItemLocator locator = new RoundedRectangleLabelPositionLocator(getMainFigure()); + borderItemContainer.add(borderItemEditPart.getFigure(), locator); + } else + { + super.addBorderItem(borderItemContainer, borderItemEditPart); + } + } + /** * @generated */ @Override protected NodeFigure createNodePlate() { - DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(40, 40); + RoundedRectangleNodePlateFigure result = new RoundedRectangleNodePlateFigure(40, 40); return result; } @@ -196,7 +238,7 @@ public class ArtifactEditPart extends NodeEditPart { * @generated */ @Override - protected NodeFigure createNodeFigure() { + protected NodeFigure createMainFigure() { return new SelectableBorderedNodeFigure(createMainFigureWithSVG()); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ArtifactEditPartCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ArtifactEditPartCN.java index de88ba3568b..994c7d2c512 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ArtifactEditPartCN.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ArtifactEditPartCN.java @@ -11,27 +11,37 @@ */ package org.eclipse.papyrus.uml.diagram.composite.edit.parts; +import java.util.Collections; +import java.util.List; + import org.eclipse.draw2d.IFigure; import org.eclipse.gef.EditPart; import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.GraphicalEditPart; 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.handles.MoveHandle; import org.eclipse.gef.requests.CreateRequest; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.BorderItemSelectionEditPolicy; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles; +import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; -import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure; import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure; import org.eclipse.gmf.runtime.notation.View; import org.eclipse.papyrus.infra.gmfdiag.common.editpart.NodeEditPart; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.GetChildLayoutEditPolicy; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.IPapyrusNodeFigure; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.RoundedRectangleNodePlateFigure; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.SelectableBorderedNodeFigure; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeNodeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.QualifiedNameDisplayEditPolicy; -import org.eclipse.papyrus.uml.diagram.common.figure.node.NodeNamedElementFigure; +import org.eclipse.papyrus.uml.diagram.common.figure.node.RoundedCompartmentFigure; +import org.eclipse.papyrus.uml.diagram.common.locator.RoundedRectangleLabelPositionLocator; import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.CustomGraphicalNodeEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.edit.policies.ArtifactItemSemanticEditPolicyCN; import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; @@ -75,6 +85,7 @@ public class ArtifactEditPartCN extends NodeEditPart { installEditPolicy(QualifiedNameDisplayEditPolicy.QUALIFIED_NAME_POLICY, new QualifiedNameDisplayEditPolicy()); installEditPolicy(AppliedStereotypeLabelDisplayEditPolicy.STEREOTYPE_LABEL_POLICY, new AppliedStereotypeNodeLabelDisplayEditPolicy()); installEditPolicy(EditPolicy.GRAPHICAL_NODE_ROLE, new CustomGraphicalNodeEditPolicy()); + installEditPolicy(EditPolicy.LAYOUT_ROLE, new GetChildLayoutEditPolicy()); // XXX need an SCR to runtime to have another abstract superclass that would let children add reasonable editpolicies // removeEditPolicy(org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles.CONNECTION_HANDLES_ROLE); } @@ -87,6 +98,20 @@ public class ArtifactEditPartCN extends NodeEditPart { @Override protected EditPolicy createChildEditPolicy(EditPart child) { + View childView = (View) child.getModel(); + switch (UMLVisualIDRegistry.getVisualID(childView)) { + case ArtifactFloatingLabelEditPartCN.VISUAL_ID: + return new BorderItemSelectionEditPolicy() { + + @Override + protected List createSelectionHandles() { + MoveHandle mh = new MoveHandle((GraphicalEditPart) getHost()); + mh.setBorder(null); + return Collections.singletonList(mh); + } + } + ; + } EditPolicy result = child.getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); if (result == null) { result = new NonResizableEditPolicy(); @@ -112,7 +137,7 @@ public class ArtifactEditPartCN extends NodeEditPart { */ @Override protected IFigure createNodeShape() { - return primaryShape = new NodeNamedElementFigure(); + return primaryShape = new RoundedCompartmentFigure(); } /** @@ -121,8 +146,8 @@ public class ArtifactEditPartCN extends NodeEditPart { * @generated */ @Override - public NodeNamedElementFigure getPrimaryShape() { - return (NodeNamedElementFigure) primaryShape; + public RoundedCompartmentFigure getPrimaryShape() { + return (RoundedCompartmentFigure) primaryShape; } /** @@ -175,15 +200,32 @@ public class ArtifactEditPartCN extends NodeEditPart { */ @Override protected IFigure getContentPaneFor(IGraphicalEditPart editPart) { + if (editPart instanceof IBorderItemEditPart) { + return getBorderedFigure().getBorderItemContainer(); + } return getContentPane(); } + /** + * @generated + */ + @Override + protected void addBorderItem(IFigure borderItemContainer, IBorderItemEditPart borderItemEditPart) { + if (borderItemEditPart instanceof ArtifactFloatingLabelEditPartCN) { + IBorderItemLocator locator = new RoundedRectangleLabelPositionLocator(getMainFigure()); + borderItemContainer.add(borderItemEditPart.getFigure(), locator); + } else + { + super.addBorderItem(borderItemContainer, borderItemEditPart); + } + } + /** * @generated */ @Override protected NodeFigure createNodePlate() { - DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(40, 40); + RoundedRectangleNodePlateFigure result = new RoundedRectangleNodePlateFigure(40, 40); return result; } @@ -196,7 +238,7 @@ public class ArtifactEditPartCN extends NodeEditPart { * @generated */ @Override - protected NodeFigure createNodeFigure() { + protected NodeFigure createMainFigure() { return new SelectableBorderedNodeFigure(createMainFigureWithSVG()); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ArtifactFloatingLabelEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ArtifactFloatingLabelEditPart.java new file mode 100644 index 00000000000..477db2c8da1 --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ArtifactFloatingLabelEditPart.java @@ -0,0 +1,860 @@ +/** + * 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.uml.diagram.composite.edit.parts; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.Label; +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.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.RunnableWithResult; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gef.AccessibleEditPart; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.Request; +import org.eclipse.gef.requests.DirectEditRequest; +import org.eclipse.gef.tools.DirectEditManager; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; +import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; +import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; +import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; +import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; +import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; +import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; +import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; +import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; +import org.eclipse.gmf.runtime.notation.FontStyle; +import org.eclipse.gmf.runtime.notation.NotationPackage; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.text.contentassist.IContentAssistProcessor; +import org.eclipse.jface.viewers.ICellEditorValidator; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.extensionpoints.editors.Activator; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; +import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; +import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.ExternalLabelPrimaryDragRoleEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.PapyrusWrappingLabel; +import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; +import org.eclipse.papyrus.uml.diagram.common.editparts.FloatingLabelEditPart; +import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; +import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; +import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; +import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.accessibility.AccessibleEvent; +import org.eclipse.swt.custom.BusyIndicator; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; +import org.eclipse.uml2.uml.Feature; + +/** + * @generated + */ +public class ArtifactFloatingLabelEditPart extends FloatingLabelEditPart + implements ITextAwareEditPart, IBorderItemEditPart +{ + + /** + * @generated + */ + public static final int VISUAL_ID = 6097; + + /** + * @generated + */ + private DirectEditManager manager; + + /** + * @generated + */ + private IParser parser; + + /** + * @generated + */ + private List parserElements; + + /** + * @generated + */ + private String defaultText; + + /** + * direct edition mode (default, undefined, registered editor, etc.) + * + * @generated + */ + protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; + + /** + * configuration from a registered edit dialog + * + * @generated + */ + protected IDirectEditorConfiguration configuration; + + + /** + * @generated + */ + static { + registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.ArtifactFloatingLabelEditPart.VISUAL_ID), new Point(0, 0)); + } + + /** + * @generated + */ + public ArtifactFloatingLabelEditPart(View view) { + super(view); + } + + /** + * @generated + */ + @Override + protected void createDefaultEditPolicies() { + super.createDefaultEditPolicies(); + installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); + installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ExternalLabelPrimaryDragRoleEditPolicy()); + } + + /** + * @generated + */ + @Override + public IBorderItemLocator getBorderItemLocator() { + IFigure parentFigure = getFigure().getParent(); + if (parentFigure != null && parentFigure.getLayoutManager() != null) { + Object constraint = parentFigure.getLayoutManager().getConstraint(getFigure()); + return (IBorderItemLocator) constraint; + } + return null; + } + + /** + * @generated + */ + @Override + public void refreshBounds() { + int x = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_X())).intValue(); + int y = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_Y())).intValue(); + int width = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Width())).intValue(); + int height = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Height())).intValue(); + getBorderItemLocator().setConstraint(new Rectangle(x, y, width, height)); + } + + + /** + * @generated + */ + protected String getLabelTextHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getText(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getText(); + } else { + return ((Label) figure).getText(); + } + } + + /** + * @generated + */ + protected void setLabelTextHelper(IFigure figure, String text) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setText(text); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setText(text); + } else { + ((Label) figure).setText(text); + } + } + + /** + * @generated + */ + protected Image getLabelIconHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getIcon(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getIcon(); + } else { + return ((Label) figure).getIcon(); + } + } + + /** + * @generated + */ + protected void setLabelIconHelper(IFigure figure, Image icon) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setIcon(icon); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setIcon(icon); + } else { + ((Label) figure).setIcon(icon); + } + } + + /** + * @generated + */ + public void setLabel(IFigure + figure) { + unregisterVisuals(); + setFigure(figure); + defaultText = getLabelTextHelper(figure); + registerVisuals(); + refreshVisuals(); + } + + /** + * @generated + */ + @Override + protected List getModelChildren() { + return Collections.EMPTY_LIST; + } + + /** + * @generated + */ + @Override + public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { + return null; + } + + /** + * @generated + */ + public void setParser(IParser parser) { + this.parser = parser; + } + + /** + * @generated + */ + protected EObject getParserElement() { + return resolveSemanticElement(); + } + + /** + * @generated + */ + protected Image getLabelIcon() { + return null; + } + + /** + * @generated + */ + protected String getLabelText() { + String text = null; + EObject parserElement = getParserElement(); + if (parserElement != null && getParser() != null) { + text = getParser().getPrintString( + new EObjectAdapter(parserElement), + getParserOptions().intValue()); + } + if (text == null || text.length() == 0) { + text = defaultText; + } + return text; + } + + /** + * @generated + */ + @Override + public void setLabelText(String text) { + setLabelTextHelper(getFigure(), text); + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + @Override + public String getEditText() { + if (getParserElement() == null || getParser() == null) { + return ""; //$NON-NLS-1$ + } + return getParser().getEditString( + new EObjectAdapter(getParserElement()), + getParserOptions().intValue()); + } + + /** + * @generated + */ + protected boolean isEditable() { + return getParser() != null; + } + + /** + * @generated + */ + @Override + public ICellEditorValidator getEditTextValidator() { + return new ICellEditorValidator() { + + @Override + public String isValid(final Object value) { + if (value instanceof String) { + final EObject element = getParserElement(); + final IParser parser = getParser(); + try { + IParserEditStatus valid = + (IParserEditStatus) getEditingDomain().runExclusive( + new RunnableWithResult.Impl() { + + @Override + public void run() { + setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); + } + }); + return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); + } catch (InterruptedException ie) { + ie.printStackTrace(); + } + } + + // shouldn't get here + return null; + } + }; + } + + /** + * @generated + */ + @Override + public IContentAssistProcessor getCompletionProcessor() { + if (getParserElement() == null || getParser() == null) { + return null; + } + return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); + } + + /** + * @generated + */ + @Override + public ParserOptions getParserOptions() { + return ParserOptions.NONE; + } + + /** + * @generated + */ + @Override + public IParser getParser() { + if (parser == null) { + parser = UMLParserProvider.getParser(UMLElementTypes.Artifact_2079, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.ArtifactFloatingLabelEditPart.VISUAL_ID)); + } + return parser; + } + + /** + * @generated + */ + protected DirectEditManager getManager() { + if (manager == null) { + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + } + return manager; + } + + /** + * @generated + */ + protected void setManager(DirectEditManager manager) { + this.manager = manager; + } + + /** + * @generated + */ + protected void performDirectEdit() { + BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { + + @Override + public void run() { + getManager().show(); + } + }); + } + + /** + * @generated + */ + protected void performDirectEdit(Point eventLocation) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); + } + } + + /** + * @generated + */ + private void performDirectEdit(char initialCharacter) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(initialCharacter); + } else { + performDirectEdit(); + } + } + + /** + * @generated + */ + @Override + protected void performDirectEditRequest(Request request) { + + final Request theRequest = request; + + if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { + directEditionMode = getDirectEditionType(); + } + switch (directEditionMode) { + case IDirectEdition.NO_DIRECT_EDITION: + // no direct edition mode => does nothing + return; + case IDirectEdition.EXTENDED_DIRECT_EDITOR: + updateExtendedEditorConfiguration(); + if (configuration == null || configuration.getLanguage() == null) { + // Create default edit manager + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + performDefaultDirectEditorEdit(theRequest); + } else { + configuration.preEditAction(resolveSemanticElement()); + Dialog dialog = null; + if (configuration instanceof ICustomDirectEditorConfiguration) { + setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); + initializeDirectEditManager(theRequest); + return; + } else if (configuration instanceof IPopupEditorConfiguration) { + IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); + helper.showEditor(); + return; + } + else if (configuration instanceof IAdvancedEditorConfiguration) { + dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); + } else if (configuration instanceof IDirectEditorConfiguration) { + dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), + configuration); + } else { + return; + } + final Dialog finalDialog = dialog; + + if (Window.OK == dialog.open()) { + TransactionalEditingDomain domain = getEditingDomain(); + RecordingCommand command = new RecordingCommand(domain, "Edit Label") { + + @Override + protected void doExecute() { + configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); + + } + }; + domain.getCommandStack().execute(command); + } + } + break; + case IDirectEdition.DEFAULT_DIRECT_EDITOR: + initializeDirectEditManager(theRequest); + break; + default: + break; + } + } + + /** + * @generated + */ + protected void initializeDirectEditManager(final Request request) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + @Override + public void run() { + if (isActive() && isEditable()) { + if (request.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } + else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void refreshVisuals() { + super.refreshVisuals(); + refreshLabel(); + refreshFont(); + refreshFontColor(); + refreshUnderline(); + refreshStrikeThrough(); + } + + /** + * @generated + */ + protected void refreshLabel() { + EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); + if (maskLabelPolicy == null) { + maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); + } + if (maskLabelPolicy == null) { + View view = (View) getModel(); + if (view.isVisible()) { + setLabelTextHelper(getFigure(), getLabelText()); + setLabelIconHelper(getFigure(), getLabelIcon()); + } + else { + setLabelTextHelper(getFigure(), ""); //$NON-NLS-1$ + setLabelIconHelper(getFigure(), null); + } + } + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + protected void refreshUnderline() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); + } + if (resolveSemanticElement() instanceof Feature) { + if (((Feature) resolveSemanticElement()).isStatic()) { + ((WrappingLabel) getFigure()).setTextUnderline(true); + } + else { + ((WrappingLabel) getFigure()).setTextUnderline(false); + } + } + } + + /** + * @generated + */ + protected void refreshStrikeThrough() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); + } + } + + /** + * @generated + */ + @Override + protected void refreshFont() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null) { + FontData fontData = new FontData( + style.getFontName(), style.getFontHeight(), + (style.isBold() ? SWT.BOLD : SWT.NORMAL) | + (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); + setFont(fontData); + } + } + + /** + * @generated + */ + @Override + protected void setFontColor(Color color) { + getFigure().setForegroundColor(color); + } + + /** + * @generated + */ + @Override + protected void addSemanticListeners() { + if (getParser() instanceof ISemanticParser) { + EObject element = resolveSemanticElement(); + parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); + for (int i = 0; i < parserElements.size(); i++) { + addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ + } + } else { + super.addSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected void removeSemanticListeners() { + if (parserElements != null) { + for (int i = 0; i < parserElements.size(); i++) { + removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ + } + } else { + super.removeSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected AccessibleEditPart getAccessibleEditPart() { + if (accessibleEP == null) { + accessibleEP = new AccessibleGraphicalEditPart() { + + @Override + public void getName(AccessibleEvent e) { + e.result = getLabelTextHelper(getFigure()); + } + }; + } + return accessibleEP; + } + + /** + * @generated + */ + private View getFontStyleOwnerView() { + return getPrimaryView(); + } + + /** + * Returns the kind of associated editor for direct edition. + * + * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition + * @generated + */ + public int getDirectEditionType() { + if (checkExtendedEditor()) { + initExtendedEditorConfiguration(); + return IDirectEdition.EXTENDED_DIRECT_EDITOR; + } + if (checkDefaultEdition()) { + return IDirectEdition.DEFAULT_DIRECT_EDITOR; + } + + // not a named element. no specific editor => do nothing + return IDirectEdition.NO_DIRECT_EDITION; + } + + /** + * Checks if an extended editor is present. + * + * @return true if an extended editor is present. + * @generated + */ + protected boolean checkExtendedEditor() { + if (resolveSemanticElement() != null) { + return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); + } + return false; + } + + /** + * Checks if a default direct edition is available + * + * @return true if a default direct edition is available + * @generated + */ + protected boolean checkDefaultEdition() { + return (getParser() != null); + } + + /** + * Initializes the extended editor configuration + * + * @generated + */ + protected void initExtendedEditorConfiguration() { + if (configuration == null) { + final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("")) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); + } else { + configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); + } + } + } + + /** + * Updates the preference configuration + * + * @generated + */ + protected void updateExtendedEditorConfiguration() { + String languagePreferred = Activator.getDefault().getPreferenceStore().getString( + IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() + .eClass().getInstanceClassName()); + } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { + configuration = null; + } + } + + /** + * Performs the direct edit usually used by GMF editors. + * + * @param theRequest + * the direct edit request that starts the direct edit system + * @generated + */ + protected void performDefaultDirectEditorEdit(final Request theRequest) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + + @Override + public void run() { + if (isActive() && isEditable()) { + if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) theRequest.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { + DirectEditRequest editRequest = (DirectEditRequest) theRequest; + performDirectEdit(editRequest.getLocation()); + } else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + + /** + * @generated + */ + @Override + protected void handleNotificationEvent(Notification event) { + Object feature = event.getFeature(); + if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { + Integer c = (Integer) event.getNewValue(); + setFontColor(DiagramColorRegistry.getInstance().getColor(c)); + } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { + refreshUnderline(); + } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { + refreshStrikeThrough(); + } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { + refreshFont(); + } else { + if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { + refreshLabel(); + } + if (getParser() instanceof ISemanticParser) { + ISemanticParser modelParser = + (ISemanticParser) getParser(); + if (modelParser.areSemanticElementsAffected(null, event)) { + removeSemanticListeners(); + if (resolveSemanticElement() != null) { + addSemanticListeners(); + } + refreshLabel(); + } + } + } + super.handleNotificationEvent(event); + } + + /** + * @generated + */ + @Override + protected IFigure createFigure() { + IFigure label = createFigurePrim(); + defaultText = getLabelTextHelper(label); + return label; + } + + /** + * @generated + */ + protected IFigure createFigurePrim() { + return new PapyrusWrappingLabel(); + } + +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ArtifactFloatingLabelEditPartCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ArtifactFloatingLabelEditPartCN.java new file mode 100644 index 00000000000..d36294e2dab --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ArtifactFloatingLabelEditPartCN.java @@ -0,0 +1,860 @@ +/** + * 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.uml.diagram.composite.edit.parts; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.Label; +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.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.RunnableWithResult; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gef.AccessibleEditPart; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.Request; +import org.eclipse.gef.requests.DirectEditRequest; +import org.eclipse.gef.tools.DirectEditManager; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; +import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; +import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; +import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; +import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; +import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; +import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; +import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; +import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; +import org.eclipse.gmf.runtime.notation.FontStyle; +import org.eclipse.gmf.runtime.notation.NotationPackage; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.text.contentassist.IContentAssistProcessor; +import org.eclipse.jface.viewers.ICellEditorValidator; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.extensionpoints.editors.Activator; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; +import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; +import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.ExternalLabelPrimaryDragRoleEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.PapyrusWrappingLabel; +import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; +import org.eclipse.papyrus.uml.diagram.common.editparts.FloatingLabelEditPart; +import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; +import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; +import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; +import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.accessibility.AccessibleEvent; +import org.eclipse.swt.custom.BusyIndicator; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; +import org.eclipse.uml2.uml.Feature; + +/** + * @generated + */ +public class ArtifactFloatingLabelEditPartCN extends FloatingLabelEditPart + implements ITextAwareEditPart, IBorderItemEditPart +{ + + /** + * @generated + */ + public static final int VISUAL_ID = 6075; + + /** + * @generated + */ + private DirectEditManager manager; + + /** + * @generated + */ + private IParser parser; + + /** + * @generated + */ + private List parserElements; + + /** + * @generated + */ + private String defaultText; + + /** + * direct edition mode (default, undefined, registered editor, etc.) + * + * @generated + */ + protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; + + /** + * configuration from a registered edit dialog + * + * @generated + */ + protected IDirectEditorConfiguration configuration; + + + /** + * @generated + */ + static { + registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.ArtifactFloatingLabelEditPartCN.VISUAL_ID), new Point(0, 0)); + } + + /** + * @generated + */ + public ArtifactFloatingLabelEditPartCN(View view) { + super(view); + } + + /** + * @generated + */ + @Override + protected void createDefaultEditPolicies() { + super.createDefaultEditPolicies(); + installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); + installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ExternalLabelPrimaryDragRoleEditPolicy()); + } + + /** + * @generated + */ + @Override + public IBorderItemLocator getBorderItemLocator() { + IFigure parentFigure = getFigure().getParent(); + if (parentFigure != null && parentFigure.getLayoutManager() != null) { + Object constraint = parentFigure.getLayoutManager().getConstraint(getFigure()); + return (IBorderItemLocator) constraint; + } + return null; + } + + /** + * @generated + */ + @Override + public void refreshBounds() { + int x = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_X())).intValue(); + int y = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_Y())).intValue(); + int width = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Width())).intValue(); + int height = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Height())).intValue(); + getBorderItemLocator().setConstraint(new Rectangle(x, y, width, height)); + } + + + /** + * @generated + */ + protected String getLabelTextHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getText(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getText(); + } else { + return ((Label) figure).getText(); + } + } + + /** + * @generated + */ + protected void setLabelTextHelper(IFigure figure, String text) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setText(text); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setText(text); + } else { + ((Label) figure).setText(text); + } + } + + /** + * @generated + */ + protected Image getLabelIconHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getIcon(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getIcon(); + } else { + return ((Label) figure).getIcon(); + } + } + + /** + * @generated + */ + protected void setLabelIconHelper(IFigure figure, Image icon) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setIcon(icon); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setIcon(icon); + } else { + ((Label) figure).setIcon(icon); + } + } + + /** + * @generated + */ + public void setLabel(IFigure + figure) { + unregisterVisuals(); + setFigure(figure); + defaultText = getLabelTextHelper(figure); + registerVisuals(); + refreshVisuals(); + } + + /** + * @generated + */ + @Override + protected List getModelChildren() { + return Collections.EMPTY_LIST; + } + + /** + * @generated + */ + @Override + public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { + return null; + } + + /** + * @generated + */ + public void setParser(IParser parser) { + this.parser = parser; + } + + /** + * @generated + */ + protected EObject getParserElement() { + return resolveSemanticElement(); + } + + /** + * @generated + */ + protected Image getLabelIcon() { + return null; + } + + /** + * @generated + */ + protected String getLabelText() { + String text = null; + EObject parserElement = getParserElement(); + if (parserElement != null && getParser() != null) { + text = getParser().getPrintString( + new EObjectAdapter(parserElement), + getParserOptions().intValue()); + } + if (text == null || text.length() == 0) { + text = defaultText; + } + return text; + } + + /** + * @generated + */ + @Override + public void setLabelText(String text) { + setLabelTextHelper(getFigure(), text); + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + @Override + public String getEditText() { + if (getParserElement() == null || getParser() == null) { + return ""; //$NON-NLS-1$ + } + return getParser().getEditString( + new EObjectAdapter(getParserElement()), + getParserOptions().intValue()); + } + + /** + * @generated + */ + protected boolean isEditable() { + return getParser() != null; + } + + /** + * @generated + */ + @Override + public ICellEditorValidator getEditTextValidator() { + return new ICellEditorValidator() { + + @Override + public String isValid(final Object value) { + if (value instanceof String) { + final EObject element = getParserElement(); + final IParser parser = getParser(); + try { + IParserEditStatus valid = + (IParserEditStatus) getEditingDomain().runExclusive( + new RunnableWithResult.Impl() { + + @Override + public void run() { + setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); + } + }); + return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); + } catch (InterruptedException ie) { + ie.printStackTrace(); + } + } + + // shouldn't get here + return null; + } + }; + } + + /** + * @generated + */ + @Override + public IContentAssistProcessor getCompletionProcessor() { + if (getParserElement() == null || getParser() == null) { + return null; + } + return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); + } + + /** + * @generated + */ + @Override + public ParserOptions getParserOptions() { + return ParserOptions.NONE; + } + + /** + * @generated + */ + @Override + public IParser getParser() { + if (parser == null) { + parser = UMLParserProvider.getParser(UMLElementTypes.Artifact_3093, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.ArtifactFloatingLabelEditPartCN.VISUAL_ID)); + } + return parser; + } + + /** + * @generated + */ + protected DirectEditManager getManager() { + if (manager == null) { + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + } + return manager; + } + + /** + * @generated + */ + protected void setManager(DirectEditManager manager) { + this.manager = manager; + } + + /** + * @generated + */ + protected void performDirectEdit() { + BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { + + @Override + public void run() { + getManager().show(); + } + }); + } + + /** + * @generated + */ + protected void performDirectEdit(Point eventLocation) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); + } + } + + /** + * @generated + */ + private void performDirectEdit(char initialCharacter) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(initialCharacter); + } else { + performDirectEdit(); + } + } + + /** + * @generated + */ + @Override + protected void performDirectEditRequest(Request request) { + + final Request theRequest = request; + + if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { + directEditionMode = getDirectEditionType(); + } + switch (directEditionMode) { + case IDirectEdition.NO_DIRECT_EDITION: + // no direct edition mode => does nothing + return; + case IDirectEdition.EXTENDED_DIRECT_EDITOR: + updateExtendedEditorConfiguration(); + if (configuration == null || configuration.getLanguage() == null) { + // Create default edit manager + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + performDefaultDirectEditorEdit(theRequest); + } else { + configuration.preEditAction(resolveSemanticElement()); + Dialog dialog = null; + if (configuration instanceof ICustomDirectEditorConfiguration) { + setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); + initializeDirectEditManager(theRequest); + return; + } else if (configuration instanceof IPopupEditorConfiguration) { + IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); + helper.showEditor(); + return; + } + else if (configuration instanceof IAdvancedEditorConfiguration) { + dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); + } else if (configuration instanceof IDirectEditorConfiguration) { + dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), + configuration); + } else { + return; + } + final Dialog finalDialog = dialog; + + if (Window.OK == dialog.open()) { + TransactionalEditingDomain domain = getEditingDomain(); + RecordingCommand command = new RecordingCommand(domain, "Edit Label") { + + @Override + protected void doExecute() { + configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); + + } + }; + domain.getCommandStack().execute(command); + } + } + break; + case IDirectEdition.DEFAULT_DIRECT_EDITOR: + initializeDirectEditManager(theRequest); + break; + default: + break; + } + } + + /** + * @generated + */ + protected void initializeDirectEditManager(final Request request) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + @Override + public void run() { + if (isActive() && isEditable()) { + if (request.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } + else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void refreshVisuals() { + super.refreshVisuals(); + refreshLabel(); + refreshFont(); + refreshFontColor(); + refreshUnderline(); + refreshStrikeThrough(); + } + + /** + * @generated + */ + protected void refreshLabel() { + EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); + if (maskLabelPolicy == null) { + maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); + } + if (maskLabelPolicy == null) { + View view = (View) getModel(); + if (view.isVisible()) { + setLabelTextHelper(getFigure(), getLabelText()); + setLabelIconHelper(getFigure(), getLabelIcon()); + } + else { + setLabelTextHelper(getFigure(), ""); //$NON-NLS-1$ + setLabelIconHelper(getFigure(), null); + } + } + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + protected void refreshUnderline() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); + } + if (resolveSemanticElement() instanceof Feature) { + if (((Feature) resolveSemanticElement()).isStatic()) { + ((WrappingLabel) getFigure()).setTextUnderline(true); + } + else { + ((WrappingLabel) getFigure()).setTextUnderline(false); + } + } + } + + /** + * @generated + */ + protected void refreshStrikeThrough() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); + } + } + + /** + * @generated + */ + @Override + protected void refreshFont() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null) { + FontData fontData = new FontData( + style.getFontName(), style.getFontHeight(), + (style.isBold() ? SWT.BOLD : SWT.NORMAL) | + (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); + setFont(fontData); + } + } + + /** + * @generated + */ + @Override + protected void setFontColor(Color color) { + getFigure().setForegroundColor(color); + } + + /** + * @generated + */ + @Override + protected void addSemanticListeners() { + if (getParser() instanceof ISemanticParser) { + EObject element = resolveSemanticElement(); + parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); + for (int i = 0; i < parserElements.size(); i++) { + addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ + } + } else { + super.addSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected void removeSemanticListeners() { + if (parserElements != null) { + for (int i = 0; i < parserElements.size(); i++) { + removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ + } + } else { + super.removeSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected AccessibleEditPart getAccessibleEditPart() { + if (accessibleEP == null) { + accessibleEP = new AccessibleGraphicalEditPart() { + + @Override + public void getName(AccessibleEvent e) { + e.result = getLabelTextHelper(getFigure()); + } + }; + } + return accessibleEP; + } + + /** + * @generated + */ + private View getFontStyleOwnerView() { + return getPrimaryView(); + } + + /** + * Returns the kind of associated editor for direct edition. + * + * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition + * @generated + */ + public int getDirectEditionType() { + if (checkExtendedEditor()) { + initExtendedEditorConfiguration(); + return IDirectEdition.EXTENDED_DIRECT_EDITOR; + } + if (checkDefaultEdition()) { + return IDirectEdition.DEFAULT_DIRECT_EDITOR; + } + + // not a named element. no specific editor => do nothing + return IDirectEdition.NO_DIRECT_EDITION; + } + + /** + * Checks if an extended editor is present. + * + * @return true if an extended editor is present. + * @generated + */ + protected boolean checkExtendedEditor() { + if (resolveSemanticElement() != null) { + return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); + } + return false; + } + + /** + * Checks if a default direct edition is available + * + * @return true if a default direct edition is available + * @generated + */ + protected boolean checkDefaultEdition() { + return (getParser() != null); + } + + /** + * Initializes the extended editor configuration + * + * @generated + */ + protected void initExtendedEditorConfiguration() { + if (configuration == null) { + final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("")) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); + } else { + configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); + } + } + } + + /** + * Updates the preference configuration + * + * @generated + */ + protected void updateExtendedEditorConfiguration() { + String languagePreferred = Activator.getDefault().getPreferenceStore().getString( + IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() + .eClass().getInstanceClassName()); + } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { + configuration = null; + } + } + + /** + * Performs the direct edit usually used by GMF editors. + * + * @param theRequest + * the direct edit request that starts the direct edit system + * @generated + */ + protected void performDefaultDirectEditorEdit(final Request theRequest) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + + @Override + public void run() { + if (isActive() && isEditable()) { + if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) theRequest.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { + DirectEditRequest editRequest = (DirectEditRequest) theRequest; + performDirectEdit(editRequest.getLocation()); + } else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + + /** + * @generated + */ + @Override + protected void handleNotificationEvent(Notification event) { + Object feature = event.getFeature(); + if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { + Integer c = (Integer) event.getNewValue(); + setFontColor(DiagramColorRegistry.getInstance().getColor(c)); + } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { + refreshUnderline(); + } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { + refreshStrikeThrough(); + } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { + refreshFont(); + } else { + if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { + refreshLabel(); + } + if (getParser() instanceof ISemanticParser) { + ISemanticParser modelParser = + (ISemanticParser) getParser(); + if (modelParser.areSemanticElementsAffected(null, event)) { + removeSemanticListeners(); + if (resolveSemanticElement() != null) { + addSemanticListeners(); + } + refreshLabel(); + } + } + } + super.handleNotificationEvent(event); + } + + /** + * @generated + */ + @Override + protected IFigure createFigure() { + IFigure label = createFigurePrim(); + defaultText = getLabelTextHelper(label); + return label; + } + + /** + * @generated + */ + protected IFigure createFigurePrim() { + return new PapyrusWrappingLabel(); + } + +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ArtifactNameEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ArtifactNameEditPart.java index eb4df815562..3fc78bb7c72 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ArtifactNameEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ArtifactNameEditPart.java @@ -864,7 +864,7 @@ public class ArtifactNameEditPart extends PapyrusCompartmentEditPart implements * @generated */ protected void addOwnerElementListeners() { - addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); + addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ArtifactNameEditPartCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ArtifactNameEditPartCN.java index 1c470573b59..fd7adc4f495 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ArtifactNameEditPartCN.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ArtifactNameEditPartCN.java @@ -864,7 +864,7 @@ public class ArtifactNameEditPartCN extends PapyrusCompartmentEditPart implement * @generated */ protected void addOwnerElementListeners() { - addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); + addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/BehaviorPortEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/BehaviorPortEditPart.java index 0b8d143d575..8c97c20a028 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/BehaviorPortEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/BehaviorPortEditPart.java @@ -11,25 +11,38 @@ */ package org.eclipse.papyrus.uml.diagram.composite.edit.parts; +import java.util.Collections; +import java.util.List; + import org.eclipse.draw2d.IFigure; import org.eclipse.emf.common.notify.Notification; import org.eclipse.gef.EditPart; import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.GraphicalEditPart; 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.handles.MoveHandle; import org.eclipse.gef.requests.CreateRequest; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.BorderItemSelectionEditPolicy; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles; -import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure; +import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure; +import org.eclipse.gmf.runtime.notation.Edge; +import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.GetChildLayoutEditPolicy; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.IPapyrusNodeFigure; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.RoundedRectangleNodePlateFigure; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.SelectableBorderedNodeFigure; -import org.eclipse.papyrus.uml.diagram.common.figure.node.PapyrusRoundedNodeFigure; +import org.eclipse.papyrus.uml.diagram.common.figure.node.RoundedCompartmentFigure; +import org.eclipse.papyrus.uml.diagram.common.locator.RoundedRectangleLabelPositionLocator; import org.eclipse.papyrus.uml.diagram.composite.custom.edit.parts.AbstractBehaviorPortEditPart; import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.BehaviorSymbolEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.NoConnectableEditPolicy; +import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; import org.eclipse.swt.graphics.Color; /** @@ -69,6 +82,7 @@ public class BehaviorPortEditPart extends AbstractBehaviorPortEditPart { installEditPolicy(EditPolicy.LAYOUT_ROLE, createLayoutEditPolicy()); installEditPolicy(BehaviorSymbolEditPolicy.BEHAVIOR_SYMBOL, new BehaviorSymbolEditPolicy()); installEditPolicy(EditPolicy.GRAPHICAL_NODE_ROLE, new NoConnectableEditPolicy()); + installEditPolicy(EditPolicy.LAYOUT_ROLE, new GetChildLayoutEditPolicy()); // XXX need an SCR to runtime to have another abstract superclass that would let children add reasonable editpolicies // removeEditPolicy(org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles.CONNECTION_HANDLES_ROLE); } @@ -81,6 +95,20 @@ public class BehaviorPortEditPart extends AbstractBehaviorPortEditPart { @Override protected EditPolicy createChildEditPolicy(EditPart child) { + View childView = (View) child.getModel(); + switch (UMLVisualIDRegistry.getVisualID(childView)) { + case BehaviorPortFloatingLabelEditPart.VISUAL_ID: + return new BorderItemSelectionEditPolicy() { + + @Override + protected List createSelectionHandles() { + MoveHandle mh = new MoveHandle((GraphicalEditPart) getHost()); + mh.setBorder(null); + return Collections.singletonList(mh); + } + } + ; + } EditPolicy result = child.getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); if (result == null) { result = new NonResizableEditPolicy(); @@ -108,6 +136,19 @@ public class BehaviorPortEditPart extends AbstractBehaviorPortEditPart { **/ @Override protected void handleNotificationEvent(Notification event) { + /* + * when a node have external node labels, the methods refreshChildren() remove the EditPart corresponding to the Label from the EditPart + * Registry. After that, we can't reset the visibility to true (using the Show/Hide Label Action)! + */ + if (NotationPackage.eINSTANCE.getView_Visible().equals(event.getFeature())) { + Object notifier = event.getNotifier(); + List modelChildren = ((View) getModel()).getChildren(); + if (!(notifier instanceof Edge)) { + if (modelChildren.contains(event.getNotifier())) { + return; + } + } + } super.handleNotificationEvent(event); } @@ -117,7 +158,7 @@ public class BehaviorPortEditPart extends AbstractBehaviorPortEditPart { */ @Override protected IFigure createNodeShape() { - return primaryShape = new PapyrusRoundedNodeFigure(); + return primaryShape = new RoundedCompartmentFigure(); } /** @@ -126,8 +167,22 @@ public class BehaviorPortEditPart extends AbstractBehaviorPortEditPart { * @generated */ @Override - public PapyrusRoundedNodeFigure getPrimaryShape() { - return (PapyrusRoundedNodeFigure) primaryShape; + public RoundedCompartmentFigure getPrimaryShape() { + return (RoundedCompartmentFigure) primaryShape; + } + + /** + * @generated + */ + @Override + protected void addBorderItem(IFigure borderItemContainer, IBorderItemEditPart borderItemEditPart) { + if (borderItemEditPart instanceof BehaviorPortFloatingLabelEditPart) { + IBorderItemLocator locator = new RoundedRectangleLabelPositionLocator(getMainFigure()); + borderItemContainer.add(borderItemEditPart.getFigure(), locator); + } else + { + super.addBorderItem(borderItemContainer, borderItemEditPart); + } } /** @@ -135,7 +190,7 @@ public class BehaviorPortEditPart extends AbstractBehaviorPortEditPart { */ @Override protected NodeFigure createNodePlate() { - DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(40, 40); + RoundedRectangleNodePlateFigure result = new RoundedRectangleNodePlateFigure(40, 40); return result; } @@ -148,7 +203,7 @@ public class BehaviorPortEditPart extends AbstractBehaviorPortEditPart { * @generated */ @Override - protected NodeFigure createNodeFigure() { + protected NodeFigure createMainFigure() { return new SelectableBorderedNodeFigure(createMainFigureWithSVG()); } @@ -204,4 +259,12 @@ public class BehaviorPortEditPart extends AbstractBehaviorPortEditPart { ((IPapyrusNodeFigure) primaryShape).setLineStyle(style); } } + + /** + * @generated + */ + @Override + public EditPart getPrimaryChildEditPart() { + return getChildBySemanticHint(UMLVisualIDRegistry.getType(BehaviorPortFloatingLabelEditPart.VISUAL_ID)); + } } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/BehaviorPortFloatingLabelEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/BehaviorPortFloatingLabelEditPart.java new file mode 100644 index 00000000000..bd3a201c406 --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/BehaviorPortFloatingLabelEditPart.java @@ -0,0 +1,861 @@ +/** + * 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.uml.diagram.composite.edit.parts; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.Label; +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.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.RunnableWithResult; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gef.AccessibleEditPart; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.Request; +import org.eclipse.gef.requests.DirectEditRequest; +import org.eclipse.gef.tools.DirectEditManager; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; +import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; +import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; +import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; +import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; +import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; +import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; +import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; +import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; +import org.eclipse.gmf.runtime.notation.FontStyle; +import org.eclipse.gmf.runtime.notation.NotationPackage; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.text.contentassist.IContentAssistProcessor; +import org.eclipse.jface.viewers.ICellEditorValidator; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.extensionpoints.editors.Activator; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; +import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; +import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.ExternalLabelPrimaryDragRoleEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.PapyrusWrappingLabel; +import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; +import org.eclipse.papyrus.uml.diagram.common.editparts.FloatingLabelEditPart; +import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; +import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; +import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; +import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.accessibility.AccessibleEvent; +import org.eclipse.swt.custom.BusyIndicator; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; +import org.eclipse.uml2.uml.Feature; + +/** + * @generated + */ +public class BehaviorPortFloatingLabelEditPart extends + FloatingLabelEditPart + implements ITextAwareEditPart, IBorderItemEditPart +{ + + /** + * @generated + */ + public static final int VISUAL_ID = 6053; + + /** + * @generated + */ + private DirectEditManager manager; + + /** + * @generated + */ + private IParser parser; + + /** + * @generated + */ + private List parserElements; + + /** + * @generated + */ + private String defaultText; + + /** + * direct edition mode (default, undefined, registered editor, etc.) + * + * @generated + */ + protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; + + /** + * configuration from a registered edit dialog + * + * @generated + */ + protected IDirectEditorConfiguration configuration; + + + /** + * @generated + */ + static { + registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.BehaviorPortFloatingLabelEditPart.VISUAL_ID), new Point(0, 0)); + } + + /** + * @generated + */ + public BehaviorPortFloatingLabelEditPart(View view) { + super(view); + } + + /** + * @generated + */ + @Override + protected void createDefaultEditPolicies() { + super.createDefaultEditPolicies(); + installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); + installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ExternalLabelPrimaryDragRoleEditPolicy()); + } + + /** + * @generated + */ + @Override + public IBorderItemLocator getBorderItemLocator() { + IFigure parentFigure = getFigure().getParent(); + if (parentFigure != null && parentFigure.getLayoutManager() != null) { + Object constraint = parentFigure.getLayoutManager().getConstraint(getFigure()); + return (IBorderItemLocator) constraint; + } + return null; + } + + /** + * @generated + */ + @Override + public void refreshBounds() { + int x = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_X())).intValue(); + int y = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_Y())).intValue(); + int width = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Width())).intValue(); + int height = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Height())).intValue(); + getBorderItemLocator().setConstraint(new Rectangle(x, y, width, height)); + } + + + /** + * @generated + */ + protected String getLabelTextHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getText(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getText(); + } else { + return ((Label) figure).getText(); + } + } + + /** + * @generated + */ + protected void setLabelTextHelper(IFigure figure, String text) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setText(text); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setText(text); + } else { + ((Label) figure).setText(text); + } + } + + /** + * @generated + */ + protected Image getLabelIconHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getIcon(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getIcon(); + } else { + return ((Label) figure).getIcon(); + } + } + + /** + * @generated + */ + protected void setLabelIconHelper(IFigure figure, Image icon) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setIcon(icon); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setIcon(icon); + } else { + ((Label) figure).setIcon(icon); + } + } + + /** + * @generated + */ + public void setLabel(IFigure + figure) { + unregisterVisuals(); + setFigure(figure); + defaultText = getLabelTextHelper(figure); + registerVisuals(); + refreshVisuals(); + } + + /** + * @generated + */ + @Override + protected List getModelChildren() { + return Collections.EMPTY_LIST; + } + + /** + * @generated + */ + @Override + public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { + return null; + } + + /** + * @generated + */ + public void setParser(IParser parser) { + this.parser = parser; + } + + /** + * @generated + */ + protected EObject getParserElement() { + return resolveSemanticElement(); + } + + /** + * @generated + */ + protected Image getLabelIcon() { + return null; + } + + /** + * @generated + */ + protected String getLabelText() { + String text = null; + EObject parserElement = getParserElement(); + if (parserElement != null && getParser() != null) { + text = getParser().getPrintString( + new EObjectAdapter(parserElement), + getParserOptions().intValue()); + } + if (text == null || text.length() == 0) { + text = defaultText; + } + return text; + } + + /** + * @generated + */ + @Override + public void setLabelText(String text) { + setLabelTextHelper(getFigure(), text); + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + @Override + public String getEditText() { + if (getParserElement() == null || getParser() == null) { + return ""; //$NON-NLS-1$ + } + return getParser().getEditString( + new EObjectAdapter(getParserElement()), + getParserOptions().intValue()); + } + + /** + * @generated + */ + protected boolean isEditable() { + return getParser() != null; + } + + /** + * @generated + */ + @Override + public ICellEditorValidator getEditTextValidator() { + return new ICellEditorValidator() { + + @Override + public String isValid(final Object value) { + if (value instanceof String) { + final EObject element = getParserElement(); + final IParser parser = getParser(); + try { + IParserEditStatus valid = + (IParserEditStatus) getEditingDomain().runExclusive( + new RunnableWithResult.Impl() { + + @Override + public void run() { + setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); + } + }); + return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); + } catch (InterruptedException ie) { + ie.printStackTrace(); + } + } + + // shouldn't get here + return null; + } + }; + } + + /** + * @generated + */ + @Override + public IContentAssistProcessor getCompletionProcessor() { + if (getParserElement() == null || getParser() == null) { + return null; + } + return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); + } + + /** + * @generated + */ + @Override + public ParserOptions getParserOptions() { + return ParserOptions.NONE; + } + + /** + * @generated + */ + @Override + public IParser getParser() { + if (parser == null) { + parser = UMLParserProvider.getParser(UMLElementTypes.Node_3121, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.BehaviorPortFloatingLabelEditPart.VISUAL_ID)); + } + return parser; + } + + /** + * @generated + */ + protected DirectEditManager getManager() { + if (manager == null) { + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + } + return manager; + } + + /** + * @generated + */ + protected void setManager(DirectEditManager manager) { + this.manager = manager; + } + + /** + * @generated + */ + protected void performDirectEdit() { + BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { + + @Override + public void run() { + getManager().show(); + } + }); + } + + /** + * @generated + */ + protected void performDirectEdit(Point eventLocation) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); + } + } + + /** + * @generated + */ + private void performDirectEdit(char initialCharacter) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(initialCharacter); + } else { + performDirectEdit(); + } + } + + /** + * @generated + */ + @Override + protected void performDirectEditRequest(Request request) { + + final Request theRequest = request; + + if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { + directEditionMode = getDirectEditionType(); + } + switch (directEditionMode) { + case IDirectEdition.NO_DIRECT_EDITION: + // no direct edition mode => does nothing + return; + case IDirectEdition.EXTENDED_DIRECT_EDITOR: + updateExtendedEditorConfiguration(); + if (configuration == null || configuration.getLanguage() == null) { + // Create default edit manager + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + performDefaultDirectEditorEdit(theRequest); + } else { + configuration.preEditAction(resolveSemanticElement()); + Dialog dialog = null; + if (configuration instanceof ICustomDirectEditorConfiguration) { + setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); + initializeDirectEditManager(theRequest); + return; + } else if (configuration instanceof IPopupEditorConfiguration) { + IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); + helper.showEditor(); + return; + } + else if (configuration instanceof IAdvancedEditorConfiguration) { + dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); + } else if (configuration instanceof IDirectEditorConfiguration) { + dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), + configuration); + } else { + return; + } + final Dialog finalDialog = dialog; + + if (Window.OK == dialog.open()) { + TransactionalEditingDomain domain = getEditingDomain(); + RecordingCommand command = new RecordingCommand(domain, "Edit Label") { + + @Override + protected void doExecute() { + configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); + + } + }; + domain.getCommandStack().execute(command); + } + } + break; + case IDirectEdition.DEFAULT_DIRECT_EDITOR: + initializeDirectEditManager(theRequest); + break; + default: + break; + } + } + + /** + * @generated + */ + protected void initializeDirectEditManager(final Request request) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + @Override + public void run() { + if (isActive() && isEditable()) { + if (request.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } + else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void refreshVisuals() { + super.refreshVisuals(); + refreshLabel(); + refreshFont(); + refreshFontColor(); + refreshUnderline(); + refreshStrikeThrough(); + } + + /** + * @generated + */ + protected void refreshLabel() { + EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); + if (maskLabelPolicy == null) { + maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); + } + if (maskLabelPolicy == null) { + View view = (View) getModel(); + if (view.isVisible()) { + setLabelTextHelper(getFigure(), getLabelText()); + setLabelIconHelper(getFigure(), getLabelIcon()); + } + else { + setLabelTextHelper(getFigure(), ""); //$NON-NLS-1$ + setLabelIconHelper(getFigure(), null); + } + } + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + protected void refreshUnderline() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); + } + if (resolveSemanticElement() instanceof Feature) { + if (((Feature) resolveSemanticElement()).isStatic()) { + ((WrappingLabel) getFigure()).setTextUnderline(true); + } + else { + ((WrappingLabel) getFigure()).setTextUnderline(false); + } + } + } + + /** + * @generated + */ + protected void refreshStrikeThrough() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); + } + } + + /** + * @generated + */ + @Override + protected void refreshFont() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null) { + FontData fontData = new FontData( + style.getFontName(), style.getFontHeight(), + (style.isBold() ? SWT.BOLD : SWT.NORMAL) | + (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); + setFont(fontData); + } + } + + /** + * @generated + */ + @Override + protected void setFontColor(Color color) { + getFigure().setForegroundColor(color); + } + + /** + * @generated + */ + @Override + protected void addSemanticListeners() { + if (getParser() instanceof ISemanticParser) { + EObject element = resolveSemanticElement(); + parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); + for (int i = 0; i < parserElements.size(); i++) { + addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ + } + } else { + super.addSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected void removeSemanticListeners() { + if (parserElements != null) { + for (int i = 0; i < parserElements.size(); i++) { + removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ + } + } else { + super.removeSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected AccessibleEditPart getAccessibleEditPart() { + if (accessibleEP == null) { + accessibleEP = new AccessibleGraphicalEditPart() { + + @Override + public void getName(AccessibleEvent e) { + e.result = getLabelTextHelper(getFigure()); + } + }; + } + return accessibleEP; + } + + /** + * @generated + */ + private View getFontStyleOwnerView() { + return getPrimaryView(); + } + + /** + * Returns the kind of associated editor for direct edition. + * + * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition + * @generated + */ + public int getDirectEditionType() { + if (checkExtendedEditor()) { + initExtendedEditorConfiguration(); + return IDirectEdition.EXTENDED_DIRECT_EDITOR; + } + if (checkDefaultEdition()) { + return IDirectEdition.DEFAULT_DIRECT_EDITOR; + } + + // not a named element. no specific editor => do nothing + return IDirectEdition.NO_DIRECT_EDITION; + } + + /** + * Checks if an extended editor is present. + * + * @return true if an extended editor is present. + * @generated + */ + protected boolean checkExtendedEditor() { + if (resolveSemanticElement() != null) { + return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); + } + return false; + } + + /** + * Checks if a default direct edition is available + * + * @return true if a default direct edition is available + * @generated + */ + protected boolean checkDefaultEdition() { + return (getParser() != null); + } + + /** + * Initializes the extended editor configuration + * + * @generated + */ + protected void initExtendedEditorConfiguration() { + if (configuration == null) { + final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("")) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); + } else { + configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); + } + } + } + + /** + * Updates the preference configuration + * + * @generated + */ + protected void updateExtendedEditorConfiguration() { + String languagePreferred = Activator.getDefault().getPreferenceStore().getString( + IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() + .eClass().getInstanceClassName()); + } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { + configuration = null; + } + } + + /** + * Performs the direct edit usually used by GMF editors. + * + * @param theRequest + * the direct edit request that starts the direct edit system + * @generated + */ + protected void performDefaultDirectEditorEdit(final Request theRequest) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + + @Override + public void run() { + if (isActive() && isEditable()) { + if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) theRequest.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { + DirectEditRequest editRequest = (DirectEditRequest) theRequest; + performDirectEdit(editRequest.getLocation()); + } else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + + /** + * @generated + */ + @Override + protected void handleNotificationEvent(Notification event) { + Object feature = event.getFeature(); + if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { + Integer c = (Integer) event.getNewValue(); + setFontColor(DiagramColorRegistry.getInstance().getColor(c)); + } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { + refreshUnderline(); + } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { + refreshStrikeThrough(); + } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { + refreshFont(); + } else { + if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { + refreshLabel(); + } + if (getParser() instanceof ISemanticParser) { + ISemanticParser modelParser = + (ISemanticParser) getParser(); + if (modelParser.areSemanticElementsAffected(null, event)) { + removeSemanticListeners(); + if (resolveSemanticElement() != null) { + addSemanticListeners(); + } + refreshLabel(); + } + } + } + super.handleNotificationEvent(event); + } + + /** + * @generated + */ + @Override + protected IFigure createFigure() { + IFigure label = createFigurePrim(); + defaultText = getLabelTextHelper(label); + return label; + } + + /** + * @generated + */ + protected IFigure createFigurePrim() { + return new PapyrusWrappingLabel(); + } + +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/CallEventEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/CallEventEditPart.java index b0d874dadf4..a02cb1e3df7 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/CallEventEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/CallEventEditPart.java @@ -11,27 +11,40 @@ */ package org.eclipse.papyrus.uml.diagram.composite.edit.parts; +import java.util.Collections; +import java.util.List; + import org.eclipse.draw2d.IFigure; +import org.eclipse.emf.common.notify.Notification; import org.eclipse.gef.EditPart; import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.GraphicalEditPart; 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.handles.MoveHandle; import org.eclipse.gef.requests.CreateRequest; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.BorderItemSelectionEditPolicy; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles; +import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; -import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure; import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure; +import org.eclipse.gmf.runtime.notation.Edge; +import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.gmf.runtime.notation.View; -import org.eclipse.papyrus.infra.gmfdiag.common.editpart.NodeEditPart; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.GetChildLayoutEditPolicy; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.IPapyrusNodeFigure; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.RoundedRectangleNodePlateFigure; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.SelectableBorderedNodeFigure; +import org.eclipse.papyrus.uml.diagram.common.editparts.RoundedCompartmentEditPart; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeNodeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.QualifiedNameDisplayEditPolicy; -import org.eclipse.papyrus.uml.diagram.common.figure.node.NodeNamedElementFigure; +import org.eclipse.papyrus.uml.diagram.common.figure.node.RoundedCompartmentFigure; +import org.eclipse.papyrus.uml.diagram.common.locator.RoundedRectangleLabelPositionLocator; import org.eclipse.papyrus.uml.diagram.composite.edit.policies.CallEventItemSemanticEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; import org.eclipse.swt.graphics.Color; @@ -39,7 +52,7 @@ import org.eclipse.swt.graphics.Color; /** * @generated */ -public class CallEventEditPart extends NodeEditPart { +public class CallEventEditPart extends RoundedCompartmentEditPart { /** * @generated @@ -73,6 +86,7 @@ public class CallEventEditPart extends NodeEditPart { installEditPolicy(EditPolicy.LAYOUT_ROLE, createLayoutEditPolicy()); installEditPolicy(QualifiedNameDisplayEditPolicy.QUALIFIED_NAME_POLICY, new QualifiedNameDisplayEditPolicy()); installEditPolicy(AppliedStereotypeLabelDisplayEditPolicy.STEREOTYPE_LABEL_POLICY, new AppliedStereotypeNodeLabelDisplayEditPolicy()); + installEditPolicy(EditPolicy.LAYOUT_ROLE, new GetChildLayoutEditPolicy()); // XXX need an SCR to runtime to have another abstract superclass that would let children add reasonable editpolicies // removeEditPolicy(org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles.CONNECTION_HANDLES_ROLE); } @@ -85,6 +99,20 @@ public class CallEventEditPart extends NodeEditPart { @Override protected EditPolicy createChildEditPolicy(EditPart child) { + View childView = (View) child.getModel(); + switch (UMLVisualIDRegistry.getVisualID(childView)) { + case CallEventFloatingLabelEditPart.VISUAL_ID: + return new BorderItemSelectionEditPolicy() { + + @Override + protected List createSelectionHandles() { + MoveHandle mh = new MoveHandle((GraphicalEditPart) getHost()); + mh.setBorder(null); + return Collections.singletonList(mh); + } + } + ; + } EditPolicy result = child.getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); if (result == null) { result = new NonResizableEditPolicy(); @@ -105,12 +133,36 @@ public class CallEventEditPart extends NodeEditPart { return lep; } + /** + * Papyrus codeGen + * + * @generated + **/ + @Override + protected void handleNotificationEvent(Notification event) { + /* + * when a node have external node labels, the methods refreshChildren() remove the EditPart corresponding to the Label from the EditPart + * Registry. After that, we can't reset the visibility to true (using the Show/Hide Label Action)! + */ + if (NotationPackage.eINSTANCE.getView_Visible().equals(event.getFeature())) { + Object notifier = event.getNotifier(); + List modelChildren = ((View) getModel()).getChildren(); + if (!(notifier instanceof Edge)) { + if (modelChildren.contains(event.getNotifier())) { + return; + } + } + } + super.handleNotificationEvent(event); + + } + /** * @generated */ @Override protected IFigure createNodeShape() { - return primaryShape = new NodeNamedElementFigure(); + return primaryShape = new RoundedCompartmentFigure(); } /** @@ -119,8 +171,8 @@ public class CallEventEditPart extends NodeEditPart { * @generated */ @Override - public NodeNamedElementFigure getPrimaryShape() { - return (NodeNamedElementFigure) primaryShape; + public RoundedCompartmentFigure getPrimaryShape() { + return (RoundedCompartmentFigure) primaryShape; } /** @@ -173,15 +225,32 @@ public class CallEventEditPart extends NodeEditPart { */ @Override protected IFigure getContentPaneFor(IGraphicalEditPart editPart) { + if (editPart instanceof IBorderItemEditPart) { + return getBorderedFigure().getBorderItemContainer(); + } return getContentPane(); } + /** + * @generated + */ + @Override + protected void addBorderItem(IFigure borderItemContainer, IBorderItemEditPart borderItemEditPart) { + if (borderItemEditPart instanceof CallEventFloatingLabelEditPart) { + IBorderItemLocator locator = new RoundedRectangleLabelPositionLocator(getMainFigure()); + borderItemContainer.add(borderItemEditPart.getFigure(), locator); + } else + { + super.addBorderItem(borderItemContainer, borderItemEditPart); + } + } + /** * @generated */ @Override protected NodeFigure createNodePlate() { - DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(40, 40); + RoundedRectangleNodePlateFigure result = new RoundedRectangleNodePlateFigure(40, 40); return result; } @@ -194,7 +263,7 @@ public class CallEventEditPart extends NodeEditPart { * @generated */ @Override - protected NodeFigure createNodeFigure() { + protected NodeFigure createMainFigure() { return new SelectableBorderedNodeFigure(createMainFigureWithSVG()); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/CallEventFloatingLabelEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/CallEventFloatingLabelEditPart.java new file mode 100644 index 00000000000..72381108684 --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/CallEventFloatingLabelEditPart.java @@ -0,0 +1,860 @@ +/** + * 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.uml.diagram.composite.edit.parts; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.Label; +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.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.RunnableWithResult; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gef.AccessibleEditPart; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.Request; +import org.eclipse.gef.requests.DirectEditRequest; +import org.eclipse.gef.tools.DirectEditManager; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; +import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; +import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; +import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; +import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; +import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; +import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; +import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; +import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; +import org.eclipse.gmf.runtime.notation.FontStyle; +import org.eclipse.gmf.runtime.notation.NotationPackage; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.text.contentassist.IContentAssistProcessor; +import org.eclipse.jface.viewers.ICellEditorValidator; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.extensionpoints.editors.Activator; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; +import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; +import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.ExternalLabelPrimaryDragRoleEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.PapyrusWrappingLabel; +import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; +import org.eclipse.papyrus.uml.diagram.common.editparts.FloatingLabelEditPart; +import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; +import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; +import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; +import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.accessibility.AccessibleEvent; +import org.eclipse.swt.custom.BusyIndicator; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; +import org.eclipse.uml2.uml.Feature; + +/** + * @generated + */ +public class CallEventFloatingLabelEditPart extends FloatingLabelEditPart + implements ITextAwareEditPart, IBorderItemEditPart +{ + + /** + * @generated + */ + public static final int VISUAL_ID = 6102; + + /** + * @generated + */ + private DirectEditManager manager; + + /** + * @generated + */ + private IParser parser; + + /** + * @generated + */ + private List parserElements; + + /** + * @generated + */ + private String defaultText; + + /** + * direct edition mode (default, undefined, registered editor, etc.) + * + * @generated + */ + protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; + + /** + * configuration from a registered edit dialog + * + * @generated + */ + protected IDirectEditorConfiguration configuration; + + + /** + * @generated + */ + static { + registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.CallEventFloatingLabelEditPart.VISUAL_ID), new Point(0, 0)); + } + + /** + * @generated + */ + public CallEventFloatingLabelEditPart(View view) { + super(view); + } + + /** + * @generated + */ + @Override + protected void createDefaultEditPolicies() { + super.createDefaultEditPolicies(); + installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); + installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ExternalLabelPrimaryDragRoleEditPolicy()); + } + + /** + * @generated + */ + @Override + public IBorderItemLocator getBorderItemLocator() { + IFigure parentFigure = getFigure().getParent(); + if (parentFigure != null && parentFigure.getLayoutManager() != null) { + Object constraint = parentFigure.getLayoutManager().getConstraint(getFigure()); + return (IBorderItemLocator) constraint; + } + return null; + } + + /** + * @generated + */ + @Override + public void refreshBounds() { + int x = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_X())).intValue(); + int y = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_Y())).intValue(); + int width = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Width())).intValue(); + int height = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Height())).intValue(); + getBorderItemLocator().setConstraint(new Rectangle(x, y, width, height)); + } + + + /** + * @generated + */ + protected String getLabelTextHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getText(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getText(); + } else { + return ((Label) figure).getText(); + } + } + + /** + * @generated + */ + protected void setLabelTextHelper(IFigure figure, String text) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setText(text); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setText(text); + } else { + ((Label) figure).setText(text); + } + } + + /** + * @generated + */ + protected Image getLabelIconHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getIcon(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getIcon(); + } else { + return ((Label) figure).getIcon(); + } + } + + /** + * @generated + */ + protected void setLabelIconHelper(IFigure figure, Image icon) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setIcon(icon); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setIcon(icon); + } else { + ((Label) figure).setIcon(icon); + } + } + + /** + * @generated + */ + public void setLabel(IFigure + figure) { + unregisterVisuals(); + setFigure(figure); + defaultText = getLabelTextHelper(figure); + registerVisuals(); + refreshVisuals(); + } + + /** + * @generated + */ + @Override + protected List getModelChildren() { + return Collections.EMPTY_LIST; + } + + /** + * @generated + */ + @Override + public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { + return null; + } + + /** + * @generated + */ + public void setParser(IParser parser) { + this.parser = parser; + } + + /** + * @generated + */ + protected EObject getParserElement() { + return resolveSemanticElement(); + } + + /** + * @generated + */ + protected Image getLabelIcon() { + return null; + } + + /** + * @generated + */ + protected String getLabelText() { + String text = null; + EObject parserElement = getParserElement(); + if (parserElement != null && getParser() != null) { + text = getParser().getPrintString( + new EObjectAdapter(parserElement), + getParserOptions().intValue()); + } + if (text == null || text.length() == 0) { + text = defaultText; + } + return text; + } + + /** + * @generated + */ + @Override + public void setLabelText(String text) { + setLabelTextHelper(getFigure(), text); + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + @Override + public String getEditText() { + if (getParserElement() == null || getParser() == null) { + return ""; //$NON-NLS-1$ + } + return getParser().getEditString( + new EObjectAdapter(getParserElement()), + getParserOptions().intValue()); + } + + /** + * @generated + */ + protected boolean isEditable() { + return getParser() != null; + } + + /** + * @generated + */ + @Override + public ICellEditorValidator getEditTextValidator() { + return new ICellEditorValidator() { + + @Override + public String isValid(final Object value) { + if (value instanceof String) { + final EObject element = getParserElement(); + final IParser parser = getParser(); + try { + IParserEditStatus valid = + (IParserEditStatus) getEditingDomain().runExclusive( + new RunnableWithResult.Impl() { + + @Override + public void run() { + setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); + } + }); + return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); + } catch (InterruptedException ie) { + ie.printStackTrace(); + } + } + + // shouldn't get here + return null; + } + }; + } + + /** + * @generated + */ + @Override + public IContentAssistProcessor getCompletionProcessor() { + if (getParserElement() == null || getParser() == null) { + return null; + } + return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); + } + + /** + * @generated + */ + @Override + public ParserOptions getParserOptions() { + return ParserOptions.NONE; + } + + /** + * @generated + */ + @Override + public IParser getParser() { + if (parser == null) { + parser = UMLParserProvider.getParser(UMLElementTypes.CallEvent_2084, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.CallEventFloatingLabelEditPart.VISUAL_ID)); + } + return parser; + } + + /** + * @generated + */ + protected DirectEditManager getManager() { + if (manager == null) { + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + } + return manager; + } + + /** + * @generated + */ + protected void setManager(DirectEditManager manager) { + this.manager = manager; + } + + /** + * @generated + */ + protected void performDirectEdit() { + BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { + + @Override + public void run() { + getManager().show(); + } + }); + } + + /** + * @generated + */ + protected void performDirectEdit(Point eventLocation) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); + } + } + + /** + * @generated + */ + private void performDirectEdit(char initialCharacter) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(initialCharacter); + } else { + performDirectEdit(); + } + } + + /** + * @generated + */ + @Override + protected void performDirectEditRequest(Request request) { + + final Request theRequest = request; + + if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { + directEditionMode = getDirectEditionType(); + } + switch (directEditionMode) { + case IDirectEdition.NO_DIRECT_EDITION: + // no direct edition mode => does nothing + return; + case IDirectEdition.EXTENDED_DIRECT_EDITOR: + updateExtendedEditorConfiguration(); + if (configuration == null || configuration.getLanguage() == null) { + // Create default edit manager + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + performDefaultDirectEditorEdit(theRequest); + } else { + configuration.preEditAction(resolveSemanticElement()); + Dialog dialog = null; + if (configuration instanceof ICustomDirectEditorConfiguration) { + setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); + initializeDirectEditManager(theRequest); + return; + } else if (configuration instanceof IPopupEditorConfiguration) { + IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); + helper.showEditor(); + return; + } + else if (configuration instanceof IAdvancedEditorConfiguration) { + dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); + } else if (configuration instanceof IDirectEditorConfiguration) { + dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), + configuration); + } else { + return; + } + final Dialog finalDialog = dialog; + + if (Window.OK == dialog.open()) { + TransactionalEditingDomain domain = getEditingDomain(); + RecordingCommand command = new RecordingCommand(domain, "Edit Label") { + + @Override + protected void doExecute() { + configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); + + } + }; + domain.getCommandStack().execute(command); + } + } + break; + case IDirectEdition.DEFAULT_DIRECT_EDITOR: + initializeDirectEditManager(theRequest); + break; + default: + break; + } + } + + /** + * @generated + */ + protected void initializeDirectEditManager(final Request request) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + @Override + public void run() { + if (isActive() && isEditable()) { + if (request.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } + else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void refreshVisuals() { + super.refreshVisuals(); + refreshLabel(); + refreshFont(); + refreshFontColor(); + refreshUnderline(); + refreshStrikeThrough(); + } + + /** + * @generated + */ + protected void refreshLabel() { + EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); + if (maskLabelPolicy == null) { + maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); + } + if (maskLabelPolicy == null) { + View view = (View) getModel(); + if (view.isVisible()) { + setLabelTextHelper(getFigure(), getLabelText()); + setLabelIconHelper(getFigure(), getLabelIcon()); + } + else { + setLabelTextHelper(getFigure(), ""); //$NON-NLS-1$ + setLabelIconHelper(getFigure(), null); + } + } + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + protected void refreshUnderline() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); + } + if (resolveSemanticElement() instanceof Feature) { + if (((Feature) resolveSemanticElement()).isStatic()) { + ((WrappingLabel) getFigure()).setTextUnderline(true); + } + else { + ((WrappingLabel) getFigure()).setTextUnderline(false); + } + } + } + + /** + * @generated + */ + protected void refreshStrikeThrough() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); + } + } + + /** + * @generated + */ + @Override + protected void refreshFont() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null) { + FontData fontData = new FontData( + style.getFontName(), style.getFontHeight(), + (style.isBold() ? SWT.BOLD : SWT.NORMAL) | + (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); + setFont(fontData); + } + } + + /** + * @generated + */ + @Override + protected void setFontColor(Color color) { + getFigure().setForegroundColor(color); + } + + /** + * @generated + */ + @Override + protected void addSemanticListeners() { + if (getParser() instanceof ISemanticParser) { + EObject element = resolveSemanticElement(); + parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); + for (int i = 0; i < parserElements.size(); i++) { + addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ + } + } else { + super.addSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected void removeSemanticListeners() { + if (parserElements != null) { + for (int i = 0; i < parserElements.size(); i++) { + removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ + } + } else { + super.removeSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected AccessibleEditPart getAccessibleEditPart() { + if (accessibleEP == null) { + accessibleEP = new AccessibleGraphicalEditPart() { + + @Override + public void getName(AccessibleEvent e) { + e.result = getLabelTextHelper(getFigure()); + } + }; + } + return accessibleEP; + } + + /** + * @generated + */ + private View getFontStyleOwnerView() { + return getPrimaryView(); + } + + /** + * Returns the kind of associated editor for direct edition. + * + * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition + * @generated + */ + public int getDirectEditionType() { + if (checkExtendedEditor()) { + initExtendedEditorConfiguration(); + return IDirectEdition.EXTENDED_DIRECT_EDITOR; + } + if (checkDefaultEdition()) { + return IDirectEdition.DEFAULT_DIRECT_EDITOR; + } + + // not a named element. no specific editor => do nothing + return IDirectEdition.NO_DIRECT_EDITION; + } + + /** + * Checks if an extended editor is present. + * + * @return true if an extended editor is present. + * @generated + */ + protected boolean checkExtendedEditor() { + if (resolveSemanticElement() != null) { + return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); + } + return false; + } + + /** + * Checks if a default direct edition is available + * + * @return true if a default direct edition is available + * @generated + */ + protected boolean checkDefaultEdition() { + return (getParser() != null); + } + + /** + * Initializes the extended editor configuration + * + * @generated + */ + protected void initExtendedEditorConfiguration() { + if (configuration == null) { + final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("")) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); + } else { + configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); + } + } + } + + /** + * Updates the preference configuration + * + * @generated + */ + protected void updateExtendedEditorConfiguration() { + String languagePreferred = Activator.getDefault().getPreferenceStore().getString( + IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() + .eClass().getInstanceClassName()); + } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { + configuration = null; + } + } + + /** + * Performs the direct edit usually used by GMF editors. + * + * @param theRequest + * the direct edit request that starts the direct edit system + * @generated + */ + protected void performDefaultDirectEditorEdit(final Request theRequest) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + + @Override + public void run() { + if (isActive() && isEditable()) { + if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) theRequest.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { + DirectEditRequest editRequest = (DirectEditRequest) theRequest; + performDirectEdit(editRequest.getLocation()); + } else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + + /** + * @generated + */ + @Override + protected void handleNotificationEvent(Notification event) { + Object feature = event.getFeature(); + if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { + Integer c = (Integer) event.getNewValue(); + setFontColor(DiagramColorRegistry.getInstance().getColor(c)); + } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { + refreshUnderline(); + } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { + refreshStrikeThrough(); + } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { + refreshFont(); + } else { + if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { + refreshLabel(); + } + if (getParser() instanceof ISemanticParser) { + ISemanticParser modelParser = + (ISemanticParser) getParser(); + if (modelParser.areSemanticElementsAffected(null, event)) { + removeSemanticListeners(); + if (resolveSemanticElement() != null) { + addSemanticListeners(); + } + refreshLabel(); + } + } + } + super.handleNotificationEvent(event); + } + + /** + * @generated + */ + @Override + protected IFigure createFigure() { + IFigure label = createFigurePrim(); + defaultText = getLabelTextHelper(label); + return label; + } + + /** + * @generated + */ + protected IFigure createFigurePrim() { + return new PapyrusWrappingLabel(); + } + +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/CallEventNameEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/CallEventNameEditPart.java index e1cb5006fe1..2051a2502ff 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/CallEventNameEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/CallEventNameEditPart.java @@ -864,7 +864,7 @@ public class CallEventNameEditPart extends PapyrusCompartmentEditPart implements * @generated */ protected void addOwnerElementListeners() { - addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); + addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ChangeEventEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ChangeEventEditPart.java index aef7e3215d6..2501590c124 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ChangeEventEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ChangeEventEditPart.java @@ -11,27 +11,40 @@ */ package org.eclipse.papyrus.uml.diagram.composite.edit.parts; +import java.util.Collections; +import java.util.List; + import org.eclipse.draw2d.IFigure; +import org.eclipse.emf.common.notify.Notification; import org.eclipse.gef.EditPart; import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.GraphicalEditPart; 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.handles.MoveHandle; import org.eclipse.gef.requests.CreateRequest; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.BorderItemSelectionEditPolicy; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles; +import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; -import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure; import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure; +import org.eclipse.gmf.runtime.notation.Edge; +import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.gmf.runtime.notation.View; -import org.eclipse.papyrus.infra.gmfdiag.common.editpart.NodeEditPart; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.GetChildLayoutEditPolicy; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.IPapyrusNodeFigure; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.RoundedRectangleNodePlateFigure; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.SelectableBorderedNodeFigure; +import org.eclipse.papyrus.uml.diagram.common.editparts.RoundedCompartmentEditPart; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeNodeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.QualifiedNameDisplayEditPolicy; -import org.eclipse.papyrus.uml.diagram.common.figure.node.NodeNamedElementFigure; +import org.eclipse.papyrus.uml.diagram.common.figure.node.RoundedCompartmentFigure; +import org.eclipse.papyrus.uml.diagram.common.locator.RoundedRectangleLabelPositionLocator; import org.eclipse.papyrus.uml.diagram.composite.edit.policies.ChangeEventItemSemanticEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; import org.eclipse.swt.graphics.Color; @@ -39,7 +52,7 @@ import org.eclipse.swt.graphics.Color; /** * @generated */ -public class ChangeEventEditPart extends NodeEditPart { +public class ChangeEventEditPart extends RoundedCompartmentEditPart { /** * @generated @@ -73,6 +86,7 @@ public class ChangeEventEditPart extends NodeEditPart { installEditPolicy(EditPolicy.LAYOUT_ROLE, createLayoutEditPolicy()); installEditPolicy(QualifiedNameDisplayEditPolicy.QUALIFIED_NAME_POLICY, new QualifiedNameDisplayEditPolicy()); installEditPolicy(AppliedStereotypeLabelDisplayEditPolicy.STEREOTYPE_LABEL_POLICY, new AppliedStereotypeNodeLabelDisplayEditPolicy()); + installEditPolicy(EditPolicy.LAYOUT_ROLE, new GetChildLayoutEditPolicy()); // XXX need an SCR to runtime to have another abstract superclass that would let children add reasonable editpolicies // removeEditPolicy(org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles.CONNECTION_HANDLES_ROLE); } @@ -85,6 +99,20 @@ public class ChangeEventEditPart extends NodeEditPart { @Override protected EditPolicy createChildEditPolicy(EditPart child) { + View childView = (View) child.getModel(); + switch (UMLVisualIDRegistry.getVisualID(childView)) { + case ChangeEventFloatingLabelEditPart.VISUAL_ID: + return new BorderItemSelectionEditPolicy() { + + @Override + protected List createSelectionHandles() { + MoveHandle mh = new MoveHandle((GraphicalEditPart) getHost()); + mh.setBorder(null); + return Collections.singletonList(mh); + } + } + ; + } EditPolicy result = child.getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); if (result == null) { result = new NonResizableEditPolicy(); @@ -105,12 +133,36 @@ public class ChangeEventEditPart extends NodeEditPart { return lep; } + /** + * Papyrus codeGen + * + * @generated + **/ + @Override + protected void handleNotificationEvent(Notification event) { + /* + * when a node have external node labels, the methods refreshChildren() remove the EditPart corresponding to the Label from the EditPart + * Registry. After that, we can't reset the visibility to true (using the Show/Hide Label Action)! + */ + if (NotationPackage.eINSTANCE.getView_Visible().equals(event.getFeature())) { + Object notifier = event.getNotifier(); + List modelChildren = ((View) getModel()).getChildren(); + if (!(notifier instanceof Edge)) { + if (modelChildren.contains(event.getNotifier())) { + return; + } + } + } + super.handleNotificationEvent(event); + + } + /** * @generated */ @Override protected IFigure createNodeShape() { - return primaryShape = new NodeNamedElementFigure(); + return primaryShape = new RoundedCompartmentFigure(); } /** @@ -119,8 +171,8 @@ public class ChangeEventEditPart extends NodeEditPart { * @generated */ @Override - public NodeNamedElementFigure getPrimaryShape() { - return (NodeNamedElementFigure) primaryShape; + public RoundedCompartmentFigure getPrimaryShape() { + return (RoundedCompartmentFigure) primaryShape; } /** @@ -173,15 +225,32 @@ public class ChangeEventEditPart extends NodeEditPart { */ @Override protected IFigure getContentPaneFor(IGraphicalEditPart editPart) { + if (editPart instanceof IBorderItemEditPart) { + return getBorderedFigure().getBorderItemContainer(); + } return getContentPane(); } + /** + * @generated + */ + @Override + protected void addBorderItem(IFigure borderItemContainer, IBorderItemEditPart borderItemEditPart) { + if (borderItemEditPart instanceof ChangeEventFloatingLabelEditPart) { + IBorderItemLocator locator = new RoundedRectangleLabelPositionLocator(getMainFigure()); + borderItemContainer.add(borderItemEditPart.getFigure(), locator); + } else + { + super.addBorderItem(borderItemContainer, borderItemEditPart); + } + } + /** * @generated */ @Override protected NodeFigure createNodePlate() { - DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(40, 40); + RoundedRectangleNodePlateFigure result = new RoundedRectangleNodePlateFigure(40, 40); return result; } @@ -194,7 +263,7 @@ public class ChangeEventEditPart extends NodeEditPart { * @generated */ @Override - protected NodeFigure createNodeFigure() { + protected NodeFigure createMainFigure() { return new SelectableBorderedNodeFigure(createMainFigureWithSVG()); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ChangeEventFloatingLabelEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ChangeEventFloatingLabelEditPart.java new file mode 100644 index 00000000000..844926f4cd2 --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ChangeEventFloatingLabelEditPart.java @@ -0,0 +1,860 @@ +/** + * 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.uml.diagram.composite.edit.parts; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.Label; +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.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.RunnableWithResult; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gef.AccessibleEditPart; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.Request; +import org.eclipse.gef.requests.DirectEditRequest; +import org.eclipse.gef.tools.DirectEditManager; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; +import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; +import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; +import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; +import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; +import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; +import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; +import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; +import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; +import org.eclipse.gmf.runtime.notation.FontStyle; +import org.eclipse.gmf.runtime.notation.NotationPackage; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.text.contentassist.IContentAssistProcessor; +import org.eclipse.jface.viewers.ICellEditorValidator; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.extensionpoints.editors.Activator; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; +import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; +import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.ExternalLabelPrimaryDragRoleEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.PapyrusWrappingLabel; +import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; +import org.eclipse.papyrus.uml.diagram.common.editparts.FloatingLabelEditPart; +import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; +import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; +import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; +import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.accessibility.AccessibleEvent; +import org.eclipse.swt.custom.BusyIndicator; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; +import org.eclipse.uml2.uml.Feature; + +/** + * @generated + */ +public class ChangeEventFloatingLabelEditPart extends FloatingLabelEditPart + implements ITextAwareEditPart, IBorderItemEditPart +{ + + /** + * @generated + */ + public static final int VISUAL_ID = 6104; + + /** + * @generated + */ + private DirectEditManager manager; + + /** + * @generated + */ + private IParser parser; + + /** + * @generated + */ + private List parserElements; + + /** + * @generated + */ + private String defaultText; + + /** + * direct edition mode (default, undefined, registered editor, etc.) + * + * @generated + */ + protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; + + /** + * configuration from a registered edit dialog + * + * @generated + */ + protected IDirectEditorConfiguration configuration; + + + /** + * @generated + */ + static { + registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.ChangeEventFloatingLabelEditPart.VISUAL_ID), new Point(0, 0)); + } + + /** + * @generated + */ + public ChangeEventFloatingLabelEditPart(View view) { + super(view); + } + + /** + * @generated + */ + @Override + protected void createDefaultEditPolicies() { + super.createDefaultEditPolicies(); + installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); + installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ExternalLabelPrimaryDragRoleEditPolicy()); + } + + /** + * @generated + */ + @Override + public IBorderItemLocator getBorderItemLocator() { + IFigure parentFigure = getFigure().getParent(); + if (parentFigure != null && parentFigure.getLayoutManager() != null) { + Object constraint = parentFigure.getLayoutManager().getConstraint(getFigure()); + return (IBorderItemLocator) constraint; + } + return null; + } + + /** + * @generated + */ + @Override + public void refreshBounds() { + int x = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_X())).intValue(); + int y = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_Y())).intValue(); + int width = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Width())).intValue(); + int height = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Height())).intValue(); + getBorderItemLocator().setConstraint(new Rectangle(x, y, width, height)); + } + + + /** + * @generated + */ + protected String getLabelTextHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getText(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getText(); + } else { + return ((Label) figure).getText(); + } + } + + /** + * @generated + */ + protected void setLabelTextHelper(IFigure figure, String text) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setText(text); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setText(text); + } else { + ((Label) figure).setText(text); + } + } + + /** + * @generated + */ + protected Image getLabelIconHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getIcon(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getIcon(); + } else { + return ((Label) figure).getIcon(); + } + } + + /** + * @generated + */ + protected void setLabelIconHelper(IFigure figure, Image icon) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setIcon(icon); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setIcon(icon); + } else { + ((Label) figure).setIcon(icon); + } + } + + /** + * @generated + */ + public void setLabel(IFigure + figure) { + unregisterVisuals(); + setFigure(figure); + defaultText = getLabelTextHelper(figure); + registerVisuals(); + refreshVisuals(); + } + + /** + * @generated + */ + @Override + protected List getModelChildren() { + return Collections.EMPTY_LIST; + } + + /** + * @generated + */ + @Override + public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { + return null; + } + + /** + * @generated + */ + public void setParser(IParser parser) { + this.parser = parser; + } + + /** + * @generated + */ + protected EObject getParserElement() { + return resolveSemanticElement(); + } + + /** + * @generated + */ + protected Image getLabelIcon() { + return null; + } + + /** + * @generated + */ + protected String getLabelText() { + String text = null; + EObject parserElement = getParserElement(); + if (parserElement != null && getParser() != null) { + text = getParser().getPrintString( + new EObjectAdapter(parserElement), + getParserOptions().intValue()); + } + if (text == null || text.length() == 0) { + text = defaultText; + } + return text; + } + + /** + * @generated + */ + @Override + public void setLabelText(String text) { + setLabelTextHelper(getFigure(), text); + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + @Override + public String getEditText() { + if (getParserElement() == null || getParser() == null) { + return ""; //$NON-NLS-1$ + } + return getParser().getEditString( + new EObjectAdapter(getParserElement()), + getParserOptions().intValue()); + } + + /** + * @generated + */ + protected boolean isEditable() { + return getParser() != null; + } + + /** + * @generated + */ + @Override + public ICellEditorValidator getEditTextValidator() { + return new ICellEditorValidator() { + + @Override + public String isValid(final Object value) { + if (value instanceof String) { + final EObject element = getParserElement(); + final IParser parser = getParser(); + try { + IParserEditStatus valid = + (IParserEditStatus) getEditingDomain().runExclusive( + new RunnableWithResult.Impl() { + + @Override + public void run() { + setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); + } + }); + return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); + } catch (InterruptedException ie) { + ie.printStackTrace(); + } + } + + // shouldn't get here + return null; + } + }; + } + + /** + * @generated + */ + @Override + public IContentAssistProcessor getCompletionProcessor() { + if (getParserElement() == null || getParser() == null) { + return null; + } + return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); + } + + /** + * @generated + */ + @Override + public ParserOptions getParserOptions() { + return ParserOptions.NONE; + } + + /** + * @generated + */ + @Override + public IParser getParser() { + if (parser == null) { + parser = UMLParserProvider.getParser(UMLElementTypes.ChangeEvent_2088, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.ChangeEventFloatingLabelEditPart.VISUAL_ID)); + } + return parser; + } + + /** + * @generated + */ + protected DirectEditManager getManager() { + if (manager == null) { + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + } + return manager; + } + + /** + * @generated + */ + protected void setManager(DirectEditManager manager) { + this.manager = manager; + } + + /** + * @generated + */ + protected void performDirectEdit() { + BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { + + @Override + public void run() { + getManager().show(); + } + }); + } + + /** + * @generated + */ + protected void performDirectEdit(Point eventLocation) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); + } + } + + /** + * @generated + */ + private void performDirectEdit(char initialCharacter) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(initialCharacter); + } else { + performDirectEdit(); + } + } + + /** + * @generated + */ + @Override + protected void performDirectEditRequest(Request request) { + + final Request theRequest = request; + + if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { + directEditionMode = getDirectEditionType(); + } + switch (directEditionMode) { + case IDirectEdition.NO_DIRECT_EDITION: + // no direct edition mode => does nothing + return; + case IDirectEdition.EXTENDED_DIRECT_EDITOR: + updateExtendedEditorConfiguration(); + if (configuration == null || configuration.getLanguage() == null) { + // Create default edit manager + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + performDefaultDirectEditorEdit(theRequest); + } else { + configuration.preEditAction(resolveSemanticElement()); + Dialog dialog = null; + if (configuration instanceof ICustomDirectEditorConfiguration) { + setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); + initializeDirectEditManager(theRequest); + return; + } else if (configuration instanceof IPopupEditorConfiguration) { + IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); + helper.showEditor(); + return; + } + else if (configuration instanceof IAdvancedEditorConfiguration) { + dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); + } else if (configuration instanceof IDirectEditorConfiguration) { + dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), + configuration); + } else { + return; + } + final Dialog finalDialog = dialog; + + if (Window.OK == dialog.open()) { + TransactionalEditingDomain domain = getEditingDomain(); + RecordingCommand command = new RecordingCommand(domain, "Edit Label") { + + @Override + protected void doExecute() { + configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); + + } + }; + domain.getCommandStack().execute(command); + } + } + break; + case IDirectEdition.DEFAULT_DIRECT_EDITOR: + initializeDirectEditManager(theRequest); + break; + default: + break; + } + } + + /** + * @generated + */ + protected void initializeDirectEditManager(final Request request) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + @Override + public void run() { + if (isActive() && isEditable()) { + if (request.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } + else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void refreshVisuals() { + super.refreshVisuals(); + refreshLabel(); + refreshFont(); + refreshFontColor(); + refreshUnderline(); + refreshStrikeThrough(); + } + + /** + * @generated + */ + protected void refreshLabel() { + EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); + if (maskLabelPolicy == null) { + maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); + } + if (maskLabelPolicy == null) { + View view = (View) getModel(); + if (view.isVisible()) { + setLabelTextHelper(getFigure(), getLabelText()); + setLabelIconHelper(getFigure(), getLabelIcon()); + } + else { + setLabelTextHelper(getFigure(), ""); //$NON-NLS-1$ + setLabelIconHelper(getFigure(), null); + } + } + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + protected void refreshUnderline() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); + } + if (resolveSemanticElement() instanceof Feature) { + if (((Feature) resolveSemanticElement()).isStatic()) { + ((WrappingLabel) getFigure()).setTextUnderline(true); + } + else { + ((WrappingLabel) getFigure()).setTextUnderline(false); + } + } + } + + /** + * @generated + */ + protected void refreshStrikeThrough() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); + } + } + + /** + * @generated + */ + @Override + protected void refreshFont() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null) { + FontData fontData = new FontData( + style.getFontName(), style.getFontHeight(), + (style.isBold() ? SWT.BOLD : SWT.NORMAL) | + (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); + setFont(fontData); + } + } + + /** + * @generated + */ + @Override + protected void setFontColor(Color color) { + getFigure().setForegroundColor(color); + } + + /** + * @generated + */ + @Override + protected void addSemanticListeners() { + if (getParser() instanceof ISemanticParser) { + EObject element = resolveSemanticElement(); + parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); + for (int i = 0; i < parserElements.size(); i++) { + addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ + } + } else { + super.addSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected void removeSemanticListeners() { + if (parserElements != null) { + for (int i = 0; i < parserElements.size(); i++) { + removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ + } + } else { + super.removeSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected AccessibleEditPart getAccessibleEditPart() { + if (accessibleEP == null) { + accessibleEP = new AccessibleGraphicalEditPart() { + + @Override + public void getName(AccessibleEvent e) { + e.result = getLabelTextHelper(getFigure()); + } + }; + } + return accessibleEP; + } + + /** + * @generated + */ + private View getFontStyleOwnerView() { + return getPrimaryView(); + } + + /** + * Returns the kind of associated editor for direct edition. + * + * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition + * @generated + */ + public int getDirectEditionType() { + if (checkExtendedEditor()) { + initExtendedEditorConfiguration(); + return IDirectEdition.EXTENDED_DIRECT_EDITOR; + } + if (checkDefaultEdition()) { + return IDirectEdition.DEFAULT_DIRECT_EDITOR; + } + + // not a named element. no specific editor => do nothing + return IDirectEdition.NO_DIRECT_EDITION; + } + + /** + * Checks if an extended editor is present. + * + * @return true if an extended editor is present. + * @generated + */ + protected boolean checkExtendedEditor() { + if (resolveSemanticElement() != null) { + return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); + } + return false; + } + + /** + * Checks if a default direct edition is available + * + * @return true if a default direct edition is available + * @generated + */ + protected boolean checkDefaultEdition() { + return (getParser() != null); + } + + /** + * Initializes the extended editor configuration + * + * @generated + */ + protected void initExtendedEditorConfiguration() { + if (configuration == null) { + final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("")) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); + } else { + configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); + } + } + } + + /** + * Updates the preference configuration + * + * @generated + */ + protected void updateExtendedEditorConfiguration() { + String languagePreferred = Activator.getDefault().getPreferenceStore().getString( + IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() + .eClass().getInstanceClassName()); + } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { + configuration = null; + } + } + + /** + * Performs the direct edit usually used by GMF editors. + * + * @param theRequest + * the direct edit request that starts the direct edit system + * @generated + */ + protected void performDefaultDirectEditorEdit(final Request theRequest) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + + @Override + public void run() { + if (isActive() && isEditable()) { + if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) theRequest.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { + DirectEditRequest editRequest = (DirectEditRequest) theRequest; + performDirectEdit(editRequest.getLocation()); + } else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + + /** + * @generated + */ + @Override + protected void handleNotificationEvent(Notification event) { + Object feature = event.getFeature(); + if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { + Integer c = (Integer) event.getNewValue(); + setFontColor(DiagramColorRegistry.getInstance().getColor(c)); + } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { + refreshUnderline(); + } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { + refreshStrikeThrough(); + } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { + refreshFont(); + } else { + if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { + refreshLabel(); + } + if (getParser() instanceof ISemanticParser) { + ISemanticParser modelParser = + (ISemanticParser) getParser(); + if (modelParser.areSemanticElementsAffected(null, event)) { + removeSemanticListeners(); + if (resolveSemanticElement() != null) { + addSemanticListeners(); + } + refreshLabel(); + } + } + } + super.handleNotificationEvent(event); + } + + /** + * @generated + */ + @Override + protected IFigure createFigure() { + IFigure label = createFigurePrim(); + defaultText = getLabelTextHelper(label); + return label; + } + + /** + * @generated + */ + protected IFigure createFigurePrim() { + return new PapyrusWrappingLabel(); + } + +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ChangeEventNameEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ChangeEventNameEditPart.java index 4c0352e25df..d3754f415c8 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ChangeEventNameEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ChangeEventNameEditPart.java @@ -864,7 +864,7 @@ public class ChangeEventNameEditPart extends PapyrusCompartmentEditPart implemen * @generated */ protected void addOwnerElementListeners() { - addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); + addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ClassCompositeCompartmentEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ClassCompositeCompartmentEditPart.java index 46bc3ebcf72..7b60372ebf2 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ClassCompositeCompartmentEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ClassCompositeCompartmentEditPart.java @@ -26,6 +26,7 @@ import org.eclipse.gmf.runtime.diagram.ui.editpolicies.ResizableCompartmentEditP import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.BorderDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.CustomContainerEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.DuplicatePasteEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.PapyrusCreationEditPolicy; @@ -75,6 +76,7 @@ public class ClassCompositeCompartmentEditPart extends ShapeCompartmentEditPart installEditPolicy(EditPolicy.GRAPHICAL_NODE_ROLE, new CustomContainerEditPolicy()); installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, new CustomDiagramDragDropEditPolicy()); installEditPolicy(EditPolicyRoles.CREATION_ROLE, new PortInCompartmentCreationEditPolicy()); + installEditPolicy(BorderDisplayEditPolicy.BORDER_DISPLAY_EDITPOLICY, new BorderDisplayEditPolicy()); } /** diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ClassCompositeCompartmentEditPartCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ClassCompositeCompartmentEditPartCN.java index fbf745619df..cd186d7c7d1 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ClassCompositeCompartmentEditPartCN.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ClassCompositeCompartmentEditPartCN.java @@ -26,6 +26,7 @@ import org.eclipse.gmf.runtime.diagram.ui.editpolicies.ResizableCompartmentEditP import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.BorderDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.CustomContainerEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.DuplicatePasteEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.PapyrusCreationEditPolicy; @@ -75,6 +76,7 @@ public class ClassCompositeCompartmentEditPartCN extends ShapeCompartmentEditPar installEditPolicy(EditPolicy.GRAPHICAL_NODE_ROLE, new CustomContainerEditPolicy()); installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, new CustomDiagramDragDropEditPolicy()); installEditPolicy(EditPolicyRoles.CREATION_ROLE, new PortInCompartmentCreationEditPolicy()); + installEditPolicy(BorderDisplayEditPolicy.BORDER_DISPLAY_EDITPOLICY, new BorderDisplayEditPolicy()); } /** diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ClassCompositeEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ClassCompositeEditPart.java index 0751540da3d..0c75a5e5b47 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ClassCompositeEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ClassCompositeEditPart.java @@ -11,28 +11,37 @@ */ package org.eclipse.papyrus.uml.diagram.composite.edit.parts; +import java.util.Collections; +import java.util.List; + import org.eclipse.draw2d.IFigure; import org.eclipse.draw2d.PositionConstants; import org.eclipse.emf.common.notify.Notification; import org.eclipse.gef.EditPart; import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.GraphicalEditPart; 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.handles.MoveHandle; import org.eclipse.gef.requests.CreateRequest; import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.BorderItemSelectionEditPolicy; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.DragDropEditPolicy; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles; import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; -import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure; import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure; +import org.eclipse.gmf.runtime.notation.Edge; +import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.GetChildLayoutEditPolicy; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.IPapyrusNodeFigure; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.RoundedRectangleNodePlateFigure; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.SelectableBorderedNodeFigure; -import org.eclipse.papyrus.uml.diagram.common.editparts.NamedElementEditPart; +import org.eclipse.papyrus.uml.diagram.common.editparts.RoundedCompartmentEditPart; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AffixedNodeAlignmentEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeNodeLabelDisplayEditPolicy; @@ -41,12 +50,12 @@ import org.eclipse.papyrus.uml.diagram.common.editpolicies.PapyrusCreationEditPo import org.eclipse.papyrus.uml.diagram.common.editpolicies.QualifiedNameDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.ShowHideClassifierContentsEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.ShowHideCompartmentEditPolicy; +import org.eclipse.papyrus.uml.diagram.common.locator.RoundedRectangleLabelPositionLocator; import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.CustomDiagramDragDropEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.CustomGraphicalNodeEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.RemoveOrphanViewPolicy; import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.StructuredClassifierLayoutEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.custom.figures.ClassCompositeFigure; -import org.eclipse.papyrus.uml.diagram.composite.custom.locators.PortPositionLocator; import org.eclipse.papyrus.uml.diagram.composite.edit.policies.ClassCompositeItemSemanticEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; import org.eclipse.swt.graphics.Color; @@ -54,7 +63,7 @@ import org.eclipse.swt.graphics.Color; /** * @generated */ -public class ClassCompositeEditPart extends NamedElementEditPart { +public class ClassCompositeEditPart extends RoundedCompartmentEditPart { /** * @generated @@ -97,6 +106,7 @@ public class ClassCompositeEditPart extends NamedElementEditPart { installEditPolicy(ShowHideCompartmentEditPolicy.SHOW_HIDE_COMPARTMENT_POLICY, new ShowHideCompartmentEditPolicy()); installEditPolicy(AffixedNodeAlignmentEditPolicy.AFFIXED_CHILD_ALIGNMENT_ROLE, new AffixedNodeAlignmentEditPolicy()); installEditPolicy("REMOVE_ORPHAN_VIEW", new RemoveOrphanViewPolicy()); //$NON-NLS-1$ + installEditPolicy(EditPolicy.LAYOUT_ROLE, new GetChildLayoutEditPolicy()); // XXX need an SCR to runtime to have another abstract superclass that would let children add reasonable editpolicies // removeEditPolicy(org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles.CONNECTION_HANDLES_ROLE); } @@ -111,6 +121,17 @@ public class ClassCompositeEditPart extends NamedElementEditPart { protected EditPolicy createChildEditPolicy(EditPart child) { View childView = (View) child.getModel(); switch (UMLVisualIDRegistry.getVisualID(childView)) { + case ClassCompositeFloatingLabelEditPart.VISUAL_ID: + return new BorderItemSelectionEditPolicy() { + + @Override + protected List createSelectionHandles() { + MoveHandle mh = new MoveHandle((GraphicalEditPart) getHost()); + mh.setBorder(null); + return Collections.singletonList(mh); + } + } + ; case PortEditPart.VISUAL_ID: return new BorderItemResizableEditPolicy(); } @@ -141,6 +162,19 @@ public class ClassCompositeEditPart extends NamedElementEditPart { **/ @Override protected void handleNotificationEvent(Notification event) { + /* + * when a node have external node labels, the methods refreshChildren() remove the EditPart corresponding to the Label from the EditPart + * Registry. After that, we can't reset the visibility to true (using the Show/Hide Label Action)! + */ + if (NotationPackage.eINSTANCE.getView_Visible().equals(event.getFeature())) { + Object notifier = event.getNotifier(); + List modelChildren = ((View) getModel()).getChildren(); + if (!(notifier instanceof Edge)) { + if (modelChildren.contains(event.getNotifier())) { + return; + } + } + } super.handleNotificationEvent(event); } @@ -182,9 +216,9 @@ public class ClassCompositeEditPart extends NamedElementEditPart { - //Papyrus Gencode :Affixed Port locator + // Papyrus Gencode :Affixed Port locator if (childEditPart instanceof PortEditPart) { - IBorderItemLocator locator = new PortPositionLocator(getMainFigure(), PositionConstants.NONE); + IBorderItemLocator locator = new org.eclipse.papyrus.uml.diagram.common.locator.PortPositionLocator(getMainFigure(), PositionConstants.NONE); getBorderedFigure().getBorderItemContainer().add(((PortEditPart) childEditPart).getFigure(), locator); return true; } @@ -248,12 +282,26 @@ public class ClassCompositeEditPart extends NamedElementEditPart { return getContentPane(); } + /** + * @generated + */ + @Override + protected void addBorderItem(IFigure borderItemContainer, IBorderItemEditPart borderItemEditPart) { + if (borderItemEditPart instanceof ClassCompositeFloatingLabelEditPart) { + IBorderItemLocator locator = new RoundedRectangleLabelPositionLocator(getMainFigure()); + borderItemContainer.add(borderItemEditPart.getFigure(), locator); + } else + { + super.addBorderItem(borderItemContainer, borderItemEditPart); + } + } + /** * @generated */ @Override protected NodeFigure createNodePlate() { - DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(40, 40); + RoundedRectangleNodePlateFigure result = new RoundedRectangleNodePlateFigure(40, 40); return result; } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ClassCompositeEditPartCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ClassCompositeEditPartCN.java index 8af6f25bc39..f3fda4b3a78 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ClassCompositeEditPartCN.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ClassCompositeEditPartCN.java @@ -11,28 +11,37 @@ */ package org.eclipse.papyrus.uml.diagram.composite.edit.parts; +import java.util.Collections; +import java.util.List; + import org.eclipse.draw2d.IFigure; import org.eclipse.draw2d.PositionConstants; import org.eclipse.emf.common.notify.Notification; import org.eclipse.gef.EditPart; import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.GraphicalEditPart; 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.handles.MoveHandle; import org.eclipse.gef.requests.CreateRequest; import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.BorderItemSelectionEditPolicy; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.DragDropEditPolicy; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles; import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; -import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure; import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure; +import org.eclipse.gmf.runtime.notation.Edge; +import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.GetChildLayoutEditPolicy; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.IPapyrusNodeFigure; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.RoundedRectangleNodePlateFigure; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.SelectableBorderedNodeFigure; -import org.eclipse.papyrus.uml.diagram.common.editparts.NamedElementEditPart; +import org.eclipse.papyrus.uml.diagram.common.editparts.RoundedCompartmentEditPart; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AffixedNodeAlignmentEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeNodeLabelDisplayEditPolicy; @@ -41,12 +50,12 @@ import org.eclipse.papyrus.uml.diagram.common.editpolicies.PapyrusCreationEditPo import org.eclipse.papyrus.uml.diagram.common.editpolicies.QualifiedNameDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.ShowHideClassifierContentsEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.ShowHideCompartmentEditPolicy; +import org.eclipse.papyrus.uml.diagram.common.locator.RoundedRectangleLabelPositionLocator; import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.CustomDiagramDragDropEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.CustomGraphicalNodeEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.RemoveOrphanViewPolicy; import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.StructuredClassifierLayoutEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.custom.figures.ClassCompositeFigure; -import org.eclipse.papyrus.uml.diagram.composite.custom.locators.PortPositionLocator; import org.eclipse.papyrus.uml.diagram.composite.edit.policies.ClassCompositeItemSemanticEditPolicyCN; import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; import org.eclipse.swt.graphics.Color; @@ -54,7 +63,7 @@ import org.eclipse.swt.graphics.Color; /** * @generated */ -public class ClassCompositeEditPartCN extends NamedElementEditPart { +public class ClassCompositeEditPartCN extends RoundedCompartmentEditPart { /** * @generated @@ -97,6 +106,7 @@ public class ClassCompositeEditPartCN extends NamedElementEditPart { installEditPolicy(ShowHideCompartmentEditPolicy.SHOW_HIDE_COMPARTMENT_POLICY, new ShowHideCompartmentEditPolicy()); installEditPolicy(AffixedNodeAlignmentEditPolicy.AFFIXED_CHILD_ALIGNMENT_ROLE, new AffixedNodeAlignmentEditPolicy()); installEditPolicy("REMOVE_ORPHAN_VIEW", new RemoveOrphanViewPolicy()); //$NON-NLS-1$ + installEditPolicy(EditPolicy.LAYOUT_ROLE, new GetChildLayoutEditPolicy()); // XXX need an SCR to runtime to have another abstract superclass that would let children add reasonable editpolicies // removeEditPolicy(org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles.CONNECTION_HANDLES_ROLE); } @@ -111,6 +121,17 @@ public class ClassCompositeEditPartCN extends NamedElementEditPart { protected EditPolicy createChildEditPolicy(EditPart child) { View childView = (View) child.getModel(); switch (UMLVisualIDRegistry.getVisualID(childView)) { + case ClassCompositeFloatingLabelEditPartCN.VISUAL_ID: + return new BorderItemSelectionEditPolicy() { + + @Override + protected List createSelectionHandles() { + MoveHandle mh = new MoveHandle((GraphicalEditPart) getHost()); + mh.setBorder(null); + return Collections.singletonList(mh); + } + } + ; case PortEditPart.VISUAL_ID: return new BorderItemResizableEditPolicy(); } @@ -141,6 +162,19 @@ public class ClassCompositeEditPartCN extends NamedElementEditPart { **/ @Override protected void handleNotificationEvent(Notification event) { + /* + * when a node have external node labels, the methods refreshChildren() remove the EditPart corresponding to the Label from the EditPart + * Registry. After that, we can't reset the visibility to true (using the Show/Hide Label Action)! + */ + if (NotationPackage.eINSTANCE.getView_Visible().equals(event.getFeature())) { + Object notifier = event.getNotifier(); + List modelChildren = ((View) getModel()).getChildren(); + if (!(notifier instanceof Edge)) { + if (modelChildren.contains(event.getNotifier())) { + return; + } + } + } super.handleNotificationEvent(event); } @@ -182,9 +216,9 @@ public class ClassCompositeEditPartCN extends NamedElementEditPart { - //Papyrus Gencode :Affixed Port locator + // Papyrus Gencode :Affixed Port locator if (childEditPart instanceof PortEditPart) { - IBorderItemLocator locator = new PortPositionLocator(getMainFigure(), PositionConstants.NONE); + IBorderItemLocator locator = new org.eclipse.papyrus.uml.diagram.common.locator.PortPositionLocator(getMainFigure(), PositionConstants.NONE); getBorderedFigure().getBorderItemContainer().add(((PortEditPart) childEditPart).getFigure(), locator); return true; } @@ -248,12 +282,26 @@ public class ClassCompositeEditPartCN extends NamedElementEditPart { return getContentPane(); } + /** + * @generated + */ + @Override + protected void addBorderItem(IFigure borderItemContainer, IBorderItemEditPart borderItemEditPart) { + if (borderItemEditPart instanceof ClassCompositeFloatingLabelEditPartCN) { + IBorderItemLocator locator = new RoundedRectangleLabelPositionLocator(getMainFigure()); + borderItemContainer.add(borderItemEditPart.getFigure(), locator); + } else + { + super.addBorderItem(borderItemContainer, borderItemEditPart); + } + } + /** * @generated */ @Override protected NodeFigure createNodePlate() { - DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(40, 40); + RoundedRectangleNodePlateFigure result = new RoundedRectangleNodePlateFigure(40, 40); return result; } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ClassCompositeFloatingLabelEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ClassCompositeFloatingLabelEditPart.java new file mode 100644 index 00000000000..167de32b53d --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ClassCompositeFloatingLabelEditPart.java @@ -0,0 +1,860 @@ +/** + * 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.uml.diagram.composite.edit.parts; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.Label; +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.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.RunnableWithResult; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gef.AccessibleEditPart; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.Request; +import org.eclipse.gef.requests.DirectEditRequest; +import org.eclipse.gef.tools.DirectEditManager; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; +import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; +import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; +import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; +import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; +import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; +import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; +import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; +import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; +import org.eclipse.gmf.runtime.notation.FontStyle; +import org.eclipse.gmf.runtime.notation.NotationPackage; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.text.contentassist.IContentAssistProcessor; +import org.eclipse.jface.viewers.ICellEditorValidator; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.extensionpoints.editors.Activator; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; +import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; +import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.ExternalLabelPrimaryDragRoleEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.PapyrusWrappingLabel; +import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; +import org.eclipse.papyrus.uml.diagram.common.editparts.FloatingLabelEditPart; +import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; +import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; +import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; +import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.accessibility.AccessibleEvent; +import org.eclipse.swt.custom.BusyIndicator; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; +import org.eclipse.uml2.uml.Feature; + +/** + * @generated + */ +public class ClassCompositeFloatingLabelEditPart extends FloatingLabelEditPart + implements ITextAwareEditPart, IBorderItemEditPart +{ + + /** + * @generated + */ + public static final int VISUAL_ID = 6089; + + /** + * @generated + */ + private DirectEditManager manager; + + /** + * @generated + */ + private IParser parser; + + /** + * @generated + */ + private List parserElements; + + /** + * @generated + */ + private String defaultText; + + /** + * direct edition mode (default, undefined, registered editor, etc.) + * + * @generated + */ + protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; + + /** + * configuration from a registered edit dialog + * + * @generated + */ + protected IDirectEditorConfiguration configuration; + + + /** + * @generated + */ + static { + registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.ClassCompositeFloatingLabelEditPart.VISUAL_ID), new Point(0, 0)); + } + + /** + * @generated + */ + public ClassCompositeFloatingLabelEditPart(View view) { + super(view); + } + + /** + * @generated + */ + @Override + protected void createDefaultEditPolicies() { + super.createDefaultEditPolicies(); + installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); + installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ExternalLabelPrimaryDragRoleEditPolicy()); + } + + /** + * @generated + */ + @Override + public IBorderItemLocator getBorderItemLocator() { + IFigure parentFigure = getFigure().getParent(); + if (parentFigure != null && parentFigure.getLayoutManager() != null) { + Object constraint = parentFigure.getLayoutManager().getConstraint(getFigure()); + return (IBorderItemLocator) constraint; + } + return null; + } + + /** + * @generated + */ + @Override + public void refreshBounds() { + int x = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_X())).intValue(); + int y = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_Y())).intValue(); + int width = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Width())).intValue(); + int height = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Height())).intValue(); + getBorderItemLocator().setConstraint(new Rectangle(x, y, width, height)); + } + + + /** + * @generated + */ + protected String getLabelTextHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getText(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getText(); + } else { + return ((Label) figure).getText(); + } + } + + /** + * @generated + */ + protected void setLabelTextHelper(IFigure figure, String text) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setText(text); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setText(text); + } else { + ((Label) figure).setText(text); + } + } + + /** + * @generated + */ + protected Image getLabelIconHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getIcon(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getIcon(); + } else { + return ((Label) figure).getIcon(); + } + } + + /** + * @generated + */ + protected void setLabelIconHelper(IFigure figure, Image icon) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setIcon(icon); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setIcon(icon); + } else { + ((Label) figure).setIcon(icon); + } + } + + /** + * @generated + */ + public void setLabel(IFigure + figure) { + unregisterVisuals(); + setFigure(figure); + defaultText = getLabelTextHelper(figure); + registerVisuals(); + refreshVisuals(); + } + + /** + * @generated + */ + @Override + protected List getModelChildren() { + return Collections.EMPTY_LIST; + } + + /** + * @generated + */ + @Override + public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { + return null; + } + + /** + * @generated + */ + public void setParser(IParser parser) { + this.parser = parser; + } + + /** + * @generated + */ + protected EObject getParserElement() { + return resolveSemanticElement(); + } + + /** + * @generated + */ + protected Image getLabelIcon() { + return null; + } + + /** + * @generated + */ + protected String getLabelText() { + String text = null; + EObject parserElement = getParserElement(); + if (parserElement != null && getParser() != null) { + text = getParser().getPrintString( + new EObjectAdapter(parserElement), + getParserOptions().intValue()); + } + if (text == null || text.length() == 0) { + text = defaultText; + } + return text; + } + + /** + * @generated + */ + @Override + public void setLabelText(String text) { + setLabelTextHelper(getFigure(), text); + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + @Override + public String getEditText() { + if (getParserElement() == null || getParser() == null) { + return ""; //$NON-NLS-1$ + } + return getParser().getEditString( + new EObjectAdapter(getParserElement()), + getParserOptions().intValue()); + } + + /** + * @generated + */ + protected boolean isEditable() { + return getParser() != null; + } + + /** + * @generated + */ + @Override + public ICellEditorValidator getEditTextValidator() { + return new ICellEditorValidator() { + + @Override + public String isValid(final Object value) { + if (value instanceof String) { + final EObject element = getParserElement(); + final IParser parser = getParser(); + try { + IParserEditStatus valid = + (IParserEditStatus) getEditingDomain().runExclusive( + new RunnableWithResult.Impl() { + + @Override + public void run() { + setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); + } + }); + return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); + } catch (InterruptedException ie) { + ie.printStackTrace(); + } + } + + // shouldn't get here + return null; + } + }; + } + + /** + * @generated + */ + @Override + public IContentAssistProcessor getCompletionProcessor() { + if (getParserElement() == null || getParser() == null) { + return null; + } + return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); + } + + /** + * @generated + */ + @Override + public ParserOptions getParserOptions() { + return ParserOptions.NONE; + } + + /** + * @generated + */ + @Override + public IParser getParser() { + if (parser == null) { + parser = UMLParserProvider.getParser(UMLElementTypes.Class_2073, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.ClassCompositeFloatingLabelEditPart.VISUAL_ID)); + } + return parser; + } + + /** + * @generated + */ + protected DirectEditManager getManager() { + if (manager == null) { + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + } + return manager; + } + + /** + * @generated + */ + protected void setManager(DirectEditManager manager) { + this.manager = manager; + } + + /** + * @generated + */ + protected void performDirectEdit() { + BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { + + @Override + public void run() { + getManager().show(); + } + }); + } + + /** + * @generated + */ + protected void performDirectEdit(Point eventLocation) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); + } + } + + /** + * @generated + */ + private void performDirectEdit(char initialCharacter) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(initialCharacter); + } else { + performDirectEdit(); + } + } + + /** + * @generated + */ + @Override + protected void performDirectEditRequest(Request request) { + + final Request theRequest = request; + + if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { + directEditionMode = getDirectEditionType(); + } + switch (directEditionMode) { + case IDirectEdition.NO_DIRECT_EDITION: + // no direct edition mode => does nothing + return; + case IDirectEdition.EXTENDED_DIRECT_EDITOR: + updateExtendedEditorConfiguration(); + if (configuration == null || configuration.getLanguage() == null) { + // Create default edit manager + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + performDefaultDirectEditorEdit(theRequest); + } else { + configuration.preEditAction(resolveSemanticElement()); + Dialog dialog = null; + if (configuration instanceof ICustomDirectEditorConfiguration) { + setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); + initializeDirectEditManager(theRequest); + return; + } else if (configuration instanceof IPopupEditorConfiguration) { + IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); + helper.showEditor(); + return; + } + else if (configuration instanceof IAdvancedEditorConfiguration) { + dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); + } else if (configuration instanceof IDirectEditorConfiguration) { + dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), + configuration); + } else { + return; + } + final Dialog finalDialog = dialog; + + if (Window.OK == dialog.open()) { + TransactionalEditingDomain domain = getEditingDomain(); + RecordingCommand command = new RecordingCommand(domain, "Edit Label") { + + @Override + protected void doExecute() { + configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); + + } + }; + domain.getCommandStack().execute(command); + } + } + break; + case IDirectEdition.DEFAULT_DIRECT_EDITOR: + initializeDirectEditManager(theRequest); + break; + default: + break; + } + } + + /** + * @generated + */ + protected void initializeDirectEditManager(final Request request) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + @Override + public void run() { + if (isActive() && isEditable()) { + if (request.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } + else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void refreshVisuals() { + super.refreshVisuals(); + refreshLabel(); + refreshFont(); + refreshFontColor(); + refreshUnderline(); + refreshStrikeThrough(); + } + + /** + * @generated + */ + protected void refreshLabel() { + EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); + if (maskLabelPolicy == null) { + maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); + } + if (maskLabelPolicy == null) { + View view = (View) getModel(); + if (view.isVisible()) { + setLabelTextHelper(getFigure(), getLabelText()); + setLabelIconHelper(getFigure(), getLabelIcon()); + } + else { + setLabelTextHelper(getFigure(), ""); //$NON-NLS-1$ + setLabelIconHelper(getFigure(), null); + } + } + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + protected void refreshUnderline() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); + } + if (resolveSemanticElement() instanceof Feature) { + if (((Feature) resolveSemanticElement()).isStatic()) { + ((WrappingLabel) getFigure()).setTextUnderline(true); + } + else { + ((WrappingLabel) getFigure()).setTextUnderline(false); + } + } + } + + /** + * @generated + */ + protected void refreshStrikeThrough() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); + } + } + + /** + * @generated + */ + @Override + protected void refreshFont() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null) { + FontData fontData = new FontData( + style.getFontName(), style.getFontHeight(), + (style.isBold() ? SWT.BOLD : SWT.NORMAL) | + (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); + setFont(fontData); + } + } + + /** + * @generated + */ + @Override + protected void setFontColor(Color color) { + getFigure().setForegroundColor(color); + } + + /** + * @generated + */ + @Override + protected void addSemanticListeners() { + if (getParser() instanceof ISemanticParser) { + EObject element = resolveSemanticElement(); + parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); + for (int i = 0; i < parserElements.size(); i++) { + addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ + } + } else { + super.addSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected void removeSemanticListeners() { + if (parserElements != null) { + for (int i = 0; i < parserElements.size(); i++) { + removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ + } + } else { + super.removeSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected AccessibleEditPart getAccessibleEditPart() { + if (accessibleEP == null) { + accessibleEP = new AccessibleGraphicalEditPart() { + + @Override + public void getName(AccessibleEvent e) { + e.result = getLabelTextHelper(getFigure()); + } + }; + } + return accessibleEP; + } + + /** + * @generated + */ + private View getFontStyleOwnerView() { + return getPrimaryView(); + } + + /** + * Returns the kind of associated editor for direct edition. + * + * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition + * @generated + */ + public int getDirectEditionType() { + if (checkExtendedEditor()) { + initExtendedEditorConfiguration(); + return IDirectEdition.EXTENDED_DIRECT_EDITOR; + } + if (checkDefaultEdition()) { + return IDirectEdition.DEFAULT_DIRECT_EDITOR; + } + + // not a named element. no specific editor => do nothing + return IDirectEdition.NO_DIRECT_EDITION; + } + + /** + * Checks if an extended editor is present. + * + * @return true if an extended editor is present. + * @generated + */ + protected boolean checkExtendedEditor() { + if (resolveSemanticElement() != null) { + return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); + } + return false; + } + + /** + * Checks if a default direct edition is available + * + * @return true if a default direct edition is available + * @generated + */ + protected boolean checkDefaultEdition() { + return (getParser() != null); + } + + /** + * Initializes the extended editor configuration + * + * @generated + */ + protected void initExtendedEditorConfiguration() { + if (configuration == null) { + final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("")) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); + } else { + configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); + } + } + } + + /** + * Updates the preference configuration + * + * @generated + */ + protected void updateExtendedEditorConfiguration() { + String languagePreferred = Activator.getDefault().getPreferenceStore().getString( + IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() + .eClass().getInstanceClassName()); + } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { + configuration = null; + } + } + + /** + * Performs the direct edit usually used by GMF editors. + * + * @param theRequest + * the direct edit request that starts the direct edit system + * @generated + */ + protected void performDefaultDirectEditorEdit(final Request theRequest) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + + @Override + public void run() { + if (isActive() && isEditable()) { + if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) theRequest.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { + DirectEditRequest editRequest = (DirectEditRequest) theRequest; + performDirectEdit(editRequest.getLocation()); + } else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + + /** + * @generated + */ + @Override + protected void handleNotificationEvent(Notification event) { + Object feature = event.getFeature(); + if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { + Integer c = (Integer) event.getNewValue(); + setFontColor(DiagramColorRegistry.getInstance().getColor(c)); + } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { + refreshUnderline(); + } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { + refreshStrikeThrough(); + } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { + refreshFont(); + } else { + if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { + refreshLabel(); + } + if (getParser() instanceof ISemanticParser) { + ISemanticParser modelParser = + (ISemanticParser) getParser(); + if (modelParser.areSemanticElementsAffected(null, event)) { + removeSemanticListeners(); + if (resolveSemanticElement() != null) { + addSemanticListeners(); + } + refreshLabel(); + } + } + } + super.handleNotificationEvent(event); + } + + /** + * @generated + */ + @Override + protected IFigure createFigure() { + IFigure label = createFigurePrim(); + defaultText = getLabelTextHelper(label); + return label; + } + + /** + * @generated + */ + protected IFigure createFigurePrim() { + return new PapyrusWrappingLabel(); + } + +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ClassCompositeFloatingLabelEditPartCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ClassCompositeFloatingLabelEditPartCN.java new file mode 100644 index 00000000000..0b2c7535aaa --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ClassCompositeFloatingLabelEditPartCN.java @@ -0,0 +1,860 @@ +/** + * 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.uml.diagram.composite.edit.parts; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.Label; +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.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.RunnableWithResult; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gef.AccessibleEditPart; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.Request; +import org.eclipse.gef.requests.DirectEditRequest; +import org.eclipse.gef.tools.DirectEditManager; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; +import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; +import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; +import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; +import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; +import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; +import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; +import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; +import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; +import org.eclipse.gmf.runtime.notation.FontStyle; +import org.eclipse.gmf.runtime.notation.NotationPackage; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.text.contentassist.IContentAssistProcessor; +import org.eclipse.jface.viewers.ICellEditorValidator; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.extensionpoints.editors.Activator; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; +import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; +import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.ExternalLabelPrimaryDragRoleEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.PapyrusWrappingLabel; +import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; +import org.eclipse.papyrus.uml.diagram.common.editparts.FloatingLabelEditPart; +import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; +import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; +import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; +import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.accessibility.AccessibleEvent; +import org.eclipse.swt.custom.BusyIndicator; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; +import org.eclipse.uml2.uml.Feature; + +/** + * @generated + */ +public class ClassCompositeFloatingLabelEditPartCN extends FloatingLabelEditPart + implements ITextAwareEditPart, IBorderItemEditPart +{ + + /** + * @generated + */ + public static final int VISUAL_ID = 6067; + + /** + * @generated + */ + private DirectEditManager manager; + + /** + * @generated + */ + private IParser parser; + + /** + * @generated + */ + private List parserElements; + + /** + * @generated + */ + private String defaultText; + + /** + * direct edition mode (default, undefined, registered editor, etc.) + * + * @generated + */ + protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; + + /** + * configuration from a registered edit dialog + * + * @generated + */ + protected IDirectEditorConfiguration configuration; + + + /** + * @generated + */ + static { + registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.ClassCompositeFloatingLabelEditPartCN.VISUAL_ID), new Point(0, 0)); + } + + /** + * @generated + */ + public ClassCompositeFloatingLabelEditPartCN(View view) { + super(view); + } + + /** + * @generated + */ + @Override + protected void createDefaultEditPolicies() { + super.createDefaultEditPolicies(); + installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); + installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ExternalLabelPrimaryDragRoleEditPolicy()); + } + + /** + * @generated + */ + @Override + public IBorderItemLocator getBorderItemLocator() { + IFigure parentFigure = getFigure().getParent(); + if (parentFigure != null && parentFigure.getLayoutManager() != null) { + Object constraint = parentFigure.getLayoutManager().getConstraint(getFigure()); + return (IBorderItemLocator) constraint; + } + return null; + } + + /** + * @generated + */ + @Override + public void refreshBounds() { + int x = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_X())).intValue(); + int y = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_Y())).intValue(); + int width = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Width())).intValue(); + int height = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Height())).intValue(); + getBorderItemLocator().setConstraint(new Rectangle(x, y, width, height)); + } + + + /** + * @generated + */ + protected String getLabelTextHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getText(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getText(); + } else { + return ((Label) figure).getText(); + } + } + + /** + * @generated + */ + protected void setLabelTextHelper(IFigure figure, String text) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setText(text); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setText(text); + } else { + ((Label) figure).setText(text); + } + } + + /** + * @generated + */ + protected Image getLabelIconHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getIcon(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getIcon(); + } else { + return ((Label) figure).getIcon(); + } + } + + /** + * @generated + */ + protected void setLabelIconHelper(IFigure figure, Image icon) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setIcon(icon); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setIcon(icon); + } else { + ((Label) figure).setIcon(icon); + } + } + + /** + * @generated + */ + public void setLabel(IFigure + figure) { + unregisterVisuals(); + setFigure(figure); + defaultText = getLabelTextHelper(figure); + registerVisuals(); + refreshVisuals(); + } + + /** + * @generated + */ + @Override + protected List getModelChildren() { + return Collections.EMPTY_LIST; + } + + /** + * @generated + */ + @Override + public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { + return null; + } + + /** + * @generated + */ + public void setParser(IParser parser) { + this.parser = parser; + } + + /** + * @generated + */ + protected EObject getParserElement() { + return resolveSemanticElement(); + } + + /** + * @generated + */ + protected Image getLabelIcon() { + return null; + } + + /** + * @generated + */ + protected String getLabelText() { + String text = null; + EObject parserElement = getParserElement(); + if (parserElement != null && getParser() != null) { + text = getParser().getPrintString( + new EObjectAdapter(parserElement), + getParserOptions().intValue()); + } + if (text == null || text.length() == 0) { + text = defaultText; + } + return text; + } + + /** + * @generated + */ + @Override + public void setLabelText(String text) { + setLabelTextHelper(getFigure(), text); + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + @Override + public String getEditText() { + if (getParserElement() == null || getParser() == null) { + return ""; //$NON-NLS-1$ + } + return getParser().getEditString( + new EObjectAdapter(getParserElement()), + getParserOptions().intValue()); + } + + /** + * @generated + */ + protected boolean isEditable() { + return getParser() != null; + } + + /** + * @generated + */ + @Override + public ICellEditorValidator getEditTextValidator() { + return new ICellEditorValidator() { + + @Override + public String isValid(final Object value) { + if (value instanceof String) { + final EObject element = getParserElement(); + final IParser parser = getParser(); + try { + IParserEditStatus valid = + (IParserEditStatus) getEditingDomain().runExclusive( + new RunnableWithResult.Impl() { + + @Override + public void run() { + setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); + } + }); + return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); + } catch (InterruptedException ie) { + ie.printStackTrace(); + } + } + + // shouldn't get here + return null; + } + }; + } + + /** + * @generated + */ + @Override + public IContentAssistProcessor getCompletionProcessor() { + if (getParserElement() == null || getParser() == null) { + return null; + } + return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); + } + + /** + * @generated + */ + @Override + public ParserOptions getParserOptions() { + return ParserOptions.NONE; + } + + /** + * @generated + */ + @Override + public IParser getParser() { + if (parser == null) { + parser = UMLParserProvider.getParser(UMLElementTypes.Class_3085, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.ClassCompositeFloatingLabelEditPartCN.VISUAL_ID)); + } + return parser; + } + + /** + * @generated + */ + protected DirectEditManager getManager() { + if (manager == null) { + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + } + return manager; + } + + /** + * @generated + */ + protected void setManager(DirectEditManager manager) { + this.manager = manager; + } + + /** + * @generated + */ + protected void performDirectEdit() { + BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { + + @Override + public void run() { + getManager().show(); + } + }); + } + + /** + * @generated + */ + protected void performDirectEdit(Point eventLocation) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); + } + } + + /** + * @generated + */ + private void performDirectEdit(char initialCharacter) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(initialCharacter); + } else { + performDirectEdit(); + } + } + + /** + * @generated + */ + @Override + protected void performDirectEditRequest(Request request) { + + final Request theRequest = request; + + if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { + directEditionMode = getDirectEditionType(); + } + switch (directEditionMode) { + case IDirectEdition.NO_DIRECT_EDITION: + // no direct edition mode => does nothing + return; + case IDirectEdition.EXTENDED_DIRECT_EDITOR: + updateExtendedEditorConfiguration(); + if (configuration == null || configuration.getLanguage() == null) { + // Create default edit manager + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + performDefaultDirectEditorEdit(theRequest); + } else { + configuration.preEditAction(resolveSemanticElement()); + Dialog dialog = null; + if (configuration instanceof ICustomDirectEditorConfiguration) { + setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); + initializeDirectEditManager(theRequest); + return; + } else if (configuration instanceof IPopupEditorConfiguration) { + IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); + helper.showEditor(); + return; + } + else if (configuration instanceof IAdvancedEditorConfiguration) { + dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); + } else if (configuration instanceof IDirectEditorConfiguration) { + dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), + configuration); + } else { + return; + } + final Dialog finalDialog = dialog; + + if (Window.OK == dialog.open()) { + TransactionalEditingDomain domain = getEditingDomain(); + RecordingCommand command = new RecordingCommand(domain, "Edit Label") { + + @Override + protected void doExecute() { + configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); + + } + }; + domain.getCommandStack().execute(command); + } + } + break; + case IDirectEdition.DEFAULT_DIRECT_EDITOR: + initializeDirectEditManager(theRequest); + break; + default: + break; + } + } + + /** + * @generated + */ + protected void initializeDirectEditManager(final Request request) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + @Override + public void run() { + if (isActive() && isEditable()) { + if (request.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } + else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void refreshVisuals() { + super.refreshVisuals(); + refreshLabel(); + refreshFont(); + refreshFontColor(); + refreshUnderline(); + refreshStrikeThrough(); + } + + /** + * @generated + */ + protected void refreshLabel() { + EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); + if (maskLabelPolicy == null) { + maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); + } + if (maskLabelPolicy == null) { + View view = (View) getModel(); + if (view.isVisible()) { + setLabelTextHelper(getFigure(), getLabelText()); + setLabelIconHelper(getFigure(), getLabelIcon()); + } + else { + setLabelTextHelper(getFigure(), ""); //$NON-NLS-1$ + setLabelIconHelper(getFigure(), null); + } + } + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + protected void refreshUnderline() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); + } + if (resolveSemanticElement() instanceof Feature) { + if (((Feature) resolveSemanticElement()).isStatic()) { + ((WrappingLabel) getFigure()).setTextUnderline(true); + } + else { + ((WrappingLabel) getFigure()).setTextUnderline(false); + } + } + } + + /** + * @generated + */ + protected void refreshStrikeThrough() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); + } + } + + /** + * @generated + */ + @Override + protected void refreshFont() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null) { + FontData fontData = new FontData( + style.getFontName(), style.getFontHeight(), + (style.isBold() ? SWT.BOLD : SWT.NORMAL) | + (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); + setFont(fontData); + } + } + + /** + * @generated + */ + @Override + protected void setFontColor(Color color) { + getFigure().setForegroundColor(color); + } + + /** + * @generated + */ + @Override + protected void addSemanticListeners() { + if (getParser() instanceof ISemanticParser) { + EObject element = resolveSemanticElement(); + parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); + for (int i = 0; i < parserElements.size(); i++) { + addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ + } + } else { + super.addSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected void removeSemanticListeners() { + if (parserElements != null) { + for (int i = 0; i < parserElements.size(); i++) { + removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ + } + } else { + super.removeSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected AccessibleEditPart getAccessibleEditPart() { + if (accessibleEP == null) { + accessibleEP = new AccessibleGraphicalEditPart() { + + @Override + public void getName(AccessibleEvent e) { + e.result = getLabelTextHelper(getFigure()); + } + }; + } + return accessibleEP; + } + + /** + * @generated + */ + private View getFontStyleOwnerView() { + return getPrimaryView(); + } + + /** + * Returns the kind of associated editor for direct edition. + * + * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition + * @generated + */ + public int getDirectEditionType() { + if (checkExtendedEditor()) { + initExtendedEditorConfiguration(); + return IDirectEdition.EXTENDED_DIRECT_EDITOR; + } + if (checkDefaultEdition()) { + return IDirectEdition.DEFAULT_DIRECT_EDITOR; + } + + // not a named element. no specific editor => do nothing + return IDirectEdition.NO_DIRECT_EDITION; + } + + /** + * Checks if an extended editor is present. + * + * @return true if an extended editor is present. + * @generated + */ + protected boolean checkExtendedEditor() { + if (resolveSemanticElement() != null) { + return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); + } + return false; + } + + /** + * Checks if a default direct edition is available + * + * @return true if a default direct edition is available + * @generated + */ + protected boolean checkDefaultEdition() { + return (getParser() != null); + } + + /** + * Initializes the extended editor configuration + * + * @generated + */ + protected void initExtendedEditorConfiguration() { + if (configuration == null) { + final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("")) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); + } else { + configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); + } + } + } + + /** + * Updates the preference configuration + * + * @generated + */ + protected void updateExtendedEditorConfiguration() { + String languagePreferred = Activator.getDefault().getPreferenceStore().getString( + IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() + .eClass().getInstanceClassName()); + } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { + configuration = null; + } + } + + /** + * Performs the direct edit usually used by GMF editors. + * + * @param theRequest + * the direct edit request that starts the direct edit system + * @generated + */ + protected void performDefaultDirectEditorEdit(final Request theRequest) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + + @Override + public void run() { + if (isActive() && isEditable()) { + if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) theRequest.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { + DirectEditRequest editRequest = (DirectEditRequest) theRequest; + performDirectEdit(editRequest.getLocation()); + } else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + + /** + * @generated + */ + @Override + protected void handleNotificationEvent(Notification event) { + Object feature = event.getFeature(); + if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { + Integer c = (Integer) event.getNewValue(); + setFontColor(DiagramColorRegistry.getInstance().getColor(c)); + } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { + refreshUnderline(); + } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { + refreshStrikeThrough(); + } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { + refreshFont(); + } else { + if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { + refreshLabel(); + } + if (getParser() instanceof ISemanticParser) { + ISemanticParser modelParser = + (ISemanticParser) getParser(); + if (modelParser.areSemanticElementsAffected(null, event)) { + removeSemanticListeners(); + if (resolveSemanticElement() != null) { + addSemanticListeners(); + } + refreshLabel(); + } + } + } + super.handleNotificationEvent(event); + } + + /** + * @generated + */ + @Override + protected IFigure createFigure() { + IFigure label = createFigurePrim(); + defaultText = getLabelTextHelper(label); + return label; + } + + /** + * @generated + */ + protected IFigure createFigurePrim() { + return new PapyrusWrappingLabel(); + } + +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ClassCompositeNameEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ClassCompositeNameEditPart.java index 0bc110eae62..bda42c7f20a 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ClassCompositeNameEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ClassCompositeNameEditPart.java @@ -864,7 +864,7 @@ public class ClassCompositeNameEditPart extends PapyrusCompartmentEditPart imple * @generated */ protected void addOwnerElementListeners() { - addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); + addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ClassCompositeNameEditPartCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ClassCompositeNameEditPartCN.java index 92d8064d3fe..7ac79c04068 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ClassCompositeNameEditPartCN.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ClassCompositeNameEditPartCN.java @@ -864,7 +864,7 @@ public class ClassCompositeNameEditPartCN extends PapyrusCompartmentEditPart imp * @generated */ protected void addOwnerElementListeners() { - addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); + addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/CollaborationCompositeCompartmentEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/CollaborationCompositeCompartmentEditPart.java index 9304a3277dc..c404c6478dc 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/CollaborationCompositeCompartmentEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/CollaborationCompositeCompartmentEditPart.java @@ -26,6 +26,7 @@ import org.eclipse.gmf.runtime.diagram.ui.editpolicies.ResizableCompartmentEditP import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.BorderDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.CustomContainerEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.DuplicatePasteEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.PapyrusCreationEditPolicy; @@ -75,6 +76,7 @@ public class CollaborationCompositeCompartmentEditPart extends ShapeCompartmentE installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new CustomCollaborationCompositeCompartmentItemSemanticEditPolicy()); installEditPolicy(EditPolicy.GRAPHICAL_NODE_ROLE, new CustomContainerEditPolicy()); installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, new CustomDiagramDragDropEditPolicy()); + installEditPolicy(BorderDisplayEditPolicy.BORDER_DISPLAY_EDITPOLICY, new BorderDisplayEditPolicy()); } /** diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/CollaborationCompositeCompartmentEditPartCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/CollaborationCompositeCompartmentEditPartCN.java index 836c8b75b36..1cec2dd9be8 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/CollaborationCompositeCompartmentEditPartCN.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/CollaborationCompositeCompartmentEditPartCN.java @@ -26,6 +26,7 @@ import org.eclipse.gmf.runtime.diagram.ui.editpolicies.ResizableCompartmentEditP import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.BorderDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.CustomContainerEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.DuplicatePasteEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.PapyrusCreationEditPolicy; @@ -75,6 +76,7 @@ public class CollaborationCompositeCompartmentEditPartCN extends ShapeCompartmen installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new CustomCollaborationCompositeCompartmentItemSemanticEditPolicy()); installEditPolicy(EditPolicy.GRAPHICAL_NODE_ROLE, new CustomContainerEditPolicy()); installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, new CustomDiagramDragDropEditPolicy()); + installEditPolicy(BorderDisplayEditPolicy.BORDER_DISPLAY_EDITPOLICY, new BorderDisplayEditPolicy()); } /** diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/CollaborationCompositeEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/CollaborationCompositeEditPart.java index 8a1ab4dc2f7..b0934f52b86 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/CollaborationCompositeEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/CollaborationCompositeEditPart.java @@ -11,29 +11,41 @@ */ package org.eclipse.papyrus.uml.diagram.composite.edit.parts; +import java.util.Collections; +import java.util.List; + import org.eclipse.draw2d.IFigure; import org.eclipse.emf.common.notify.Notification; import org.eclipse.gef.EditPart; import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.GraphicalEditPart; 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.handles.MoveHandle; import org.eclipse.gef.requests.CreateRequest; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.BorderItemSelectionEditPolicy; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles; +import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; -import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure; import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure; +import org.eclipse.gmf.runtime.notation.Edge; +import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.GetChildLayoutEditPolicy; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.IPapyrusNodeFigure; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.RoundedRectangleNodePlateFigure; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.SelectableBorderedNodeFigure; -import org.eclipse.papyrus.uml.diagram.common.editparts.NamedElementEditPart; +import org.eclipse.papyrus.uml.diagram.common.editparts.RoundedCompartmentEditPart; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeNodeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.QualifiedNameDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.ShowHideClassifierContentsEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.ShowHideCompartmentEditPolicy; +import org.eclipse.papyrus.uml.diagram.common.locator.RoundedRectangleLabelPositionLocator; import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.CustomDiagramDragDropEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.custom.figures.CollaborationCompositeFigure; import org.eclipse.papyrus.uml.diagram.composite.edit.policies.CollaborationCompositeItemSemanticEditPolicy; @@ -43,7 +55,7 @@ import org.eclipse.swt.graphics.Color; /** * @generated */ -public class CollaborationCompositeEditPart extends NamedElementEditPart { +public class CollaborationCompositeEditPart extends RoundedCompartmentEditPart { /** * @generated @@ -80,6 +92,7 @@ public class CollaborationCompositeEditPart extends NamedElementEditPart { installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, new CustomDiagramDragDropEditPolicy()); installEditPolicy(ShowHideClassifierContentsEditPolicy.SHOW_HIDE_CLASSIFIER_CONTENTS_POLICY, new ShowHideClassifierContentsEditPolicy()); installEditPolicy(ShowHideCompartmentEditPolicy.SHOW_HIDE_COMPARTMENT_POLICY, new ShowHideCompartmentEditPolicy()); + installEditPolicy(EditPolicy.LAYOUT_ROLE, new GetChildLayoutEditPolicy()); // XXX need an SCR to runtime to have another abstract superclass that would let children add reasonable editpolicies // removeEditPolicy(org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles.CONNECTION_HANDLES_ROLE); } @@ -92,6 +105,20 @@ public class CollaborationCompositeEditPart extends NamedElementEditPart { @Override protected EditPolicy createChildEditPolicy(EditPart child) { + View childView = (View) child.getModel(); + switch (UMLVisualIDRegistry.getVisualID(childView)) { + case CollaborationCompositeFloatingLabelEditPart.VISUAL_ID: + return new BorderItemSelectionEditPolicy() { + + @Override + protected List createSelectionHandles() { + MoveHandle mh = new MoveHandle((GraphicalEditPart) getHost()); + mh.setBorder(null); + return Collections.singletonList(mh); + } + } + ; + } EditPolicy result = child.getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); if (result == null) { result = new NonResizableEditPolicy(); @@ -119,6 +146,19 @@ public class CollaborationCompositeEditPart extends NamedElementEditPart { **/ @Override protected void handleNotificationEvent(Notification event) { + /* + * when a node have external node labels, the methods refreshChildren() remove the EditPart corresponding to the Label from the EditPart + * Registry. After that, we can't reset the visibility to true (using the Show/Hide Label Action)! + */ + if (NotationPackage.eINSTANCE.getView_Visible().equals(event.getFeature())) { + Object notifier = event.getNotifier(); + List modelChildren = ((View) getModel()).getChildren(); + if (!(notifier instanceof Edge)) { + if (modelChildren.contains(event.getNotifier())) { + return; + } + } + } super.handleNotificationEvent(event); } @@ -206,15 +246,32 @@ public class CollaborationCompositeEditPart extends NamedElementEditPart { if (editPart instanceof CollaborationCompositeCompartmentEditPart) { return getPrimaryShape().getCompositeCompartmentFigure(); } + if (editPart instanceof IBorderItemEditPart) { + return getBorderedFigure().getBorderItemContainer(); + } return getContentPane(); } + /** + * @generated + */ + @Override + protected void addBorderItem(IFigure borderItemContainer, IBorderItemEditPart borderItemEditPart) { + if (borderItemEditPart instanceof CollaborationCompositeFloatingLabelEditPart) { + IBorderItemLocator locator = new RoundedRectangleLabelPositionLocator(getMainFigure()); + borderItemContainer.add(borderItemEditPart.getFigure(), locator); + } else + { + super.addBorderItem(borderItemContainer, borderItemEditPart); + } + } + /** * @generated */ @Override protected NodeFigure createNodePlate() { - DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(40, 40); + RoundedRectangleNodePlateFigure result = new RoundedRectangleNodePlateFigure(40, 40); return result; } @@ -227,7 +284,7 @@ public class CollaborationCompositeEditPart extends NamedElementEditPart { * @generated */ @Override - protected NodeFigure createNodeFigure() { + protected NodeFigure createMainFigure() { return new SelectableBorderedNodeFigure(createMainFigureWithSVG()); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/CollaborationCompositeEditPartCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/CollaborationCompositeEditPartCN.java index eef3769adf5..d0b54685684 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/CollaborationCompositeEditPartCN.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/CollaborationCompositeEditPartCN.java @@ -11,29 +11,41 @@ */ package org.eclipse.papyrus.uml.diagram.composite.edit.parts; +import java.util.Collections; +import java.util.List; + import org.eclipse.draw2d.IFigure; import org.eclipse.emf.common.notify.Notification; import org.eclipse.gef.EditPart; import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.GraphicalEditPart; 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.handles.MoveHandle; import org.eclipse.gef.requests.CreateRequest; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.BorderItemSelectionEditPolicy; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles; +import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; -import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure; import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure; +import org.eclipse.gmf.runtime.notation.Edge; +import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.GetChildLayoutEditPolicy; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.IPapyrusNodeFigure; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.RoundedRectangleNodePlateFigure; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.SelectableBorderedNodeFigure; -import org.eclipse.papyrus.uml.diagram.common.editparts.NamedElementEditPart; +import org.eclipse.papyrus.uml.diagram.common.editparts.RoundedCompartmentEditPart; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeNodeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.QualifiedNameDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.ShowHideClassifierContentsEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.ShowHideCompartmentEditPolicy; +import org.eclipse.papyrus.uml.diagram.common.locator.RoundedRectangleLabelPositionLocator; import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.CustomDiagramDragDropEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.custom.figures.CollaborationCompositeFigure; import org.eclipse.papyrus.uml.diagram.composite.edit.policies.CollaborationCompositeItemSemanticEditPolicyCN; @@ -43,7 +55,7 @@ import org.eclipse.swt.graphics.Color; /** * @generated */ -public class CollaborationCompositeEditPartCN extends NamedElementEditPart { +public class CollaborationCompositeEditPartCN extends RoundedCompartmentEditPart { /** * @generated @@ -80,6 +92,7 @@ public class CollaborationCompositeEditPartCN extends NamedElementEditPart { installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, new CustomDiagramDragDropEditPolicy()); installEditPolicy(ShowHideClassifierContentsEditPolicy.SHOW_HIDE_CLASSIFIER_CONTENTS_POLICY, new ShowHideClassifierContentsEditPolicy()); installEditPolicy(ShowHideCompartmentEditPolicy.SHOW_HIDE_COMPARTMENT_POLICY, new ShowHideCompartmentEditPolicy()); + installEditPolicy(EditPolicy.LAYOUT_ROLE, new GetChildLayoutEditPolicy()); // XXX need an SCR to runtime to have another abstract superclass that would let children add reasonable editpolicies // removeEditPolicy(org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles.CONNECTION_HANDLES_ROLE); } @@ -92,6 +105,20 @@ public class CollaborationCompositeEditPartCN extends NamedElementEditPart { @Override protected EditPolicy createChildEditPolicy(EditPart child) { + View childView = (View) child.getModel(); + switch (UMLVisualIDRegistry.getVisualID(childView)) { + case CollaborationCompositeFloatingLabelEditPartCN.VISUAL_ID: + return new BorderItemSelectionEditPolicy() { + + @Override + protected List createSelectionHandles() { + MoveHandle mh = new MoveHandle((GraphicalEditPart) getHost()); + mh.setBorder(null); + return Collections.singletonList(mh); + } + } + ; + } EditPolicy result = child.getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); if (result == null) { result = new NonResizableEditPolicy(); @@ -119,6 +146,19 @@ public class CollaborationCompositeEditPartCN extends NamedElementEditPart { **/ @Override protected void handleNotificationEvent(Notification event) { + /* + * when a node have external node labels, the methods refreshChildren() remove the EditPart corresponding to the Label from the EditPart + * Registry. After that, we can't reset the visibility to true (using the Show/Hide Label Action)! + */ + if (NotationPackage.eINSTANCE.getView_Visible().equals(event.getFeature())) { + Object notifier = event.getNotifier(); + List modelChildren = ((View) getModel()).getChildren(); + if (!(notifier instanceof Edge)) { + if (modelChildren.contains(event.getNotifier())) { + return; + } + } + } super.handleNotificationEvent(event); } @@ -206,15 +246,32 @@ public class CollaborationCompositeEditPartCN extends NamedElementEditPart { if (editPart instanceof CollaborationCompositeCompartmentEditPartCN) { return getPrimaryShape().getCompositeCompartmentFigure(); } + if (editPart instanceof IBorderItemEditPart) { + return getBorderedFigure().getBorderItemContainer(); + } return getContentPane(); } + /** + * @generated + */ + @Override + protected void addBorderItem(IFigure borderItemContainer, IBorderItemEditPart borderItemEditPart) { + if (borderItemEditPart instanceof CollaborationCompositeFloatingLabelEditPartCN) { + IBorderItemLocator locator = new RoundedRectangleLabelPositionLocator(getMainFigure()); + borderItemContainer.add(borderItemEditPart.getFigure(), locator); + } else + { + super.addBorderItem(borderItemContainer, borderItemEditPart); + } + } + /** * @generated */ @Override protected NodeFigure createNodePlate() { - DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(40, 40); + RoundedRectangleNodePlateFigure result = new RoundedRectangleNodePlateFigure(40, 40); return result; } @@ -227,7 +284,7 @@ public class CollaborationCompositeEditPartCN extends NamedElementEditPart { * @generated */ @Override - protected NodeFigure createNodeFigure() { + protected NodeFigure createMainFigure() { return new SelectableBorderedNodeFigure(createMainFigureWithSVG()); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/CollaborationCompositeFloatingLabelEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/CollaborationCompositeFloatingLabelEditPart.java new file mode 100644 index 00000000000..405d16c7ea3 --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/CollaborationCompositeFloatingLabelEditPart.java @@ -0,0 +1,860 @@ +/** + * 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.uml.diagram.composite.edit.parts; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.Label; +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.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.RunnableWithResult; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gef.AccessibleEditPart; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.Request; +import org.eclipse.gef.requests.DirectEditRequest; +import org.eclipse.gef.tools.DirectEditManager; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; +import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; +import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; +import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; +import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; +import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; +import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; +import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; +import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; +import org.eclipse.gmf.runtime.notation.FontStyle; +import org.eclipse.gmf.runtime.notation.NotationPackage; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.text.contentassist.IContentAssistProcessor; +import org.eclipse.jface.viewers.ICellEditorValidator; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.extensionpoints.editors.Activator; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; +import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; +import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.ExternalLabelPrimaryDragRoleEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.PapyrusWrappingLabel; +import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; +import org.eclipse.papyrus.uml.diagram.common.editparts.FloatingLabelEditPart; +import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; +import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; +import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; +import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.accessibility.AccessibleEvent; +import org.eclipse.swt.custom.BusyIndicator; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; +import org.eclipse.uml2.uml.Feature; + +/** + * @generated + */ +public class CollaborationCompositeFloatingLabelEditPart extends FloatingLabelEditPart + implements ITextAwareEditPart, IBorderItemEditPart +{ + + /** + * @generated + */ + public static final int VISUAL_ID = 6090; + + /** + * @generated + */ + private DirectEditManager manager; + + /** + * @generated + */ + private IParser parser; + + /** + * @generated + */ + private List parserElements; + + /** + * @generated + */ + private String defaultText; + + /** + * direct edition mode (default, undefined, registered editor, etc.) + * + * @generated + */ + protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; + + /** + * configuration from a registered edit dialog + * + * @generated + */ + protected IDirectEditorConfiguration configuration; + + + /** + * @generated + */ + static { + registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.CollaborationCompositeFloatingLabelEditPart.VISUAL_ID), new Point(0, 0)); + } + + /** + * @generated + */ + public CollaborationCompositeFloatingLabelEditPart(View view) { + super(view); + } + + /** + * @generated + */ + @Override + protected void createDefaultEditPolicies() { + super.createDefaultEditPolicies(); + installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); + installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ExternalLabelPrimaryDragRoleEditPolicy()); + } + + /** + * @generated + */ + @Override + public IBorderItemLocator getBorderItemLocator() { + IFigure parentFigure = getFigure().getParent(); + if (parentFigure != null && parentFigure.getLayoutManager() != null) { + Object constraint = parentFigure.getLayoutManager().getConstraint(getFigure()); + return (IBorderItemLocator) constraint; + } + return null; + } + + /** + * @generated + */ + @Override + public void refreshBounds() { + int x = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_X())).intValue(); + int y = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_Y())).intValue(); + int width = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Width())).intValue(); + int height = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Height())).intValue(); + getBorderItemLocator().setConstraint(new Rectangle(x, y, width, height)); + } + + + /** + * @generated + */ + protected String getLabelTextHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getText(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getText(); + } else { + return ((Label) figure).getText(); + } + } + + /** + * @generated + */ + protected void setLabelTextHelper(IFigure figure, String text) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setText(text); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setText(text); + } else { + ((Label) figure).setText(text); + } + } + + /** + * @generated + */ + protected Image getLabelIconHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getIcon(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getIcon(); + } else { + return ((Label) figure).getIcon(); + } + } + + /** + * @generated + */ + protected void setLabelIconHelper(IFigure figure, Image icon) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setIcon(icon); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setIcon(icon); + } else { + ((Label) figure).setIcon(icon); + } + } + + /** + * @generated + */ + public void setLabel(IFigure + figure) { + unregisterVisuals(); + setFigure(figure); + defaultText = getLabelTextHelper(figure); + registerVisuals(); + refreshVisuals(); + } + + /** + * @generated + */ + @Override + protected List getModelChildren() { + return Collections.EMPTY_LIST; + } + + /** + * @generated + */ + @Override + public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { + return null; + } + + /** + * @generated + */ + public void setParser(IParser parser) { + this.parser = parser; + } + + /** + * @generated + */ + protected EObject getParserElement() { + return resolveSemanticElement(); + } + + /** + * @generated + */ + protected Image getLabelIcon() { + return null; + } + + /** + * @generated + */ + protected String getLabelText() { + String text = null; + EObject parserElement = getParserElement(); + if (parserElement != null && getParser() != null) { + text = getParser().getPrintString( + new EObjectAdapter(parserElement), + getParserOptions().intValue()); + } + if (text == null || text.length() == 0) { + text = defaultText; + } + return text; + } + + /** + * @generated + */ + @Override + public void setLabelText(String text) { + setLabelTextHelper(getFigure(), text); + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + @Override + public String getEditText() { + if (getParserElement() == null || getParser() == null) { + return ""; //$NON-NLS-1$ + } + return getParser().getEditString( + new EObjectAdapter(getParserElement()), + getParserOptions().intValue()); + } + + /** + * @generated + */ + protected boolean isEditable() { + return getParser() != null; + } + + /** + * @generated + */ + @Override + public ICellEditorValidator getEditTextValidator() { + return new ICellEditorValidator() { + + @Override + public String isValid(final Object value) { + if (value instanceof String) { + final EObject element = getParserElement(); + final IParser parser = getParser(); + try { + IParserEditStatus valid = + (IParserEditStatus) getEditingDomain().runExclusive( + new RunnableWithResult.Impl() { + + @Override + public void run() { + setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); + } + }); + return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); + } catch (InterruptedException ie) { + ie.printStackTrace(); + } + } + + // shouldn't get here + return null; + } + }; + } + + /** + * @generated + */ + @Override + public IContentAssistProcessor getCompletionProcessor() { + if (getParserElement() == null || getParser() == null) { + return null; + } + return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); + } + + /** + * @generated + */ + @Override + public ParserOptions getParserOptions() { + return ParserOptions.NONE; + } + + /** + * @generated + */ + @Override + public IParser getParser() { + if (parser == null) { + parser = UMLParserProvider.getParser(UMLElementTypes.Collaboration_2075, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.CollaborationCompositeFloatingLabelEditPart.VISUAL_ID)); + } + return parser; + } + + /** + * @generated + */ + protected DirectEditManager getManager() { + if (manager == null) { + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + } + return manager; + } + + /** + * @generated + */ + protected void setManager(DirectEditManager manager) { + this.manager = manager; + } + + /** + * @generated + */ + protected void performDirectEdit() { + BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { + + @Override + public void run() { + getManager().show(); + } + }); + } + + /** + * @generated + */ + protected void performDirectEdit(Point eventLocation) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); + } + } + + /** + * @generated + */ + private void performDirectEdit(char initialCharacter) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(initialCharacter); + } else { + performDirectEdit(); + } + } + + /** + * @generated + */ + @Override + protected void performDirectEditRequest(Request request) { + + final Request theRequest = request; + + if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { + directEditionMode = getDirectEditionType(); + } + switch (directEditionMode) { + case IDirectEdition.NO_DIRECT_EDITION: + // no direct edition mode => does nothing + return; + case IDirectEdition.EXTENDED_DIRECT_EDITOR: + updateExtendedEditorConfiguration(); + if (configuration == null || configuration.getLanguage() == null) { + // Create default edit manager + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + performDefaultDirectEditorEdit(theRequest); + } else { + configuration.preEditAction(resolveSemanticElement()); + Dialog dialog = null; + if (configuration instanceof ICustomDirectEditorConfiguration) { + setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); + initializeDirectEditManager(theRequest); + return; + } else if (configuration instanceof IPopupEditorConfiguration) { + IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); + helper.showEditor(); + return; + } + else if (configuration instanceof IAdvancedEditorConfiguration) { + dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); + } else if (configuration instanceof IDirectEditorConfiguration) { + dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), + configuration); + } else { + return; + } + final Dialog finalDialog = dialog; + + if (Window.OK == dialog.open()) { + TransactionalEditingDomain domain = getEditingDomain(); + RecordingCommand command = new RecordingCommand(domain, "Edit Label") { + + @Override + protected void doExecute() { + configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); + + } + }; + domain.getCommandStack().execute(command); + } + } + break; + case IDirectEdition.DEFAULT_DIRECT_EDITOR: + initializeDirectEditManager(theRequest); + break; + default: + break; + } + } + + /** + * @generated + */ + protected void initializeDirectEditManager(final Request request) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + @Override + public void run() { + if (isActive() && isEditable()) { + if (request.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } + else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void refreshVisuals() { + super.refreshVisuals(); + refreshLabel(); + refreshFont(); + refreshFontColor(); + refreshUnderline(); + refreshStrikeThrough(); + } + + /** + * @generated + */ + protected void refreshLabel() { + EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); + if (maskLabelPolicy == null) { + maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); + } + if (maskLabelPolicy == null) { + View view = (View) getModel(); + if (view.isVisible()) { + setLabelTextHelper(getFigure(), getLabelText()); + setLabelIconHelper(getFigure(), getLabelIcon()); + } + else { + setLabelTextHelper(getFigure(), ""); //$NON-NLS-1$ + setLabelIconHelper(getFigure(), null); + } + } + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + protected void refreshUnderline() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); + } + if (resolveSemanticElement() instanceof Feature) { + if (((Feature) resolveSemanticElement()).isStatic()) { + ((WrappingLabel) getFigure()).setTextUnderline(true); + } + else { + ((WrappingLabel) getFigure()).setTextUnderline(false); + } + } + } + + /** + * @generated + */ + protected void refreshStrikeThrough() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); + } + } + + /** + * @generated + */ + @Override + protected void refreshFont() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null) { + FontData fontData = new FontData( + style.getFontName(), style.getFontHeight(), + (style.isBold() ? SWT.BOLD : SWT.NORMAL) | + (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); + setFont(fontData); + } + } + + /** + * @generated + */ + @Override + protected void setFontColor(Color color) { + getFigure().setForegroundColor(color); + } + + /** + * @generated + */ + @Override + protected void addSemanticListeners() { + if (getParser() instanceof ISemanticParser) { + EObject element = resolveSemanticElement(); + parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); + for (int i = 0; i < parserElements.size(); i++) { + addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ + } + } else { + super.addSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected void removeSemanticListeners() { + if (parserElements != null) { + for (int i = 0; i < parserElements.size(); i++) { + removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ + } + } else { + super.removeSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected AccessibleEditPart getAccessibleEditPart() { + if (accessibleEP == null) { + accessibleEP = new AccessibleGraphicalEditPart() { + + @Override + public void getName(AccessibleEvent e) { + e.result = getLabelTextHelper(getFigure()); + } + }; + } + return accessibleEP; + } + + /** + * @generated + */ + private View getFontStyleOwnerView() { + return getPrimaryView(); + } + + /** + * Returns the kind of associated editor for direct edition. + * + * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition + * @generated + */ + public int getDirectEditionType() { + if (checkExtendedEditor()) { + initExtendedEditorConfiguration(); + return IDirectEdition.EXTENDED_DIRECT_EDITOR; + } + if (checkDefaultEdition()) { + return IDirectEdition.DEFAULT_DIRECT_EDITOR; + } + + // not a named element. no specific editor => do nothing + return IDirectEdition.NO_DIRECT_EDITION; + } + + /** + * Checks if an extended editor is present. + * + * @return true if an extended editor is present. + * @generated + */ + protected boolean checkExtendedEditor() { + if (resolveSemanticElement() != null) { + return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); + } + return false; + } + + /** + * Checks if a default direct edition is available + * + * @return true if a default direct edition is available + * @generated + */ + protected boolean checkDefaultEdition() { + return (getParser() != null); + } + + /** + * Initializes the extended editor configuration + * + * @generated + */ + protected void initExtendedEditorConfiguration() { + if (configuration == null) { + final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("")) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); + } else { + configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); + } + } + } + + /** + * Updates the preference configuration + * + * @generated + */ + protected void updateExtendedEditorConfiguration() { + String languagePreferred = Activator.getDefault().getPreferenceStore().getString( + IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() + .eClass().getInstanceClassName()); + } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { + configuration = null; + } + } + + /** + * Performs the direct edit usually used by GMF editors. + * + * @param theRequest + * the direct edit request that starts the direct edit system + * @generated + */ + protected void performDefaultDirectEditorEdit(final Request theRequest) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + + @Override + public void run() { + if (isActive() && isEditable()) { + if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) theRequest.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { + DirectEditRequest editRequest = (DirectEditRequest) theRequest; + performDirectEdit(editRequest.getLocation()); + } else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + + /** + * @generated + */ + @Override + protected void handleNotificationEvent(Notification event) { + Object feature = event.getFeature(); + if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { + Integer c = (Integer) event.getNewValue(); + setFontColor(DiagramColorRegistry.getInstance().getColor(c)); + } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { + refreshUnderline(); + } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { + refreshStrikeThrough(); + } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { + refreshFont(); + } else { + if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { + refreshLabel(); + } + if (getParser() instanceof ISemanticParser) { + ISemanticParser modelParser = + (ISemanticParser) getParser(); + if (modelParser.areSemanticElementsAffected(null, event)) { + removeSemanticListeners(); + if (resolveSemanticElement() != null) { + addSemanticListeners(); + } + refreshLabel(); + } + } + } + super.handleNotificationEvent(event); + } + + /** + * @generated + */ + @Override + protected IFigure createFigure() { + IFigure label = createFigurePrim(); + defaultText = getLabelTextHelper(label); + return label; + } + + /** + * @generated + */ + protected IFigure createFigurePrim() { + return new PapyrusWrappingLabel(); + } + +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/CollaborationCompositeFloatingLabelEditPartCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/CollaborationCompositeFloatingLabelEditPartCN.java new file mode 100644 index 00000000000..88ffbfee5c3 --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/CollaborationCompositeFloatingLabelEditPartCN.java @@ -0,0 +1,860 @@ +/** + * 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.uml.diagram.composite.edit.parts; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.Label; +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.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.RunnableWithResult; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gef.AccessibleEditPart; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.Request; +import org.eclipse.gef.requests.DirectEditRequest; +import org.eclipse.gef.tools.DirectEditManager; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; +import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; +import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; +import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; +import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; +import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; +import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; +import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; +import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; +import org.eclipse.gmf.runtime.notation.FontStyle; +import org.eclipse.gmf.runtime.notation.NotationPackage; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.text.contentassist.IContentAssistProcessor; +import org.eclipse.jface.viewers.ICellEditorValidator; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.extensionpoints.editors.Activator; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; +import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; +import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.ExternalLabelPrimaryDragRoleEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.PapyrusWrappingLabel; +import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; +import org.eclipse.papyrus.uml.diagram.common.editparts.FloatingLabelEditPart; +import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; +import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; +import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; +import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.accessibility.AccessibleEvent; +import org.eclipse.swt.custom.BusyIndicator; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; +import org.eclipse.uml2.uml.Feature; + +/** + * @generated + */ +public class CollaborationCompositeFloatingLabelEditPartCN extends FloatingLabelEditPart + implements ITextAwareEditPart, IBorderItemEditPart +{ + + /** + * @generated + */ + public static final int VISUAL_ID = 6068; + + /** + * @generated + */ + private DirectEditManager manager; + + /** + * @generated + */ + private IParser parser; + + /** + * @generated + */ + private List parserElements; + + /** + * @generated + */ + private String defaultText; + + /** + * direct edition mode (default, undefined, registered editor, etc.) + * + * @generated + */ + protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; + + /** + * configuration from a registered edit dialog + * + * @generated + */ + protected IDirectEditorConfiguration configuration; + + + /** + * @generated + */ + static { + registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.CollaborationCompositeFloatingLabelEditPartCN.VISUAL_ID), new Point(0, 0)); + } + + /** + * @generated + */ + public CollaborationCompositeFloatingLabelEditPartCN(View view) { + super(view); + } + + /** + * @generated + */ + @Override + protected void createDefaultEditPolicies() { + super.createDefaultEditPolicies(); + installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); + installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ExternalLabelPrimaryDragRoleEditPolicy()); + } + + /** + * @generated + */ + @Override + public IBorderItemLocator getBorderItemLocator() { + IFigure parentFigure = getFigure().getParent(); + if (parentFigure != null && parentFigure.getLayoutManager() != null) { + Object constraint = parentFigure.getLayoutManager().getConstraint(getFigure()); + return (IBorderItemLocator) constraint; + } + return null; + } + + /** + * @generated + */ + @Override + public void refreshBounds() { + int x = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_X())).intValue(); + int y = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_Y())).intValue(); + int width = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Width())).intValue(); + int height = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Height())).intValue(); + getBorderItemLocator().setConstraint(new Rectangle(x, y, width, height)); + } + + + /** + * @generated + */ + protected String getLabelTextHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getText(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getText(); + } else { + return ((Label) figure).getText(); + } + } + + /** + * @generated + */ + protected void setLabelTextHelper(IFigure figure, String text) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setText(text); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setText(text); + } else { + ((Label) figure).setText(text); + } + } + + /** + * @generated + */ + protected Image getLabelIconHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getIcon(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getIcon(); + } else { + return ((Label) figure).getIcon(); + } + } + + /** + * @generated + */ + protected void setLabelIconHelper(IFigure figure, Image icon) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setIcon(icon); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setIcon(icon); + } else { + ((Label) figure).setIcon(icon); + } + } + + /** + * @generated + */ + public void setLabel(IFigure + figure) { + unregisterVisuals(); + setFigure(figure); + defaultText = getLabelTextHelper(figure); + registerVisuals(); + refreshVisuals(); + } + + /** + * @generated + */ + @Override + protected List getModelChildren() { + return Collections.EMPTY_LIST; + } + + /** + * @generated + */ + @Override + public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { + return null; + } + + /** + * @generated + */ + public void setParser(IParser parser) { + this.parser = parser; + } + + /** + * @generated + */ + protected EObject getParserElement() { + return resolveSemanticElement(); + } + + /** + * @generated + */ + protected Image getLabelIcon() { + return null; + } + + /** + * @generated + */ + protected String getLabelText() { + String text = null; + EObject parserElement = getParserElement(); + if (parserElement != null && getParser() != null) { + text = getParser().getPrintString( + new EObjectAdapter(parserElement), + getParserOptions().intValue()); + } + if (text == null || text.length() == 0) { + text = defaultText; + } + return text; + } + + /** + * @generated + */ + @Override + public void setLabelText(String text) { + setLabelTextHelper(getFigure(), text); + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + @Override + public String getEditText() { + if (getParserElement() == null || getParser() == null) { + return ""; //$NON-NLS-1$ + } + return getParser().getEditString( + new EObjectAdapter(getParserElement()), + getParserOptions().intValue()); + } + + /** + * @generated + */ + protected boolean isEditable() { + return getParser() != null; + } + + /** + * @generated + */ + @Override + public ICellEditorValidator getEditTextValidator() { + return new ICellEditorValidator() { + + @Override + public String isValid(final Object value) { + if (value instanceof String) { + final EObject element = getParserElement(); + final IParser parser = getParser(); + try { + IParserEditStatus valid = + (IParserEditStatus) getEditingDomain().runExclusive( + new RunnableWithResult.Impl() { + + @Override + public void run() { + setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); + } + }); + return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); + } catch (InterruptedException ie) { + ie.printStackTrace(); + } + } + + // shouldn't get here + return null; + } + }; + } + + /** + * @generated + */ + @Override + public IContentAssistProcessor getCompletionProcessor() { + if (getParserElement() == null || getParser() == null) { + return null; + } + return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); + } + + /** + * @generated + */ + @Override + public ParserOptions getParserOptions() { + return ParserOptions.NONE; + } + + /** + * @generated + */ + @Override + public IParser getParser() { + if (parser == null) { + parser = UMLParserProvider.getParser(UMLElementTypes.Collaboration_3086, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.CollaborationCompositeFloatingLabelEditPartCN.VISUAL_ID)); + } + return parser; + } + + /** + * @generated + */ + protected DirectEditManager getManager() { + if (manager == null) { + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + } + return manager; + } + + /** + * @generated + */ + protected void setManager(DirectEditManager manager) { + this.manager = manager; + } + + /** + * @generated + */ + protected void performDirectEdit() { + BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { + + @Override + public void run() { + getManager().show(); + } + }); + } + + /** + * @generated + */ + protected void performDirectEdit(Point eventLocation) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); + } + } + + /** + * @generated + */ + private void performDirectEdit(char initialCharacter) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(initialCharacter); + } else { + performDirectEdit(); + } + } + + /** + * @generated + */ + @Override + protected void performDirectEditRequest(Request request) { + + final Request theRequest = request; + + if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { + directEditionMode = getDirectEditionType(); + } + switch (directEditionMode) { + case IDirectEdition.NO_DIRECT_EDITION: + // no direct edition mode => does nothing + return; + case IDirectEdition.EXTENDED_DIRECT_EDITOR: + updateExtendedEditorConfiguration(); + if (configuration == null || configuration.getLanguage() == null) { + // Create default edit manager + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + performDefaultDirectEditorEdit(theRequest); + } else { + configuration.preEditAction(resolveSemanticElement()); + Dialog dialog = null; + if (configuration instanceof ICustomDirectEditorConfiguration) { + setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); + initializeDirectEditManager(theRequest); + return; + } else if (configuration instanceof IPopupEditorConfiguration) { + IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); + helper.showEditor(); + return; + } + else if (configuration instanceof IAdvancedEditorConfiguration) { + dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); + } else if (configuration instanceof IDirectEditorConfiguration) { + dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), + configuration); + } else { + return; + } + final Dialog finalDialog = dialog; + + if (Window.OK == dialog.open()) { + TransactionalEditingDomain domain = getEditingDomain(); + RecordingCommand command = new RecordingCommand(domain, "Edit Label") { + + @Override + protected void doExecute() { + configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); + + } + }; + domain.getCommandStack().execute(command); + } + } + break; + case IDirectEdition.DEFAULT_DIRECT_EDITOR: + initializeDirectEditManager(theRequest); + break; + default: + break; + } + } + + /** + * @generated + */ + protected void initializeDirectEditManager(final Request request) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + @Override + public void run() { + if (isActive() && isEditable()) { + if (request.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } + else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void refreshVisuals() { + super.refreshVisuals(); + refreshLabel(); + refreshFont(); + refreshFontColor(); + refreshUnderline(); + refreshStrikeThrough(); + } + + /** + * @generated + */ + protected void refreshLabel() { + EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); + if (maskLabelPolicy == null) { + maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); + } + if (maskLabelPolicy == null) { + View view = (View) getModel(); + if (view.isVisible()) { + setLabelTextHelper(getFigure(), getLabelText()); + setLabelIconHelper(getFigure(), getLabelIcon()); + } + else { + setLabelTextHelper(getFigure(), ""); //$NON-NLS-1$ + setLabelIconHelper(getFigure(), null); + } + } + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + protected void refreshUnderline() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); + } + if (resolveSemanticElement() instanceof Feature) { + if (((Feature) resolveSemanticElement()).isStatic()) { + ((WrappingLabel) getFigure()).setTextUnderline(true); + } + else { + ((WrappingLabel) getFigure()).setTextUnderline(false); + } + } + } + + /** + * @generated + */ + protected void refreshStrikeThrough() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); + } + } + + /** + * @generated + */ + @Override + protected void refreshFont() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null) { + FontData fontData = new FontData( + style.getFontName(), style.getFontHeight(), + (style.isBold() ? SWT.BOLD : SWT.NORMAL) | + (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); + setFont(fontData); + } + } + + /** + * @generated + */ + @Override + protected void setFontColor(Color color) { + getFigure().setForegroundColor(color); + } + + /** + * @generated + */ + @Override + protected void addSemanticListeners() { + if (getParser() instanceof ISemanticParser) { + EObject element = resolveSemanticElement(); + parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); + for (int i = 0; i < parserElements.size(); i++) { + addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ + } + } else { + super.addSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected void removeSemanticListeners() { + if (parserElements != null) { + for (int i = 0; i < parserElements.size(); i++) { + removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ + } + } else { + super.removeSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected AccessibleEditPart getAccessibleEditPart() { + if (accessibleEP == null) { + accessibleEP = new AccessibleGraphicalEditPart() { + + @Override + public void getName(AccessibleEvent e) { + e.result = getLabelTextHelper(getFigure()); + } + }; + } + return accessibleEP; + } + + /** + * @generated + */ + private View getFontStyleOwnerView() { + return getPrimaryView(); + } + + /** + * Returns the kind of associated editor for direct edition. + * + * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition + * @generated + */ + public int getDirectEditionType() { + if (checkExtendedEditor()) { + initExtendedEditorConfiguration(); + return IDirectEdition.EXTENDED_DIRECT_EDITOR; + } + if (checkDefaultEdition()) { + return IDirectEdition.DEFAULT_DIRECT_EDITOR; + } + + // not a named element. no specific editor => do nothing + return IDirectEdition.NO_DIRECT_EDITION; + } + + /** + * Checks if an extended editor is present. + * + * @return true if an extended editor is present. + * @generated + */ + protected boolean checkExtendedEditor() { + if (resolveSemanticElement() != null) { + return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); + } + return false; + } + + /** + * Checks if a default direct edition is available + * + * @return true if a default direct edition is available + * @generated + */ + protected boolean checkDefaultEdition() { + return (getParser() != null); + } + + /** + * Initializes the extended editor configuration + * + * @generated + */ + protected void initExtendedEditorConfiguration() { + if (configuration == null) { + final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("")) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); + } else { + configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); + } + } + } + + /** + * Updates the preference configuration + * + * @generated + */ + protected void updateExtendedEditorConfiguration() { + String languagePreferred = Activator.getDefault().getPreferenceStore().getString( + IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() + .eClass().getInstanceClassName()); + } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { + configuration = null; + } + } + + /** + * Performs the direct edit usually used by GMF editors. + * + * @param theRequest + * the direct edit request that starts the direct edit system + * @generated + */ + protected void performDefaultDirectEditorEdit(final Request theRequest) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + + @Override + public void run() { + if (isActive() && isEditable()) { + if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) theRequest.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { + DirectEditRequest editRequest = (DirectEditRequest) theRequest; + performDirectEdit(editRequest.getLocation()); + } else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + + /** + * @generated + */ + @Override + protected void handleNotificationEvent(Notification event) { + Object feature = event.getFeature(); + if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { + Integer c = (Integer) event.getNewValue(); + setFontColor(DiagramColorRegistry.getInstance().getColor(c)); + } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { + refreshUnderline(); + } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { + refreshStrikeThrough(); + } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { + refreshFont(); + } else { + if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { + refreshLabel(); + } + if (getParser() instanceof ISemanticParser) { + ISemanticParser modelParser = + (ISemanticParser) getParser(); + if (modelParser.areSemanticElementsAffected(null, event)) { + removeSemanticListeners(); + if (resolveSemanticElement() != null) { + addSemanticListeners(); + } + refreshLabel(); + } + } + } + super.handleNotificationEvent(event); + } + + /** + * @generated + */ + @Override + protected IFigure createFigure() { + IFigure label = createFigurePrim(); + defaultText = getLabelTextHelper(label); + return label; + } + + /** + * @generated + */ + protected IFigure createFigurePrim() { + return new PapyrusWrappingLabel(); + } + +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/CollaborationCompositeNameEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/CollaborationCompositeNameEditPart.java index 46ae8bb5d8b..30fdd5fcd98 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/CollaborationCompositeNameEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/CollaborationCompositeNameEditPart.java @@ -864,7 +864,7 @@ public class CollaborationCompositeNameEditPart extends PapyrusCompartmentEditPa * @generated */ protected void addOwnerElementListeners() { - addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); + addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/CollaborationCompositeNameEditPartCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/CollaborationCompositeNameEditPartCN.java index bb1870ae291..ad25065c808 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/CollaborationCompositeNameEditPartCN.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/CollaborationCompositeNameEditPartCN.java @@ -864,7 +864,7 @@ public class CollaborationCompositeNameEditPartCN extends PapyrusCompartmentEdit * @generated */ protected void addOwnerElementListeners() { - addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); + addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/CollaborationRoleEditPartCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/CollaborationRoleEditPartCN.java index 5a0393f6705..98b10297c75 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/CollaborationRoleEditPartCN.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/CollaborationRoleEditPartCN.java @@ -11,27 +11,39 @@ */ package org.eclipse.papyrus.uml.diagram.composite.edit.parts; +import java.util.Collections; +import java.util.List; + import org.eclipse.draw2d.IFigure; import org.eclipse.emf.common.notify.Notification; import org.eclipse.gef.EditPart; import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.GraphicalEditPart; 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.handles.MoveHandle; import org.eclipse.gef.requests.CreateRequest; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.BorderItemSelectionEditPolicy; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles; +import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; -import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure; import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure; +import org.eclipse.gmf.runtime.notation.Edge; +import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.GetChildLayoutEditPolicy; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.IPapyrusNodeFigure; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.RoundedRectangleNodePlateFigure; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.SelectableBorderedNodeFigure; -import org.eclipse.papyrus.uml.diagram.common.editparts.NamedElementEditPart; +import org.eclipse.papyrus.uml.diagram.common.editparts.RoundedCompartmentEditPart; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeNodeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.QualifiedNameDisplayEditPolicy; +import org.eclipse.papyrus.uml.diagram.common.locator.RoundedRectangleLabelPositionLocator; import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.CollaborationRoleItemSemanticEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.CustomGraphicalNodeEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.custom.figures.CollaborationRoleFigure; @@ -42,7 +54,7 @@ import org.eclipse.swt.graphics.Color; /** * @generated */ -public class CollaborationRoleEditPartCN extends NamedElementEditPart { +public class CollaborationRoleEditPartCN extends RoundedCompartmentEditPart { /** * @generated @@ -78,6 +90,7 @@ public class CollaborationRoleEditPartCN extends NamedElementEditPart { installEditPolicy(EditPolicy.GRAPHICAL_NODE_ROLE, new CustomGraphicalNodeEditPolicy()); installEditPolicy(QualifiedNameDisplayEditPolicy.QUALIFIED_NAME_POLICY, new QualifiedNameDisplayEditPolicy()); installEditPolicy(AppliedStereotypeLabelDisplayEditPolicy.STEREOTYPE_LABEL_POLICY, new AppliedStereotypeNodeLabelDisplayEditPolicy()); + installEditPolicy(EditPolicy.LAYOUT_ROLE, new GetChildLayoutEditPolicy()); // XXX need an SCR to runtime to have another abstract superclass that would let children add reasonable editpolicies // removeEditPolicy(org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles.CONNECTION_HANDLES_ROLE); } @@ -90,6 +103,20 @@ public class CollaborationRoleEditPartCN extends NamedElementEditPart { @Override protected EditPolicy createChildEditPolicy(EditPart child) { + View childView = (View) child.getModel(); + switch (UMLVisualIDRegistry.getVisualID(childView)) { + case CollaborationRoleFloatingLabelEditPartCN.VISUAL_ID: + return new BorderItemSelectionEditPolicy() { + + @Override + protected List createSelectionHandles() { + MoveHandle mh = new MoveHandle((GraphicalEditPart) getHost()); + mh.setBorder(null); + return Collections.singletonList(mh); + } + } + ; + } EditPolicy result = child.getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); if (result == null) { result = new NonResizableEditPolicy(); @@ -117,6 +144,19 @@ public class CollaborationRoleEditPartCN extends NamedElementEditPart { **/ @Override protected void handleNotificationEvent(Notification event) { + /* + * when a node have external node labels, the methods refreshChildren() remove the EditPart corresponding to the Label from the EditPart + * Registry. After that, we can't reset the visibility to true (using the Show/Hide Label Action)! + */ + if (NotationPackage.eINSTANCE.getView_Visible().equals(event.getFeature())) { + Object notifier = event.getNotifier(); + List modelChildren = ((View) getModel()).getChildren(); + if (!(notifier instanceof Edge)) { + if (modelChildren.contains(event.getNotifier())) { + return; + } + } + } super.handleNotificationEvent(event); } @@ -189,15 +229,32 @@ public class CollaborationRoleEditPartCN extends NamedElementEditPart { */ @Override protected IFigure getContentPaneFor(IGraphicalEditPart editPart) { + if (editPart instanceof IBorderItemEditPart) { + return getBorderedFigure().getBorderItemContainer(); + } return getContentPane(); } + /** + * @generated + */ + @Override + protected void addBorderItem(IFigure borderItemContainer, IBorderItemEditPart borderItemEditPart) { + if (borderItemEditPart instanceof CollaborationRoleFloatingLabelEditPartCN) { + IBorderItemLocator locator = new RoundedRectangleLabelPositionLocator(getMainFigure()); + borderItemContainer.add(borderItemEditPart.getFigure(), locator); + } else + { + super.addBorderItem(borderItemContainer, borderItemEditPart); + } + } + /** * @generated */ @Override protected NodeFigure createNodePlate() { - DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(40, 40); + RoundedRectangleNodePlateFigure result = new RoundedRectangleNodePlateFigure(40, 40); return result; } @@ -210,7 +267,7 @@ public class CollaborationRoleEditPartCN extends NamedElementEditPart { * @generated */ @Override - protected NodeFigure createNodeFigure() { + protected NodeFigure createMainFigure() { return new SelectableBorderedNodeFigure(createMainFigureWithSVG()); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/CollaborationRoleFloatingLabelEditPartCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/CollaborationRoleFloatingLabelEditPartCN.java new file mode 100644 index 00000000000..81bb8e9ec77 --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/CollaborationRoleFloatingLabelEditPartCN.java @@ -0,0 +1,860 @@ +/** + * 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.uml.diagram.composite.edit.parts; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.Label; +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.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.RunnableWithResult; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gef.AccessibleEditPart; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.Request; +import org.eclipse.gef.requests.DirectEditRequest; +import org.eclipse.gef.tools.DirectEditManager; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; +import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; +import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; +import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; +import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; +import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; +import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; +import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; +import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; +import org.eclipse.gmf.runtime.notation.FontStyle; +import org.eclipse.gmf.runtime.notation.NotationPackage; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.text.contentassist.IContentAssistProcessor; +import org.eclipse.jface.viewers.ICellEditorValidator; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.extensionpoints.editors.Activator; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; +import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; +import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.ExternalLabelPrimaryDragRoleEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.PapyrusWrappingLabel; +import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; +import org.eclipse.papyrus.uml.diagram.common.editparts.FloatingLabelEditPart; +import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; +import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; +import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; +import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.accessibility.AccessibleEvent; +import org.eclipse.swt.custom.BusyIndicator; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; +import org.eclipse.uml2.uml.Feature; + +/** + * @generated + */ +public class CollaborationRoleFloatingLabelEditPartCN extends FloatingLabelEditPart + implements ITextAwareEditPart, IBorderItemEditPart +{ + + /** + * @generated + */ + public static final int VISUAL_ID = 6055; + + /** + * @generated + */ + private DirectEditManager manager; + + /** + * @generated + */ + private IParser parser; + + /** + * @generated + */ + private List parserElements; + + /** + * @generated + */ + private String defaultText; + + /** + * direct edition mode (default, undefined, registered editor, etc.) + * + * @generated + */ + protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; + + /** + * configuration from a registered edit dialog + * + * @generated + */ + protected IDirectEditorConfiguration configuration; + + + /** + * @generated + */ + static { + registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.CollaborationRoleFloatingLabelEditPartCN.VISUAL_ID), new Point(0, 0)); + } + + /** + * @generated + */ + public CollaborationRoleFloatingLabelEditPartCN(View view) { + super(view); + } + + /** + * @generated + */ + @Override + protected void createDefaultEditPolicies() { + super.createDefaultEditPolicies(); + installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); + installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ExternalLabelPrimaryDragRoleEditPolicy()); + } + + /** + * @generated + */ + @Override + public IBorderItemLocator getBorderItemLocator() { + IFigure parentFigure = getFigure().getParent(); + if (parentFigure != null && parentFigure.getLayoutManager() != null) { + Object constraint = parentFigure.getLayoutManager().getConstraint(getFigure()); + return (IBorderItemLocator) constraint; + } + return null; + } + + /** + * @generated + */ + @Override + public void refreshBounds() { + int x = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_X())).intValue(); + int y = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_Y())).intValue(); + int width = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Width())).intValue(); + int height = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Height())).intValue(); + getBorderItemLocator().setConstraint(new Rectangle(x, y, width, height)); + } + + + /** + * @generated + */ + protected String getLabelTextHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getText(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getText(); + } else { + return ((Label) figure).getText(); + } + } + + /** + * @generated + */ + protected void setLabelTextHelper(IFigure figure, String text) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setText(text); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setText(text); + } else { + ((Label) figure).setText(text); + } + } + + /** + * @generated + */ + protected Image getLabelIconHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getIcon(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getIcon(); + } else { + return ((Label) figure).getIcon(); + } + } + + /** + * @generated + */ + protected void setLabelIconHelper(IFigure figure, Image icon) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setIcon(icon); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setIcon(icon); + } else { + ((Label) figure).setIcon(icon); + } + } + + /** + * @generated + */ + public void setLabel(IFigure + figure) { + unregisterVisuals(); + setFigure(figure); + defaultText = getLabelTextHelper(figure); + registerVisuals(); + refreshVisuals(); + } + + /** + * @generated + */ + @Override + protected List getModelChildren() { + return Collections.EMPTY_LIST; + } + + /** + * @generated + */ + @Override + public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { + return null; + } + + /** + * @generated + */ + public void setParser(IParser parser) { + this.parser = parser; + } + + /** + * @generated + */ + protected EObject getParserElement() { + return resolveSemanticElement(); + } + + /** + * @generated + */ + protected Image getLabelIcon() { + return null; + } + + /** + * @generated + */ + protected String getLabelText() { + String text = null; + EObject parserElement = getParserElement(); + if (parserElement != null && getParser() != null) { + text = getParser().getPrintString( + new EObjectAdapter(parserElement), + getParserOptions().intValue()); + } + if (text == null || text.length() == 0) { + text = defaultText; + } + return text; + } + + /** + * @generated + */ + @Override + public void setLabelText(String text) { + setLabelTextHelper(getFigure(), text); + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + @Override + public String getEditText() { + if (getParserElement() == null || getParser() == null) { + return ""; //$NON-NLS-1$ + } + return getParser().getEditString( + new EObjectAdapter(getParserElement()), + getParserOptions().intValue()); + } + + /** + * @generated + */ + protected boolean isEditable() { + return getParser() != null; + } + + /** + * @generated + */ + @Override + public ICellEditorValidator getEditTextValidator() { + return new ICellEditorValidator() { + + @Override + public String isValid(final Object value) { + if (value instanceof String) { + final EObject element = getParserElement(); + final IParser parser = getParser(); + try { + IParserEditStatus valid = + (IParserEditStatus) getEditingDomain().runExclusive( + new RunnableWithResult.Impl() { + + @Override + public void run() { + setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); + } + }); + return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); + } catch (InterruptedException ie) { + ie.printStackTrace(); + } + } + + // shouldn't get here + return null; + } + }; + } + + /** + * @generated + */ + @Override + public IContentAssistProcessor getCompletionProcessor() { + if (getParserElement() == null || getParser() == null) { + return null; + } + return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); + } + + /** + * @generated + */ + @Override + public ParserOptions getParserOptions() { + return ParserOptions.NONE; + } + + /** + * @generated + */ + @Override + public IParser getParser() { + if (parser == null) { + parser = UMLParserProvider.getParser(UMLElementTypes.ConnectableElement_3115, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.CollaborationRoleFloatingLabelEditPartCN.VISUAL_ID)); + } + return parser; + } + + /** + * @generated + */ + protected DirectEditManager getManager() { + if (manager == null) { + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + } + return manager; + } + + /** + * @generated + */ + protected void setManager(DirectEditManager manager) { + this.manager = manager; + } + + /** + * @generated + */ + protected void performDirectEdit() { + BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { + + @Override + public void run() { + getManager().show(); + } + }); + } + + /** + * @generated + */ + protected void performDirectEdit(Point eventLocation) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); + } + } + + /** + * @generated + */ + private void performDirectEdit(char initialCharacter) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(initialCharacter); + } else { + performDirectEdit(); + } + } + + /** + * @generated + */ + @Override + protected void performDirectEditRequest(Request request) { + + final Request theRequest = request; + + if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { + directEditionMode = getDirectEditionType(); + } + switch (directEditionMode) { + case IDirectEdition.NO_DIRECT_EDITION: + // no direct edition mode => does nothing + return; + case IDirectEdition.EXTENDED_DIRECT_EDITOR: + updateExtendedEditorConfiguration(); + if (configuration == null || configuration.getLanguage() == null) { + // Create default edit manager + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + performDefaultDirectEditorEdit(theRequest); + } else { + configuration.preEditAction(resolveSemanticElement()); + Dialog dialog = null; + if (configuration instanceof ICustomDirectEditorConfiguration) { + setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); + initializeDirectEditManager(theRequest); + return; + } else if (configuration instanceof IPopupEditorConfiguration) { + IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); + helper.showEditor(); + return; + } + else if (configuration instanceof IAdvancedEditorConfiguration) { + dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); + } else if (configuration instanceof IDirectEditorConfiguration) { + dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), + configuration); + } else { + return; + } + final Dialog finalDialog = dialog; + + if (Window.OK == dialog.open()) { + TransactionalEditingDomain domain = getEditingDomain(); + RecordingCommand command = new RecordingCommand(domain, "Edit Label") { + + @Override + protected void doExecute() { + configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); + + } + }; + domain.getCommandStack().execute(command); + } + } + break; + case IDirectEdition.DEFAULT_DIRECT_EDITOR: + initializeDirectEditManager(theRequest); + break; + default: + break; + } + } + + /** + * @generated + */ + protected void initializeDirectEditManager(final Request request) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + @Override + public void run() { + if (isActive() && isEditable()) { + if (request.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } + else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void refreshVisuals() { + super.refreshVisuals(); + refreshLabel(); + refreshFont(); + refreshFontColor(); + refreshUnderline(); + refreshStrikeThrough(); + } + + /** + * @generated + */ + protected void refreshLabel() { + EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); + if (maskLabelPolicy == null) { + maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); + } + if (maskLabelPolicy == null) { + View view = (View) getModel(); + if (view.isVisible()) { + setLabelTextHelper(getFigure(), getLabelText()); + setLabelIconHelper(getFigure(), getLabelIcon()); + } + else { + setLabelTextHelper(getFigure(), ""); //$NON-NLS-1$ + setLabelIconHelper(getFigure(), null); + } + } + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + protected void refreshUnderline() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); + } + if (resolveSemanticElement() instanceof Feature) { + if (((Feature) resolveSemanticElement()).isStatic()) { + ((WrappingLabel) getFigure()).setTextUnderline(true); + } + else { + ((WrappingLabel) getFigure()).setTextUnderline(false); + } + } + } + + /** + * @generated + */ + protected void refreshStrikeThrough() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); + } + } + + /** + * @generated + */ + @Override + protected void refreshFont() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null) { + FontData fontData = new FontData( + style.getFontName(), style.getFontHeight(), + (style.isBold() ? SWT.BOLD : SWT.NORMAL) | + (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); + setFont(fontData); + } + } + + /** + * @generated + */ + @Override + protected void setFontColor(Color color) { + getFigure().setForegroundColor(color); + } + + /** + * @generated + */ + @Override + protected void addSemanticListeners() { + if (getParser() instanceof ISemanticParser) { + EObject element = resolveSemanticElement(); + parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); + for (int i = 0; i < parserElements.size(); i++) { + addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ + } + } else { + super.addSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected void removeSemanticListeners() { + if (parserElements != null) { + for (int i = 0; i < parserElements.size(); i++) { + removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ + } + } else { + super.removeSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected AccessibleEditPart getAccessibleEditPart() { + if (accessibleEP == null) { + accessibleEP = new AccessibleGraphicalEditPart() { + + @Override + public void getName(AccessibleEvent e) { + e.result = getLabelTextHelper(getFigure()); + } + }; + } + return accessibleEP; + } + + /** + * @generated + */ + private View getFontStyleOwnerView() { + return getPrimaryView(); + } + + /** + * Returns the kind of associated editor for direct edition. + * + * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition + * @generated + */ + public int getDirectEditionType() { + if (checkExtendedEditor()) { + initExtendedEditorConfiguration(); + return IDirectEdition.EXTENDED_DIRECT_EDITOR; + } + if (checkDefaultEdition()) { + return IDirectEdition.DEFAULT_DIRECT_EDITOR; + } + + // not a named element. no specific editor => do nothing + return IDirectEdition.NO_DIRECT_EDITION; + } + + /** + * Checks if an extended editor is present. + * + * @return true if an extended editor is present. + * @generated + */ + protected boolean checkExtendedEditor() { + if (resolveSemanticElement() != null) { + return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); + } + return false; + } + + /** + * Checks if a default direct edition is available + * + * @return true if a default direct edition is available + * @generated + */ + protected boolean checkDefaultEdition() { + return (getParser() != null); + } + + /** + * Initializes the extended editor configuration + * + * @generated + */ + protected void initExtendedEditorConfiguration() { + if (configuration == null) { + final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("")) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); + } else { + configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); + } + } + } + + /** + * Updates the preference configuration + * + * @generated + */ + protected void updateExtendedEditorConfiguration() { + String languagePreferred = Activator.getDefault().getPreferenceStore().getString( + IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() + .eClass().getInstanceClassName()); + } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { + configuration = null; + } + } + + /** + * Performs the direct edit usually used by GMF editors. + * + * @param theRequest + * the direct edit request that starts the direct edit system + * @generated + */ + protected void performDefaultDirectEditorEdit(final Request theRequest) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + + @Override + public void run() { + if (isActive() && isEditable()) { + if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) theRequest.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { + DirectEditRequest editRequest = (DirectEditRequest) theRequest; + performDirectEdit(editRequest.getLocation()); + } else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + + /** + * @generated + */ + @Override + protected void handleNotificationEvent(Notification event) { + Object feature = event.getFeature(); + if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { + Integer c = (Integer) event.getNewValue(); + setFontColor(DiagramColorRegistry.getInstance().getColor(c)); + } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { + refreshUnderline(); + } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { + refreshStrikeThrough(); + } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { + refreshFont(); + } else { + if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { + refreshLabel(); + } + if (getParser() instanceof ISemanticParser) { + ISemanticParser modelParser = + (ISemanticParser) getParser(); + if (modelParser.areSemanticElementsAffected(null, event)) { + removeSemanticListeners(); + if (resolveSemanticElement() != null) { + addSemanticListeners(); + } + refreshLabel(); + } + } + } + super.handleNotificationEvent(event); + } + + /** + * @generated + */ + @Override + protected IFigure createFigure() { + IFigure label = createFigurePrim(); + defaultText = getLabelTextHelper(label); + return label; + } + + /** + * @generated + */ + protected IFigure createFigurePrim() { + return new PapyrusWrappingLabel(); + } + +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/CollaborationRoleNameEditPartCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/CollaborationRoleNameEditPartCN.java index 135418ab7f0..00c1b71beeb 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/CollaborationRoleNameEditPartCN.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/CollaborationRoleNameEditPartCN.java @@ -856,7 +856,7 @@ public class CollaborationRoleNameEditPartCN extends PapyrusCompartmentEditPart * @generated */ protected void addOwnerElementListeners() { - addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); + addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/CollaborationUseEditPartCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/CollaborationUseEditPartCN.java index 9c3aa78b52f..b545cc2cfae 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/CollaborationUseEditPartCN.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/CollaborationUseEditPartCN.java @@ -11,30 +11,42 @@ */ package org.eclipse.papyrus.uml.diagram.composite.edit.parts; +import java.util.Collections; +import java.util.List; + import org.eclipse.draw2d.IFigure; import org.eclipse.emf.common.notify.Notification; import org.eclipse.gef.EditPart; import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.GraphicalEditPart; 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.handles.MoveHandle; import org.eclipse.gef.requests.CreateRequest; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.BorderItemSelectionEditPolicy; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles; +import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; -import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure; import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure; +import org.eclipse.gmf.runtime.notation.Edge; +import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.GetChildLayoutEditPolicy; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.IPapyrusNodeFigure; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.RoundedRectangleNodePlateFigure; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.SelectableBorderedNodeFigure; -import org.eclipse.papyrus.uml.diagram.common.editparts.NamedElementEditPart; +import org.eclipse.papyrus.uml.diagram.common.editparts.RoundedCompartmentEditPart; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeNodeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.QualifiedNameDisplayEditPolicy; +import org.eclipse.papyrus.uml.diagram.common.figure.node.RoundedCompartmentFigure; +import org.eclipse.papyrus.uml.diagram.common.locator.RoundedRectangleLabelPositionLocator; import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.CustomCollaborationUseItemSemanticEditPolicyCN; import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.CustomDiagramDragDropEditPolicy; -import org.eclipse.papyrus.uml.diagram.composite.custom.figures.CollaborationUseFigure; import org.eclipse.papyrus.uml.diagram.composite.edit.policies.CollaborationUseItemSemanticEditPolicyCN; import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; import org.eclipse.swt.graphics.Color; @@ -42,7 +54,7 @@ import org.eclipse.swt.graphics.Color; /** * @generated */ -public class CollaborationUseEditPartCN extends NamedElementEditPart { +public class CollaborationUseEditPartCN extends RoundedCompartmentEditPart { /** * @generated @@ -78,6 +90,7 @@ public class CollaborationUseEditPartCN extends NamedElementEditPart { installEditPolicy(QualifiedNameDisplayEditPolicy.QUALIFIED_NAME_POLICY, new QualifiedNameDisplayEditPolicy()); installEditPolicy(AppliedStereotypeLabelDisplayEditPolicy.STEREOTYPE_LABEL_POLICY, new AppliedStereotypeNodeLabelDisplayEditPolicy()); installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, new CustomDiagramDragDropEditPolicy()); + installEditPolicy(EditPolicy.LAYOUT_ROLE, new GetChildLayoutEditPolicy()); // XXX need an SCR to runtime to have another abstract superclass that would let children add reasonable editpolicies // removeEditPolicy(org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles.CONNECTION_HANDLES_ROLE); } @@ -90,6 +103,20 @@ public class CollaborationUseEditPartCN extends NamedElementEditPart { @Override protected EditPolicy createChildEditPolicy(EditPart child) { + View childView = (View) child.getModel(); + switch (UMLVisualIDRegistry.getVisualID(childView)) { + case CollaborationUseFloatingLabelEditPartCN.VISUAL_ID: + return new BorderItemSelectionEditPolicy() { + + @Override + protected List createSelectionHandles() { + MoveHandle mh = new MoveHandle((GraphicalEditPart) getHost()); + mh.setBorder(null); + return Collections.singletonList(mh); + } + } + ; + } EditPolicy result = child.getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); if (result == null) { result = new NonResizableEditPolicy(); @@ -117,6 +144,19 @@ public class CollaborationUseEditPartCN extends NamedElementEditPart { **/ @Override protected void handleNotificationEvent(Notification event) { + /* + * when a node have external node labels, the methods refreshChildren() remove the EditPart corresponding to the Label from the EditPart + * Registry. After that, we can't reset the visibility to true (using the Show/Hide Label Action)! + */ + if (NotationPackage.eINSTANCE.getView_Visible().equals(event.getFeature())) { + Object notifier = event.getNotifier(); + List modelChildren = ((View) getModel()).getChildren(); + if (!(notifier instanceof Edge)) { + if (modelChildren.contains(event.getNotifier())) { + return; + } + } + } super.handleNotificationEvent(event); } @@ -126,7 +166,7 @@ public class CollaborationUseEditPartCN extends NamedElementEditPart { */ @Override protected IFigure createNodeShape() { - return primaryShape = new CollaborationUseFigure(); + return primaryShape = new RoundedCompartmentFigure(); } /** @@ -135,8 +175,8 @@ public class CollaborationUseEditPartCN extends NamedElementEditPart { * @generated */ @Override - public CollaborationUseFigure getPrimaryShape() { - return (CollaborationUseFigure) primaryShape; + public RoundedCompartmentFigure getPrimaryShape() { + return (RoundedCompartmentFigure) primaryShape; } /** @@ -189,15 +229,32 @@ public class CollaborationUseEditPartCN extends NamedElementEditPart { */ @Override protected IFigure getContentPaneFor(IGraphicalEditPart editPart) { + if (editPart instanceof IBorderItemEditPart) { + return getBorderedFigure().getBorderItemContainer(); + } return getContentPane(); } + /** + * @generated + */ + @Override + protected void addBorderItem(IFigure borderItemContainer, IBorderItemEditPart borderItemEditPart) { + if (borderItemEditPart instanceof CollaborationUseFloatingLabelEditPartCN) { + IBorderItemLocator locator = new RoundedRectangleLabelPositionLocator(getMainFigure()); + borderItemContainer.add(borderItemEditPart.getFigure(), locator); + } else + { + super.addBorderItem(borderItemContainer, borderItemEditPart); + } + } + /** * @generated */ @Override protected NodeFigure createNodePlate() { - DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(40, 40); + RoundedRectangleNodePlateFigure result = new RoundedRectangleNodePlateFigure(40, 40); return result; } @@ -210,7 +267,7 @@ public class CollaborationUseEditPartCN extends NamedElementEditPart { * @generated */ @Override - protected NodeFigure createNodeFigure() { + protected NodeFigure createMainFigure() { return new SelectableBorderedNodeFigure(createMainFigureWithSVG()); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/CollaborationUseFloatingLabelEditPartCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/CollaborationUseFloatingLabelEditPartCN.java new file mode 100644 index 00000000000..c7b25d59da8 --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/CollaborationUseFloatingLabelEditPartCN.java @@ -0,0 +1,860 @@ +/** + * 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.uml.diagram.composite.edit.parts; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.Label; +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.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.RunnableWithResult; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gef.AccessibleEditPart; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.Request; +import org.eclipse.gef.requests.DirectEditRequest; +import org.eclipse.gef.tools.DirectEditManager; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; +import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; +import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; +import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; +import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; +import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; +import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; +import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; +import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; +import org.eclipse.gmf.runtime.notation.FontStyle; +import org.eclipse.gmf.runtime.notation.NotationPackage; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.text.contentassist.IContentAssistProcessor; +import org.eclipse.jface.viewers.ICellEditorValidator; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.extensionpoints.editors.Activator; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; +import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; +import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.ExternalLabelPrimaryDragRoleEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.PapyrusWrappingLabel; +import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; +import org.eclipse.papyrus.uml.diagram.common.editparts.FloatingLabelEditPart; +import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; +import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; +import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; +import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.accessibility.AccessibleEvent; +import org.eclipse.swt.custom.BusyIndicator; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; +import org.eclipse.uml2.uml.Feature; + +/** + * @generated + */ +public class CollaborationUseFloatingLabelEditPartCN extends FloatingLabelEditPart + implements ITextAwareEditPart, IBorderItemEditPart +{ + + /** + * @generated + */ + public static final int VISUAL_ID = 6056; + + /** + * @generated + */ + private DirectEditManager manager; + + /** + * @generated + */ + private IParser parser; + + /** + * @generated + */ + private List parserElements; + + /** + * @generated + */ + private String defaultText; + + /** + * direct edition mode (default, undefined, registered editor, etc.) + * + * @generated + */ + protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; + + /** + * configuration from a registered edit dialog + * + * @generated + */ + protected IDirectEditorConfiguration configuration; + + + /** + * @generated + */ + static { + registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.CollaborationUseFloatingLabelEditPartCN.VISUAL_ID), new Point(0, 0)); + } + + /** + * @generated + */ + public CollaborationUseFloatingLabelEditPartCN(View view) { + super(view); + } + + /** + * @generated + */ + @Override + protected void createDefaultEditPolicies() { + super.createDefaultEditPolicies(); + installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); + installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ExternalLabelPrimaryDragRoleEditPolicy()); + } + + /** + * @generated + */ + @Override + public IBorderItemLocator getBorderItemLocator() { + IFigure parentFigure = getFigure().getParent(); + if (parentFigure != null && parentFigure.getLayoutManager() != null) { + Object constraint = parentFigure.getLayoutManager().getConstraint(getFigure()); + return (IBorderItemLocator) constraint; + } + return null; + } + + /** + * @generated + */ + @Override + public void refreshBounds() { + int x = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_X())).intValue(); + int y = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_Y())).intValue(); + int width = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Width())).intValue(); + int height = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Height())).intValue(); + getBorderItemLocator().setConstraint(new Rectangle(x, y, width, height)); + } + + + /** + * @generated + */ + protected String getLabelTextHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getText(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getText(); + } else { + return ((Label) figure).getText(); + } + } + + /** + * @generated + */ + protected void setLabelTextHelper(IFigure figure, String text) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setText(text); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setText(text); + } else { + ((Label) figure).setText(text); + } + } + + /** + * @generated + */ + protected Image getLabelIconHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getIcon(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getIcon(); + } else { + return ((Label) figure).getIcon(); + } + } + + /** + * @generated + */ + protected void setLabelIconHelper(IFigure figure, Image icon) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setIcon(icon); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setIcon(icon); + } else { + ((Label) figure).setIcon(icon); + } + } + + /** + * @generated + */ + public void setLabel(IFigure + figure) { + unregisterVisuals(); + setFigure(figure); + defaultText = getLabelTextHelper(figure); + registerVisuals(); + refreshVisuals(); + } + + /** + * @generated + */ + @Override + protected List getModelChildren() { + return Collections.EMPTY_LIST; + } + + /** + * @generated + */ + @Override + public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { + return null; + } + + /** + * @generated + */ + public void setParser(IParser parser) { + this.parser = parser; + } + + /** + * @generated + */ + protected EObject getParserElement() { + return resolveSemanticElement(); + } + + /** + * @generated + */ + protected Image getLabelIcon() { + return null; + } + + /** + * @generated + */ + protected String getLabelText() { + String text = null; + EObject parserElement = getParserElement(); + if (parserElement != null && getParser() != null) { + text = getParser().getPrintString( + new EObjectAdapter(parserElement), + getParserOptions().intValue()); + } + if (text == null || text.length() == 0) { + text = defaultText; + } + return text; + } + + /** + * @generated + */ + @Override + public void setLabelText(String text) { + setLabelTextHelper(getFigure(), text); + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + @Override + public String getEditText() { + if (getParserElement() == null || getParser() == null) { + return ""; //$NON-NLS-1$ + } + return getParser().getEditString( + new EObjectAdapter(getParserElement()), + getParserOptions().intValue()); + } + + /** + * @generated + */ + protected boolean isEditable() { + return getParser() != null; + } + + /** + * @generated + */ + @Override + public ICellEditorValidator getEditTextValidator() { + return new ICellEditorValidator() { + + @Override + public String isValid(final Object value) { + if (value instanceof String) { + final EObject element = getParserElement(); + final IParser parser = getParser(); + try { + IParserEditStatus valid = + (IParserEditStatus) getEditingDomain().runExclusive( + new RunnableWithResult.Impl() { + + @Override + public void run() { + setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); + } + }); + return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); + } catch (InterruptedException ie) { + ie.printStackTrace(); + } + } + + // shouldn't get here + return null; + } + }; + } + + /** + * @generated + */ + @Override + public IContentAssistProcessor getCompletionProcessor() { + if (getParserElement() == null || getParser() == null) { + return null; + } + return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); + } + + /** + * @generated + */ + @Override + public ParserOptions getParserOptions() { + return ParserOptions.NONE; + } + + /** + * @generated + */ + @Override + public IParser getParser() { + if (parser == null) { + parser = UMLParserProvider.getParser(UMLElementTypes.CollaborationUse_3071, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.CollaborationUseFloatingLabelEditPartCN.VISUAL_ID)); + } + return parser; + } + + /** + * @generated + */ + protected DirectEditManager getManager() { + if (manager == null) { + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + } + return manager; + } + + /** + * @generated + */ + protected void setManager(DirectEditManager manager) { + this.manager = manager; + } + + /** + * @generated + */ + protected void performDirectEdit() { + BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { + + @Override + public void run() { + getManager().show(); + } + }); + } + + /** + * @generated + */ + protected void performDirectEdit(Point eventLocation) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); + } + } + + /** + * @generated + */ + private void performDirectEdit(char initialCharacter) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(initialCharacter); + } else { + performDirectEdit(); + } + } + + /** + * @generated + */ + @Override + protected void performDirectEditRequest(Request request) { + + final Request theRequest = request; + + if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { + directEditionMode = getDirectEditionType(); + } + switch (directEditionMode) { + case IDirectEdition.NO_DIRECT_EDITION: + // no direct edition mode => does nothing + return; + case IDirectEdition.EXTENDED_DIRECT_EDITOR: + updateExtendedEditorConfiguration(); + if (configuration == null || configuration.getLanguage() == null) { + // Create default edit manager + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + performDefaultDirectEditorEdit(theRequest); + } else { + configuration.preEditAction(resolveSemanticElement()); + Dialog dialog = null; + if (configuration instanceof ICustomDirectEditorConfiguration) { + setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); + initializeDirectEditManager(theRequest); + return; + } else if (configuration instanceof IPopupEditorConfiguration) { + IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); + helper.showEditor(); + return; + } + else if (configuration instanceof IAdvancedEditorConfiguration) { + dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); + } else if (configuration instanceof IDirectEditorConfiguration) { + dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), + configuration); + } else { + return; + } + final Dialog finalDialog = dialog; + + if (Window.OK == dialog.open()) { + TransactionalEditingDomain domain = getEditingDomain(); + RecordingCommand command = new RecordingCommand(domain, "Edit Label") { + + @Override + protected void doExecute() { + configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); + + } + }; + domain.getCommandStack().execute(command); + } + } + break; + case IDirectEdition.DEFAULT_DIRECT_EDITOR: + initializeDirectEditManager(theRequest); + break; + default: + break; + } + } + + /** + * @generated + */ + protected void initializeDirectEditManager(final Request request) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + @Override + public void run() { + if (isActive() && isEditable()) { + if (request.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } + else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void refreshVisuals() { + super.refreshVisuals(); + refreshLabel(); + refreshFont(); + refreshFontColor(); + refreshUnderline(); + refreshStrikeThrough(); + } + + /** + * @generated + */ + protected void refreshLabel() { + EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); + if (maskLabelPolicy == null) { + maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); + } + if (maskLabelPolicy == null) { + View view = (View) getModel(); + if (view.isVisible()) { + setLabelTextHelper(getFigure(), getLabelText()); + setLabelIconHelper(getFigure(), getLabelIcon()); + } + else { + setLabelTextHelper(getFigure(), ""); //$NON-NLS-1$ + setLabelIconHelper(getFigure(), null); + } + } + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + protected void refreshUnderline() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); + } + if (resolveSemanticElement() instanceof Feature) { + if (((Feature) resolveSemanticElement()).isStatic()) { + ((WrappingLabel) getFigure()).setTextUnderline(true); + } + else { + ((WrappingLabel) getFigure()).setTextUnderline(false); + } + } + } + + /** + * @generated + */ + protected void refreshStrikeThrough() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); + } + } + + /** + * @generated + */ + @Override + protected void refreshFont() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null) { + FontData fontData = new FontData( + style.getFontName(), style.getFontHeight(), + (style.isBold() ? SWT.BOLD : SWT.NORMAL) | + (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); + setFont(fontData); + } + } + + /** + * @generated + */ + @Override + protected void setFontColor(Color color) { + getFigure().setForegroundColor(color); + } + + /** + * @generated + */ + @Override + protected void addSemanticListeners() { + if (getParser() instanceof ISemanticParser) { + EObject element = resolveSemanticElement(); + parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); + for (int i = 0; i < parserElements.size(); i++) { + addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ + } + } else { + super.addSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected void removeSemanticListeners() { + if (parserElements != null) { + for (int i = 0; i < parserElements.size(); i++) { + removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ + } + } else { + super.removeSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected AccessibleEditPart getAccessibleEditPart() { + if (accessibleEP == null) { + accessibleEP = new AccessibleGraphicalEditPart() { + + @Override + public void getName(AccessibleEvent e) { + e.result = getLabelTextHelper(getFigure()); + } + }; + } + return accessibleEP; + } + + /** + * @generated + */ + private View getFontStyleOwnerView() { + return getPrimaryView(); + } + + /** + * Returns the kind of associated editor for direct edition. + * + * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition + * @generated + */ + public int getDirectEditionType() { + if (checkExtendedEditor()) { + initExtendedEditorConfiguration(); + return IDirectEdition.EXTENDED_DIRECT_EDITOR; + } + if (checkDefaultEdition()) { + return IDirectEdition.DEFAULT_DIRECT_EDITOR; + } + + // not a named element. no specific editor => do nothing + return IDirectEdition.NO_DIRECT_EDITION; + } + + /** + * Checks if an extended editor is present. + * + * @return true if an extended editor is present. + * @generated + */ + protected boolean checkExtendedEditor() { + if (resolveSemanticElement() != null) { + return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); + } + return false; + } + + /** + * Checks if a default direct edition is available + * + * @return true if a default direct edition is available + * @generated + */ + protected boolean checkDefaultEdition() { + return (getParser() != null); + } + + /** + * Initializes the extended editor configuration + * + * @generated + */ + protected void initExtendedEditorConfiguration() { + if (configuration == null) { + final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("")) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); + } else { + configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); + } + } + } + + /** + * Updates the preference configuration + * + * @generated + */ + protected void updateExtendedEditorConfiguration() { + String languagePreferred = Activator.getDefault().getPreferenceStore().getString( + IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() + .eClass().getInstanceClassName()); + } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { + configuration = null; + } + } + + /** + * Performs the direct edit usually used by GMF editors. + * + * @param theRequest + * the direct edit request that starts the direct edit system + * @generated + */ + protected void performDefaultDirectEditorEdit(final Request theRequest) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + + @Override + public void run() { + if (isActive() && isEditable()) { + if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) theRequest.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { + DirectEditRequest editRequest = (DirectEditRequest) theRequest; + performDirectEdit(editRequest.getLocation()); + } else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + + /** + * @generated + */ + @Override + protected void handleNotificationEvent(Notification event) { + Object feature = event.getFeature(); + if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { + Integer c = (Integer) event.getNewValue(); + setFontColor(DiagramColorRegistry.getInstance().getColor(c)); + } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { + refreshUnderline(); + } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { + refreshStrikeThrough(); + } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { + refreshFont(); + } else { + if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { + refreshLabel(); + } + if (getParser() instanceof ISemanticParser) { + ISemanticParser modelParser = + (ISemanticParser) getParser(); + if (modelParser.areSemanticElementsAffected(null, event)) { + removeSemanticListeners(); + if (resolveSemanticElement() != null) { + addSemanticListeners(); + } + refreshLabel(); + } + } + } + super.handleNotificationEvent(event); + } + + /** + * @generated + */ + @Override + protected IFigure createFigure() { + IFigure label = createFigurePrim(); + defaultText = getLabelTextHelper(label); + return label; + } + + /** + * @generated + */ + protected IFigure createFigurePrim() { + return new PapyrusWrappingLabel(); + } + +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/CollaborationUseNameEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/CollaborationUseNameEditPart.java index 599b940311d..f4a23e201ea 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/CollaborationUseNameEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/CollaborationUseNameEditPart.java @@ -866,7 +866,7 @@ public class CollaborationUseNameEditPart extends PapyrusCompartmentEditPart imp * @generated */ protected void addOwnerElementListeners() { - addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); + addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/CommentBodyEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/CommentBodyEditPart.java index 5e55f05e3c5..617f4fc5861 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/CommentBodyEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/CommentBodyEditPart.java @@ -847,7 +847,7 @@ public class CommentBodyEditPart extends PapyrusCompartmentEditPart implements I * @generated */ protected void addOwnerElementListeners() { - addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); + addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/CommentBodyEditPartCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/CommentBodyEditPartCN.java index 783a4bb14fd..050cbfe9050 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/CommentBodyEditPartCN.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/CommentBodyEditPartCN.java @@ -847,7 +847,7 @@ public class CommentBodyEditPartCN extends PapyrusCompartmentEditPart implements * @generated */ protected void addOwnerElementListeners() { - addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); + addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/CommentEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/CommentEditPart.java index 8b9ea0e426d..55c99314009 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/CommentEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/CommentEditPart.java @@ -23,11 +23,11 @@ import org.eclipse.gef.requests.CreateRequest; import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles; import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; -import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure; import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure; import org.eclipse.gmf.runtime.notation.View; import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.PapyrusReflowableShapeEditPolicy; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.IPapyrusNodeFigure; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.RoundedRectangleNodePlateFigure; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.SelectableBorderedNodeFigure; import org.eclipse.papyrus.uml.diagram.common.editparts.AbstractCommentEditPart; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeLabelDisplayEditPolicy; @@ -193,7 +193,7 @@ public class CommentEditPart extends AbstractCommentEditPart { */ @Override protected NodeFigure createNodePlate() { - DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(40, 40); + RoundedRectangleNodePlateFigure result = new RoundedRectangleNodePlateFigure(40, 40); return result; } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/CommentEditPartCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/CommentEditPartCN.java index e622a787f0c..93db8edea89 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/CommentEditPartCN.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/CommentEditPartCN.java @@ -23,11 +23,11 @@ import org.eclipse.gef.requests.CreateRequest; import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles; import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; -import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure; import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure; import org.eclipse.gmf.runtime.notation.View; import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.PapyrusReflowableShapeEditPolicy; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.IPapyrusNodeFigure; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.RoundedRectangleNodePlateFigure; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.SelectableBorderedNodeFigure; import org.eclipse.papyrus.uml.diagram.common.editparts.AbstractCommentEditPart; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeLabelDisplayEditPolicy; @@ -193,7 +193,7 @@ public class CommentEditPartCN extends AbstractCommentEditPart { */ @Override protected NodeFigure createNodePlate() { - DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(40, 40); + RoundedRectangleNodePlateFigure result = new RoundedRectangleNodePlateFigure(40, 40); return result; } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ComponentCompositeCompartmentEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ComponentCompositeCompartmentEditPart.java index 95483a708d5..f8d12b501c8 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ComponentCompositeCompartmentEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ComponentCompositeCompartmentEditPart.java @@ -26,6 +26,7 @@ import org.eclipse.gmf.runtime.diagram.ui.editpolicies.ResizableCompartmentEditP import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.BorderDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.CustomContainerEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.DuplicatePasteEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.PapyrusCreationEditPolicy; @@ -75,6 +76,7 @@ public class ComponentCompositeCompartmentEditPart extends ShapeCompartmentEditP installEditPolicy(EditPolicy.GRAPHICAL_NODE_ROLE, new CustomContainerEditPolicy()); installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, new CustomDiagramDragDropEditPolicy()); installEditPolicy(EditPolicyRoles.CREATION_ROLE, new PortInCompartmentCreationEditPolicy()); + installEditPolicy(BorderDisplayEditPolicy.BORDER_DISPLAY_EDITPOLICY, new BorderDisplayEditPolicy()); } /** diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ComponentCompositeCompartmentEditPartCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ComponentCompositeCompartmentEditPartCN.java index c058d527e5a..880045adaa3 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ComponentCompositeCompartmentEditPartCN.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ComponentCompositeCompartmentEditPartCN.java @@ -26,6 +26,7 @@ import org.eclipse.gmf.runtime.diagram.ui.editpolicies.ResizableCompartmentEditP import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.BorderDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.CustomContainerEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.DuplicatePasteEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.PapyrusCreationEditPolicy; @@ -75,6 +76,7 @@ public class ComponentCompositeCompartmentEditPartCN extends ShapeCompartmentEdi installEditPolicy(EditPolicy.GRAPHICAL_NODE_ROLE, new CustomContainerEditPolicy()); installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, new CustomDiagramDragDropEditPolicy()); installEditPolicy(EditPolicyRoles.CREATION_ROLE, new PortInCompartmentCreationEditPolicy()); + installEditPolicy(BorderDisplayEditPolicy.BORDER_DISPLAY_EDITPOLICY, new BorderDisplayEditPolicy()); } /** diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ComponentCompositeEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ComponentCompositeEditPart.java index cb04e185434..05ef6748b0f 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ComponentCompositeEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ComponentCompositeEditPart.java @@ -11,28 +11,37 @@ */ package org.eclipse.papyrus.uml.diagram.composite.edit.parts; +import java.util.Collections; +import java.util.List; + import org.eclipse.draw2d.IFigure; import org.eclipse.draw2d.PositionConstants; import org.eclipse.emf.common.notify.Notification; import org.eclipse.gef.EditPart; import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.GraphicalEditPart; 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.handles.MoveHandle; import org.eclipse.gef.requests.CreateRequest; import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.BorderItemSelectionEditPolicy; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.DragDropEditPolicy; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles; import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; -import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure; import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure; +import org.eclipse.gmf.runtime.notation.Edge; +import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.GetChildLayoutEditPolicy; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.IPapyrusNodeFigure; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.RoundedRectangleNodePlateFigure; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.SelectableBorderedNodeFigure; -import org.eclipse.papyrus.uml.diagram.common.editparts.NamedElementEditPart; +import org.eclipse.papyrus.uml.diagram.common.editparts.RoundedCompartmentEditPart; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AffixedNodeAlignmentEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeNodeLabelDisplayEditPolicy; @@ -41,12 +50,12 @@ import org.eclipse.papyrus.uml.diagram.common.editpolicies.PapyrusCreationEditPo import org.eclipse.papyrus.uml.diagram.common.editpolicies.QualifiedNameDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.ShowHideClassifierContentsEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.ShowHideCompartmentEditPolicy; +import org.eclipse.papyrus.uml.diagram.common.locator.RoundedRectangleLabelPositionLocator; import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.CustomDiagramDragDropEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.CustomGraphicalNodeEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.RemoveOrphanViewPolicy; import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.StructuredClassifierLayoutEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.custom.figures.ComponentCompositeFigure; -import org.eclipse.papyrus.uml.diagram.composite.custom.locators.PortPositionLocator; import org.eclipse.papyrus.uml.diagram.composite.edit.policies.ComponentCompositeItemSemanticEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; import org.eclipse.swt.graphics.Color; @@ -54,7 +63,7 @@ import org.eclipse.swt.graphics.Color; /** * @generated */ -public class ComponentCompositeEditPart extends NamedElementEditPart { +public class ComponentCompositeEditPart extends RoundedCompartmentEditPart { /** * @generated @@ -97,6 +106,7 @@ public class ComponentCompositeEditPart extends NamedElementEditPart { installEditPolicy(ShowHideCompartmentEditPolicy.SHOW_HIDE_COMPARTMENT_POLICY, new ShowHideCompartmentEditPolicy()); installEditPolicy(AffixedNodeAlignmentEditPolicy.AFFIXED_CHILD_ALIGNMENT_ROLE, new AffixedNodeAlignmentEditPolicy()); installEditPolicy("REMOVE_ORPHAN_VIEW", new RemoveOrphanViewPolicy()); //$NON-NLS-1$ + installEditPolicy(EditPolicy.LAYOUT_ROLE, new GetChildLayoutEditPolicy()); // XXX need an SCR to runtime to have another abstract superclass that would let children add reasonable editpolicies // removeEditPolicy(org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles.CONNECTION_HANDLES_ROLE); } @@ -111,6 +121,17 @@ public class ComponentCompositeEditPart extends NamedElementEditPart { protected EditPolicy createChildEditPolicy(EditPart child) { View childView = (View) child.getModel(); switch (UMLVisualIDRegistry.getVisualID(childView)) { + case ComponentCompositeFloatingLabelEditPart.VISUAL_ID: + return new BorderItemSelectionEditPolicy() { + + @Override + protected List createSelectionHandles() { + MoveHandle mh = new MoveHandle((GraphicalEditPart) getHost()); + mh.setBorder(null); + return Collections.singletonList(mh); + } + } + ; case PortEditPart.VISUAL_ID: return new BorderItemResizableEditPolicy(); } @@ -141,6 +162,19 @@ public class ComponentCompositeEditPart extends NamedElementEditPart { **/ @Override protected void handleNotificationEvent(Notification event) { + /* + * when a node have external node labels, the methods refreshChildren() remove the EditPart corresponding to the Label from the EditPart + * Registry. After that, we can't reset the visibility to true (using the Show/Hide Label Action)! + */ + if (NotationPackage.eINSTANCE.getView_Visible().equals(event.getFeature())) { + Object notifier = event.getNotifier(); + List modelChildren = ((View) getModel()).getChildren(); + if (!(notifier instanceof Edge)) { + if (modelChildren.contains(event.getNotifier())) { + return; + } + } + } super.handleNotificationEvent(event); } @@ -182,9 +216,9 @@ public class ComponentCompositeEditPart extends NamedElementEditPart { - //Papyrus Gencode :Affixed Port locator + // Papyrus Gencode :Affixed Port locator if (childEditPart instanceof PortEditPart) { - IBorderItemLocator locator = new PortPositionLocator(getMainFigure(), PositionConstants.NONE); + IBorderItemLocator locator = new org.eclipse.papyrus.uml.diagram.common.locator.PortPositionLocator(getMainFigure(), PositionConstants.NONE); getBorderedFigure().getBorderItemContainer().add(((PortEditPart) childEditPart).getFigure(), locator); return true; } @@ -248,12 +282,26 @@ public class ComponentCompositeEditPart extends NamedElementEditPart { return getContentPane(); } + /** + * @generated + */ + @Override + protected void addBorderItem(IFigure borderItemContainer, IBorderItemEditPart borderItemEditPart) { + if (borderItemEditPart instanceof ComponentCompositeFloatingLabelEditPart) { + IBorderItemLocator locator = new RoundedRectangleLabelPositionLocator(getMainFigure()); + borderItemContainer.add(borderItemEditPart.getFigure(), locator); + } else + { + super.addBorderItem(borderItemContainer, borderItemEditPart); + } + } + /** * @generated */ @Override protected NodeFigure createNodePlate() { - DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(40, 40); + RoundedRectangleNodePlateFigure result = new RoundedRectangleNodePlateFigure(40, 40); return result; } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ComponentCompositeEditPartCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ComponentCompositeEditPartCN.java index 563154d014c..04bc91c8e70 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ComponentCompositeEditPartCN.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ComponentCompositeEditPartCN.java @@ -11,28 +11,37 @@ */ package org.eclipse.papyrus.uml.diagram.composite.edit.parts; +import java.util.Collections; +import java.util.List; + import org.eclipse.draw2d.IFigure; import org.eclipse.draw2d.PositionConstants; import org.eclipse.emf.common.notify.Notification; import org.eclipse.gef.EditPart; import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.GraphicalEditPart; 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.handles.MoveHandle; import org.eclipse.gef.requests.CreateRequest; import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.BorderItemSelectionEditPolicy; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.DragDropEditPolicy; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles; import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; -import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure; import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure; +import org.eclipse.gmf.runtime.notation.Edge; +import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.GetChildLayoutEditPolicy; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.IPapyrusNodeFigure; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.RoundedRectangleNodePlateFigure; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.SelectableBorderedNodeFigure; -import org.eclipse.papyrus.uml.diagram.common.editparts.NamedElementEditPart; +import org.eclipse.papyrus.uml.diagram.common.editparts.RoundedCompartmentEditPart; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AffixedNodeAlignmentEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeNodeLabelDisplayEditPolicy; @@ -41,12 +50,12 @@ import org.eclipse.papyrus.uml.diagram.common.editpolicies.PapyrusCreationEditPo import org.eclipse.papyrus.uml.diagram.common.editpolicies.QualifiedNameDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.ShowHideClassifierContentsEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.ShowHideCompartmentEditPolicy; +import org.eclipse.papyrus.uml.diagram.common.locator.RoundedRectangleLabelPositionLocator; import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.CustomDiagramDragDropEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.CustomGraphicalNodeEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.RemoveOrphanViewPolicy; import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.StructuredClassifierLayoutEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.custom.figures.ComponentCompositeFigure; -import org.eclipse.papyrus.uml.diagram.composite.custom.locators.PortPositionLocator; import org.eclipse.papyrus.uml.diagram.composite.edit.policies.ComponentCompositeItemSemanticEditPolicyCN; import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; import org.eclipse.swt.graphics.Color; @@ -54,7 +63,7 @@ import org.eclipse.swt.graphics.Color; /** * @generated */ -public class ComponentCompositeEditPartCN extends NamedElementEditPart { +public class ComponentCompositeEditPartCN extends RoundedCompartmentEditPart { /** * @generated @@ -97,6 +106,7 @@ public class ComponentCompositeEditPartCN extends NamedElementEditPart { installEditPolicy(ShowHideCompartmentEditPolicy.SHOW_HIDE_COMPARTMENT_POLICY, new ShowHideCompartmentEditPolicy()); installEditPolicy(AffixedNodeAlignmentEditPolicy.AFFIXED_CHILD_ALIGNMENT_ROLE, new AffixedNodeAlignmentEditPolicy()); installEditPolicy("REMOVE_ORPHAN_VIEW", new RemoveOrphanViewPolicy()); //$NON-NLS-1$ + installEditPolicy(EditPolicy.LAYOUT_ROLE, new GetChildLayoutEditPolicy()); // XXX need an SCR to runtime to have another abstract superclass that would let children add reasonable editpolicies // removeEditPolicy(org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles.CONNECTION_HANDLES_ROLE); } @@ -111,6 +121,17 @@ public class ComponentCompositeEditPartCN extends NamedElementEditPart { protected EditPolicy createChildEditPolicy(EditPart child) { View childView = (View) child.getModel(); switch (UMLVisualIDRegistry.getVisualID(childView)) { + case ComponentCompositeFloatingLabelEditPartCN.VISUAL_ID: + return new BorderItemSelectionEditPolicy() { + + @Override + protected List createSelectionHandles() { + MoveHandle mh = new MoveHandle((GraphicalEditPart) getHost()); + mh.setBorder(null); + return Collections.singletonList(mh); + } + } + ; case PortEditPart.VISUAL_ID: return new BorderItemResizableEditPolicy(); } @@ -141,6 +162,19 @@ public class ComponentCompositeEditPartCN extends NamedElementEditPart { **/ @Override protected void handleNotificationEvent(Notification event) { + /* + * when a node have external node labels, the methods refreshChildren() remove the EditPart corresponding to the Label from the EditPart + * Registry. After that, we can't reset the visibility to true (using the Show/Hide Label Action)! + */ + if (NotationPackage.eINSTANCE.getView_Visible().equals(event.getFeature())) { + Object notifier = event.getNotifier(); + List modelChildren = ((View) getModel()).getChildren(); + if (!(notifier instanceof Edge)) { + if (modelChildren.contains(event.getNotifier())) { + return; + } + } + } super.handleNotificationEvent(event); } @@ -182,9 +216,9 @@ public class ComponentCompositeEditPartCN extends NamedElementEditPart { - //Papyrus Gencode :Affixed Port locator + // Papyrus Gencode :Affixed Port locator if (childEditPart instanceof PortEditPart) { - IBorderItemLocator locator = new PortPositionLocator(getMainFigure(), PositionConstants.NONE); + IBorderItemLocator locator = new org.eclipse.papyrus.uml.diagram.common.locator.PortPositionLocator(getMainFigure(), PositionConstants.NONE); getBorderedFigure().getBorderItemContainer().add(((PortEditPart) childEditPart).getFigure(), locator); return true; } @@ -248,12 +282,26 @@ public class ComponentCompositeEditPartCN extends NamedElementEditPart { return getContentPane(); } + /** + * @generated + */ + @Override + protected void addBorderItem(IFigure borderItemContainer, IBorderItemEditPart borderItemEditPart) { + if (borderItemEditPart instanceof ComponentCompositeFloatingLabelEditPartCN) { + IBorderItemLocator locator = new RoundedRectangleLabelPositionLocator(getMainFigure()); + borderItemContainer.add(borderItemEditPart.getFigure(), locator); + } else + { + super.addBorderItem(borderItemContainer, borderItemEditPart); + } + } + /** * @generated */ @Override protected NodeFigure createNodePlate() { - DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(40, 40); + RoundedRectangleNodePlateFigure result = new RoundedRectangleNodePlateFigure(40, 40); return result; } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ComponentCompositeFloatingLabelEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ComponentCompositeFloatingLabelEditPart.java new file mode 100644 index 00000000000..573b72c41f1 --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ComponentCompositeFloatingLabelEditPart.java @@ -0,0 +1,860 @@ +/** + * 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.uml.diagram.composite.edit.parts; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.Label; +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.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.RunnableWithResult; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gef.AccessibleEditPart; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.Request; +import org.eclipse.gef.requests.DirectEditRequest; +import org.eclipse.gef.tools.DirectEditManager; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; +import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; +import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; +import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; +import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; +import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; +import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; +import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; +import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; +import org.eclipse.gmf.runtime.notation.FontStyle; +import org.eclipse.gmf.runtime.notation.NotationPackage; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.text.contentassist.IContentAssistProcessor; +import org.eclipse.jface.viewers.ICellEditorValidator; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.extensionpoints.editors.Activator; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; +import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; +import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.ExternalLabelPrimaryDragRoleEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.PapyrusWrappingLabel; +import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; +import org.eclipse.papyrus.uml.diagram.common.editparts.FloatingLabelEditPart; +import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; +import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; +import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; +import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.accessibility.AccessibleEvent; +import org.eclipse.swt.custom.BusyIndicator; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; +import org.eclipse.uml2.uml.Feature; + +/** + * @generated + */ +public class ComponentCompositeFloatingLabelEditPart extends FloatingLabelEditPart + implements ITextAwareEditPart, IBorderItemEditPart +{ + + /** + * @generated + */ + public static final int VISUAL_ID = 6085; + + /** + * @generated + */ + private DirectEditManager manager; + + /** + * @generated + */ + private IParser parser; + + /** + * @generated + */ + private List parserElements; + + /** + * @generated + */ + private String defaultText; + + /** + * direct edition mode (default, undefined, registered editor, etc.) + * + * @generated + */ + protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; + + /** + * configuration from a registered edit dialog + * + * @generated + */ + protected IDirectEditorConfiguration configuration; + + + /** + * @generated + */ + static { + registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.ComponentCompositeFloatingLabelEditPart.VISUAL_ID), new Point(0, 0)); + } + + /** + * @generated + */ + public ComponentCompositeFloatingLabelEditPart(View view) { + super(view); + } + + /** + * @generated + */ + @Override + protected void createDefaultEditPolicies() { + super.createDefaultEditPolicies(); + installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); + installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ExternalLabelPrimaryDragRoleEditPolicy()); + } + + /** + * @generated + */ + @Override + public IBorderItemLocator getBorderItemLocator() { + IFigure parentFigure = getFigure().getParent(); + if (parentFigure != null && parentFigure.getLayoutManager() != null) { + Object constraint = parentFigure.getLayoutManager().getConstraint(getFigure()); + return (IBorderItemLocator) constraint; + } + return null; + } + + /** + * @generated + */ + @Override + public void refreshBounds() { + int x = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_X())).intValue(); + int y = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_Y())).intValue(); + int width = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Width())).intValue(); + int height = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Height())).intValue(); + getBorderItemLocator().setConstraint(new Rectangle(x, y, width, height)); + } + + + /** + * @generated + */ + protected String getLabelTextHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getText(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getText(); + } else { + return ((Label) figure).getText(); + } + } + + /** + * @generated + */ + protected void setLabelTextHelper(IFigure figure, String text) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setText(text); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setText(text); + } else { + ((Label) figure).setText(text); + } + } + + /** + * @generated + */ + protected Image getLabelIconHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getIcon(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getIcon(); + } else { + return ((Label) figure).getIcon(); + } + } + + /** + * @generated + */ + protected void setLabelIconHelper(IFigure figure, Image icon) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setIcon(icon); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setIcon(icon); + } else { + ((Label) figure).setIcon(icon); + } + } + + /** + * @generated + */ + public void setLabel(IFigure + figure) { + unregisterVisuals(); + setFigure(figure); + defaultText = getLabelTextHelper(figure); + registerVisuals(); + refreshVisuals(); + } + + /** + * @generated + */ + @Override + protected List getModelChildren() { + return Collections.EMPTY_LIST; + } + + /** + * @generated + */ + @Override + public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { + return null; + } + + /** + * @generated + */ + public void setParser(IParser parser) { + this.parser = parser; + } + + /** + * @generated + */ + protected EObject getParserElement() { + return resolveSemanticElement(); + } + + /** + * @generated + */ + protected Image getLabelIcon() { + return null; + } + + /** + * @generated + */ + protected String getLabelText() { + String text = null; + EObject parserElement = getParserElement(); + if (parserElement != null && getParser() != null) { + text = getParser().getPrintString( + new EObjectAdapter(parserElement), + getParserOptions().intValue()); + } + if (text == null || text.length() == 0) { + text = defaultText; + } + return text; + } + + /** + * @generated + */ + @Override + public void setLabelText(String text) { + setLabelTextHelper(getFigure(), text); + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + @Override + public String getEditText() { + if (getParserElement() == null || getParser() == null) { + return ""; //$NON-NLS-1$ + } + return getParser().getEditString( + new EObjectAdapter(getParserElement()), + getParserOptions().intValue()); + } + + /** + * @generated + */ + protected boolean isEditable() { + return getParser() != null; + } + + /** + * @generated + */ + @Override + public ICellEditorValidator getEditTextValidator() { + return new ICellEditorValidator() { + + @Override + public String isValid(final Object value) { + if (value instanceof String) { + final EObject element = getParserElement(); + final IParser parser = getParser(); + try { + IParserEditStatus valid = + (IParserEditStatus) getEditingDomain().runExclusive( + new RunnableWithResult.Impl() { + + @Override + public void run() { + setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); + } + }); + return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); + } catch (InterruptedException ie) { + ie.printStackTrace(); + } + } + + // shouldn't get here + return null; + } + }; + } + + /** + * @generated + */ + @Override + public IContentAssistProcessor getCompletionProcessor() { + if (getParserElement() == null || getParser() == null) { + return null; + } + return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); + } + + /** + * @generated + */ + @Override + public ParserOptions getParserOptions() { + return ParserOptions.NONE; + } + + /** + * @generated + */ + @Override + public IParser getParser() { + if (parser == null) { + parser = UMLParserProvider.getParser(UMLElementTypes.Component_2069, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.ComponentCompositeFloatingLabelEditPart.VISUAL_ID)); + } + return parser; + } + + /** + * @generated + */ + protected DirectEditManager getManager() { + if (manager == null) { + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + } + return manager; + } + + /** + * @generated + */ + protected void setManager(DirectEditManager manager) { + this.manager = manager; + } + + /** + * @generated + */ + protected void performDirectEdit() { + BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { + + @Override + public void run() { + getManager().show(); + } + }); + } + + /** + * @generated + */ + protected void performDirectEdit(Point eventLocation) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); + } + } + + /** + * @generated + */ + private void performDirectEdit(char initialCharacter) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(initialCharacter); + } else { + performDirectEdit(); + } + } + + /** + * @generated + */ + @Override + protected void performDirectEditRequest(Request request) { + + final Request theRequest = request; + + if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { + directEditionMode = getDirectEditionType(); + } + switch (directEditionMode) { + case IDirectEdition.NO_DIRECT_EDITION: + // no direct edition mode => does nothing + return; + case IDirectEdition.EXTENDED_DIRECT_EDITOR: + updateExtendedEditorConfiguration(); + if (configuration == null || configuration.getLanguage() == null) { + // Create default edit manager + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + performDefaultDirectEditorEdit(theRequest); + } else { + configuration.preEditAction(resolveSemanticElement()); + Dialog dialog = null; + if (configuration instanceof ICustomDirectEditorConfiguration) { + setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); + initializeDirectEditManager(theRequest); + return; + } else if (configuration instanceof IPopupEditorConfiguration) { + IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); + helper.showEditor(); + return; + } + else if (configuration instanceof IAdvancedEditorConfiguration) { + dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); + } else if (configuration instanceof IDirectEditorConfiguration) { + dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), + configuration); + } else { + return; + } + final Dialog finalDialog = dialog; + + if (Window.OK == dialog.open()) { + TransactionalEditingDomain domain = getEditingDomain(); + RecordingCommand command = new RecordingCommand(domain, "Edit Label") { + + @Override + protected void doExecute() { + configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); + + } + }; + domain.getCommandStack().execute(command); + } + } + break; + case IDirectEdition.DEFAULT_DIRECT_EDITOR: + initializeDirectEditManager(theRequest); + break; + default: + break; + } + } + + /** + * @generated + */ + protected void initializeDirectEditManager(final Request request) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + @Override + public void run() { + if (isActive() && isEditable()) { + if (request.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } + else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void refreshVisuals() { + super.refreshVisuals(); + refreshLabel(); + refreshFont(); + refreshFontColor(); + refreshUnderline(); + refreshStrikeThrough(); + } + + /** + * @generated + */ + protected void refreshLabel() { + EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); + if (maskLabelPolicy == null) { + maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); + } + if (maskLabelPolicy == null) { + View view = (View) getModel(); + if (view.isVisible()) { + setLabelTextHelper(getFigure(), getLabelText()); + setLabelIconHelper(getFigure(), getLabelIcon()); + } + else { + setLabelTextHelper(getFigure(), ""); //$NON-NLS-1$ + setLabelIconHelper(getFigure(), null); + } + } + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + protected void refreshUnderline() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); + } + if (resolveSemanticElement() instanceof Feature) { + if (((Feature) resolveSemanticElement()).isStatic()) { + ((WrappingLabel) getFigure()).setTextUnderline(true); + } + else { + ((WrappingLabel) getFigure()).setTextUnderline(false); + } + } + } + + /** + * @generated + */ + protected void refreshStrikeThrough() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); + } + } + + /** + * @generated + */ + @Override + protected void refreshFont() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null) { + FontData fontData = new FontData( + style.getFontName(), style.getFontHeight(), + (style.isBold() ? SWT.BOLD : SWT.NORMAL) | + (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); + setFont(fontData); + } + } + + /** + * @generated + */ + @Override + protected void setFontColor(Color color) { + getFigure().setForegroundColor(color); + } + + /** + * @generated + */ + @Override + protected void addSemanticListeners() { + if (getParser() instanceof ISemanticParser) { + EObject element = resolveSemanticElement(); + parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); + for (int i = 0; i < parserElements.size(); i++) { + addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ + } + } else { + super.addSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected void removeSemanticListeners() { + if (parserElements != null) { + for (int i = 0; i < parserElements.size(); i++) { + removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ + } + } else { + super.removeSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected AccessibleEditPart getAccessibleEditPart() { + if (accessibleEP == null) { + accessibleEP = new AccessibleGraphicalEditPart() { + + @Override + public void getName(AccessibleEvent e) { + e.result = getLabelTextHelper(getFigure()); + } + }; + } + return accessibleEP; + } + + /** + * @generated + */ + private View getFontStyleOwnerView() { + return getPrimaryView(); + } + + /** + * Returns the kind of associated editor for direct edition. + * + * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition + * @generated + */ + public int getDirectEditionType() { + if (checkExtendedEditor()) { + initExtendedEditorConfiguration(); + return IDirectEdition.EXTENDED_DIRECT_EDITOR; + } + if (checkDefaultEdition()) { + return IDirectEdition.DEFAULT_DIRECT_EDITOR; + } + + // not a named element. no specific editor => do nothing + return IDirectEdition.NO_DIRECT_EDITION; + } + + /** + * Checks if an extended editor is present. + * + * @return true if an extended editor is present. + * @generated + */ + protected boolean checkExtendedEditor() { + if (resolveSemanticElement() != null) { + return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); + } + return false; + } + + /** + * Checks if a default direct edition is available + * + * @return true if a default direct edition is available + * @generated + */ + protected boolean checkDefaultEdition() { + return (getParser() != null); + } + + /** + * Initializes the extended editor configuration + * + * @generated + */ + protected void initExtendedEditorConfiguration() { + if (configuration == null) { + final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("")) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); + } else { + configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); + } + } + } + + /** + * Updates the preference configuration + * + * @generated + */ + protected void updateExtendedEditorConfiguration() { + String languagePreferred = Activator.getDefault().getPreferenceStore().getString( + IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() + .eClass().getInstanceClassName()); + } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { + configuration = null; + } + } + + /** + * Performs the direct edit usually used by GMF editors. + * + * @param theRequest + * the direct edit request that starts the direct edit system + * @generated + */ + protected void performDefaultDirectEditorEdit(final Request theRequest) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + + @Override + public void run() { + if (isActive() && isEditable()) { + if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) theRequest.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { + DirectEditRequest editRequest = (DirectEditRequest) theRequest; + performDirectEdit(editRequest.getLocation()); + } else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + + /** + * @generated + */ + @Override + protected void handleNotificationEvent(Notification event) { + Object feature = event.getFeature(); + if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { + Integer c = (Integer) event.getNewValue(); + setFontColor(DiagramColorRegistry.getInstance().getColor(c)); + } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { + refreshUnderline(); + } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { + refreshStrikeThrough(); + } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { + refreshFont(); + } else { + if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { + refreshLabel(); + } + if (getParser() instanceof ISemanticParser) { + ISemanticParser modelParser = + (ISemanticParser) getParser(); + if (modelParser.areSemanticElementsAffected(null, event)) { + removeSemanticListeners(); + if (resolveSemanticElement() != null) { + addSemanticListeners(); + } + refreshLabel(); + } + } + } + super.handleNotificationEvent(event); + } + + /** + * @generated + */ + @Override + protected IFigure createFigure() { + IFigure label = createFigurePrim(); + defaultText = getLabelTextHelper(label); + return label; + } + + /** + * @generated + */ + protected IFigure createFigurePrim() { + return new PapyrusWrappingLabel(); + } + +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ComponentCompositeFloatingLabelEditPartCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ComponentCompositeFloatingLabelEditPartCN.java new file mode 100644 index 00000000000..19e0c4ec51e --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ComponentCompositeFloatingLabelEditPartCN.java @@ -0,0 +1,860 @@ +/** + * 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.uml.diagram.composite.edit.parts; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.Label; +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.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.RunnableWithResult; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gef.AccessibleEditPart; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.Request; +import org.eclipse.gef.requests.DirectEditRequest; +import org.eclipse.gef.tools.DirectEditManager; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; +import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; +import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; +import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; +import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; +import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; +import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; +import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; +import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; +import org.eclipse.gmf.runtime.notation.FontStyle; +import org.eclipse.gmf.runtime.notation.NotationPackage; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.text.contentassist.IContentAssistProcessor; +import org.eclipse.jface.viewers.ICellEditorValidator; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.extensionpoints.editors.Activator; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; +import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; +import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.ExternalLabelPrimaryDragRoleEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.PapyrusWrappingLabel; +import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; +import org.eclipse.papyrus.uml.diagram.common.editparts.FloatingLabelEditPart; +import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; +import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; +import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; +import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.accessibility.AccessibleEvent; +import org.eclipse.swt.custom.BusyIndicator; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; +import org.eclipse.uml2.uml.Feature; + +/** + * @generated + */ +public class ComponentCompositeFloatingLabelEditPartCN extends FloatingLabelEditPart + implements ITextAwareEditPart, IBorderItemEditPart +{ + + /** + * @generated + */ + public static final int VISUAL_ID = 6063; + + /** + * @generated + */ + private DirectEditManager manager; + + /** + * @generated + */ + private IParser parser; + + /** + * @generated + */ + private List parserElements; + + /** + * @generated + */ + private String defaultText; + + /** + * direct edition mode (default, undefined, registered editor, etc.) + * + * @generated + */ + protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; + + /** + * configuration from a registered edit dialog + * + * @generated + */ + protected IDirectEditorConfiguration configuration; + + + /** + * @generated + */ + static { + registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.ComponentCompositeFloatingLabelEditPartCN.VISUAL_ID), new Point(0, 0)); + } + + /** + * @generated + */ + public ComponentCompositeFloatingLabelEditPartCN(View view) { + super(view); + } + + /** + * @generated + */ + @Override + protected void createDefaultEditPolicies() { + super.createDefaultEditPolicies(); + installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); + installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ExternalLabelPrimaryDragRoleEditPolicy()); + } + + /** + * @generated + */ + @Override + public IBorderItemLocator getBorderItemLocator() { + IFigure parentFigure = getFigure().getParent(); + if (parentFigure != null && parentFigure.getLayoutManager() != null) { + Object constraint = parentFigure.getLayoutManager().getConstraint(getFigure()); + return (IBorderItemLocator) constraint; + } + return null; + } + + /** + * @generated + */ + @Override + public void refreshBounds() { + int x = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_X())).intValue(); + int y = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_Y())).intValue(); + int width = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Width())).intValue(); + int height = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Height())).intValue(); + getBorderItemLocator().setConstraint(new Rectangle(x, y, width, height)); + } + + + /** + * @generated + */ + protected String getLabelTextHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getText(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getText(); + } else { + return ((Label) figure).getText(); + } + } + + /** + * @generated + */ + protected void setLabelTextHelper(IFigure figure, String text) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setText(text); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setText(text); + } else { + ((Label) figure).setText(text); + } + } + + /** + * @generated + */ + protected Image getLabelIconHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getIcon(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getIcon(); + } else { + return ((Label) figure).getIcon(); + } + } + + /** + * @generated + */ + protected void setLabelIconHelper(IFigure figure, Image icon) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setIcon(icon); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setIcon(icon); + } else { + ((Label) figure).setIcon(icon); + } + } + + /** + * @generated + */ + public void setLabel(IFigure + figure) { + unregisterVisuals(); + setFigure(figure); + defaultText = getLabelTextHelper(figure); + registerVisuals(); + refreshVisuals(); + } + + /** + * @generated + */ + @Override + protected List getModelChildren() { + return Collections.EMPTY_LIST; + } + + /** + * @generated + */ + @Override + public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { + return null; + } + + /** + * @generated + */ + public void setParser(IParser parser) { + this.parser = parser; + } + + /** + * @generated + */ + protected EObject getParserElement() { + return resolveSemanticElement(); + } + + /** + * @generated + */ + protected Image getLabelIcon() { + return null; + } + + /** + * @generated + */ + protected String getLabelText() { + String text = null; + EObject parserElement = getParserElement(); + if (parserElement != null && getParser() != null) { + text = getParser().getPrintString( + new EObjectAdapter(parserElement), + getParserOptions().intValue()); + } + if (text == null || text.length() == 0) { + text = defaultText; + } + return text; + } + + /** + * @generated + */ + @Override + public void setLabelText(String text) { + setLabelTextHelper(getFigure(), text); + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + @Override + public String getEditText() { + if (getParserElement() == null || getParser() == null) { + return ""; //$NON-NLS-1$ + } + return getParser().getEditString( + new EObjectAdapter(getParserElement()), + getParserOptions().intValue()); + } + + /** + * @generated + */ + protected boolean isEditable() { + return getParser() != null; + } + + /** + * @generated + */ + @Override + public ICellEditorValidator getEditTextValidator() { + return new ICellEditorValidator() { + + @Override + public String isValid(final Object value) { + if (value instanceof String) { + final EObject element = getParserElement(); + final IParser parser = getParser(); + try { + IParserEditStatus valid = + (IParserEditStatus) getEditingDomain().runExclusive( + new RunnableWithResult.Impl() { + + @Override + public void run() { + setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); + } + }); + return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); + } catch (InterruptedException ie) { + ie.printStackTrace(); + } + } + + // shouldn't get here + return null; + } + }; + } + + /** + * @generated + */ + @Override + public IContentAssistProcessor getCompletionProcessor() { + if (getParserElement() == null || getParser() == null) { + return null; + } + return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); + } + + /** + * @generated + */ + @Override + public ParserOptions getParserOptions() { + return ParserOptions.NONE; + } + + /** + * @generated + */ + @Override + public IParser getParser() { + if (parser == null) { + parser = UMLParserProvider.getParser(UMLElementTypes.Component_3081, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.ComponentCompositeFloatingLabelEditPartCN.VISUAL_ID)); + } + return parser; + } + + /** + * @generated + */ + protected DirectEditManager getManager() { + if (manager == null) { + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + } + return manager; + } + + /** + * @generated + */ + protected void setManager(DirectEditManager manager) { + this.manager = manager; + } + + /** + * @generated + */ + protected void performDirectEdit() { + BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { + + @Override + public void run() { + getManager().show(); + } + }); + } + + /** + * @generated + */ + protected void performDirectEdit(Point eventLocation) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); + } + } + + /** + * @generated + */ + private void performDirectEdit(char initialCharacter) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(initialCharacter); + } else { + performDirectEdit(); + } + } + + /** + * @generated + */ + @Override + protected void performDirectEditRequest(Request request) { + + final Request theRequest = request; + + if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { + directEditionMode = getDirectEditionType(); + } + switch (directEditionMode) { + case IDirectEdition.NO_DIRECT_EDITION: + // no direct edition mode => does nothing + return; + case IDirectEdition.EXTENDED_DIRECT_EDITOR: + updateExtendedEditorConfiguration(); + if (configuration == null || configuration.getLanguage() == null) { + // Create default edit manager + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + performDefaultDirectEditorEdit(theRequest); + } else { + configuration.preEditAction(resolveSemanticElement()); + Dialog dialog = null; + if (configuration instanceof ICustomDirectEditorConfiguration) { + setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); + initializeDirectEditManager(theRequest); + return; + } else if (configuration instanceof IPopupEditorConfiguration) { + IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); + helper.showEditor(); + return; + } + else if (configuration instanceof IAdvancedEditorConfiguration) { + dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); + } else if (configuration instanceof IDirectEditorConfiguration) { + dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), + configuration); + } else { + return; + } + final Dialog finalDialog = dialog; + + if (Window.OK == dialog.open()) { + TransactionalEditingDomain domain = getEditingDomain(); + RecordingCommand command = new RecordingCommand(domain, "Edit Label") { + + @Override + protected void doExecute() { + configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); + + } + }; + domain.getCommandStack().execute(command); + } + } + break; + case IDirectEdition.DEFAULT_DIRECT_EDITOR: + initializeDirectEditManager(theRequest); + break; + default: + break; + } + } + + /** + * @generated + */ + protected void initializeDirectEditManager(final Request request) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + @Override + public void run() { + if (isActive() && isEditable()) { + if (request.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } + else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void refreshVisuals() { + super.refreshVisuals(); + refreshLabel(); + refreshFont(); + refreshFontColor(); + refreshUnderline(); + refreshStrikeThrough(); + } + + /** + * @generated + */ + protected void refreshLabel() { + EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); + if (maskLabelPolicy == null) { + maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); + } + if (maskLabelPolicy == null) { + View view = (View) getModel(); + if (view.isVisible()) { + setLabelTextHelper(getFigure(), getLabelText()); + setLabelIconHelper(getFigure(), getLabelIcon()); + } + else { + setLabelTextHelper(getFigure(), ""); //$NON-NLS-1$ + setLabelIconHelper(getFigure(), null); + } + } + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + protected void refreshUnderline() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); + } + if (resolveSemanticElement() instanceof Feature) { + if (((Feature) resolveSemanticElement()).isStatic()) { + ((WrappingLabel) getFigure()).setTextUnderline(true); + } + else { + ((WrappingLabel) getFigure()).setTextUnderline(false); + } + } + } + + /** + * @generated + */ + protected void refreshStrikeThrough() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); + } + } + + /** + * @generated + */ + @Override + protected void refreshFont() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null) { + FontData fontData = new FontData( + style.getFontName(), style.getFontHeight(), + (style.isBold() ? SWT.BOLD : SWT.NORMAL) | + (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); + setFont(fontData); + } + } + + /** + * @generated + */ + @Override + protected void setFontColor(Color color) { + getFigure().setForegroundColor(color); + } + + /** + * @generated + */ + @Override + protected void addSemanticListeners() { + if (getParser() instanceof ISemanticParser) { + EObject element = resolveSemanticElement(); + parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); + for (int i = 0; i < parserElements.size(); i++) { + addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ + } + } else { + super.addSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected void removeSemanticListeners() { + if (parserElements != null) { + for (int i = 0; i < parserElements.size(); i++) { + removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ + } + } else { + super.removeSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected AccessibleEditPart getAccessibleEditPart() { + if (accessibleEP == null) { + accessibleEP = new AccessibleGraphicalEditPart() { + + @Override + public void getName(AccessibleEvent e) { + e.result = getLabelTextHelper(getFigure()); + } + }; + } + return accessibleEP; + } + + /** + * @generated + */ + private View getFontStyleOwnerView() { + return getPrimaryView(); + } + + /** + * Returns the kind of associated editor for direct edition. + * + * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition + * @generated + */ + public int getDirectEditionType() { + if (checkExtendedEditor()) { + initExtendedEditorConfiguration(); + return IDirectEdition.EXTENDED_DIRECT_EDITOR; + } + if (checkDefaultEdition()) { + return IDirectEdition.DEFAULT_DIRECT_EDITOR; + } + + // not a named element. no specific editor => do nothing + return IDirectEdition.NO_DIRECT_EDITION; + } + + /** + * Checks if an extended editor is present. + * + * @return true if an extended editor is present. + * @generated + */ + protected boolean checkExtendedEditor() { + if (resolveSemanticElement() != null) { + return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); + } + return false; + } + + /** + * Checks if a default direct edition is available + * + * @return true if a default direct edition is available + * @generated + */ + protected boolean checkDefaultEdition() { + return (getParser() != null); + } + + /** + * Initializes the extended editor configuration + * + * @generated + */ + protected void initExtendedEditorConfiguration() { + if (configuration == null) { + final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("")) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); + } else { + configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); + } + } + } + + /** + * Updates the preference configuration + * + * @generated + */ + protected void updateExtendedEditorConfiguration() { + String languagePreferred = Activator.getDefault().getPreferenceStore().getString( + IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() + .eClass().getInstanceClassName()); + } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { + configuration = null; + } + } + + /** + * Performs the direct edit usually used by GMF editors. + * + * @param theRequest + * the direct edit request that starts the direct edit system + * @generated + */ + protected void performDefaultDirectEditorEdit(final Request theRequest) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + + @Override + public void run() { + if (isActive() && isEditable()) { + if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) theRequest.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { + DirectEditRequest editRequest = (DirectEditRequest) theRequest; + performDirectEdit(editRequest.getLocation()); + } else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + + /** + * @generated + */ + @Override + protected void handleNotificationEvent(Notification event) { + Object feature = event.getFeature(); + if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { + Integer c = (Integer) event.getNewValue(); + setFontColor(DiagramColorRegistry.getInstance().getColor(c)); + } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { + refreshUnderline(); + } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { + refreshStrikeThrough(); + } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { + refreshFont(); + } else { + if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { + refreshLabel(); + } + if (getParser() instanceof ISemanticParser) { + ISemanticParser modelParser = + (ISemanticParser) getParser(); + if (modelParser.areSemanticElementsAffected(null, event)) { + removeSemanticListeners(); + if (resolveSemanticElement() != null) { + addSemanticListeners(); + } + refreshLabel(); + } + } + } + super.handleNotificationEvent(event); + } + + /** + * @generated + */ + @Override + protected IFigure createFigure() { + IFigure label = createFigurePrim(); + defaultText = getLabelTextHelper(label); + return label; + } + + /** + * @generated + */ + protected IFigure createFigurePrim() { + return new PapyrusWrappingLabel(); + } + +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ComponentCompositeNameEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ComponentCompositeNameEditPart.java index aead6a85642..5b6fff0423d 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ComponentCompositeNameEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ComponentCompositeNameEditPart.java @@ -864,7 +864,7 @@ public class ComponentCompositeNameEditPart extends PapyrusCompartmentEditPart i * @generated */ protected void addOwnerElementListeners() { - addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); + addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ComponentCompositeNameEditPartCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ComponentCompositeNameEditPartCN.java index 971b9b4455d..b2312f2e3dd 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ComponentCompositeNameEditPartCN.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ComponentCompositeNameEditPartCN.java @@ -864,7 +864,7 @@ public class ComponentCompositeNameEditPartCN extends PapyrusCompartmentEditPart * @generated */ protected void addOwnerElementListeners() { - addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); + addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ComponentRealizationAppliedStereotypeEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ComponentRealizationAppliedStereotypeEditPart.java index 38e3c9da63a..b4518782bde 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ComponentRealizationAppliedStereotypeEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ComponentRealizationAppliedStereotypeEditPart.java @@ -1,820 +1,815 @@ -/** - * 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.uml.diagram.composite.edit.parts; - -import java.util.Collections; -import java.util.List; - -import org.eclipse.draw2d.ConnectionLocator; -import org.eclipse.draw2d.IFigure; -import org.eclipse.draw2d.Label; -import org.eclipse.draw2d.geometry.Point; -import org.eclipse.emf.common.notify.Notification; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.transaction.RecordingCommand; -import org.eclipse.emf.transaction.RunnableWithResult; -import org.eclipse.emf.transaction.TransactionalEditingDomain; -import org.eclipse.gef.AccessibleEditPart; -import org.eclipse.gef.EditPolicy; -import org.eclipse.gef.Request; -import org.eclipse.gef.requests.DirectEditRequest; -import org.eclipse.gef.tools.DirectEditManager; -import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; -import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; -import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; -import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; -import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; -import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; -import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; -import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; -import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; -import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; -import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; -import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; -import org.eclipse.gmf.runtime.notation.FontStyle; -import org.eclipse.gmf.runtime.notation.NotationPackage; -import org.eclipse.gmf.runtime.notation.View; -import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.jface.text.contentassist.IContentAssistProcessor; -import org.eclipse.jface.viewers.ICellEditorValidator; -import org.eclipse.jface.window.Window; -import org.eclipse.papyrus.extensionpoints.editors.Activator; -import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; -import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; -import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; -import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; -import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; -import org.eclipse.papyrus.infra.gmfdiag.common.editpart.IControlParserForDirectEdit; -import org.eclipse.papyrus.infra.gmfdiag.common.editpart.PapyrusLabelEditPart; -import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; -import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; -import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.PapyrusLinkLabelDragPolicy; -import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; -import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; -import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; -import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; -import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; -import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; -import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; -import org.eclipse.swt.SWT; -import org.eclipse.swt.accessibility.AccessibleEvent; -import org.eclipse.swt.custom.BusyIndicator; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.FontData; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.widgets.Display; -import org.eclipse.ui.PlatformUI; -import org.eclipse.uml2.uml.Feature; - -/** - * @generated - */ -public class ComponentRealizationAppliedStereotypeEditPart extends PapyrusLabelEditPart implements ITextAwareEditPart, IControlParserForDirectEdit { - - /** - * @generated - */ - public static final int VISUAL_ID = 6015; - - /** - * @generated - */ - private DirectEditManager manager; - - /** - * @generated - */ - private IParser parser; - - /** - * @generated - */ - private List parserElements; - - /** - * @generated - */ - private String defaultText; - - /** - * direct edition mode (default, undefined, registered editor, etc.) - * - * @generated - */ - protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; - - /** - * configuration from a registered edit dialog - * - * @generated - */ - protected IDirectEditorConfiguration configuration; - /** - * @generated - */ - static { - registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.ComponentRealizationAppliedStereotypeEditPart.VISUAL_ID), new Point(0, 30)); - } - - /** - * @generated - */ - public ComponentRealizationAppliedStereotypeEditPart(View view) { - super(view); - } - - /** - * @generated - */ - @Override - protected void createDefaultEditPolicies() { - super.createDefaultEditPolicies(); - installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); - installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); - installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new PapyrusLinkLabelDragPolicy()); - } - - /** - * @generated - */ - @Override - public int getKeyPoint() { - return ConnectionLocator.MIDDLE; - } - - /** - * @generated - */ - protected String getLabelTextHelper(IFigure figure) { - if (figure instanceof WrappingLabel) { - return ((WrappingLabel) figure).getText(); - } else if (figure instanceof ILabelFigure) { - return ((ILabelFigure) figure).getText(); - } else { - return ((Label) figure).getText(); - } - } - - /** - * @generated - */ - protected void setLabelTextHelper(IFigure figure, String text) { - if (figure instanceof WrappingLabel) { - ((WrappingLabel) figure).setText(text); - } else if (figure instanceof ILabelFigure) { - ((ILabelFigure) figure).setText(text); - } else { - ((Label) figure).setText(text); - } - } - - /** - * @generated - */ - protected Image getLabelIconHelper(IFigure figure) { - if (figure instanceof WrappingLabel) { - return ((WrappingLabel) figure).getIcon(); - } else if (figure instanceof ILabelFigure) { - return ((ILabelFigure) figure).getIcon(); - } else { - return ((Label) figure).getIcon(); - } - } - - /** - * @generated - */ - protected void setLabelIconHelper(IFigure figure, Image icon) { - if (figure instanceof WrappingLabel) { - ((WrappingLabel) figure).setIcon(icon); - } else if (figure instanceof ILabelFigure) { - ((ILabelFigure) figure).setIcon(icon); - } else { - ((Label) figure).setIcon(icon); - } - } - - /** - * @generated - */ - public void setLabel(IFigure - figure) { - unregisterVisuals(); - setFigure(figure); - defaultText = getLabelTextHelper(figure); - registerVisuals(); - refreshVisuals(); - } - - /** - * @generated - */ - @Override - protected List getModelChildren() { - return Collections.EMPTY_LIST; - } - - /** - * @generated - */ - @Override - public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { - return null; - } - - /** - * @generated - */ - @Override - public void setParser(IParser parser) { - this.parser = parser; - } - - /** - * @generated - */ - protected EObject getParserElement() { - return resolveSemanticElement(); - } - - /** - * @generated - */ - protected Image getLabelIcon() { - return null; - } - - /** - * @generated - */ - protected String getLabelText() { - String text = null; - EObject parserElement = getParserElement(); - if (parserElement != null && getParser() != null) { - text = getParser().getPrintString( - new EObjectAdapter(parserElement), - getParserOptions().intValue()); - } - if (text == null || text.length() == 0) { - text = defaultText; - } - return text; - } - - /** - * @generated - */ - @Override - public void setLabelText(String text) { - setLabelTextHelper(getFigure(), text); - Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); - if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); - } - Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); - if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); - } - } - - /** - * @generated - */ - @Override - public String getEditText() { - if (getParserElement() == null || getParser() == null) { - return ""; //$NON-NLS-1$ - } - return getParser().getEditString( - new EObjectAdapter(getParserElement()), - getParserOptions().intValue()); - } - - /** - * @generated - */ - protected boolean isEditable() { - return false; - } - - /** - * @generated - */ - @Override - public ICellEditorValidator getEditTextValidator() { - return new ICellEditorValidator() { - - @Override - public String isValid(final Object value) { - if (value instanceof String) { - final EObject element = getParserElement(); - final IParser parser = getParser(); - try { - IParserEditStatus valid = - (IParserEditStatus) getEditingDomain().runExclusive( - new RunnableWithResult.Impl() { - - @Override - public void run() { - setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); - } - }); - return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); - } catch (InterruptedException ie) { - ie.printStackTrace(); - } - } - - // shouldn't get here - return null; - } - }; - } - - /** - * @generated - */ - @Override - public IContentAssistProcessor getCompletionProcessor() { - if (getParserElement() == null || getParser() == null) { - return null; - } - return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); - } - - /** - * @generated - */ - @Override - public ParserOptions getParserOptions() { - return ParserOptions.NONE; - } - - /** - * @generated - */ - @Override - public IParser getParser() { - if (parser == null) { - parser = UMLParserProvider.getParser(UMLElementTypes.ComponentRealization_4004, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.ComponentRealizationAppliedStereotypeEditPart.VISUAL_ID)); - } - return parser; - } - - /** - * @generated - */ - protected DirectEditManager getManager() { - if (manager == null) { - setManager(new MultilineLabelDirectEditManager(this, - MultilineLabelDirectEditManager.getTextCellEditorClass(this), - UMLEditPartFactory.getTextCellEditorLocator(this))); - } - return manager; - } - - /** - * @generated - */ - protected void setManager(DirectEditManager manager) { - this.manager = manager; - } - - /** - * @generated - */ - protected void performDirectEdit() { - BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { - - @Override - public void run() { - getManager().show(); - } - }); - } - - /** - * @generated - */ - protected void performDirectEdit(Point eventLocation) { - if (getManager() instanceof TextDirectEditManager) { - ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); - } - } - - /** - * @generated - */ - private void performDirectEdit(char initialCharacter) { - if (getManager() instanceof TextDirectEditManager) { - ((TextDirectEditManager) getManager()).show(initialCharacter); - } else { - performDirectEdit(); - } - } - - /** - * @generated - */ - @Override - protected void performDirectEditRequest(Request request) { - - final Request theRequest = request; - - if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { - directEditionMode = getDirectEditionType(); - } - switch (directEditionMode) { - case IDirectEdition.NO_DIRECT_EDITION: - // no direct edition mode => does nothing - return; - case IDirectEdition.EXTENDED_DIRECT_EDITOR: - updateExtendedEditorConfiguration(); - if (configuration == null || configuration.getLanguage() == null) { - // Create default edit manager - setManager(new MultilineLabelDirectEditManager(this, - MultilineLabelDirectEditManager.getTextCellEditorClass(this), - UMLEditPartFactory.getTextCellEditorLocator(this))); - performDefaultDirectEditorEdit(theRequest); - } else { - configuration.preEditAction(resolveSemanticElement()); - Dialog dialog = null; - if (configuration instanceof ICustomDirectEditorConfiguration) { - setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); - initializeDirectEditManager(theRequest); - return; - } else if (configuration instanceof IPopupEditorConfiguration) { - IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); - helper.showEditor(); - return; - } - else if (configuration instanceof IAdvancedEditorConfiguration) { - dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); - } else if (configuration instanceof IDirectEditorConfiguration) { - dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), - configuration); - } else { - return; - } - final Dialog finalDialog = dialog; - - if (Window.OK == dialog.open()) { - TransactionalEditingDomain domain = getEditingDomain(); - RecordingCommand command = new RecordingCommand(domain, "Edit Label") { - - @Override - protected void doExecute() { - configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); - - } - }; - domain.getCommandStack().execute(command); - } - } - break; - case IDirectEdition.DEFAULT_DIRECT_EDITOR: - initializeDirectEditManager(theRequest); - break; - default: - break; - } - } - - /** - * @generated - */ - protected void initializeDirectEditManager(final Request request) { - // initialize the direct edit manager - try { - getEditingDomain().runExclusive(new Runnable() { - @Override - public void run() { - if (isActive() && isEditable()) { - if (request.getExtendedData().get( - RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { - Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); - performDirectEdit(initialChar.charValue()); - } - else { - performDirectEdit(); - } - } - } - }); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - - /** - * @generated - */ - @Override - protected void refreshVisuals() { - super.refreshVisuals(); - refreshLabel(); - refreshFont(); - refreshFontColor(); - refreshUnderline(); - refreshStrikeThrough(); - } - - /** - * @generated - */ - protected void refreshLabel() { - EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); - if (maskLabelPolicy == null) { - maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); - } - if (maskLabelPolicy == null) { - View view = (View) getModel(); - if (view.isVisible()) { - setLabelTextHelper(getFigure(), getLabelText()); - setLabelIconHelper(getFigure(), getLabelIcon()); - } - else { - setLabelTextHelper(getFigure(), ""); //$NON-NLS-1$ - setLabelIconHelper(getFigure(), null); - } - } - Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); - if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); - } - Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); - if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); - } - } - - /** - * @generated - */ - protected void refreshUnderline() { - FontStyle style = - (FontStyle) getFontStyleOwnerView().getStyle( - NotationPackage.eINSTANCE.getFontStyle()); - if (style != null && getFigure() instanceof WrappingLabel) { - ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); - } - if (resolveSemanticElement() instanceof Feature) { - if (((Feature) resolveSemanticElement()).isStatic()) { - ((WrappingLabel) getFigure()).setTextUnderline(true); - } - else { - ((WrappingLabel) getFigure()).setTextUnderline(false); - } - } - } - - /** - * @generated - */ - protected void refreshStrikeThrough() { - FontStyle style = - (FontStyle) getFontStyleOwnerView().getStyle( - NotationPackage.eINSTANCE.getFontStyle()); - if (style != null && getFigure() instanceof WrappingLabel) { - ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); - } - } - - /** - * @generated - */ - @Override - protected void refreshFont() { - FontStyle style = - (FontStyle) getFontStyleOwnerView().getStyle( - NotationPackage.eINSTANCE.getFontStyle()); - if (style != null) { - FontData fontData = new FontData( - style.getFontName(), style.getFontHeight(), - (style.isBold() ? SWT.BOLD : SWT.NORMAL) | - (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); - setFont(fontData); - } - } - - /** - * @generated - */ - @Override - protected void setFontColor(Color color) { - getFigure().setForegroundColor(color); - } - - /** - * @generated - */ - @Override - protected void addSemanticListeners() { - if (getParser() instanceof ISemanticParser) { - EObject element = resolveSemanticElement(); - parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); - for (int i = 0; i < parserElements.size(); i++) { - addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ - } - } else { - super.addSemanticListeners(); - } - } - - /** - * @generated - */ - @Override - protected void removeSemanticListeners() { - if (parserElements != null) { - for (int i = 0; i < parserElements.size(); i++) { - removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ - } - } else { - super.removeSemanticListeners(); - } - } - - /** - * @generated - */ - @Override - protected AccessibleEditPart getAccessibleEditPart() { - if (accessibleEP == null) { - accessibleEP = new AccessibleGraphicalEditPart() { - - @Override - public void getName(AccessibleEvent e) { - e.result = getLabelTextHelper(getFigure()); - } - }; - } - return accessibleEP; - } - - /** - * @generated - */ - private View getFontStyleOwnerView() { - return getPrimaryView(); - } - - /** - * Returns the kind of associated editor for direct edition. - * - * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition - * @generated - */ - public int getDirectEditionType() { - // The label is read-only (defined in GMFGen model) - return IDirectEdition.NO_DIRECT_EDITION; - } - - /** - * Checks if an extended editor is present. - * - * @return true if an extended editor is present. - * @generated - */ - protected boolean checkExtendedEditor() { - if (resolveSemanticElement() != null) { - return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); - } - return false; - } - - /** - * Checks if a default direct edition is available - * - * @return true if a default direct edition is available - * @generated - */ - protected boolean checkDefaultEdition() { - return (getParser() != null); - } - - /** - * Initializes the extended editor configuration - * - * @generated - */ - protected void initExtendedEditorConfiguration() { - if (configuration == null) { - final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); - if (languagePreferred != null && !languagePreferred.equals("")) { - configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); - } else { - configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); - } - } - } - - /** - * Updates the preference configuration - * - * @generated - */ - protected void updateExtendedEditorConfiguration() { - String languagePreferred = Activator.getDefault().getPreferenceStore().getString( - IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); - if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { - configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() - .eClass().getInstanceClassName()); - } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { - configuration = null; - } - } - - /** - * Performs the direct edit usually used by GMF editors. - * - * @param theRequest - * the direct edit request that starts the direct edit system - * @generated - */ - protected void performDefaultDirectEditorEdit(final Request theRequest) { - // initialize the direct edit manager - try { - getEditingDomain().runExclusive(new Runnable() { - - @Override - public void run() { - if (isActive() && isEditable()) { - if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { - Character initialChar = (Character) theRequest.getExtendedData().get( - RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); - performDirectEdit(initialChar.charValue()); - } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { - DirectEditRequest editRequest = (DirectEditRequest) theRequest; - performDirectEdit(editRequest.getLocation()); - } else { - performDirectEdit(); - } - } - } - }); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - - /** - * @generated - */ - @Override - protected void handleNotificationEvent(Notification event) { - Object feature = event.getFeature(); - if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { - Integer c = (Integer) event.getNewValue(); - setFontColor(DiagramColorRegistry.getInstance().getColor(c)); - } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { - refreshUnderline(); - } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { - refreshStrikeThrough(); - } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || - NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || - NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || - NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { - refreshFont(); - } else { - if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { - refreshLabel(); - } - if (getParser() instanceof ISemanticParser) { - ISemanticParser modelParser = - (ISemanticParser) getParser(); - if (modelParser.areSemanticElementsAffected(null, event)) { - removeSemanticListeners(); - if (resolveSemanticElement() != null) { - addSemanticListeners(); - } - refreshLabel(); - } - } - } - - super.handleNotificationEvent(event); - } - - /** - * @generated - */ - @Override - protected IFigure createFigure() { - // Parent should assign one using setLabel() method - return 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.uml.diagram.composite.edit.parts; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.draw2d.ConnectionLocator; +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.Label; +import org.eclipse.draw2d.geometry.Point; +import org.eclipse.emf.common.notify.Notification; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.RunnableWithResult; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gef.AccessibleEditPart; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.Request; +import org.eclipse.gef.requests.DirectEditRequest; +import org.eclipse.gef.tools.DirectEditManager; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; +import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; +import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; +import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; +import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; +import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; +import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; +import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; +import org.eclipse.gmf.runtime.notation.FontStyle; +import org.eclipse.gmf.runtime.notation.NotationPackage; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.gmf.tooling.runtime.edit.policies.DefaultLinkLabelDragPolicy; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.text.contentassist.IContentAssistProcessor; +import org.eclipse.jface.viewers.ICellEditorValidator; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.extensionpoints.editors.Activator; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; +import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; +import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; +import org.eclipse.papyrus.infra.gmfdiag.common.editpart.IControlParserForDirectEdit; +import org.eclipse.papyrus.infra.gmfdiag.common.editpart.PapyrusLabelEditPart; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.PapyrusLinkLabelDragPolicy; +import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; +import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; +import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; +import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; +import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.accessibility.AccessibleEvent; +import org.eclipse.swt.custom.BusyIndicator; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; +import org.eclipse.uml2.uml.Feature; + +/** + * @generated + */ +public class ComponentRealizationAppliedStereotypeEditPart extends PapyrusLabelEditPart implements ITextAwareEditPart, IControlParserForDirectEdit { + + /** + * @generated + */ + public static final int VISUAL_ID = 6015; + + /** + * @generated + */ + private DirectEditManager manager; + + /** + * @generated + */ + private IParser parser; + + /** + * @generated + */ + private List parserElements; + + /** + * @generated + */ + private String defaultText; + + /** + * direct edition mode (default, undefined, registered editor, etc.) + * + * @generated + */ + protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; + + /** + * configuration from a registered edit dialog + * + * @generated + */ + protected IDirectEditorConfiguration configuration; + /** + * @generated + */ + static { + registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.ComponentRealizationAppliedStereotypeEditPart.VISUAL_ID), new Point(0, 30)); + } + + /** + * @generated + */ + public ComponentRealizationAppliedStereotypeEditPart(View view) { + super(view); + } + + /** + * @generated + */ + @Override + protected void createDefaultEditPolicies() { + super.createDefaultEditPolicies(); + installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); + installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new DefaultLinkLabelDragPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new PapyrusLinkLabelDragPolicy()); + } + + /** + * @generated + */ + @Override + public int getKeyPoint() { + return ConnectionLocator.MIDDLE; + } + + /** + * @generated + */ + protected String getLabelTextHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getText(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getText(); + } else { + return ((Label) figure).getText(); + } + } + + /** + * @generated + */ + protected void setLabelTextHelper(IFigure figure, String text) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setText(text); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setText(text); + } else { + ((Label) figure).setText(text); + } + } + + /** + * @generated + */ + protected Image getLabelIconHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getIcon(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getIcon(); + } else { + return ((Label) figure).getIcon(); + } + } + + /** + * @generated + */ + protected void setLabelIconHelper(IFigure figure, Image icon) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setIcon(icon); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setIcon(icon); + } else { + ((Label) figure).setIcon(icon); + } + } + + /** + * @generated + */ + public void setLabel(IFigure + figure) { + unregisterVisuals(); + setFigure(figure); + defaultText = getLabelTextHelper(figure); + registerVisuals(); + refreshVisuals(); + } + + /** + * @generated + */ + @Override + protected List getModelChildren() { + return Collections.EMPTY_LIST; + } + + /** + * @generated + */ + @Override + public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { + return null; + } + + /** + * @generated + */ + @Override + public void setParser(IParser parser) { + this.parser = parser; + } + + /** + * @generated + */ + protected EObject getParserElement() { + return resolveSemanticElement(); + } + + /** + * @generated + */ + protected Image getLabelIcon() { + return null; + } + + /** + * @generated + */ + protected String getLabelText() { + String text = null; + EObject parserElement = getParserElement(); + if (parserElement != null && getParser() != null) { + text = getParser().getPrintString( + new EObjectAdapter(parserElement), + getParserOptions().intValue()); + } + if (text == null || text.length() == 0) { + text = defaultText; + } + return text; + } + + /** + * @generated + */ + @Override + public void setLabelText(String text) { + setLabelTextHelper(getFigure(), text); + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + @Override + public String getEditText() { + if (getParserElement() == null || getParser() == null) { + return ""; //$NON-NLS-1$ + } + return getParser().getEditString( + new EObjectAdapter(getParserElement()), + getParserOptions().intValue()); + } + + /** + * @generated + */ + protected boolean isEditable() { + return false; + } + + /** + * @generated + */ + @Override + public ICellEditorValidator getEditTextValidator() { + return new ICellEditorValidator() { + + @Override + public String isValid(final Object value) { + if (value instanceof String) { + final EObject element = getParserElement(); + final IParser parser = getParser(); + try { + IParserEditStatus valid = + (IParserEditStatus) getEditingDomain().runExclusive( + new RunnableWithResult.Impl() { + + @Override + public void run() { + setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); + } + }); + return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); + } catch (InterruptedException ie) { + ie.printStackTrace(); + } + } + + // shouldn't get here + return null; + } + }; + } + + /** + * @generated + */ + @Override + public IContentAssistProcessor getCompletionProcessor() { + if (getParserElement() == null || getParser() == null) { + return null; + } + return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); + } + + /** + * @generated + */ + @Override + public ParserOptions getParserOptions() { + return ParserOptions.NONE; + } + + /** + * @generated + */ + @Override + public IParser getParser() { + if (parser == null) { + parser = UMLParserProvider.getParser(UMLElementTypes.ComponentRealization_4004, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.ComponentRealizationAppliedStereotypeEditPart.VISUAL_ID)); + } + return parser; + } + + /** + * @generated + */ + protected DirectEditManager getManager() { + if (manager == null) { + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + } + return manager; + } + + /** + * @generated + */ + protected void setManager(DirectEditManager manager) { + this.manager = manager; + } + + /** + * @generated + */ + protected void performDirectEdit() { + BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { + + @Override + public void run() { + getManager().show(); + } + }); + } + + /** + * @generated + */ + protected void performDirectEdit(Point eventLocation) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); + } + } + + /** + * @generated + */ + private void performDirectEdit(char initialCharacter) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(initialCharacter); + } else { + performDirectEdit(); + } + } + + /** + * @generated + */ + @Override + protected void performDirectEditRequest(Request request) { + + final Request theRequest = request; + + if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { + directEditionMode = getDirectEditionType(); + } + switch (directEditionMode) { + case IDirectEdition.NO_DIRECT_EDITION: + // no direct edition mode => does nothing + return; + case IDirectEdition.EXTENDED_DIRECT_EDITOR: + updateExtendedEditorConfiguration(); + if (configuration == null || configuration.getLanguage() == null) { + // Create default edit manager + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + performDefaultDirectEditorEdit(theRequest); + } else { + configuration.preEditAction(resolveSemanticElement()); + Dialog dialog = null; + if (configuration instanceof ICustomDirectEditorConfiguration) { + setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); + initializeDirectEditManager(theRequest); + return; + } else if (configuration instanceof IPopupEditorConfiguration) { + IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); + helper.showEditor(); + return; + } + else if (configuration instanceof IAdvancedEditorConfiguration) { + dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); + } else if (configuration instanceof IDirectEditorConfiguration) { + dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), + configuration); + } else { + return; + } + final Dialog finalDialog = dialog; + + if (Window.OK == dialog.open()) { + TransactionalEditingDomain domain = getEditingDomain(); + RecordingCommand command = new RecordingCommand(domain, "Edit Label") { + + @Override + protected void doExecute() { + configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); + + } + }; + domain.getCommandStack().execute(command); + } + } + break; + case IDirectEdition.DEFAULT_DIRECT_EDITOR: + initializeDirectEditManager(theRequest); + break; + default: + break; + } + } + + /** + * @generated + */ + protected void initializeDirectEditManager(final Request request) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + @Override + public void run() { + if (isActive() && isEditable()) { + if (request.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } + else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void refreshVisuals() { + super.refreshVisuals(); + refreshLabel(); + refreshFont(); + refreshFontColor(); + refreshUnderline(); + refreshStrikeThrough(); + } + + /** + * @generated + */ + protected void refreshLabel() { + EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); + if (maskLabelPolicy == null) { + maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); + } + if (maskLabelPolicy == null) { + setLabelTextHelper(getFigure(), getLabelText()); + setLabelIconHelper(getFigure(), getLabelIcon()); + } + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + protected void refreshUnderline() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); + } + if (resolveSemanticElement() instanceof Feature) { + if (((Feature) resolveSemanticElement()).isStatic()) { + ((WrappingLabel) getFigure()).setTextUnderline(true); + } + else { + ((WrappingLabel) getFigure()).setTextUnderline(false); + } + } + } + + /** + * @generated + */ + protected void refreshStrikeThrough() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); + } + } + + /** + * @generated + */ + @Override + protected void refreshFont() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null) { + FontData fontData = new FontData( + style.getFontName(), style.getFontHeight(), + (style.isBold() ? SWT.BOLD : SWT.NORMAL) | + (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); + setFont(fontData); + } + } + + /** + * @generated + */ + @Override + protected void setFontColor(Color color) { + getFigure().setForegroundColor(color); + } + + /** + * @generated + */ + @Override + protected void addSemanticListeners() { + if (getParser() instanceof ISemanticParser) { + EObject element = resolveSemanticElement(); + parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); + for (int i = 0; i < parserElements.size(); i++) { + addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ + } + } else { + super.addSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected void removeSemanticListeners() { + if (parserElements != null) { + for (int i = 0; i < parserElements.size(); i++) { + removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ + } + } else { + super.removeSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected AccessibleEditPart getAccessibleEditPart() { + if (accessibleEP == null) { + accessibleEP = new AccessibleGraphicalEditPart() { + + @Override + public void getName(AccessibleEvent e) { + e.result = getLabelTextHelper(getFigure()); + } + }; + } + return accessibleEP; + } + + /** + * @generated + */ + private View getFontStyleOwnerView() { + return getPrimaryView(); + } + + /** + * Returns the kind of associated editor for direct edition. + * + * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition + * @generated + */ + public int getDirectEditionType() { + // The label is read-only (defined in GMFGen model) + return IDirectEdition.NO_DIRECT_EDITION; + } + + /** + * Checks if an extended editor is present. + * + * @return true if an extended editor is present. + * @generated + */ + protected boolean checkExtendedEditor() { + if (resolveSemanticElement() != null) { + return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); + } + return false; + } + + /** + * Checks if a default direct edition is available + * + * @return true if a default direct edition is available + * @generated + */ + protected boolean checkDefaultEdition() { + return (getParser() != null); + } + + /** + * Initializes the extended editor configuration + * + * @generated + */ + protected void initExtendedEditorConfiguration() { + if (configuration == null) { + final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("")) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); + } else { + configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); + } + } + } + + /** + * Updates the preference configuration + * + * @generated + */ + protected void updateExtendedEditorConfiguration() { + String languagePreferred = Activator.getDefault().getPreferenceStore().getString( + IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() + .eClass().getInstanceClassName()); + } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { + configuration = null; + } + } + + /** + * Performs the direct edit usually used by GMF editors. + * + * @param theRequest + * the direct edit request that starts the direct edit system + * @generated + */ + protected void performDefaultDirectEditorEdit(final Request theRequest) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + + @Override + public void run() { + if (isActive() && isEditable()) { + if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) theRequest.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { + DirectEditRequest editRequest = (DirectEditRequest) theRequest; + performDirectEdit(editRequest.getLocation()); + } else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void handleNotificationEvent(Notification event) { + Object feature = event.getFeature(); + if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { + Integer c = (Integer) event.getNewValue(); + setFontColor(DiagramColorRegistry.getInstance().getColor(c)); + } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { + refreshUnderline(); + } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { + refreshStrikeThrough(); + } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { + refreshFont(); + } else { + if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { + refreshLabel(); + } + if (getParser() instanceof ISemanticParser) { + ISemanticParser modelParser = + (ISemanticParser) getParser(); + if (modelParser.areSemanticElementsAffected(null, event)) { + removeSemanticListeners(); + if (resolveSemanticElement() != null) { + addSemanticListeners(); + } + refreshLabel(); + } + } + } + + super.handleNotificationEvent(event); + } + + /** + * @generated + */ + @Override + protected IFigure createFigure() { + // Parent should assign one using setLabel() method + return null; + } +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ComponentRealizationNameEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ComponentRealizationNameEditPart.java index 0dba77605de..a3048c9bafc 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ComponentRealizationNameEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ComponentRealizationNameEditPart.java @@ -1,828 +1,823 @@ -/** - * 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.uml.diagram.composite.edit.parts; - -import java.util.Collections; -import java.util.List; - -import org.eclipse.draw2d.ConnectionLocator; -import org.eclipse.draw2d.IFigure; -import org.eclipse.draw2d.Label; -import org.eclipse.draw2d.geometry.Point; -import org.eclipse.emf.common.notify.Notification; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.transaction.RecordingCommand; -import org.eclipse.emf.transaction.RunnableWithResult; -import org.eclipse.emf.transaction.TransactionalEditingDomain; -import org.eclipse.gef.AccessibleEditPart; -import org.eclipse.gef.EditPolicy; -import org.eclipse.gef.Request; -import org.eclipse.gef.requests.DirectEditRequest; -import org.eclipse.gef.tools.DirectEditManager; -import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; -import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; -import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; -import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; -import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; -import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; -import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; -import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; -import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; -import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; -import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; -import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; -import org.eclipse.gmf.runtime.notation.FontStyle; -import org.eclipse.gmf.runtime.notation.NotationPackage; -import org.eclipse.gmf.runtime.notation.View; -import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.jface.text.contentassist.IContentAssistProcessor; -import org.eclipse.jface.viewers.ICellEditorValidator; -import org.eclipse.jface.window.Window; -import org.eclipse.papyrus.extensionpoints.editors.Activator; -import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; -import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; -import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; -import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; -import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; -import org.eclipse.papyrus.infra.gmfdiag.common.editpart.IControlParserForDirectEdit; -import org.eclipse.papyrus.infra.gmfdiag.common.editpart.PapyrusLabelEditPart; -import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; -import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; -import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.PapyrusLinkLabelDragPolicy; -import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; -import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; -import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; -import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; -import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; -import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; -import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; -import org.eclipse.swt.SWT; -import org.eclipse.swt.accessibility.AccessibleEvent; -import org.eclipse.swt.custom.BusyIndicator; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.FontData; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.widgets.Display; -import org.eclipse.ui.PlatformUI; -import org.eclipse.uml2.uml.Feature; - -/** - * @generated - */ -public class ComponentRealizationNameEditPart extends PapyrusLabelEditPart implements ITextAwareEditPart, IControlParserForDirectEdit { - - /** - * @generated - */ - public static final int VISUAL_ID = 6001; - - /** - * @generated - */ - private DirectEditManager manager; - - /** - * @generated - */ - private IParser parser; - - /** - * @generated - */ - private List parserElements; - - /** - * @generated - */ - private String defaultText; - - /** - * direct edition mode (default, undefined, registered editor, etc.) - * - * @generated - */ - protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; - - /** - * configuration from a registered edit dialog - * - * @generated - */ - protected IDirectEditorConfiguration configuration; - /** - * @generated - */ - static { - registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.ComponentRealizationNameEditPart.VISUAL_ID), new Point(0, 60)); - } - - /** - * @generated - */ - public ComponentRealizationNameEditPart(View view) { - super(view); - } - - /** - * @generated - */ - @Override - protected void createDefaultEditPolicies() { - super.createDefaultEditPolicies(); - installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); - installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); - installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new PapyrusLinkLabelDragPolicy()); - } - - /** - * @generated - */ - @Override - public int getKeyPoint() { - return ConnectionLocator.MIDDLE; - } - - /** - * @generated - */ - protected String getLabelTextHelper(IFigure figure) { - if (figure instanceof WrappingLabel) { - return ((WrappingLabel) figure).getText(); - } else if (figure instanceof ILabelFigure) { - return ((ILabelFigure) figure).getText(); - } else { - return ((Label) figure).getText(); - } - } - - /** - * @generated - */ - protected void setLabelTextHelper(IFigure figure, String text) { - if (figure instanceof WrappingLabel) { - ((WrappingLabel) figure).setText(text); - } else if (figure instanceof ILabelFigure) { - ((ILabelFigure) figure).setText(text); - } else { - ((Label) figure).setText(text); - } - } - - /** - * @generated - */ - protected Image getLabelIconHelper(IFigure figure) { - if (figure instanceof WrappingLabel) { - return ((WrappingLabel) figure).getIcon(); - } else if (figure instanceof ILabelFigure) { - return ((ILabelFigure) figure).getIcon(); - } else { - return ((Label) figure).getIcon(); - } - } - - /** - * @generated - */ - protected void setLabelIconHelper(IFigure figure, Image icon) { - if (figure instanceof WrappingLabel) { - ((WrappingLabel) figure).setIcon(icon); - } else if (figure instanceof ILabelFigure) { - ((ILabelFigure) figure).setIcon(icon); - } else { - ((Label) figure).setIcon(icon); - } - } - - /** - * @generated - */ - public void setLabel(IFigure - figure) { - unregisterVisuals(); - setFigure(figure); - defaultText = getLabelTextHelper(figure); - registerVisuals(); - refreshVisuals(); - } - - /** - * @generated - */ - @Override - protected List getModelChildren() { - return Collections.EMPTY_LIST; - } - - /** - * @generated - */ - @Override - public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { - return null; - } - - /** - * @generated - */ - @Override - public void setParser(IParser parser) { - this.parser = parser; - } - - /** - * @generated - */ - protected EObject getParserElement() { - return resolveSemanticElement(); - } - - /** - * @generated - */ - protected Image getLabelIcon() { - return null; - } - - /** - * @generated - */ - protected String getLabelText() { - String text = null; - EObject parserElement = getParserElement(); - if (parserElement != null && getParser() != null) { - text = getParser().getPrintString( - new EObjectAdapter(parserElement), - getParserOptions().intValue()); - } - if (text == null || text.length() == 0) { - text = defaultText; - } - return text; - } - - /** - * @generated - */ - @Override - public void setLabelText(String text) { - setLabelTextHelper(getFigure(), text); - Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); - if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); - } - Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); - if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); - } - } - - /** - * @generated - */ - @Override - public String getEditText() { - if (getParserElement() == null || getParser() == null) { - return ""; //$NON-NLS-1$ - } - return getParser().getEditString( - new EObjectAdapter(getParserElement()), - getParserOptions().intValue()); - } - - /** - * @generated - */ - protected boolean isEditable() { - return getParser() != null; - } - - /** - * @generated - */ - @Override - public ICellEditorValidator getEditTextValidator() { - return new ICellEditorValidator() { - - @Override - public String isValid(final Object value) { - if (value instanceof String) { - final EObject element = getParserElement(); - final IParser parser = getParser(); - try { - IParserEditStatus valid = - (IParserEditStatus) getEditingDomain().runExclusive( - new RunnableWithResult.Impl() { - - @Override - public void run() { - setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); - } - }); - return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); - } catch (InterruptedException ie) { - ie.printStackTrace(); - } - } - - // shouldn't get here - return null; - } - }; - } - - /** - * @generated - */ - @Override - public IContentAssistProcessor getCompletionProcessor() { - if (getParserElement() == null || getParser() == null) { - return null; - } - return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); - } - - /** - * @generated - */ - @Override - public ParserOptions getParserOptions() { - return ParserOptions.NONE; - } - - /** - * @generated - */ - @Override - public IParser getParser() { - if (parser == null) { - parser = UMLParserProvider.getParser(UMLElementTypes.ComponentRealization_4004, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.ComponentRealizationNameEditPart.VISUAL_ID)); - } - return parser; - } - - /** - * @generated - */ - protected DirectEditManager getManager() { - if (manager == null) { - setManager(new MultilineLabelDirectEditManager(this, - MultilineLabelDirectEditManager.getTextCellEditorClass(this), - UMLEditPartFactory.getTextCellEditorLocator(this))); - } - return manager; - } - - /** - * @generated - */ - protected void setManager(DirectEditManager manager) { - this.manager = manager; - } - - /** - * @generated - */ - protected void performDirectEdit() { - BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { - - @Override - public void run() { - getManager().show(); - } - }); - } - - /** - * @generated - */ - protected void performDirectEdit(Point eventLocation) { - if (getManager() instanceof TextDirectEditManager) { - ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); - } - } - - /** - * @generated - */ - private void performDirectEdit(char initialCharacter) { - if (getManager() instanceof TextDirectEditManager) { - ((TextDirectEditManager) getManager()).show(initialCharacter); - } else { - performDirectEdit(); - } - } - - /** - * @generated - */ - @Override - protected void performDirectEditRequest(Request request) { - - final Request theRequest = request; - - if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { - directEditionMode = getDirectEditionType(); - } - switch (directEditionMode) { - case IDirectEdition.NO_DIRECT_EDITION: - // no direct edition mode => does nothing - return; - case IDirectEdition.EXTENDED_DIRECT_EDITOR: - updateExtendedEditorConfiguration(); - if (configuration == null || configuration.getLanguage() == null) { - // Create default edit manager - setManager(new MultilineLabelDirectEditManager(this, - MultilineLabelDirectEditManager.getTextCellEditorClass(this), - UMLEditPartFactory.getTextCellEditorLocator(this))); - performDefaultDirectEditorEdit(theRequest); - } else { - configuration.preEditAction(resolveSemanticElement()); - Dialog dialog = null; - if (configuration instanceof ICustomDirectEditorConfiguration) { - setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); - initializeDirectEditManager(theRequest); - return; - } else if (configuration instanceof IPopupEditorConfiguration) { - IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); - helper.showEditor(); - return; - } - else if (configuration instanceof IAdvancedEditorConfiguration) { - dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); - } else if (configuration instanceof IDirectEditorConfiguration) { - dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), - configuration); - } else { - return; - } - final Dialog finalDialog = dialog; - - if (Window.OK == dialog.open()) { - TransactionalEditingDomain domain = getEditingDomain(); - RecordingCommand command = new RecordingCommand(domain, "Edit Label") { - - @Override - protected void doExecute() { - configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); - - } - }; - domain.getCommandStack().execute(command); - } - } - break; - case IDirectEdition.DEFAULT_DIRECT_EDITOR: - initializeDirectEditManager(theRequest); - break; - default: - break; - } - } - - /** - * @generated - */ - protected void initializeDirectEditManager(final Request request) { - // initialize the direct edit manager - try { - getEditingDomain().runExclusive(new Runnable() { - @Override - public void run() { - if (isActive() && isEditable()) { - if (request.getExtendedData().get( - RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { - Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); - performDirectEdit(initialChar.charValue()); - } - else { - performDirectEdit(); - } - } - } - }); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - - /** - * @generated - */ - @Override - protected void refreshVisuals() { - super.refreshVisuals(); - refreshLabel(); - refreshFont(); - refreshFontColor(); - refreshUnderline(); - refreshStrikeThrough(); - } - - /** - * @generated - */ - protected void refreshLabel() { - EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); - if (maskLabelPolicy == null) { - maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); - } - if (maskLabelPolicy == null) { - View view = (View) getModel(); - if (view.isVisible()) { - setLabelTextHelper(getFigure(), getLabelText()); - setLabelIconHelper(getFigure(), getLabelIcon()); - } - else { - setLabelTextHelper(getFigure(), ""); //$NON-NLS-1$ - setLabelIconHelper(getFigure(), null); - } - } - Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); - if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); - } - Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); - if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); - } - } - - /** - * @generated - */ - protected void refreshUnderline() { - FontStyle style = - (FontStyle) getFontStyleOwnerView().getStyle( - NotationPackage.eINSTANCE.getFontStyle()); - if (style != null && getFigure() instanceof WrappingLabel) { - ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); - } - if (resolveSemanticElement() instanceof Feature) { - if (((Feature) resolveSemanticElement()).isStatic()) { - ((WrappingLabel) getFigure()).setTextUnderline(true); - } - else { - ((WrappingLabel) getFigure()).setTextUnderline(false); - } - } - } - - /** - * @generated - */ - protected void refreshStrikeThrough() { - FontStyle style = - (FontStyle) getFontStyleOwnerView().getStyle( - NotationPackage.eINSTANCE.getFontStyle()); - if (style != null && getFigure() instanceof WrappingLabel) { - ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); - } - } - - /** - * @generated - */ - @Override - protected void refreshFont() { - FontStyle style = - (FontStyle) getFontStyleOwnerView().getStyle( - NotationPackage.eINSTANCE.getFontStyle()); - if (style != null) { - FontData fontData = new FontData( - style.getFontName(), style.getFontHeight(), - (style.isBold() ? SWT.BOLD : SWT.NORMAL) | - (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); - setFont(fontData); - } - } - - /** - * @generated - */ - @Override - protected void setFontColor(Color color) { - getFigure().setForegroundColor(color); - } - - /** - * @generated - */ - @Override - protected void addSemanticListeners() { - if (getParser() instanceof ISemanticParser) { - EObject element = resolveSemanticElement(); - parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); - for (int i = 0; i < parserElements.size(); i++) { - addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ - } - } else { - super.addSemanticListeners(); - } - } - - /** - * @generated - */ - @Override - protected void removeSemanticListeners() { - if (parserElements != null) { - for (int i = 0; i < parserElements.size(); i++) { - removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ - } - } else { - super.removeSemanticListeners(); - } - } - - /** - * @generated - */ - @Override - protected AccessibleEditPart getAccessibleEditPart() { - if (accessibleEP == null) { - accessibleEP = new AccessibleGraphicalEditPart() { - - @Override - public void getName(AccessibleEvent e) { - e.result = getLabelTextHelper(getFigure()); - } - }; - } - return accessibleEP; - } - - /** - * @generated - */ - private View getFontStyleOwnerView() { - return getPrimaryView(); - } - - /** - * Returns the kind of associated editor for direct edition. - * - * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition - * @generated - */ - public int getDirectEditionType() { - if (checkExtendedEditor()) { - initExtendedEditorConfiguration(); - return IDirectEdition.EXTENDED_DIRECT_EDITOR; - } - if (checkDefaultEdition()) { - return IDirectEdition.DEFAULT_DIRECT_EDITOR; - } - - // not a named element. no specific editor => do nothing - return IDirectEdition.NO_DIRECT_EDITION; - } - - /** - * Checks if an extended editor is present. - * - * @return true if an extended editor is present. - * @generated - */ - protected boolean checkExtendedEditor() { - if (resolveSemanticElement() != null) { - return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); - } - return false; - } - - /** - * Checks if a default direct edition is available - * - * @return true if a default direct edition is available - * @generated - */ - protected boolean checkDefaultEdition() { - return (getParser() != null); - } - - /** - * Initializes the extended editor configuration - * - * @generated - */ - protected void initExtendedEditorConfiguration() { - if (configuration == null) { - final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); - if (languagePreferred != null && !languagePreferred.equals("")) { - configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); - } else { - configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); - } - } - } - - /** - * Updates the preference configuration - * - * @generated - */ - protected void updateExtendedEditorConfiguration() { - String languagePreferred = Activator.getDefault().getPreferenceStore().getString( - IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); - if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { - configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() - .eClass().getInstanceClassName()); - } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { - configuration = null; - } - } - - /** - * Performs the direct edit usually used by GMF editors. - * - * @param theRequest - * the direct edit request that starts the direct edit system - * @generated - */ - protected void performDefaultDirectEditorEdit(final Request theRequest) { - // initialize the direct edit manager - try { - getEditingDomain().runExclusive(new Runnable() { - - @Override - public void run() { - if (isActive() && isEditable()) { - if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { - Character initialChar = (Character) theRequest.getExtendedData().get( - RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); - performDirectEdit(initialChar.charValue()); - } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { - DirectEditRequest editRequest = (DirectEditRequest) theRequest; - performDirectEdit(editRequest.getLocation()); - } else { - performDirectEdit(); - } - } - } - }); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - - /** - * @generated - */ - @Override - protected void handleNotificationEvent(Notification event) { - Object feature = event.getFeature(); - if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { - Integer c = (Integer) event.getNewValue(); - setFontColor(DiagramColorRegistry.getInstance().getColor(c)); - } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { - refreshUnderline(); - } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { - refreshStrikeThrough(); - } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || - NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || - NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || - NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { - refreshFont(); - } else { - if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { - refreshLabel(); - } - if (getParser() instanceof ISemanticParser) { - ISemanticParser modelParser = - (ISemanticParser) getParser(); - if (modelParser.areSemanticElementsAffected(null, event)) { - removeSemanticListeners(); - if (resolveSemanticElement() != null) { - addSemanticListeners(); - } - refreshLabel(); - } - } - } - - super.handleNotificationEvent(event); - } - - /** - * @generated - */ - @Override - protected IFigure createFigure() { - // Parent should assign one using setLabel() method - return 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.uml.diagram.composite.edit.parts; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.draw2d.ConnectionLocator; +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.Label; +import org.eclipse.draw2d.geometry.Point; +import org.eclipse.emf.common.notify.Notification; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.RunnableWithResult; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gef.AccessibleEditPart; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.Request; +import org.eclipse.gef.requests.DirectEditRequest; +import org.eclipse.gef.tools.DirectEditManager; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; +import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; +import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; +import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; +import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; +import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; +import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; +import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; +import org.eclipse.gmf.runtime.notation.FontStyle; +import org.eclipse.gmf.runtime.notation.NotationPackage; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.gmf.tooling.runtime.edit.policies.DefaultLinkLabelDragPolicy; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.text.contentassist.IContentAssistProcessor; +import org.eclipse.jface.viewers.ICellEditorValidator; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.extensionpoints.editors.Activator; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; +import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; +import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; +import org.eclipse.papyrus.infra.gmfdiag.common.editpart.IControlParserForDirectEdit; +import org.eclipse.papyrus.infra.gmfdiag.common.editpart.PapyrusLabelEditPart; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.PapyrusLinkLabelDragPolicy; +import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; +import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; +import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; +import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; +import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.accessibility.AccessibleEvent; +import org.eclipse.swt.custom.BusyIndicator; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; +import org.eclipse.uml2.uml.Feature; + +/** + * @generated + */ +public class ComponentRealizationNameEditPart extends PapyrusLabelEditPart implements ITextAwareEditPart, IControlParserForDirectEdit { + + /** + * @generated + */ + public static final int VISUAL_ID = 6001; + + /** + * @generated + */ + private DirectEditManager manager; + + /** + * @generated + */ + private IParser parser; + + /** + * @generated + */ + private List parserElements; + + /** + * @generated + */ + private String defaultText; + + /** + * direct edition mode (default, undefined, registered editor, etc.) + * + * @generated + */ + protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; + + /** + * configuration from a registered edit dialog + * + * @generated + */ + protected IDirectEditorConfiguration configuration; + /** + * @generated + */ + static { + registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.ComponentRealizationNameEditPart.VISUAL_ID), new Point(0, 60)); + } + + /** + * @generated + */ + public ComponentRealizationNameEditPart(View view) { + super(view); + } + + /** + * @generated + */ + @Override + protected void createDefaultEditPolicies() { + super.createDefaultEditPolicies(); + installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); + installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new DefaultLinkLabelDragPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new PapyrusLinkLabelDragPolicy()); + } + + /** + * @generated + */ + @Override + public int getKeyPoint() { + return ConnectionLocator.MIDDLE; + } + + /** + * @generated + */ + protected String getLabelTextHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getText(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getText(); + } else { + return ((Label) figure).getText(); + } + } + + /** + * @generated + */ + protected void setLabelTextHelper(IFigure figure, String text) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setText(text); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setText(text); + } else { + ((Label) figure).setText(text); + } + } + + /** + * @generated + */ + protected Image getLabelIconHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getIcon(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getIcon(); + } else { + return ((Label) figure).getIcon(); + } + } + + /** + * @generated + */ + protected void setLabelIconHelper(IFigure figure, Image icon) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setIcon(icon); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setIcon(icon); + } else { + ((Label) figure).setIcon(icon); + } + } + + /** + * @generated + */ + public void setLabel(IFigure + figure) { + unregisterVisuals(); + setFigure(figure); + defaultText = getLabelTextHelper(figure); + registerVisuals(); + refreshVisuals(); + } + + /** + * @generated + */ + @Override + protected List getModelChildren() { + return Collections.EMPTY_LIST; + } + + /** + * @generated + */ + @Override + public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { + return null; + } + + /** + * @generated + */ + @Override + public void setParser(IParser parser) { + this.parser = parser; + } + + /** + * @generated + */ + protected EObject getParserElement() { + return resolveSemanticElement(); + } + + /** + * @generated + */ + protected Image getLabelIcon() { + return null; + } + + /** + * @generated + */ + protected String getLabelText() { + String text = null; + EObject parserElement = getParserElement(); + if (parserElement != null && getParser() != null) { + text = getParser().getPrintString( + new EObjectAdapter(parserElement), + getParserOptions().intValue()); + } + if (text == null || text.length() == 0) { + text = defaultText; + } + return text; + } + + /** + * @generated + */ + @Override + public void setLabelText(String text) { + setLabelTextHelper(getFigure(), text); + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + @Override + public String getEditText() { + if (getParserElement() == null || getParser() == null) { + return ""; //$NON-NLS-1$ + } + return getParser().getEditString( + new EObjectAdapter(getParserElement()), + getParserOptions().intValue()); + } + + /** + * @generated + */ + protected boolean isEditable() { + return getParser() != null; + } + + /** + * @generated + */ + @Override + public ICellEditorValidator getEditTextValidator() { + return new ICellEditorValidator() { + + @Override + public String isValid(final Object value) { + if (value instanceof String) { + final EObject element = getParserElement(); + final IParser parser = getParser(); + try { + IParserEditStatus valid = + (IParserEditStatus) getEditingDomain().runExclusive( + new RunnableWithResult.Impl() { + + @Override + public void run() { + setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); + } + }); + return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); + } catch (InterruptedException ie) { + ie.printStackTrace(); + } + } + + // shouldn't get here + return null; + } + }; + } + + /** + * @generated + */ + @Override + public IContentAssistProcessor getCompletionProcessor() { + if (getParserElement() == null || getParser() == null) { + return null; + } + return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); + } + + /** + * @generated + */ + @Override + public ParserOptions getParserOptions() { + return ParserOptions.NONE; + } + + /** + * @generated + */ + @Override + public IParser getParser() { + if (parser == null) { + parser = UMLParserProvider.getParser(UMLElementTypes.ComponentRealization_4004, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.ComponentRealizationNameEditPart.VISUAL_ID)); + } + return parser; + } + + /** + * @generated + */ + protected DirectEditManager getManager() { + if (manager == null) { + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + } + return manager; + } + + /** + * @generated + */ + protected void setManager(DirectEditManager manager) { + this.manager = manager; + } + + /** + * @generated + */ + protected void performDirectEdit() { + BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { + + @Override + public void run() { + getManager().show(); + } + }); + } + + /** + * @generated + */ + protected void performDirectEdit(Point eventLocation) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); + } + } + + /** + * @generated + */ + private void performDirectEdit(char initialCharacter) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(initialCharacter); + } else { + performDirectEdit(); + } + } + + /** + * @generated + */ + @Override + protected void performDirectEditRequest(Request request) { + + final Request theRequest = request; + + if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { + directEditionMode = getDirectEditionType(); + } + switch (directEditionMode) { + case IDirectEdition.NO_DIRECT_EDITION: + // no direct edition mode => does nothing + return; + case IDirectEdition.EXTENDED_DIRECT_EDITOR: + updateExtendedEditorConfiguration(); + if (configuration == null || configuration.getLanguage() == null) { + // Create default edit manager + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + performDefaultDirectEditorEdit(theRequest); + } else { + configuration.preEditAction(resolveSemanticElement()); + Dialog dialog = null; + if (configuration instanceof ICustomDirectEditorConfiguration) { + setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); + initializeDirectEditManager(theRequest); + return; + } else if (configuration instanceof IPopupEditorConfiguration) { + IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); + helper.showEditor(); + return; + } + else if (configuration instanceof IAdvancedEditorConfiguration) { + dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); + } else if (configuration instanceof IDirectEditorConfiguration) { + dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), + configuration); + } else { + return; + } + final Dialog finalDialog = dialog; + + if (Window.OK == dialog.open()) { + TransactionalEditingDomain domain = getEditingDomain(); + RecordingCommand command = new RecordingCommand(domain, "Edit Label") { + + @Override + protected void doExecute() { + configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); + + } + }; + domain.getCommandStack().execute(command); + } + } + break; + case IDirectEdition.DEFAULT_DIRECT_EDITOR: + initializeDirectEditManager(theRequest); + break; + default: + break; + } + } + + /** + * @generated + */ + protected void initializeDirectEditManager(final Request request) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + @Override + public void run() { + if (isActive() && isEditable()) { + if (request.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } + else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void refreshVisuals() { + super.refreshVisuals(); + refreshLabel(); + refreshFont(); + refreshFontColor(); + refreshUnderline(); + refreshStrikeThrough(); + } + + /** + * @generated + */ + protected void refreshLabel() { + EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); + if (maskLabelPolicy == null) { + maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); + } + if (maskLabelPolicy == null) { + setLabelTextHelper(getFigure(), getLabelText()); + setLabelIconHelper(getFigure(), getLabelIcon()); + } + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + protected void refreshUnderline() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); + } + if (resolveSemanticElement() instanceof Feature) { + if (((Feature) resolveSemanticElement()).isStatic()) { + ((WrappingLabel) getFigure()).setTextUnderline(true); + } + else { + ((WrappingLabel) getFigure()).setTextUnderline(false); + } + } + } + + /** + * @generated + */ + protected void refreshStrikeThrough() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); + } + } + + /** + * @generated + */ + @Override + protected void refreshFont() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null) { + FontData fontData = new FontData( + style.getFontName(), style.getFontHeight(), + (style.isBold() ? SWT.BOLD : SWT.NORMAL) | + (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); + setFont(fontData); + } + } + + /** + * @generated + */ + @Override + protected void setFontColor(Color color) { + getFigure().setForegroundColor(color); + } + + /** + * @generated + */ + @Override + protected void addSemanticListeners() { + if (getParser() instanceof ISemanticParser) { + EObject element = resolveSemanticElement(); + parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); + for (int i = 0; i < parserElements.size(); i++) { + addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ + } + } else { + super.addSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected void removeSemanticListeners() { + if (parserElements != null) { + for (int i = 0; i < parserElements.size(); i++) { + removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ + } + } else { + super.removeSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected AccessibleEditPart getAccessibleEditPart() { + if (accessibleEP == null) { + accessibleEP = new AccessibleGraphicalEditPart() { + + @Override + public void getName(AccessibleEvent e) { + e.result = getLabelTextHelper(getFigure()); + } + }; + } + return accessibleEP; + } + + /** + * @generated + */ + private View getFontStyleOwnerView() { + return getPrimaryView(); + } + + /** + * Returns the kind of associated editor for direct edition. + * + * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition + * @generated + */ + public int getDirectEditionType() { + if (checkExtendedEditor()) { + initExtendedEditorConfiguration(); + return IDirectEdition.EXTENDED_DIRECT_EDITOR; + } + if (checkDefaultEdition()) { + return IDirectEdition.DEFAULT_DIRECT_EDITOR; + } + + // not a named element. no specific editor => do nothing + return IDirectEdition.NO_DIRECT_EDITION; + } + + /** + * Checks if an extended editor is present. + * + * @return true if an extended editor is present. + * @generated + */ + protected boolean checkExtendedEditor() { + if (resolveSemanticElement() != null) { + return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); + } + return false; + } + + /** + * Checks if a default direct edition is available + * + * @return true if a default direct edition is available + * @generated + */ + protected boolean checkDefaultEdition() { + return (getParser() != null); + } + + /** + * Initializes the extended editor configuration + * + * @generated + */ + protected void initExtendedEditorConfiguration() { + if (configuration == null) { + final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("")) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); + } else { + configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); + } + } + } + + /** + * Updates the preference configuration + * + * @generated + */ + protected void updateExtendedEditorConfiguration() { + String languagePreferred = Activator.getDefault().getPreferenceStore().getString( + IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() + .eClass().getInstanceClassName()); + } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { + configuration = null; + } + } + + /** + * Performs the direct edit usually used by GMF editors. + * + * @param theRequest + * the direct edit request that starts the direct edit system + * @generated + */ + protected void performDefaultDirectEditorEdit(final Request theRequest) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + + @Override + public void run() { + if (isActive() && isEditable()) { + if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) theRequest.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { + DirectEditRequest editRequest = (DirectEditRequest) theRequest; + performDirectEdit(editRequest.getLocation()); + } else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void handleNotificationEvent(Notification event) { + Object feature = event.getFeature(); + if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { + Integer c = (Integer) event.getNewValue(); + setFontColor(DiagramColorRegistry.getInstance().getColor(c)); + } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { + refreshUnderline(); + } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { + refreshStrikeThrough(); + } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { + refreshFont(); + } else { + if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { + refreshLabel(); + } + if (getParser() instanceof ISemanticParser) { + ISemanticParser modelParser = + (ISemanticParser) getParser(); + if (modelParser.areSemanticElementsAffected(null, event)) { + removeSemanticListeners(); + if (resolveSemanticElement() != null) { + addSemanticListeners(); + } + refreshLabel(); + } + } + } + + super.handleNotificationEvent(event); + } + + /** + * @generated + */ + @Override + protected IFigure createFigure() { + // Parent should assign one using setLabel() method + return null; + } +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ConnectorAppliedStereotypeEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ConnectorAppliedStereotypeEditPart.java index 28032908537..476e300e169 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ConnectorAppliedStereotypeEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ConnectorAppliedStereotypeEditPart.java @@ -1,820 +1,815 @@ -/** - * 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.uml.diagram.composite.edit.parts; - -import java.util.Collections; -import java.util.List; - -import org.eclipse.draw2d.ConnectionLocator; -import org.eclipse.draw2d.IFigure; -import org.eclipse.draw2d.Label; -import org.eclipse.draw2d.geometry.Point; -import org.eclipse.emf.common.notify.Notification; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.transaction.RecordingCommand; -import org.eclipse.emf.transaction.RunnableWithResult; -import org.eclipse.emf.transaction.TransactionalEditingDomain; -import org.eclipse.gef.AccessibleEditPart; -import org.eclipse.gef.EditPolicy; -import org.eclipse.gef.Request; -import org.eclipse.gef.requests.DirectEditRequest; -import org.eclipse.gef.tools.DirectEditManager; -import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; -import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; -import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; -import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; -import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; -import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; -import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; -import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; -import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; -import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; -import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; -import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; -import org.eclipse.gmf.runtime.notation.FontStyle; -import org.eclipse.gmf.runtime.notation.NotationPackage; -import org.eclipse.gmf.runtime.notation.View; -import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.jface.text.contentassist.IContentAssistProcessor; -import org.eclipse.jface.viewers.ICellEditorValidator; -import org.eclipse.jface.window.Window; -import org.eclipse.papyrus.extensionpoints.editors.Activator; -import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; -import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; -import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; -import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; -import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; -import org.eclipse.papyrus.infra.gmfdiag.common.editpart.IControlParserForDirectEdit; -import org.eclipse.papyrus.infra.gmfdiag.common.editpart.PapyrusLabelEditPart; -import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; -import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; -import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.PapyrusLinkLabelDragPolicy; -import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; -import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; -import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; -import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; -import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; -import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; -import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; -import org.eclipse.swt.SWT; -import org.eclipse.swt.accessibility.AccessibleEvent; -import org.eclipse.swt.custom.BusyIndicator; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.FontData; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.widgets.Display; -import org.eclipse.ui.PlatformUI; -import org.eclipse.uml2.uml.Feature; - -/** - * @generated - */ -public class ConnectorAppliedStereotypeEditPart extends PapyrusLabelEditPart implements ITextAwareEditPart, IControlParserForDirectEdit { - - /** - * @generated - */ - public static final int VISUAL_ID = 6025; - - /** - * @generated - */ - private DirectEditManager manager; - - /** - * @generated - */ - private IParser parser; - - /** - * @generated - */ - private List parserElements; - - /** - * @generated - */ - private String defaultText; - - /** - * direct edition mode (default, undefined, registered editor, etc.) - * - * @generated - */ - protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; - - /** - * configuration from a registered edit dialog - * - * @generated - */ - protected IDirectEditorConfiguration configuration; - /** - * @generated - */ - static { - registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.ConnectorAppliedStereotypeEditPart.VISUAL_ID), new Point(0, 60)); - } - - /** - * @generated - */ - public ConnectorAppliedStereotypeEditPart(View view) { - super(view); - } - - /** - * @generated - */ - @Override - protected void createDefaultEditPolicies() { - super.createDefaultEditPolicies(); - installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); - installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); - installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new PapyrusLinkLabelDragPolicy()); - } - - /** - * @generated - */ - @Override - public int getKeyPoint() { - return ConnectionLocator.MIDDLE; - } - - /** - * @generated - */ - protected String getLabelTextHelper(IFigure figure) { - if (figure instanceof WrappingLabel) { - return ((WrappingLabel) figure).getText(); - } else if (figure instanceof ILabelFigure) { - return ((ILabelFigure) figure).getText(); - } else { - return ((Label) figure).getText(); - } - } - - /** - * @generated - */ - protected void setLabelTextHelper(IFigure figure, String text) { - if (figure instanceof WrappingLabel) { - ((WrappingLabel) figure).setText(text); - } else if (figure instanceof ILabelFigure) { - ((ILabelFigure) figure).setText(text); - } else { - ((Label) figure).setText(text); - } - } - - /** - * @generated - */ - protected Image getLabelIconHelper(IFigure figure) { - if (figure instanceof WrappingLabel) { - return ((WrappingLabel) figure).getIcon(); - } else if (figure instanceof ILabelFigure) { - return ((ILabelFigure) figure).getIcon(); - } else { - return ((Label) figure).getIcon(); - } - } - - /** - * @generated - */ - protected void setLabelIconHelper(IFigure figure, Image icon) { - if (figure instanceof WrappingLabel) { - ((WrappingLabel) figure).setIcon(icon); - } else if (figure instanceof ILabelFigure) { - ((ILabelFigure) figure).setIcon(icon); - } else { - ((Label) figure).setIcon(icon); - } - } - - /** - * @generated - */ - public void setLabel(IFigure - figure) { - unregisterVisuals(); - setFigure(figure); - defaultText = getLabelTextHelper(figure); - registerVisuals(); - refreshVisuals(); - } - - /** - * @generated - */ - @Override - protected List getModelChildren() { - return Collections.EMPTY_LIST; - } - - /** - * @generated - */ - @Override - public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { - return null; - } - - /** - * @generated - */ - @Override - public void setParser(IParser parser) { - this.parser = parser; - } - - /** - * @generated - */ - protected EObject getParserElement() { - return resolveSemanticElement(); - } - - /** - * @generated - */ - protected Image getLabelIcon() { - return null; - } - - /** - * @generated - */ - protected String getLabelText() { - String text = null; - EObject parserElement = getParserElement(); - if (parserElement != null && getParser() != null) { - text = getParser().getPrintString( - new EObjectAdapter(parserElement), - getParserOptions().intValue()); - } - if (text == null || text.length() == 0) { - text = defaultText; - } - return text; - } - - /** - * @generated - */ - @Override - public void setLabelText(String text) { - setLabelTextHelper(getFigure(), text); - Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); - if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); - } - Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); - if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); - } - } - - /** - * @generated - */ - @Override - public String getEditText() { - if (getParserElement() == null || getParser() == null) { - return ""; //$NON-NLS-1$ - } - return getParser().getEditString( - new EObjectAdapter(getParserElement()), - getParserOptions().intValue()); - } - - /** - * @generated - */ - protected boolean isEditable() { - return false; - } - - /** - * @generated - */ - @Override - public ICellEditorValidator getEditTextValidator() { - return new ICellEditorValidator() { - - @Override - public String isValid(final Object value) { - if (value instanceof String) { - final EObject element = getParserElement(); - final IParser parser = getParser(); - try { - IParserEditStatus valid = - (IParserEditStatus) getEditingDomain().runExclusive( - new RunnableWithResult.Impl() { - - @Override - public void run() { - setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); - } - }); - return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); - } catch (InterruptedException ie) { - ie.printStackTrace(); - } - } - - // shouldn't get here - return null; - } - }; - } - - /** - * @generated - */ - @Override - public IContentAssistProcessor getCompletionProcessor() { - if (getParserElement() == null || getParser() == null) { - return null; - } - return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); - } - - /** - * @generated - */ - @Override - public ParserOptions getParserOptions() { - return ParserOptions.NONE; - } - - /** - * @generated - */ - @Override - public IParser getParser() { - if (parser == null) { - parser = UMLParserProvider.getParser(UMLElementTypes.Connector_4013, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.ConnectorAppliedStereotypeEditPart.VISUAL_ID)); - } - return parser; - } - - /** - * @generated - */ - protected DirectEditManager getManager() { - if (manager == null) { - setManager(new MultilineLabelDirectEditManager(this, - MultilineLabelDirectEditManager.getTextCellEditorClass(this), - UMLEditPartFactory.getTextCellEditorLocator(this))); - } - return manager; - } - - /** - * @generated - */ - protected void setManager(DirectEditManager manager) { - this.manager = manager; - } - - /** - * @generated - */ - protected void performDirectEdit() { - BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { - - @Override - public void run() { - getManager().show(); - } - }); - } - - /** - * @generated - */ - protected void performDirectEdit(Point eventLocation) { - if (getManager() instanceof TextDirectEditManager) { - ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); - } - } - - /** - * @generated - */ - private void performDirectEdit(char initialCharacter) { - if (getManager() instanceof TextDirectEditManager) { - ((TextDirectEditManager) getManager()).show(initialCharacter); - } else { - performDirectEdit(); - } - } - - /** - * @generated - */ - @Override - protected void performDirectEditRequest(Request request) { - - final Request theRequest = request; - - if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { - directEditionMode = getDirectEditionType(); - } - switch (directEditionMode) { - case IDirectEdition.NO_DIRECT_EDITION: - // no direct edition mode => does nothing - return; - case IDirectEdition.EXTENDED_DIRECT_EDITOR: - updateExtendedEditorConfiguration(); - if (configuration == null || configuration.getLanguage() == null) { - // Create default edit manager - setManager(new MultilineLabelDirectEditManager(this, - MultilineLabelDirectEditManager.getTextCellEditorClass(this), - UMLEditPartFactory.getTextCellEditorLocator(this))); - performDefaultDirectEditorEdit(theRequest); - } else { - configuration.preEditAction(resolveSemanticElement()); - Dialog dialog = null; - if (configuration instanceof ICustomDirectEditorConfiguration) { - setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); - initializeDirectEditManager(theRequest); - return; - } else if (configuration instanceof IPopupEditorConfiguration) { - IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); - helper.showEditor(); - return; - } - else if (configuration instanceof IAdvancedEditorConfiguration) { - dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); - } else if (configuration instanceof IDirectEditorConfiguration) { - dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), - configuration); - } else { - return; - } - final Dialog finalDialog = dialog; - - if (Window.OK == dialog.open()) { - TransactionalEditingDomain domain = getEditingDomain(); - RecordingCommand command = new RecordingCommand(domain, "Edit Label") { - - @Override - protected void doExecute() { - configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); - - } - }; - domain.getCommandStack().execute(command); - } - } - break; - case IDirectEdition.DEFAULT_DIRECT_EDITOR: - initializeDirectEditManager(theRequest); - break; - default: - break; - } - } - - /** - * @generated - */ - protected void initializeDirectEditManager(final Request request) { - // initialize the direct edit manager - try { - getEditingDomain().runExclusive(new Runnable() { - @Override - public void run() { - if (isActive() && isEditable()) { - if (request.getExtendedData().get( - RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { - Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); - performDirectEdit(initialChar.charValue()); - } - else { - performDirectEdit(); - } - } - } - }); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - - /** - * @generated - */ - @Override - protected void refreshVisuals() { - super.refreshVisuals(); - refreshLabel(); - refreshFont(); - refreshFontColor(); - refreshUnderline(); - refreshStrikeThrough(); - } - - /** - * @generated - */ - protected void refreshLabel() { - EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); - if (maskLabelPolicy == null) { - maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); - } - if (maskLabelPolicy == null) { - View view = (View) getModel(); - if (view.isVisible()) { - setLabelTextHelper(getFigure(), getLabelText()); - setLabelIconHelper(getFigure(), getLabelIcon()); - } - else { - setLabelTextHelper(getFigure(), ""); //$NON-NLS-1$ - setLabelIconHelper(getFigure(), null); - } - } - Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); - if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); - } - Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); - if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); - } - } - - /** - * @generated - */ - protected void refreshUnderline() { - FontStyle style = - (FontStyle) getFontStyleOwnerView().getStyle( - NotationPackage.eINSTANCE.getFontStyle()); - if (style != null && getFigure() instanceof WrappingLabel) { - ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); - } - if (resolveSemanticElement() instanceof Feature) { - if (((Feature) resolveSemanticElement()).isStatic()) { - ((WrappingLabel) getFigure()).setTextUnderline(true); - } - else { - ((WrappingLabel) getFigure()).setTextUnderline(false); - } - } - } - - /** - * @generated - */ - protected void refreshStrikeThrough() { - FontStyle style = - (FontStyle) getFontStyleOwnerView().getStyle( - NotationPackage.eINSTANCE.getFontStyle()); - if (style != null && getFigure() instanceof WrappingLabel) { - ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); - } - } - - /** - * @generated - */ - @Override - protected void refreshFont() { - FontStyle style = - (FontStyle) getFontStyleOwnerView().getStyle( - NotationPackage.eINSTANCE.getFontStyle()); - if (style != null) { - FontData fontData = new FontData( - style.getFontName(), style.getFontHeight(), - (style.isBold() ? SWT.BOLD : SWT.NORMAL) | - (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); - setFont(fontData); - } - } - - /** - * @generated - */ - @Override - protected void setFontColor(Color color) { - getFigure().setForegroundColor(color); - } - - /** - * @generated - */ - @Override - protected void addSemanticListeners() { - if (getParser() instanceof ISemanticParser) { - EObject element = resolveSemanticElement(); - parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); - for (int i = 0; i < parserElements.size(); i++) { - addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ - } - } else { - super.addSemanticListeners(); - } - } - - /** - * @generated - */ - @Override - protected void removeSemanticListeners() { - if (parserElements != null) { - for (int i = 0; i < parserElements.size(); i++) { - removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ - } - } else { - super.removeSemanticListeners(); - } - } - - /** - * @generated - */ - @Override - protected AccessibleEditPart getAccessibleEditPart() { - if (accessibleEP == null) { - accessibleEP = new AccessibleGraphicalEditPart() { - - @Override - public void getName(AccessibleEvent e) { - e.result = getLabelTextHelper(getFigure()); - } - }; - } - return accessibleEP; - } - - /** - * @generated - */ - private View getFontStyleOwnerView() { - return getPrimaryView(); - } - - /** - * Returns the kind of associated editor for direct edition. - * - * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition - * @generated - */ - public int getDirectEditionType() { - // The label is read-only (defined in GMFGen model) - return IDirectEdition.NO_DIRECT_EDITION; - } - - /** - * Checks if an extended editor is present. - * - * @return true if an extended editor is present. - * @generated - */ - protected boolean checkExtendedEditor() { - if (resolveSemanticElement() != null) { - return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); - } - return false; - } - - /** - * Checks if a default direct edition is available - * - * @return true if a default direct edition is available - * @generated - */ - protected boolean checkDefaultEdition() { - return (getParser() != null); - } - - /** - * Initializes the extended editor configuration - * - * @generated - */ - protected void initExtendedEditorConfiguration() { - if (configuration == null) { - final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); - if (languagePreferred != null && !languagePreferred.equals("")) { - configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); - } else { - configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); - } - } - } - - /** - * Updates the preference configuration - * - * @generated - */ - protected void updateExtendedEditorConfiguration() { - String languagePreferred = Activator.getDefault().getPreferenceStore().getString( - IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); - if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { - configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() - .eClass().getInstanceClassName()); - } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { - configuration = null; - } - } - - /** - * Performs the direct edit usually used by GMF editors. - * - * @param theRequest - * the direct edit request that starts the direct edit system - * @generated - */ - protected void performDefaultDirectEditorEdit(final Request theRequest) { - // initialize the direct edit manager - try { - getEditingDomain().runExclusive(new Runnable() { - - @Override - public void run() { - if (isActive() && isEditable()) { - if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { - Character initialChar = (Character) theRequest.getExtendedData().get( - RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); - performDirectEdit(initialChar.charValue()); - } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { - DirectEditRequest editRequest = (DirectEditRequest) theRequest; - performDirectEdit(editRequest.getLocation()); - } else { - performDirectEdit(); - } - } - } - }); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - - /** - * @generated - */ - @Override - protected void handleNotificationEvent(Notification event) { - Object feature = event.getFeature(); - if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { - Integer c = (Integer) event.getNewValue(); - setFontColor(DiagramColorRegistry.getInstance().getColor(c)); - } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { - refreshUnderline(); - } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { - refreshStrikeThrough(); - } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || - NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || - NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || - NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { - refreshFont(); - } else { - if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { - refreshLabel(); - } - if (getParser() instanceof ISemanticParser) { - ISemanticParser modelParser = - (ISemanticParser) getParser(); - if (modelParser.areSemanticElementsAffected(null, event)) { - removeSemanticListeners(); - if (resolveSemanticElement() != null) { - addSemanticListeners(); - } - refreshLabel(); - } - } - } - - super.handleNotificationEvent(event); - } - - /** - * @generated - */ - @Override - protected IFigure createFigure() { - // Parent should assign one using setLabel() method - return 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.uml.diagram.composite.edit.parts; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.draw2d.ConnectionLocator; +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.Label; +import org.eclipse.draw2d.geometry.Point; +import org.eclipse.emf.common.notify.Notification; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.RunnableWithResult; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gef.AccessibleEditPart; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.Request; +import org.eclipse.gef.requests.DirectEditRequest; +import org.eclipse.gef.tools.DirectEditManager; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; +import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; +import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; +import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; +import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; +import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; +import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; +import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; +import org.eclipse.gmf.runtime.notation.FontStyle; +import org.eclipse.gmf.runtime.notation.NotationPackage; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.gmf.tooling.runtime.edit.policies.DefaultLinkLabelDragPolicy; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.text.contentassist.IContentAssistProcessor; +import org.eclipse.jface.viewers.ICellEditorValidator; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.extensionpoints.editors.Activator; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; +import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; +import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; +import org.eclipse.papyrus.infra.gmfdiag.common.editpart.IControlParserForDirectEdit; +import org.eclipse.papyrus.infra.gmfdiag.common.editpart.PapyrusLabelEditPart; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.PapyrusLinkLabelDragPolicy; +import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; +import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; +import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; +import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; +import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.accessibility.AccessibleEvent; +import org.eclipse.swt.custom.BusyIndicator; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; +import org.eclipse.uml2.uml.Feature; + +/** + * @generated + */ +public class ConnectorAppliedStereotypeEditPart extends PapyrusLabelEditPart implements ITextAwareEditPart, IControlParserForDirectEdit { + + /** + * @generated + */ + public static final int VISUAL_ID = 6025; + + /** + * @generated + */ + private DirectEditManager manager; + + /** + * @generated + */ + private IParser parser; + + /** + * @generated + */ + private List parserElements; + + /** + * @generated + */ + private String defaultText; + + /** + * direct edition mode (default, undefined, registered editor, etc.) + * + * @generated + */ + protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; + + /** + * configuration from a registered edit dialog + * + * @generated + */ + protected IDirectEditorConfiguration configuration; + /** + * @generated + */ + static { + registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.ConnectorAppliedStereotypeEditPart.VISUAL_ID), new Point(0, 60)); + } + + /** + * @generated + */ + public ConnectorAppliedStereotypeEditPart(View view) { + super(view); + } + + /** + * @generated + */ + @Override + protected void createDefaultEditPolicies() { + super.createDefaultEditPolicies(); + installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); + installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new DefaultLinkLabelDragPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new PapyrusLinkLabelDragPolicy()); + } + + /** + * @generated + */ + @Override + public int getKeyPoint() { + return ConnectionLocator.MIDDLE; + } + + /** + * @generated + */ + protected String getLabelTextHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getText(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getText(); + } else { + return ((Label) figure).getText(); + } + } + + /** + * @generated + */ + protected void setLabelTextHelper(IFigure figure, String text) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setText(text); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setText(text); + } else { + ((Label) figure).setText(text); + } + } + + /** + * @generated + */ + protected Image getLabelIconHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getIcon(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getIcon(); + } else { + return ((Label) figure).getIcon(); + } + } + + /** + * @generated + */ + protected void setLabelIconHelper(IFigure figure, Image icon) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setIcon(icon); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setIcon(icon); + } else { + ((Label) figure).setIcon(icon); + } + } + + /** + * @generated + */ + public void setLabel(IFigure + figure) { + unregisterVisuals(); + setFigure(figure); + defaultText = getLabelTextHelper(figure); + registerVisuals(); + refreshVisuals(); + } + + /** + * @generated + */ + @Override + protected List getModelChildren() { + return Collections.EMPTY_LIST; + } + + /** + * @generated + */ + @Override + public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { + return null; + } + + /** + * @generated + */ + @Override + public void setParser(IParser parser) { + this.parser = parser; + } + + /** + * @generated + */ + protected EObject getParserElement() { + return resolveSemanticElement(); + } + + /** + * @generated + */ + protected Image getLabelIcon() { + return null; + } + + /** + * @generated + */ + protected String getLabelText() { + String text = null; + EObject parserElement = getParserElement(); + if (parserElement != null && getParser() != null) { + text = getParser().getPrintString( + new EObjectAdapter(parserElement), + getParserOptions().intValue()); + } + if (text == null || text.length() == 0) { + text = defaultText; + } + return text; + } + + /** + * @generated + */ + @Override + public void setLabelText(String text) { + setLabelTextHelper(getFigure(), text); + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + @Override + public String getEditText() { + if (getParserElement() == null || getParser() == null) { + return ""; //$NON-NLS-1$ + } + return getParser().getEditString( + new EObjectAdapter(getParserElement()), + getParserOptions().intValue()); + } + + /** + * @generated + */ + protected boolean isEditable() { + return false; + } + + /** + * @generated + */ + @Override + public ICellEditorValidator getEditTextValidator() { + return new ICellEditorValidator() { + + @Override + public String isValid(final Object value) { + if (value instanceof String) { + final EObject element = getParserElement(); + final IParser parser = getParser(); + try { + IParserEditStatus valid = + (IParserEditStatus) getEditingDomain().runExclusive( + new RunnableWithResult.Impl() { + + @Override + public void run() { + setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); + } + }); + return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); + } catch (InterruptedException ie) { + ie.printStackTrace(); + } + } + + // shouldn't get here + return null; + } + }; + } + + /** + * @generated + */ + @Override + public IContentAssistProcessor getCompletionProcessor() { + if (getParserElement() == null || getParser() == null) { + return null; + } + return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); + } + + /** + * @generated + */ + @Override + public ParserOptions getParserOptions() { + return ParserOptions.NONE; + } + + /** + * @generated + */ + @Override + public IParser getParser() { + if (parser == null) { + parser = UMLParserProvider.getParser(UMLElementTypes.Connector_4013, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.ConnectorAppliedStereotypeEditPart.VISUAL_ID)); + } + return parser; + } + + /** + * @generated + */ + protected DirectEditManager getManager() { + if (manager == null) { + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + } + return manager; + } + + /** + * @generated + */ + protected void setManager(DirectEditManager manager) { + this.manager = manager; + } + + /** + * @generated + */ + protected void performDirectEdit() { + BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { + + @Override + public void run() { + getManager().show(); + } + }); + } + + /** + * @generated + */ + protected void performDirectEdit(Point eventLocation) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); + } + } + + /** + * @generated + */ + private void performDirectEdit(char initialCharacter) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(initialCharacter); + } else { + performDirectEdit(); + } + } + + /** + * @generated + */ + @Override + protected void performDirectEditRequest(Request request) { + + final Request theRequest = request; + + if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { + directEditionMode = getDirectEditionType(); + } + switch (directEditionMode) { + case IDirectEdition.NO_DIRECT_EDITION: + // no direct edition mode => does nothing + return; + case IDirectEdition.EXTENDED_DIRECT_EDITOR: + updateExtendedEditorConfiguration(); + if (configuration == null || configuration.getLanguage() == null) { + // Create default edit manager + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + performDefaultDirectEditorEdit(theRequest); + } else { + configuration.preEditAction(resolveSemanticElement()); + Dialog dialog = null; + if (configuration instanceof ICustomDirectEditorConfiguration) { + setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); + initializeDirectEditManager(theRequest); + return; + } else if (configuration instanceof IPopupEditorConfiguration) { + IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); + helper.showEditor(); + return; + } + else if (configuration instanceof IAdvancedEditorConfiguration) { + dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); + } else if (configuration instanceof IDirectEditorConfiguration) { + dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), + configuration); + } else { + return; + } + final Dialog finalDialog = dialog; + + if (Window.OK == dialog.open()) { + TransactionalEditingDomain domain = getEditingDomain(); + RecordingCommand command = new RecordingCommand(domain, "Edit Label") { + + @Override + protected void doExecute() { + configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); + + } + }; + domain.getCommandStack().execute(command); + } + } + break; + case IDirectEdition.DEFAULT_DIRECT_EDITOR: + initializeDirectEditManager(theRequest); + break; + default: + break; + } + } + + /** + * @generated + */ + protected void initializeDirectEditManager(final Request request) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + @Override + public void run() { + if (isActive() && isEditable()) { + if (request.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } + else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void refreshVisuals() { + super.refreshVisuals(); + refreshLabel(); + refreshFont(); + refreshFontColor(); + refreshUnderline(); + refreshStrikeThrough(); + } + + /** + * @generated + */ + protected void refreshLabel() { + EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); + if (maskLabelPolicy == null) { + maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); + } + if (maskLabelPolicy == null) { + setLabelTextHelper(getFigure(), getLabelText()); + setLabelIconHelper(getFigure(), getLabelIcon()); + } + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + protected void refreshUnderline() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); + } + if (resolveSemanticElement() instanceof Feature) { + if (((Feature) resolveSemanticElement()).isStatic()) { + ((WrappingLabel) getFigure()).setTextUnderline(true); + } + else { + ((WrappingLabel) getFigure()).setTextUnderline(false); + } + } + } + + /** + * @generated + */ + protected void refreshStrikeThrough() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); + } + } + + /** + * @generated + */ + @Override + protected void refreshFont() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null) { + FontData fontData = new FontData( + style.getFontName(), style.getFontHeight(), + (style.isBold() ? SWT.BOLD : SWT.NORMAL) | + (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); + setFont(fontData); + } + } + + /** + * @generated + */ + @Override + protected void setFontColor(Color color) { + getFigure().setForegroundColor(color); + } + + /** + * @generated + */ + @Override + protected void addSemanticListeners() { + if (getParser() instanceof ISemanticParser) { + EObject element = resolveSemanticElement(); + parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); + for (int i = 0; i < parserElements.size(); i++) { + addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ + } + } else { + super.addSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected void removeSemanticListeners() { + if (parserElements != null) { + for (int i = 0; i < parserElements.size(); i++) { + removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ + } + } else { + super.removeSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected AccessibleEditPart getAccessibleEditPart() { + if (accessibleEP == null) { + accessibleEP = new AccessibleGraphicalEditPart() { + + @Override + public void getName(AccessibleEvent e) { + e.result = getLabelTextHelper(getFigure()); + } + }; + } + return accessibleEP; + } + + /** + * @generated + */ + private View getFontStyleOwnerView() { + return getPrimaryView(); + } + + /** + * Returns the kind of associated editor for direct edition. + * + * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition + * @generated + */ + public int getDirectEditionType() { + // The label is read-only (defined in GMFGen model) + return IDirectEdition.NO_DIRECT_EDITION; + } + + /** + * Checks if an extended editor is present. + * + * @return true if an extended editor is present. + * @generated + */ + protected boolean checkExtendedEditor() { + if (resolveSemanticElement() != null) { + return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); + } + return false; + } + + /** + * Checks if a default direct edition is available + * + * @return true if a default direct edition is available + * @generated + */ + protected boolean checkDefaultEdition() { + return (getParser() != null); + } + + /** + * Initializes the extended editor configuration + * + * @generated + */ + protected void initExtendedEditorConfiguration() { + if (configuration == null) { + final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("")) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); + } else { + configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); + } + } + } + + /** + * Updates the preference configuration + * + * @generated + */ + protected void updateExtendedEditorConfiguration() { + String languagePreferred = Activator.getDefault().getPreferenceStore().getString( + IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() + .eClass().getInstanceClassName()); + } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { + configuration = null; + } + } + + /** + * Performs the direct edit usually used by GMF editors. + * + * @param theRequest + * the direct edit request that starts the direct edit system + * @generated + */ + protected void performDefaultDirectEditorEdit(final Request theRequest) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + + @Override + public void run() { + if (isActive() && isEditable()) { + if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) theRequest.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { + DirectEditRequest editRequest = (DirectEditRequest) theRequest; + performDirectEdit(editRequest.getLocation()); + } else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void handleNotificationEvent(Notification event) { + Object feature = event.getFeature(); + if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { + Integer c = (Integer) event.getNewValue(); + setFontColor(DiagramColorRegistry.getInstance().getColor(c)); + } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { + refreshUnderline(); + } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { + refreshStrikeThrough(); + } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { + refreshFont(); + } else { + if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { + refreshLabel(); + } + if (getParser() instanceof ISemanticParser) { + ISemanticParser modelParser = + (ISemanticParser) getParser(); + if (modelParser.areSemanticElementsAffected(null, event)) { + removeSemanticListeners(); + if (resolveSemanticElement() != null) { + addSemanticListeners(); + } + refreshLabel(); + } + } + } + + super.handleNotificationEvent(event); + } + + /** + * @generated + */ + @Override + protected IFigure createFigure() { + // Parent should assign one using setLabel() method + return null; + } +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ConnectorMultiplicitySourceEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ConnectorMultiplicitySourceEditPart.java index 16bb472f205..1b6808c2db6 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ConnectorMultiplicitySourceEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ConnectorMultiplicitySourceEditPart.java @@ -1,820 +1,815 @@ -/** - * 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.uml.diagram.composite.edit.parts; - -import java.util.Collections; -import java.util.List; - -import org.eclipse.draw2d.ConnectionLocator; -import org.eclipse.draw2d.IFigure; -import org.eclipse.draw2d.Label; -import org.eclipse.draw2d.geometry.Point; -import org.eclipse.emf.common.notify.Notification; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.transaction.RecordingCommand; -import org.eclipse.emf.transaction.RunnableWithResult; -import org.eclipse.emf.transaction.TransactionalEditingDomain; -import org.eclipse.gef.AccessibleEditPart; -import org.eclipse.gef.EditPolicy; -import org.eclipse.gef.Request; -import org.eclipse.gef.requests.DirectEditRequest; -import org.eclipse.gef.tools.DirectEditManager; -import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; -import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; -import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; -import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; -import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; -import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; -import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; -import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; -import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; -import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; -import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; -import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; -import org.eclipse.gmf.runtime.notation.FontStyle; -import org.eclipse.gmf.runtime.notation.NotationPackage; -import org.eclipse.gmf.runtime.notation.View; -import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.jface.text.contentassist.IContentAssistProcessor; -import org.eclipse.jface.viewers.ICellEditorValidator; -import org.eclipse.jface.window.Window; -import org.eclipse.papyrus.extensionpoints.editors.Activator; -import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; -import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; -import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; -import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; -import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; -import org.eclipse.papyrus.infra.gmfdiag.common.editpart.IControlParserForDirectEdit; -import org.eclipse.papyrus.infra.gmfdiag.common.editpart.PapyrusLabelEditPart; -import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; -import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; -import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.PapyrusLinkLabelDragPolicy; -import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; -import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; -import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; -import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; -import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; -import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; -import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; -import org.eclipse.swt.SWT; -import org.eclipse.swt.accessibility.AccessibleEvent; -import org.eclipse.swt.custom.BusyIndicator; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.FontData; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.widgets.Display; -import org.eclipse.ui.PlatformUI; -import org.eclipse.uml2.uml.Feature; - -/** - * @generated - */ -public class ConnectorMultiplicitySourceEditPart extends PapyrusLabelEditPart implements ITextAwareEditPart, IControlParserForDirectEdit { - - /** - * @generated - */ - public static final int VISUAL_ID = 6051; - - /** - * @generated - */ - private DirectEditManager manager; - - /** - * @generated - */ - private IParser parser; - - /** - * @generated - */ - private List parserElements; - - /** - * @generated - */ - private String defaultText; - - /** - * direct edition mode (default, undefined, registered editor, etc.) - * - * @generated - */ - protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; - - /** - * configuration from a registered edit dialog - * - * @generated - */ - protected IDirectEditorConfiguration configuration; - /** - * @generated - */ - static { - registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.ConnectorMultiplicitySourceEditPart.VISUAL_ID), new Point(0, 20)); - } - - /** - * @generated - */ - public ConnectorMultiplicitySourceEditPart(View view) { - super(view); - } - - /** - * @generated - */ - @Override - protected void createDefaultEditPolicies() { - super.createDefaultEditPolicies(); - installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); - installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); - installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new PapyrusLinkLabelDragPolicy()); - } - - /** - * @generated - */ - @Override - public int getKeyPoint() { - return ConnectionLocator.SOURCE; - } - - /** - * @generated - */ - protected String getLabelTextHelper(IFigure figure) { - if (figure instanceof WrappingLabel) { - return ((WrappingLabel) figure).getText(); - } else if (figure instanceof ILabelFigure) { - return ((ILabelFigure) figure).getText(); - } else { - return ((Label) figure).getText(); - } - } - - /** - * @generated - */ - protected void setLabelTextHelper(IFigure figure, String text) { - if (figure instanceof WrappingLabel) { - ((WrappingLabel) figure).setText(text); - } else if (figure instanceof ILabelFigure) { - ((ILabelFigure) figure).setText(text); - } else { - ((Label) figure).setText(text); - } - } - - /** - * @generated - */ - protected Image getLabelIconHelper(IFigure figure) { - if (figure instanceof WrappingLabel) { - return ((WrappingLabel) figure).getIcon(); - } else if (figure instanceof ILabelFigure) { - return ((ILabelFigure) figure).getIcon(); - } else { - return ((Label) figure).getIcon(); - } - } - - /** - * @generated - */ - protected void setLabelIconHelper(IFigure figure, Image icon) { - if (figure instanceof WrappingLabel) { - ((WrappingLabel) figure).setIcon(icon); - } else if (figure instanceof ILabelFigure) { - ((ILabelFigure) figure).setIcon(icon); - } else { - ((Label) figure).setIcon(icon); - } - } - - /** - * @generated - */ - public void setLabel(IFigure - figure) { - unregisterVisuals(); - setFigure(figure); - defaultText = getLabelTextHelper(figure); - registerVisuals(); - refreshVisuals(); - } - - /** - * @generated - */ - @Override - protected List getModelChildren() { - return Collections.EMPTY_LIST; - } - - /** - * @generated - */ - @Override - public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { - return null; - } - - /** - * @generated - */ - @Override - public void setParser(IParser parser) { - this.parser = parser; - } - - /** - * @generated - */ - protected EObject getParserElement() { - return resolveSemanticElement(); - } - - /** - * @generated - */ - protected Image getLabelIcon() { - return null; - } - - /** - * @generated - */ - protected String getLabelText() { - String text = null; - EObject parserElement = getParserElement(); - if (parserElement != null && getParser() != null) { - text = getParser().getPrintString( - new EObjectAdapter(parserElement), - getParserOptions().intValue()); - } - if (text == null || text.length() == 0) { - text = defaultText; - } - return text; - } - - /** - * @generated - */ - @Override - public void setLabelText(String text) { - setLabelTextHelper(getFigure(), text); - Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); - if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); - } - Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); - if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); - } - } - - /** - * @generated - */ - @Override - public String getEditText() { - if (getParserElement() == null || getParser() == null) { - return ""; //$NON-NLS-1$ - } - return getParser().getEditString( - new EObjectAdapter(getParserElement()), - getParserOptions().intValue()); - } - - /** - * @generated - */ - protected boolean isEditable() { - return false; - } - - /** - * @generated - */ - @Override - public ICellEditorValidator getEditTextValidator() { - return new ICellEditorValidator() { - - @Override - public String isValid(final Object value) { - if (value instanceof String) { - final EObject element = getParserElement(); - final IParser parser = getParser(); - try { - IParserEditStatus valid = - (IParserEditStatus) getEditingDomain().runExclusive( - new RunnableWithResult.Impl() { - - @Override - public void run() { - setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); - } - }); - return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); - } catch (InterruptedException ie) { - ie.printStackTrace(); - } - } - - // shouldn't get here - return null; - } - }; - } - - /** - * @generated - */ - @Override - public IContentAssistProcessor getCompletionProcessor() { - if (getParserElement() == null || getParser() == null) { - return null; - } - return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); - } - - /** - * @generated - */ - @Override - public ParserOptions getParserOptions() { - return ParserOptions.NONE; - } - - /** - * @generated - */ - @Override - public IParser getParser() { - if (parser == null) { - parser = UMLParserProvider.getParser(UMLElementTypes.Connector_4013, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.ConnectorMultiplicitySourceEditPart.VISUAL_ID)); - } - return parser; - } - - /** - * @generated - */ - protected DirectEditManager getManager() { - if (manager == null) { - setManager(new MultilineLabelDirectEditManager(this, - MultilineLabelDirectEditManager.getTextCellEditorClass(this), - UMLEditPartFactory.getTextCellEditorLocator(this))); - } - return manager; - } - - /** - * @generated - */ - protected void setManager(DirectEditManager manager) { - this.manager = manager; - } - - /** - * @generated - */ - protected void performDirectEdit() { - BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { - - @Override - public void run() { - getManager().show(); - } - }); - } - - /** - * @generated - */ - protected void performDirectEdit(Point eventLocation) { - if (getManager() instanceof TextDirectEditManager) { - ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); - } - } - - /** - * @generated - */ - private void performDirectEdit(char initialCharacter) { - if (getManager() instanceof TextDirectEditManager) { - ((TextDirectEditManager) getManager()).show(initialCharacter); - } else { - performDirectEdit(); - } - } - - /** - * @generated - */ - @Override - protected void performDirectEditRequest(Request request) { - - final Request theRequest = request; - - if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { - directEditionMode = getDirectEditionType(); - } - switch (directEditionMode) { - case IDirectEdition.NO_DIRECT_EDITION: - // no direct edition mode => does nothing - return; - case IDirectEdition.EXTENDED_DIRECT_EDITOR: - updateExtendedEditorConfiguration(); - if (configuration == null || configuration.getLanguage() == null) { - // Create default edit manager - setManager(new MultilineLabelDirectEditManager(this, - MultilineLabelDirectEditManager.getTextCellEditorClass(this), - UMLEditPartFactory.getTextCellEditorLocator(this))); - performDefaultDirectEditorEdit(theRequest); - } else { - configuration.preEditAction(resolveSemanticElement()); - Dialog dialog = null; - if (configuration instanceof ICustomDirectEditorConfiguration) { - setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); - initializeDirectEditManager(theRequest); - return; - } else if (configuration instanceof IPopupEditorConfiguration) { - IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); - helper.showEditor(); - return; - } - else if (configuration instanceof IAdvancedEditorConfiguration) { - dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); - } else if (configuration instanceof IDirectEditorConfiguration) { - dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), - configuration); - } else { - return; - } - final Dialog finalDialog = dialog; - - if (Window.OK == dialog.open()) { - TransactionalEditingDomain domain = getEditingDomain(); - RecordingCommand command = new RecordingCommand(domain, "Edit Label") { - - @Override - protected void doExecute() { - configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); - - } - }; - domain.getCommandStack().execute(command); - } - } - break; - case IDirectEdition.DEFAULT_DIRECT_EDITOR: - initializeDirectEditManager(theRequest); - break; - default: - break; - } - } - - /** - * @generated - */ - protected void initializeDirectEditManager(final Request request) { - // initialize the direct edit manager - try { - getEditingDomain().runExclusive(new Runnable() { - @Override - public void run() { - if (isActive() && isEditable()) { - if (request.getExtendedData().get( - RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { - Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); - performDirectEdit(initialChar.charValue()); - } - else { - performDirectEdit(); - } - } - } - }); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - - /** - * @generated - */ - @Override - protected void refreshVisuals() { - super.refreshVisuals(); - refreshLabel(); - refreshFont(); - refreshFontColor(); - refreshUnderline(); - refreshStrikeThrough(); - } - - /** - * @generated - */ - protected void refreshLabel() { - EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); - if (maskLabelPolicy == null) { - maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); - } - if (maskLabelPolicy == null) { - View view = (View) getModel(); - if (view.isVisible()) { - setLabelTextHelper(getFigure(), getLabelText()); - setLabelIconHelper(getFigure(), getLabelIcon()); - } - else { - setLabelTextHelper(getFigure(), ""); //$NON-NLS-1$ - setLabelIconHelper(getFigure(), null); - } - } - Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); - if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); - } - Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); - if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); - } - } - - /** - * @generated - */ - protected void refreshUnderline() { - FontStyle style = - (FontStyle) getFontStyleOwnerView().getStyle( - NotationPackage.eINSTANCE.getFontStyle()); - if (style != null && getFigure() instanceof WrappingLabel) { - ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); - } - if (resolveSemanticElement() instanceof Feature) { - if (((Feature) resolveSemanticElement()).isStatic()) { - ((WrappingLabel) getFigure()).setTextUnderline(true); - } - else { - ((WrappingLabel) getFigure()).setTextUnderline(false); - } - } - } - - /** - * @generated - */ - protected void refreshStrikeThrough() { - FontStyle style = - (FontStyle) getFontStyleOwnerView().getStyle( - NotationPackage.eINSTANCE.getFontStyle()); - if (style != null && getFigure() instanceof WrappingLabel) { - ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); - } - } - - /** - * @generated - */ - @Override - protected void refreshFont() { - FontStyle style = - (FontStyle) getFontStyleOwnerView().getStyle( - NotationPackage.eINSTANCE.getFontStyle()); - if (style != null) { - FontData fontData = new FontData( - style.getFontName(), style.getFontHeight(), - (style.isBold() ? SWT.BOLD : SWT.NORMAL) | - (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); - setFont(fontData); - } - } - - /** - * @generated - */ - @Override - protected void setFontColor(Color color) { - getFigure().setForegroundColor(color); - } - - /** - * @generated - */ - @Override - protected void addSemanticListeners() { - if (getParser() instanceof ISemanticParser) { - EObject element = resolveSemanticElement(); - parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); - for (int i = 0; i < parserElements.size(); i++) { - addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ - } - } else { - super.addSemanticListeners(); - } - } - - /** - * @generated - */ - @Override - protected void removeSemanticListeners() { - if (parserElements != null) { - for (int i = 0; i < parserElements.size(); i++) { - removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ - } - } else { - super.removeSemanticListeners(); - } - } - - /** - * @generated - */ - @Override - protected AccessibleEditPart getAccessibleEditPart() { - if (accessibleEP == null) { - accessibleEP = new AccessibleGraphicalEditPart() { - - @Override - public void getName(AccessibleEvent e) { - e.result = getLabelTextHelper(getFigure()); - } - }; - } - return accessibleEP; - } - - /** - * @generated - */ - private View getFontStyleOwnerView() { - return getPrimaryView(); - } - - /** - * Returns the kind of associated editor for direct edition. - * - * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition - * @generated - */ - public int getDirectEditionType() { - // The label is read-only (defined in GMFGen model) - return IDirectEdition.NO_DIRECT_EDITION; - } - - /** - * Checks if an extended editor is present. - * - * @return true if an extended editor is present. - * @generated - */ - protected boolean checkExtendedEditor() { - if (resolveSemanticElement() != null) { - return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); - } - return false; - } - - /** - * Checks if a default direct edition is available - * - * @return true if a default direct edition is available - * @generated - */ - protected boolean checkDefaultEdition() { - return (getParser() != null); - } - - /** - * Initializes the extended editor configuration - * - * @generated - */ - protected void initExtendedEditorConfiguration() { - if (configuration == null) { - final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); - if (languagePreferred != null && !languagePreferred.equals("")) { - configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); - } else { - configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); - } - } - } - - /** - * Updates the preference configuration - * - * @generated - */ - protected void updateExtendedEditorConfiguration() { - String languagePreferred = Activator.getDefault().getPreferenceStore().getString( - IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); - if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { - configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() - .eClass().getInstanceClassName()); - } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { - configuration = null; - } - } - - /** - * Performs the direct edit usually used by GMF editors. - * - * @param theRequest - * the direct edit request that starts the direct edit system - * @generated - */ - protected void performDefaultDirectEditorEdit(final Request theRequest) { - // initialize the direct edit manager - try { - getEditingDomain().runExclusive(new Runnable() { - - @Override - public void run() { - if (isActive() && isEditable()) { - if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { - Character initialChar = (Character) theRequest.getExtendedData().get( - RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); - performDirectEdit(initialChar.charValue()); - } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { - DirectEditRequest editRequest = (DirectEditRequest) theRequest; - performDirectEdit(editRequest.getLocation()); - } else { - performDirectEdit(); - } - } - } - }); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - - /** - * @generated - */ - @Override - protected void handleNotificationEvent(Notification event) { - Object feature = event.getFeature(); - if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { - Integer c = (Integer) event.getNewValue(); - setFontColor(DiagramColorRegistry.getInstance().getColor(c)); - } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { - refreshUnderline(); - } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { - refreshStrikeThrough(); - } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || - NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || - NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || - NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { - refreshFont(); - } else { - if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { - refreshLabel(); - } - if (getParser() instanceof ISemanticParser) { - ISemanticParser modelParser = - (ISemanticParser) getParser(); - if (modelParser.areSemanticElementsAffected(null, event)) { - removeSemanticListeners(); - if (resolveSemanticElement() != null) { - addSemanticListeners(); - } - refreshLabel(); - } - } - } - - super.handleNotificationEvent(event); - } - - /** - * @generated - */ - @Override - protected IFigure createFigure() { - // Parent should assign one using setLabel() method - return 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.uml.diagram.composite.edit.parts; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.draw2d.ConnectionLocator; +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.Label; +import org.eclipse.draw2d.geometry.Point; +import org.eclipse.emf.common.notify.Notification; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.RunnableWithResult; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gef.AccessibleEditPart; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.Request; +import org.eclipse.gef.requests.DirectEditRequest; +import org.eclipse.gef.tools.DirectEditManager; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; +import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; +import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; +import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; +import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; +import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; +import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; +import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; +import org.eclipse.gmf.runtime.notation.FontStyle; +import org.eclipse.gmf.runtime.notation.NotationPackage; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.gmf.tooling.runtime.edit.policies.DefaultLinkLabelDragPolicy; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.text.contentassist.IContentAssistProcessor; +import org.eclipse.jface.viewers.ICellEditorValidator; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.extensionpoints.editors.Activator; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; +import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; +import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; +import org.eclipse.papyrus.infra.gmfdiag.common.editpart.IControlParserForDirectEdit; +import org.eclipse.papyrus.infra.gmfdiag.common.editpart.PapyrusLabelEditPart; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.PapyrusLinkLabelDragPolicy; +import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; +import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; +import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; +import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; +import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.accessibility.AccessibleEvent; +import org.eclipse.swt.custom.BusyIndicator; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; +import org.eclipse.uml2.uml.Feature; + +/** + * @generated + */ +public class ConnectorMultiplicitySourceEditPart extends PapyrusLabelEditPart implements ITextAwareEditPart, IControlParserForDirectEdit { + + /** + * @generated + */ + public static final int VISUAL_ID = 6051; + + /** + * @generated + */ + private DirectEditManager manager; + + /** + * @generated + */ + private IParser parser; + + /** + * @generated + */ + private List parserElements; + + /** + * @generated + */ + private String defaultText; + + /** + * direct edition mode (default, undefined, registered editor, etc.) + * + * @generated + */ + protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; + + /** + * configuration from a registered edit dialog + * + * @generated + */ + protected IDirectEditorConfiguration configuration; + /** + * @generated + */ + static { + registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.ConnectorMultiplicitySourceEditPart.VISUAL_ID), new Point(0, 20)); + } + + /** + * @generated + */ + public ConnectorMultiplicitySourceEditPart(View view) { + super(view); + } + + /** + * @generated + */ + @Override + protected void createDefaultEditPolicies() { + super.createDefaultEditPolicies(); + installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); + installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new DefaultLinkLabelDragPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new PapyrusLinkLabelDragPolicy()); + } + + /** + * @generated + */ + @Override + public int getKeyPoint() { + return ConnectionLocator.SOURCE; + } + + /** + * @generated + */ + protected String getLabelTextHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getText(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getText(); + } else { + return ((Label) figure).getText(); + } + } + + /** + * @generated + */ + protected void setLabelTextHelper(IFigure figure, String text) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setText(text); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setText(text); + } else { + ((Label) figure).setText(text); + } + } + + /** + * @generated + */ + protected Image getLabelIconHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getIcon(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getIcon(); + } else { + return ((Label) figure).getIcon(); + } + } + + /** + * @generated + */ + protected void setLabelIconHelper(IFigure figure, Image icon) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setIcon(icon); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setIcon(icon); + } else { + ((Label) figure).setIcon(icon); + } + } + + /** + * @generated + */ + public void setLabel(IFigure + figure) { + unregisterVisuals(); + setFigure(figure); + defaultText = getLabelTextHelper(figure); + registerVisuals(); + refreshVisuals(); + } + + /** + * @generated + */ + @Override + protected List getModelChildren() { + return Collections.EMPTY_LIST; + } + + /** + * @generated + */ + @Override + public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { + return null; + } + + /** + * @generated + */ + @Override + public void setParser(IParser parser) { + this.parser = parser; + } + + /** + * @generated + */ + protected EObject getParserElement() { + return resolveSemanticElement(); + } + + /** + * @generated + */ + protected Image getLabelIcon() { + return null; + } + + /** + * @generated + */ + protected String getLabelText() { + String text = null; + EObject parserElement = getParserElement(); + if (parserElement != null && getParser() != null) { + text = getParser().getPrintString( + new EObjectAdapter(parserElement), + getParserOptions().intValue()); + } + if (text == null || text.length() == 0) { + text = defaultText; + } + return text; + } + + /** + * @generated + */ + @Override + public void setLabelText(String text) { + setLabelTextHelper(getFigure(), text); + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + @Override + public String getEditText() { + if (getParserElement() == null || getParser() == null) { + return ""; //$NON-NLS-1$ + } + return getParser().getEditString( + new EObjectAdapter(getParserElement()), + getParserOptions().intValue()); + } + + /** + * @generated + */ + protected boolean isEditable() { + return false; + } + + /** + * @generated + */ + @Override + public ICellEditorValidator getEditTextValidator() { + return new ICellEditorValidator() { + + @Override + public String isValid(final Object value) { + if (value instanceof String) { + final EObject element = getParserElement(); + final IParser parser = getParser(); + try { + IParserEditStatus valid = + (IParserEditStatus) getEditingDomain().runExclusive( + new RunnableWithResult.Impl() { + + @Override + public void run() { + setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); + } + }); + return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); + } catch (InterruptedException ie) { + ie.printStackTrace(); + } + } + + // shouldn't get here + return null; + } + }; + } + + /** + * @generated + */ + @Override + public IContentAssistProcessor getCompletionProcessor() { + if (getParserElement() == null || getParser() == null) { + return null; + } + return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); + } + + /** + * @generated + */ + @Override + public ParserOptions getParserOptions() { + return ParserOptions.NONE; + } + + /** + * @generated + */ + @Override + public IParser getParser() { + if (parser == null) { + parser = UMLParserProvider.getParser(UMLElementTypes.Connector_4013, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.ConnectorMultiplicitySourceEditPart.VISUAL_ID)); + } + return parser; + } + + /** + * @generated + */ + protected DirectEditManager getManager() { + if (manager == null) { + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + } + return manager; + } + + /** + * @generated + */ + protected void setManager(DirectEditManager manager) { + this.manager = manager; + } + + /** + * @generated + */ + protected void performDirectEdit() { + BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { + + @Override + public void run() { + getManager().show(); + } + }); + } + + /** + * @generated + */ + protected void performDirectEdit(Point eventLocation) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); + } + } + + /** + * @generated + */ + private void performDirectEdit(char initialCharacter) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(initialCharacter); + } else { + performDirectEdit(); + } + } + + /** + * @generated + */ + @Override + protected void performDirectEditRequest(Request request) { + + final Request theRequest = request; + + if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { + directEditionMode = getDirectEditionType(); + } + switch (directEditionMode) { + case IDirectEdition.NO_DIRECT_EDITION: + // no direct edition mode => does nothing + return; + case IDirectEdition.EXTENDED_DIRECT_EDITOR: + updateExtendedEditorConfiguration(); + if (configuration == null || configuration.getLanguage() == null) { + // Create default edit manager + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + performDefaultDirectEditorEdit(theRequest); + } else { + configuration.preEditAction(resolveSemanticElement()); + Dialog dialog = null; + if (configuration instanceof ICustomDirectEditorConfiguration) { + setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); + initializeDirectEditManager(theRequest); + return; + } else if (configuration instanceof IPopupEditorConfiguration) { + IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); + helper.showEditor(); + return; + } + else if (configuration instanceof IAdvancedEditorConfiguration) { + dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); + } else if (configuration instanceof IDirectEditorConfiguration) { + dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), + configuration); + } else { + return; + } + final Dialog finalDialog = dialog; + + if (Window.OK == dialog.open()) { + TransactionalEditingDomain domain = getEditingDomain(); + RecordingCommand command = new RecordingCommand(domain, "Edit Label") { + + @Override + protected void doExecute() { + configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); + + } + }; + domain.getCommandStack().execute(command); + } + } + break; + case IDirectEdition.DEFAULT_DIRECT_EDITOR: + initializeDirectEditManager(theRequest); + break; + default: + break; + } + } + + /** + * @generated + */ + protected void initializeDirectEditManager(final Request request) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + @Override + public void run() { + if (isActive() && isEditable()) { + if (request.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } + else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void refreshVisuals() { + super.refreshVisuals(); + refreshLabel(); + refreshFont(); + refreshFontColor(); + refreshUnderline(); + refreshStrikeThrough(); + } + + /** + * @generated + */ + protected void refreshLabel() { + EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); + if (maskLabelPolicy == null) { + maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); + } + if (maskLabelPolicy == null) { + setLabelTextHelper(getFigure(), getLabelText()); + setLabelIconHelper(getFigure(), getLabelIcon()); + } + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + protected void refreshUnderline() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); + } + if (resolveSemanticElement() instanceof Feature) { + if (((Feature) resolveSemanticElement()).isStatic()) { + ((WrappingLabel) getFigure()).setTextUnderline(true); + } + else { + ((WrappingLabel) getFigure()).setTextUnderline(false); + } + } + } + + /** + * @generated + */ + protected void refreshStrikeThrough() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); + } + } + + /** + * @generated + */ + @Override + protected void refreshFont() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null) { + FontData fontData = new FontData( + style.getFontName(), style.getFontHeight(), + (style.isBold() ? SWT.BOLD : SWT.NORMAL) | + (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); + setFont(fontData); + } + } + + /** + * @generated + */ + @Override + protected void setFontColor(Color color) { + getFigure().setForegroundColor(color); + } + + /** + * @generated + */ + @Override + protected void addSemanticListeners() { + if (getParser() instanceof ISemanticParser) { + EObject element = resolveSemanticElement(); + parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); + for (int i = 0; i < parserElements.size(); i++) { + addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ + } + } else { + super.addSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected void removeSemanticListeners() { + if (parserElements != null) { + for (int i = 0; i < parserElements.size(); i++) { + removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ + } + } else { + super.removeSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected AccessibleEditPart getAccessibleEditPart() { + if (accessibleEP == null) { + accessibleEP = new AccessibleGraphicalEditPart() { + + @Override + public void getName(AccessibleEvent e) { + e.result = getLabelTextHelper(getFigure()); + } + }; + } + return accessibleEP; + } + + /** + * @generated + */ + private View getFontStyleOwnerView() { + return getPrimaryView(); + } + + /** + * Returns the kind of associated editor for direct edition. + * + * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition + * @generated + */ + public int getDirectEditionType() { + // The label is read-only (defined in GMFGen model) + return IDirectEdition.NO_DIRECT_EDITION; + } + + /** + * Checks if an extended editor is present. + * + * @return true if an extended editor is present. + * @generated + */ + protected boolean checkExtendedEditor() { + if (resolveSemanticElement() != null) { + return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); + } + return false; + } + + /** + * Checks if a default direct edition is available + * + * @return true if a default direct edition is available + * @generated + */ + protected boolean checkDefaultEdition() { + return (getParser() != null); + } + + /** + * Initializes the extended editor configuration + * + * @generated + */ + protected void initExtendedEditorConfiguration() { + if (configuration == null) { + final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("")) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); + } else { + configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); + } + } + } + + /** + * Updates the preference configuration + * + * @generated + */ + protected void updateExtendedEditorConfiguration() { + String languagePreferred = Activator.getDefault().getPreferenceStore().getString( + IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() + .eClass().getInstanceClassName()); + } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { + configuration = null; + } + } + + /** + * Performs the direct edit usually used by GMF editors. + * + * @param theRequest + * the direct edit request that starts the direct edit system + * @generated + */ + protected void performDefaultDirectEditorEdit(final Request theRequest) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + + @Override + public void run() { + if (isActive() && isEditable()) { + if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) theRequest.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { + DirectEditRequest editRequest = (DirectEditRequest) theRequest; + performDirectEdit(editRequest.getLocation()); + } else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void handleNotificationEvent(Notification event) { + Object feature = event.getFeature(); + if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { + Integer c = (Integer) event.getNewValue(); + setFontColor(DiagramColorRegistry.getInstance().getColor(c)); + } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { + refreshUnderline(); + } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { + refreshStrikeThrough(); + } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { + refreshFont(); + } else { + if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { + refreshLabel(); + } + if (getParser() instanceof ISemanticParser) { + ISemanticParser modelParser = + (ISemanticParser) getParser(); + if (modelParser.areSemanticElementsAffected(null, event)) { + removeSemanticListeners(); + if (resolveSemanticElement() != null) { + addSemanticListeners(); + } + refreshLabel(); + } + } + } + + super.handleNotificationEvent(event); + } + + /** + * @generated + */ + @Override + protected IFigure createFigure() { + // Parent should assign one using setLabel() method + return null; + } +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ConnectorMultiplicityTargetEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ConnectorMultiplicityTargetEditPart.java index aca73e598bc..fe11bc39394 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ConnectorMultiplicityTargetEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ConnectorMultiplicityTargetEditPart.java @@ -1,820 +1,815 @@ -/** - * 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.uml.diagram.composite.edit.parts; - -import java.util.Collections; -import java.util.List; - -import org.eclipse.draw2d.ConnectionLocator; -import org.eclipse.draw2d.IFigure; -import org.eclipse.draw2d.Label; -import org.eclipse.draw2d.geometry.Point; -import org.eclipse.emf.common.notify.Notification; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.transaction.RecordingCommand; -import org.eclipse.emf.transaction.RunnableWithResult; -import org.eclipse.emf.transaction.TransactionalEditingDomain; -import org.eclipse.gef.AccessibleEditPart; -import org.eclipse.gef.EditPolicy; -import org.eclipse.gef.Request; -import org.eclipse.gef.requests.DirectEditRequest; -import org.eclipse.gef.tools.DirectEditManager; -import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; -import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; -import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; -import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; -import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; -import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; -import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; -import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; -import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; -import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; -import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; -import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; -import org.eclipse.gmf.runtime.notation.FontStyle; -import org.eclipse.gmf.runtime.notation.NotationPackage; -import org.eclipse.gmf.runtime.notation.View; -import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.jface.text.contentassist.IContentAssistProcessor; -import org.eclipse.jface.viewers.ICellEditorValidator; -import org.eclipse.jface.window.Window; -import org.eclipse.papyrus.extensionpoints.editors.Activator; -import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; -import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; -import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; -import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; -import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; -import org.eclipse.papyrus.infra.gmfdiag.common.editpart.IControlParserForDirectEdit; -import org.eclipse.papyrus.infra.gmfdiag.common.editpart.PapyrusLabelEditPart; -import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; -import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; -import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.PapyrusLinkLabelDragPolicy; -import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; -import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; -import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; -import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; -import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; -import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; -import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; -import org.eclipse.swt.SWT; -import org.eclipse.swt.accessibility.AccessibleEvent; -import org.eclipse.swt.custom.BusyIndicator; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.FontData; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.widgets.Display; -import org.eclipse.ui.PlatformUI; -import org.eclipse.uml2.uml.Feature; - -/** - * @generated - */ -public class ConnectorMultiplicityTargetEditPart extends PapyrusLabelEditPart implements ITextAwareEditPart, IControlParserForDirectEdit { - - /** - * @generated - */ - public static final int VISUAL_ID = 6052; - - /** - * @generated - */ - private DirectEditManager manager; - - /** - * @generated - */ - private IParser parser; - - /** - * @generated - */ - private List parserElements; - - /** - * @generated - */ - private String defaultText; - - /** - * direct edition mode (default, undefined, registered editor, etc.) - * - * @generated - */ - protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; - - /** - * configuration from a registered edit dialog - * - * @generated - */ - protected IDirectEditorConfiguration configuration; - /** - * @generated - */ - static { - registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.ConnectorMultiplicityTargetEditPart.VISUAL_ID), new Point(0, 20)); - } - - /** - * @generated - */ - public ConnectorMultiplicityTargetEditPart(View view) { - super(view); - } - - /** - * @generated - */ - @Override - protected void createDefaultEditPolicies() { - super.createDefaultEditPolicies(); - installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); - installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); - installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new PapyrusLinkLabelDragPolicy()); - } - - /** - * @generated - */ - @Override - public int getKeyPoint() { - return ConnectionLocator.TARGET; - } - - /** - * @generated - */ - protected String getLabelTextHelper(IFigure figure) { - if (figure instanceof WrappingLabel) { - return ((WrappingLabel) figure).getText(); - } else if (figure instanceof ILabelFigure) { - return ((ILabelFigure) figure).getText(); - } else { - return ((Label) figure).getText(); - } - } - - /** - * @generated - */ - protected void setLabelTextHelper(IFigure figure, String text) { - if (figure instanceof WrappingLabel) { - ((WrappingLabel) figure).setText(text); - } else if (figure instanceof ILabelFigure) { - ((ILabelFigure) figure).setText(text); - } else { - ((Label) figure).setText(text); - } - } - - /** - * @generated - */ - protected Image getLabelIconHelper(IFigure figure) { - if (figure instanceof WrappingLabel) { - return ((WrappingLabel) figure).getIcon(); - } else if (figure instanceof ILabelFigure) { - return ((ILabelFigure) figure).getIcon(); - } else { - return ((Label) figure).getIcon(); - } - } - - /** - * @generated - */ - protected void setLabelIconHelper(IFigure figure, Image icon) { - if (figure instanceof WrappingLabel) { - ((WrappingLabel) figure).setIcon(icon); - } else if (figure instanceof ILabelFigure) { - ((ILabelFigure) figure).setIcon(icon); - } else { - ((Label) figure).setIcon(icon); - } - } - - /** - * @generated - */ - public void setLabel(IFigure - figure) { - unregisterVisuals(); - setFigure(figure); - defaultText = getLabelTextHelper(figure); - registerVisuals(); - refreshVisuals(); - } - - /** - * @generated - */ - @Override - protected List getModelChildren() { - return Collections.EMPTY_LIST; - } - - /** - * @generated - */ - @Override - public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { - return null; - } - - /** - * @generated - */ - @Override - public void setParser(IParser parser) { - this.parser = parser; - } - - /** - * @generated - */ - protected EObject getParserElement() { - return resolveSemanticElement(); - } - - /** - * @generated - */ - protected Image getLabelIcon() { - return null; - } - - /** - * @generated - */ - protected String getLabelText() { - String text = null; - EObject parserElement = getParserElement(); - if (parserElement != null && getParser() != null) { - text = getParser().getPrintString( - new EObjectAdapter(parserElement), - getParserOptions().intValue()); - } - if (text == null || text.length() == 0) { - text = defaultText; - } - return text; - } - - /** - * @generated - */ - @Override - public void setLabelText(String text) { - setLabelTextHelper(getFigure(), text); - Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); - if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); - } - Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); - if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); - } - } - - /** - * @generated - */ - @Override - public String getEditText() { - if (getParserElement() == null || getParser() == null) { - return ""; //$NON-NLS-1$ - } - return getParser().getEditString( - new EObjectAdapter(getParserElement()), - getParserOptions().intValue()); - } - - /** - * @generated - */ - protected boolean isEditable() { - return false; - } - - /** - * @generated - */ - @Override - public ICellEditorValidator getEditTextValidator() { - return new ICellEditorValidator() { - - @Override - public String isValid(final Object value) { - if (value instanceof String) { - final EObject element = getParserElement(); - final IParser parser = getParser(); - try { - IParserEditStatus valid = - (IParserEditStatus) getEditingDomain().runExclusive( - new RunnableWithResult.Impl() { - - @Override - public void run() { - setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); - } - }); - return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); - } catch (InterruptedException ie) { - ie.printStackTrace(); - } - } - - // shouldn't get here - return null; - } - }; - } - - /** - * @generated - */ - @Override - public IContentAssistProcessor getCompletionProcessor() { - if (getParserElement() == null || getParser() == null) { - return null; - } - return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); - } - - /** - * @generated - */ - @Override - public ParserOptions getParserOptions() { - return ParserOptions.NONE; - } - - /** - * @generated - */ - @Override - public IParser getParser() { - if (parser == null) { - parser = UMLParserProvider.getParser(UMLElementTypes.Connector_4013, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.ConnectorMultiplicityTargetEditPart.VISUAL_ID)); - } - return parser; - } - - /** - * @generated - */ - protected DirectEditManager getManager() { - if (manager == null) { - setManager(new MultilineLabelDirectEditManager(this, - MultilineLabelDirectEditManager.getTextCellEditorClass(this), - UMLEditPartFactory.getTextCellEditorLocator(this))); - } - return manager; - } - - /** - * @generated - */ - protected void setManager(DirectEditManager manager) { - this.manager = manager; - } - - /** - * @generated - */ - protected void performDirectEdit() { - BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { - - @Override - public void run() { - getManager().show(); - } - }); - } - - /** - * @generated - */ - protected void performDirectEdit(Point eventLocation) { - if (getManager() instanceof TextDirectEditManager) { - ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); - } - } - - /** - * @generated - */ - private void performDirectEdit(char initialCharacter) { - if (getManager() instanceof TextDirectEditManager) { - ((TextDirectEditManager) getManager()).show(initialCharacter); - } else { - performDirectEdit(); - } - } - - /** - * @generated - */ - @Override - protected void performDirectEditRequest(Request request) { - - final Request theRequest = request; - - if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { - directEditionMode = getDirectEditionType(); - } - switch (directEditionMode) { - case IDirectEdition.NO_DIRECT_EDITION: - // no direct edition mode => does nothing - return; - case IDirectEdition.EXTENDED_DIRECT_EDITOR: - updateExtendedEditorConfiguration(); - if (configuration == null || configuration.getLanguage() == null) { - // Create default edit manager - setManager(new MultilineLabelDirectEditManager(this, - MultilineLabelDirectEditManager.getTextCellEditorClass(this), - UMLEditPartFactory.getTextCellEditorLocator(this))); - performDefaultDirectEditorEdit(theRequest); - } else { - configuration.preEditAction(resolveSemanticElement()); - Dialog dialog = null; - if (configuration instanceof ICustomDirectEditorConfiguration) { - setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); - initializeDirectEditManager(theRequest); - return; - } else if (configuration instanceof IPopupEditorConfiguration) { - IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); - helper.showEditor(); - return; - } - else if (configuration instanceof IAdvancedEditorConfiguration) { - dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); - } else if (configuration instanceof IDirectEditorConfiguration) { - dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), - configuration); - } else { - return; - } - final Dialog finalDialog = dialog; - - if (Window.OK == dialog.open()) { - TransactionalEditingDomain domain = getEditingDomain(); - RecordingCommand command = new RecordingCommand(domain, "Edit Label") { - - @Override - protected void doExecute() { - configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); - - } - }; - domain.getCommandStack().execute(command); - } - } - break; - case IDirectEdition.DEFAULT_DIRECT_EDITOR: - initializeDirectEditManager(theRequest); - break; - default: - break; - } - } - - /** - * @generated - */ - protected void initializeDirectEditManager(final Request request) { - // initialize the direct edit manager - try { - getEditingDomain().runExclusive(new Runnable() { - @Override - public void run() { - if (isActive() && isEditable()) { - if (request.getExtendedData().get( - RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { - Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); - performDirectEdit(initialChar.charValue()); - } - else { - performDirectEdit(); - } - } - } - }); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - - /** - * @generated - */ - @Override - protected void refreshVisuals() { - super.refreshVisuals(); - refreshLabel(); - refreshFont(); - refreshFontColor(); - refreshUnderline(); - refreshStrikeThrough(); - } - - /** - * @generated - */ - protected void refreshLabel() { - EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); - if (maskLabelPolicy == null) { - maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); - } - if (maskLabelPolicy == null) { - View view = (View) getModel(); - if (view.isVisible()) { - setLabelTextHelper(getFigure(), getLabelText()); - setLabelIconHelper(getFigure(), getLabelIcon()); - } - else { - setLabelTextHelper(getFigure(), ""); //$NON-NLS-1$ - setLabelIconHelper(getFigure(), null); - } - } - Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); - if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); - } - Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); - if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); - } - } - - /** - * @generated - */ - protected void refreshUnderline() { - FontStyle style = - (FontStyle) getFontStyleOwnerView().getStyle( - NotationPackage.eINSTANCE.getFontStyle()); - if (style != null && getFigure() instanceof WrappingLabel) { - ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); - } - if (resolveSemanticElement() instanceof Feature) { - if (((Feature) resolveSemanticElement()).isStatic()) { - ((WrappingLabel) getFigure()).setTextUnderline(true); - } - else { - ((WrappingLabel) getFigure()).setTextUnderline(false); - } - } - } - - /** - * @generated - */ - protected void refreshStrikeThrough() { - FontStyle style = - (FontStyle) getFontStyleOwnerView().getStyle( - NotationPackage.eINSTANCE.getFontStyle()); - if (style != null && getFigure() instanceof WrappingLabel) { - ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); - } - } - - /** - * @generated - */ - @Override - protected void refreshFont() { - FontStyle style = - (FontStyle) getFontStyleOwnerView().getStyle( - NotationPackage.eINSTANCE.getFontStyle()); - if (style != null) { - FontData fontData = new FontData( - style.getFontName(), style.getFontHeight(), - (style.isBold() ? SWT.BOLD : SWT.NORMAL) | - (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); - setFont(fontData); - } - } - - /** - * @generated - */ - @Override - protected void setFontColor(Color color) { - getFigure().setForegroundColor(color); - } - - /** - * @generated - */ - @Override - protected void addSemanticListeners() { - if (getParser() instanceof ISemanticParser) { - EObject element = resolveSemanticElement(); - parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); - for (int i = 0; i < parserElements.size(); i++) { - addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ - } - } else { - super.addSemanticListeners(); - } - } - - /** - * @generated - */ - @Override - protected void removeSemanticListeners() { - if (parserElements != null) { - for (int i = 0; i < parserElements.size(); i++) { - removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ - } - } else { - super.removeSemanticListeners(); - } - } - - /** - * @generated - */ - @Override - protected AccessibleEditPart getAccessibleEditPart() { - if (accessibleEP == null) { - accessibleEP = new AccessibleGraphicalEditPart() { - - @Override - public void getName(AccessibleEvent e) { - e.result = getLabelTextHelper(getFigure()); - } - }; - } - return accessibleEP; - } - - /** - * @generated - */ - private View getFontStyleOwnerView() { - return getPrimaryView(); - } - - /** - * Returns the kind of associated editor for direct edition. - * - * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition - * @generated - */ - public int getDirectEditionType() { - // The label is read-only (defined in GMFGen model) - return IDirectEdition.NO_DIRECT_EDITION; - } - - /** - * Checks if an extended editor is present. - * - * @return true if an extended editor is present. - * @generated - */ - protected boolean checkExtendedEditor() { - if (resolveSemanticElement() != null) { - return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); - } - return false; - } - - /** - * Checks if a default direct edition is available - * - * @return true if a default direct edition is available - * @generated - */ - protected boolean checkDefaultEdition() { - return (getParser() != null); - } - - /** - * Initializes the extended editor configuration - * - * @generated - */ - protected void initExtendedEditorConfiguration() { - if (configuration == null) { - final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); - if (languagePreferred != null && !languagePreferred.equals("")) { - configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); - } else { - configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); - } - } - } - - /** - * Updates the preference configuration - * - * @generated - */ - protected void updateExtendedEditorConfiguration() { - String languagePreferred = Activator.getDefault().getPreferenceStore().getString( - IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); - if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { - configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() - .eClass().getInstanceClassName()); - } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { - configuration = null; - } - } - - /** - * Performs the direct edit usually used by GMF editors. - * - * @param theRequest - * the direct edit request that starts the direct edit system - * @generated - */ - protected void performDefaultDirectEditorEdit(final Request theRequest) { - // initialize the direct edit manager - try { - getEditingDomain().runExclusive(new Runnable() { - - @Override - public void run() { - if (isActive() && isEditable()) { - if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { - Character initialChar = (Character) theRequest.getExtendedData().get( - RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); - performDirectEdit(initialChar.charValue()); - } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { - DirectEditRequest editRequest = (DirectEditRequest) theRequest; - performDirectEdit(editRequest.getLocation()); - } else { - performDirectEdit(); - } - } - } - }); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - - /** - * @generated - */ - @Override - protected void handleNotificationEvent(Notification event) { - Object feature = event.getFeature(); - if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { - Integer c = (Integer) event.getNewValue(); - setFontColor(DiagramColorRegistry.getInstance().getColor(c)); - } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { - refreshUnderline(); - } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { - refreshStrikeThrough(); - } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || - NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || - NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || - NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { - refreshFont(); - } else { - if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { - refreshLabel(); - } - if (getParser() instanceof ISemanticParser) { - ISemanticParser modelParser = - (ISemanticParser) getParser(); - if (modelParser.areSemanticElementsAffected(null, event)) { - removeSemanticListeners(); - if (resolveSemanticElement() != null) { - addSemanticListeners(); - } - refreshLabel(); - } - } - } - - super.handleNotificationEvent(event); - } - - /** - * @generated - */ - @Override - protected IFigure createFigure() { - // Parent should assign one using setLabel() method - return 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.uml.diagram.composite.edit.parts; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.draw2d.ConnectionLocator; +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.Label; +import org.eclipse.draw2d.geometry.Point; +import org.eclipse.emf.common.notify.Notification; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.RunnableWithResult; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gef.AccessibleEditPart; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.Request; +import org.eclipse.gef.requests.DirectEditRequest; +import org.eclipse.gef.tools.DirectEditManager; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; +import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; +import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; +import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; +import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; +import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; +import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; +import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; +import org.eclipse.gmf.runtime.notation.FontStyle; +import org.eclipse.gmf.runtime.notation.NotationPackage; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.gmf.tooling.runtime.edit.policies.DefaultLinkLabelDragPolicy; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.text.contentassist.IContentAssistProcessor; +import org.eclipse.jface.viewers.ICellEditorValidator; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.extensionpoints.editors.Activator; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; +import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; +import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; +import org.eclipse.papyrus.infra.gmfdiag.common.editpart.IControlParserForDirectEdit; +import org.eclipse.papyrus.infra.gmfdiag.common.editpart.PapyrusLabelEditPart; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.PapyrusLinkLabelDragPolicy; +import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; +import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; +import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; +import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; +import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.accessibility.AccessibleEvent; +import org.eclipse.swt.custom.BusyIndicator; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; +import org.eclipse.uml2.uml.Feature; + +/** + * @generated + */ +public class ConnectorMultiplicityTargetEditPart extends PapyrusLabelEditPart implements ITextAwareEditPart, IControlParserForDirectEdit { + + /** + * @generated + */ + public static final int VISUAL_ID = 6052; + + /** + * @generated + */ + private DirectEditManager manager; + + /** + * @generated + */ + private IParser parser; + + /** + * @generated + */ + private List parserElements; + + /** + * @generated + */ + private String defaultText; + + /** + * direct edition mode (default, undefined, registered editor, etc.) + * + * @generated + */ + protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; + + /** + * configuration from a registered edit dialog + * + * @generated + */ + protected IDirectEditorConfiguration configuration; + /** + * @generated + */ + static { + registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.ConnectorMultiplicityTargetEditPart.VISUAL_ID), new Point(0, 20)); + } + + /** + * @generated + */ + public ConnectorMultiplicityTargetEditPart(View view) { + super(view); + } + + /** + * @generated + */ + @Override + protected void createDefaultEditPolicies() { + super.createDefaultEditPolicies(); + installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); + installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new DefaultLinkLabelDragPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new PapyrusLinkLabelDragPolicy()); + } + + /** + * @generated + */ + @Override + public int getKeyPoint() { + return ConnectionLocator.TARGET; + } + + /** + * @generated + */ + protected String getLabelTextHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getText(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getText(); + } else { + return ((Label) figure).getText(); + } + } + + /** + * @generated + */ + protected void setLabelTextHelper(IFigure figure, String text) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setText(text); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setText(text); + } else { + ((Label) figure).setText(text); + } + } + + /** + * @generated + */ + protected Image getLabelIconHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getIcon(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getIcon(); + } else { + return ((Label) figure).getIcon(); + } + } + + /** + * @generated + */ + protected void setLabelIconHelper(IFigure figure, Image icon) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setIcon(icon); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setIcon(icon); + } else { + ((Label) figure).setIcon(icon); + } + } + + /** + * @generated + */ + public void setLabel(IFigure + figure) { + unregisterVisuals(); + setFigure(figure); + defaultText = getLabelTextHelper(figure); + registerVisuals(); + refreshVisuals(); + } + + /** + * @generated + */ + @Override + protected List getModelChildren() { + return Collections.EMPTY_LIST; + } + + /** + * @generated + */ + @Override + public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { + return null; + } + + /** + * @generated + */ + @Override + public void setParser(IParser parser) { + this.parser = parser; + } + + /** + * @generated + */ + protected EObject getParserElement() { + return resolveSemanticElement(); + } + + /** + * @generated + */ + protected Image getLabelIcon() { + return null; + } + + /** + * @generated + */ + protected String getLabelText() { + String text = null; + EObject parserElement = getParserElement(); + if (parserElement != null && getParser() != null) { + text = getParser().getPrintString( + new EObjectAdapter(parserElement), + getParserOptions().intValue()); + } + if (text == null || text.length() == 0) { + text = defaultText; + } + return text; + } + + /** + * @generated + */ + @Override + public void setLabelText(String text) { + setLabelTextHelper(getFigure(), text); + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + @Override + public String getEditText() { + if (getParserElement() == null || getParser() == null) { + return ""; //$NON-NLS-1$ + } + return getParser().getEditString( + new EObjectAdapter(getParserElement()), + getParserOptions().intValue()); + } + + /** + * @generated + */ + protected boolean isEditable() { + return false; + } + + /** + * @generated + */ + @Override + public ICellEditorValidator getEditTextValidator() { + return new ICellEditorValidator() { + + @Override + public String isValid(final Object value) { + if (value instanceof String) { + final EObject element = getParserElement(); + final IParser parser = getParser(); + try { + IParserEditStatus valid = + (IParserEditStatus) getEditingDomain().runExclusive( + new RunnableWithResult.Impl() { + + @Override + public void run() { + setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); + } + }); + return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); + } catch (InterruptedException ie) { + ie.printStackTrace(); + } + } + + // shouldn't get here + return null; + } + }; + } + + /** + * @generated + */ + @Override + public IContentAssistProcessor getCompletionProcessor() { + if (getParserElement() == null || getParser() == null) { + return null; + } + return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); + } + + /** + * @generated + */ + @Override + public ParserOptions getParserOptions() { + return ParserOptions.NONE; + } + + /** + * @generated + */ + @Override + public IParser getParser() { + if (parser == null) { + parser = UMLParserProvider.getParser(UMLElementTypes.Connector_4013, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.ConnectorMultiplicityTargetEditPart.VISUAL_ID)); + } + return parser; + } + + /** + * @generated + */ + protected DirectEditManager getManager() { + if (manager == null) { + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + } + return manager; + } + + /** + * @generated + */ + protected void setManager(DirectEditManager manager) { + this.manager = manager; + } + + /** + * @generated + */ + protected void performDirectEdit() { + BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { + + @Override + public void run() { + getManager().show(); + } + }); + } + + /** + * @generated + */ + protected void performDirectEdit(Point eventLocation) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); + } + } + + /** + * @generated + */ + private void performDirectEdit(char initialCharacter) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(initialCharacter); + } else { + performDirectEdit(); + } + } + + /** + * @generated + */ + @Override + protected void performDirectEditRequest(Request request) { + + final Request theRequest = request; + + if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { + directEditionMode = getDirectEditionType(); + } + switch (directEditionMode) { + case IDirectEdition.NO_DIRECT_EDITION: + // no direct edition mode => does nothing + return; + case IDirectEdition.EXTENDED_DIRECT_EDITOR: + updateExtendedEditorConfiguration(); + if (configuration == null || configuration.getLanguage() == null) { + // Create default edit manager + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + performDefaultDirectEditorEdit(theRequest); + } else { + configuration.preEditAction(resolveSemanticElement()); + Dialog dialog = null; + if (configuration instanceof ICustomDirectEditorConfiguration) { + setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); + initializeDirectEditManager(theRequest); + return; + } else if (configuration instanceof IPopupEditorConfiguration) { + IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); + helper.showEditor(); + return; + } + else if (configuration instanceof IAdvancedEditorConfiguration) { + dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); + } else if (configuration instanceof IDirectEditorConfiguration) { + dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), + configuration); + } else { + return; + } + final Dialog finalDialog = dialog; + + if (Window.OK == dialog.open()) { + TransactionalEditingDomain domain = getEditingDomain(); + RecordingCommand command = new RecordingCommand(domain, "Edit Label") { + + @Override + protected void doExecute() { + configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); + + } + }; + domain.getCommandStack().execute(command); + } + } + break; + case IDirectEdition.DEFAULT_DIRECT_EDITOR: + initializeDirectEditManager(theRequest); + break; + default: + break; + } + } + + /** + * @generated + */ + protected void initializeDirectEditManager(final Request request) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + @Override + public void run() { + if (isActive() && isEditable()) { + if (request.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } + else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void refreshVisuals() { + super.refreshVisuals(); + refreshLabel(); + refreshFont(); + refreshFontColor(); + refreshUnderline(); + refreshStrikeThrough(); + } + + /** + * @generated + */ + protected void refreshLabel() { + EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); + if (maskLabelPolicy == null) { + maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); + } + if (maskLabelPolicy == null) { + setLabelTextHelper(getFigure(), getLabelText()); + setLabelIconHelper(getFigure(), getLabelIcon()); + } + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + protected void refreshUnderline() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); + } + if (resolveSemanticElement() instanceof Feature) { + if (((Feature) resolveSemanticElement()).isStatic()) { + ((WrappingLabel) getFigure()).setTextUnderline(true); + } + else { + ((WrappingLabel) getFigure()).setTextUnderline(false); + } + } + } + + /** + * @generated + */ + protected void refreshStrikeThrough() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); + } + } + + /** + * @generated + */ + @Override + protected void refreshFont() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null) { + FontData fontData = new FontData( + style.getFontName(), style.getFontHeight(), + (style.isBold() ? SWT.BOLD : SWT.NORMAL) | + (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); + setFont(fontData); + } + } + + /** + * @generated + */ + @Override + protected void setFontColor(Color color) { + getFigure().setForegroundColor(color); + } + + /** + * @generated + */ + @Override + protected void addSemanticListeners() { + if (getParser() instanceof ISemanticParser) { + EObject element = resolveSemanticElement(); + parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); + for (int i = 0; i < parserElements.size(); i++) { + addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ + } + } else { + super.addSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected void removeSemanticListeners() { + if (parserElements != null) { + for (int i = 0; i < parserElements.size(); i++) { + removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ + } + } else { + super.removeSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected AccessibleEditPart getAccessibleEditPart() { + if (accessibleEP == null) { + accessibleEP = new AccessibleGraphicalEditPart() { + + @Override + public void getName(AccessibleEvent e) { + e.result = getLabelTextHelper(getFigure()); + } + }; + } + return accessibleEP; + } + + /** + * @generated + */ + private View getFontStyleOwnerView() { + return getPrimaryView(); + } + + /** + * Returns the kind of associated editor for direct edition. + * + * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition + * @generated + */ + public int getDirectEditionType() { + // The label is read-only (defined in GMFGen model) + return IDirectEdition.NO_DIRECT_EDITION; + } + + /** + * Checks if an extended editor is present. + * + * @return true if an extended editor is present. + * @generated + */ + protected boolean checkExtendedEditor() { + if (resolveSemanticElement() != null) { + return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); + } + return false; + } + + /** + * Checks if a default direct edition is available + * + * @return true if a default direct edition is available + * @generated + */ + protected boolean checkDefaultEdition() { + return (getParser() != null); + } + + /** + * Initializes the extended editor configuration + * + * @generated + */ + protected void initExtendedEditorConfiguration() { + if (configuration == null) { + final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("")) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); + } else { + configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); + } + } + } + + /** + * Updates the preference configuration + * + * @generated + */ + protected void updateExtendedEditorConfiguration() { + String languagePreferred = Activator.getDefault().getPreferenceStore().getString( + IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() + .eClass().getInstanceClassName()); + } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { + configuration = null; + } + } + + /** + * Performs the direct edit usually used by GMF editors. + * + * @param theRequest + * the direct edit request that starts the direct edit system + * @generated + */ + protected void performDefaultDirectEditorEdit(final Request theRequest) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + + @Override + public void run() { + if (isActive() && isEditable()) { + if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) theRequest.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { + DirectEditRequest editRequest = (DirectEditRequest) theRequest; + performDirectEdit(editRequest.getLocation()); + } else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void handleNotificationEvent(Notification event) { + Object feature = event.getFeature(); + if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { + Integer c = (Integer) event.getNewValue(); + setFontColor(DiagramColorRegistry.getInstance().getColor(c)); + } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { + refreshUnderline(); + } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { + refreshStrikeThrough(); + } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { + refreshFont(); + } else { + if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { + refreshLabel(); + } + if (getParser() instanceof ISemanticParser) { + ISemanticParser modelParser = + (ISemanticParser) getParser(); + if (modelParser.areSemanticElementsAffected(null, event)) { + removeSemanticListeners(); + if (resolveSemanticElement() != null) { + addSemanticListeners(); + } + refreshLabel(); + } + } + } + + super.handleNotificationEvent(event); + } + + /** + * @generated + */ + @Override + protected IFigure createFigure() { + // Parent should assign one using setLabel() method + return null; + } +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ConnectorNameEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ConnectorNameEditPart.java index e996bc594f8..27497eaf4a0 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ConnectorNameEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ConnectorNameEditPart.java @@ -1,845 +1,840 @@ -/** - * 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.uml.diagram.composite.edit.parts; - -import java.util.Collections; -import java.util.List; - -import org.eclipse.draw2d.ConnectionLocator; -import org.eclipse.draw2d.IFigure; -import org.eclipse.draw2d.Label; -import org.eclipse.draw2d.geometry.Point; -import org.eclipse.emf.common.notify.Notification; -import org.eclipse.emf.ecore.EAnnotation; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.transaction.RecordingCommand; -import org.eclipse.emf.transaction.RunnableWithResult; -import org.eclipse.emf.transaction.TransactionalEditingDomain; -import org.eclipse.gef.AccessibleEditPart; -import org.eclipse.gef.EditPolicy; -import org.eclipse.gef.Request; -import org.eclipse.gef.requests.DirectEditRequest; -import org.eclipse.gef.tools.DirectEditManager; -import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; -import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; -import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; -import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; -import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; -import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; -import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; -import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; -import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; -import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; -import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; -import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; -import org.eclipse.gmf.runtime.notation.FontStyle; -import org.eclipse.gmf.runtime.notation.NotationPackage; -import org.eclipse.gmf.runtime.notation.View; -import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.jface.text.contentassist.IContentAssistProcessor; -import org.eclipse.jface.viewers.ICellEditorValidator; -import org.eclipse.jface.window.Window; -import org.eclipse.papyrus.extensionpoints.editors.Activator; -import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; -import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; -import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; -import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; -import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; -import org.eclipse.papyrus.infra.emf.appearance.helper.AppearanceHelper; -import org.eclipse.papyrus.infra.emf.appearance.helper.VisualInformationPapyrusConstants; -import org.eclipse.papyrus.infra.gmfdiag.common.editpart.IControlParserForDirectEdit; -import org.eclipse.papyrus.infra.gmfdiag.common.editpart.PapyrusLabelEditPart; -import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; -import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; -import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.PapyrusLinkLabelDragPolicy; -import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; -import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; -import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; -import org.eclipse.papyrus.uml.diagram.common.util.DiagramEditPartsUtil; -import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; -import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; -import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; -import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; -import org.eclipse.swt.SWT; -import org.eclipse.swt.accessibility.AccessibleEvent; -import org.eclipse.swt.custom.BusyIndicator; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.FontData; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.widgets.Display; -import org.eclipse.ui.PlatformUI; -import org.eclipse.uml2.uml.Feature; - -/** - * @generated - */ -public class ConnectorNameEditPart extends PapyrusLabelEditPart implements ITextAwareEditPart, IControlParserForDirectEdit { - - /** - * @generated - */ - public static final int VISUAL_ID = 6050; - - /** - * @generated - */ - private DirectEditManager manager; - - /** - * @generated - */ - private IParser parser; - - /** - * @generated - */ - private List parserElements; - - /** - * @generated - */ - private String defaultText; - - /** - * direct edition mode (default, undefined, registered editor, etc.) - * - * @generated - */ - protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; - - /** - * configuration from a registered edit dialog - * - * @generated - */ - protected IDirectEditorConfiguration configuration; - /** - * @generated - */ - static { - registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.ConnectorNameEditPart.VISUAL_ID), new Point(0, -20)); - } - - /** - * @generated - */ - public ConnectorNameEditPart(View view) { - super(view); - } - - /** - * @generated - */ - @Override - protected void createDefaultEditPolicies() { - super.createDefaultEditPolicies(); - installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); - installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); - installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new PapyrusLinkLabelDragPolicy()); - } - - /** - * @generated - */ - @Override - public int getKeyPoint() { - return ConnectionLocator.MIDDLE; - } - - /** - * @generated - */ - protected String getLabelTextHelper(IFigure figure) { - if (figure instanceof WrappingLabel) { - return ((WrappingLabel) figure).getText(); - } else if (figure instanceof ILabelFigure) { - return ((ILabelFigure) figure).getText(); - } else { - return ((Label) figure).getText(); - } - } - - /** - * @generated - */ - protected void setLabelTextHelper(IFigure figure, String text) { - if (figure instanceof WrappingLabel) { - ((WrappingLabel) figure).setText(text); - } else if (figure instanceof ILabelFigure) { - ((ILabelFigure) figure).setText(text); - } else { - ((Label) figure).setText(text); - } - } - - /** - * @generated - */ - protected Image getLabelIconHelper(IFigure figure) { - if (figure instanceof WrappingLabel) { - return ((WrappingLabel) figure).getIcon(); - } else if (figure instanceof ILabelFigure) { - return ((ILabelFigure) figure).getIcon(); - } else { - return ((Label) figure).getIcon(); - } - } - - /** - * @generated - */ - protected void setLabelIconHelper(IFigure figure, Image icon) { - if (figure instanceof WrappingLabel) { - ((WrappingLabel) figure).setIcon(icon); - } else if (figure instanceof ILabelFigure) { - ((ILabelFigure) figure).setIcon(icon); - } else { - ((Label) figure).setIcon(icon); - } - } - - /** - * @generated - */ - public void setLabel(IFigure - figure) { - unregisterVisuals(); - setFigure(figure); - defaultText = getLabelTextHelper(figure); - registerVisuals(); - refreshVisuals(); - } - - /** - * @generated - */ - @Override - protected List getModelChildren() { - return Collections.EMPTY_LIST; - } - - /** - * @generated - */ - @Override - public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { - return null; - } - - /** - * @generated - */ - @Override - public void setParser(IParser parser) { - this.parser = parser; - } - - /** - * @generated - */ - protected EObject getParserElement() { - return resolveSemanticElement(); - } - - /** - * @generated - */ - protected Image getLabelIcon() { - EObject parserElement = getParserElement(); - if (parserElement == null) { - return null; - } - List views = DiagramEditPartsUtil.findViews(parserElement, getViewer()); - for (View view : views) { - if (AppearanceHelper.showElementIcon(view)) { - return UMLElementTypes.getImage(parserElement.eClass()); - } - } - return null; - } - - /** - * @generated - */ - protected String getLabelText() { - String text = null; - EObject parserElement = getParserElement(); - if (parserElement != null && getParser() != null) { - text = getParser().getPrintString( - new EObjectAdapter(parserElement), - getParserOptions().intValue()); - } - if (text == null || text.length() == 0) { - text = defaultText; - } - return text; - } - - /** - * @generated - */ - @Override - public void setLabelText(String text) { - setLabelTextHelper(getFigure(), text); - Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); - if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); - } - Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); - if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); - } - } - - /** - * @generated - */ - @Override - public String getEditText() { - if (getParserElement() == null || getParser() == null) { - return ""; //$NON-NLS-1$ - } - return getParser().getEditString( - new EObjectAdapter(getParserElement()), - getParserOptions().intValue()); - } - - /** - * @generated - */ - protected boolean isEditable() { - return getParser() != null; - } - - /** - * @generated - */ - @Override - public ICellEditorValidator getEditTextValidator() { - return new ICellEditorValidator() { - - @Override - public String isValid(final Object value) { - if (value instanceof String) { - final EObject element = getParserElement(); - final IParser parser = getParser(); - try { - IParserEditStatus valid = - (IParserEditStatus) getEditingDomain().runExclusive( - new RunnableWithResult.Impl() { - - @Override - public void run() { - setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); - } - }); - return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); - } catch (InterruptedException ie) { - ie.printStackTrace(); - } - } - - // shouldn't get here - return null; - } - }; - } - - /** - * @generated - */ - @Override - public IContentAssistProcessor getCompletionProcessor() { - if (getParserElement() == null || getParser() == null) { - return null; - } - return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); - } - - /** - * @generated - */ - @Override - public ParserOptions getParserOptions() { - return ParserOptions.NONE; - } - - /** - * @generated - */ - @Override - public IParser getParser() { - if (parser == null) { - parser = UMLParserProvider.getParser(UMLElementTypes.Connector_4013, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.ConnectorNameEditPart.VISUAL_ID)); - } - return parser; - } - - /** - * @generated - */ - protected DirectEditManager getManager() { - if (manager == null) { - setManager(new MultilineLabelDirectEditManager(this, - MultilineLabelDirectEditManager.getTextCellEditorClass(this), - UMLEditPartFactory.getTextCellEditorLocator(this))); - } - return manager; - } - - /** - * @generated - */ - protected void setManager(DirectEditManager manager) { - this.manager = manager; - } - - /** - * @generated - */ - protected void performDirectEdit() { - BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { - - @Override - public void run() { - getManager().show(); - } - }); - } - - /** - * @generated - */ - protected void performDirectEdit(Point eventLocation) { - if (getManager() instanceof TextDirectEditManager) { - ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); - } - } - - /** - * @generated - */ - private void performDirectEdit(char initialCharacter) { - if (getManager() instanceof TextDirectEditManager) { - ((TextDirectEditManager) getManager()).show(initialCharacter); - } else { - performDirectEdit(); - } - } - - /** - * @generated - */ - @Override - protected void performDirectEditRequest(Request request) { - - final Request theRequest = request; - - if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { - directEditionMode = getDirectEditionType(); - } - switch (directEditionMode) { - case IDirectEdition.NO_DIRECT_EDITION: - // no direct edition mode => does nothing - return; - case IDirectEdition.EXTENDED_DIRECT_EDITOR: - updateExtendedEditorConfiguration(); - if (configuration == null || configuration.getLanguage() == null) { - // Create default edit manager - setManager(new MultilineLabelDirectEditManager(this, - MultilineLabelDirectEditManager.getTextCellEditorClass(this), - UMLEditPartFactory.getTextCellEditorLocator(this))); - performDefaultDirectEditorEdit(theRequest); - } else { - configuration.preEditAction(resolveSemanticElement()); - Dialog dialog = null; - if (configuration instanceof ICustomDirectEditorConfiguration) { - setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); - initializeDirectEditManager(theRequest); - return; - } else if (configuration instanceof IPopupEditorConfiguration) { - IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); - helper.showEditor(); - return; - } - else if (configuration instanceof IAdvancedEditorConfiguration) { - dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); - } else if (configuration instanceof IDirectEditorConfiguration) { - dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), - configuration); - } else { - return; - } - final Dialog finalDialog = dialog; - - if (Window.OK == dialog.open()) { - TransactionalEditingDomain domain = getEditingDomain(); - RecordingCommand command = new RecordingCommand(domain, "Edit Label") { - - @Override - protected void doExecute() { - configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); - - } - }; - domain.getCommandStack().execute(command); - } - } - break; - case IDirectEdition.DEFAULT_DIRECT_EDITOR: - initializeDirectEditManager(theRequest); - break; - default: - break; - } - } - - /** - * @generated - */ - protected void initializeDirectEditManager(final Request request) { - // initialize the direct edit manager - try { - getEditingDomain().runExclusive(new Runnable() { - @Override - public void run() { - if (isActive() && isEditable()) { - if (request.getExtendedData().get( - RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { - Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); - performDirectEdit(initialChar.charValue()); - } - else { - performDirectEdit(); - } - } - } - }); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - - /** - * @generated - */ - @Override - protected void refreshVisuals() { - super.refreshVisuals(); - refreshLabel(); - refreshFont(); - refreshFontColor(); - refreshUnderline(); - refreshStrikeThrough(); - } - - /** - * @generated - */ - protected void refreshLabel() { - EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); - if (maskLabelPolicy == null) { - maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); - } - if (maskLabelPolicy == null) { - View view = (View) getModel(); - if (view.isVisible()) { - setLabelTextHelper(getFigure(), getLabelText()); - setLabelIconHelper(getFigure(), getLabelIcon()); - } - else { - setLabelTextHelper(getFigure(), ""); //$NON-NLS-1$ - setLabelIconHelper(getFigure(), null); - } - } - Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); - if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); - } - Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); - if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); - } - } - - /** - * @generated - */ - protected void refreshUnderline() { - FontStyle style = - (FontStyle) getFontStyleOwnerView().getStyle( - NotationPackage.eINSTANCE.getFontStyle()); - if (style != null && getFigure() instanceof WrappingLabel) { - ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); - } - if (resolveSemanticElement() instanceof Feature) { - if (((Feature) resolveSemanticElement()).isStatic()) { - ((WrappingLabel) getFigure()).setTextUnderline(true); - } - else { - ((WrappingLabel) getFigure()).setTextUnderline(false); - } - } - } - - /** - * @generated - */ - protected void refreshStrikeThrough() { - FontStyle style = - (FontStyle) getFontStyleOwnerView().getStyle( - NotationPackage.eINSTANCE.getFontStyle()); - if (style != null && getFigure() instanceof WrappingLabel) { - ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); - } - } - - /** - * @generated - */ - @Override - protected void refreshFont() { - FontStyle style = - (FontStyle) getFontStyleOwnerView().getStyle( - NotationPackage.eINSTANCE.getFontStyle()); - if (style != null) { - FontData fontData = new FontData( - style.getFontName(), style.getFontHeight(), - (style.isBold() ? SWT.BOLD : SWT.NORMAL) | - (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); - setFont(fontData); - } - } - - /** - * @generated - */ - @Override - protected void setFontColor(Color color) { - getFigure().setForegroundColor(color); - } - - /** - * @generated - */ - @Override - protected void addSemanticListeners() { - if (getParser() instanceof ISemanticParser) { - EObject element = resolveSemanticElement(); - parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); - for (int i = 0; i < parserElements.size(); i++) { - addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ - } - } else { - super.addSemanticListeners(); - } - } - - /** - * @generated - */ - @Override - protected void removeSemanticListeners() { - if (parserElements != null) { - for (int i = 0; i < parserElements.size(); i++) { - removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ - } - } else { - super.removeSemanticListeners(); - } - } - - /** - * @generated - */ - @Override - protected AccessibleEditPart getAccessibleEditPart() { - if (accessibleEP == null) { - accessibleEP = new AccessibleGraphicalEditPart() { - - @Override - public void getName(AccessibleEvent e) { - e.result = getLabelTextHelper(getFigure()); - } - }; - } - return accessibleEP; - } - - /** - * @generated - */ - private View getFontStyleOwnerView() { - return getPrimaryView(); - } - - /** - * Returns the kind of associated editor for direct edition. - * - * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition - * @generated - */ - public int getDirectEditionType() { - if (checkExtendedEditor()) { - initExtendedEditorConfiguration(); - return IDirectEdition.EXTENDED_DIRECT_EDITOR; - } - if (checkDefaultEdition()) { - return IDirectEdition.DEFAULT_DIRECT_EDITOR; - } - - // not a named element. no specific editor => do nothing - return IDirectEdition.NO_DIRECT_EDITION; - } - - /** - * Checks if an extended editor is present. - * - * @return true if an extended editor is present. - * @generated - */ - protected boolean checkExtendedEditor() { - if (resolveSemanticElement() != null) { - return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); - } - return false; - } - - /** - * Checks if a default direct edition is available - * - * @return true if a default direct edition is available - * @generated - */ - protected boolean checkDefaultEdition() { - return (getParser() != null); - } - - /** - * Initializes the extended editor configuration - * - * @generated - */ - protected void initExtendedEditorConfiguration() { - if (configuration == null) { - final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); - if (languagePreferred != null && !languagePreferred.equals("")) { - configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); - } else { - configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); - } - } - } - - /** - * Updates the preference configuration - * - * @generated - */ - protected void updateExtendedEditorConfiguration() { - String languagePreferred = Activator.getDefault().getPreferenceStore().getString( - IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); - if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { - configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() - .eClass().getInstanceClassName()); - } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { - configuration = null; - } - } - - /** - * Performs the direct edit usually used by GMF editors. - * - * @param theRequest - * the direct edit request that starts the direct edit system - * @generated - */ - protected void performDefaultDirectEditorEdit(final Request theRequest) { - // initialize the direct edit manager - try { - getEditingDomain().runExclusive(new Runnable() { - - @Override - public void run() { - if (isActive() && isEditable()) { - if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { - Character initialChar = (Character) theRequest.getExtendedData().get( - RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); - performDirectEdit(initialChar.charValue()); - } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { - DirectEditRequest editRequest = (DirectEditRequest) theRequest; - performDirectEdit(editRequest.getLocation()); - } else { - performDirectEdit(); - } - } - } - }); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - - /** - * @generated - */ - @Override - protected void handleNotificationEvent(Notification event) { - Object feature = event.getFeature(); - if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { - Integer c = (Integer) event.getNewValue(); - setFontColor(DiagramColorRegistry.getInstance().getColor(c)); - } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { - refreshUnderline(); - } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { - refreshStrikeThrough(); - } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || - NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || - NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || - NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { - refreshFont(); - } else { - if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { - refreshLabel(); - } - if (getParser() instanceof ISemanticParser) { - ISemanticParser modelParser = - (ISemanticParser) getParser(); - if (modelParser.areSemanticElementsAffected(null, event)) { - removeSemanticListeners(); - if (resolveSemanticElement() != null) { - addSemanticListeners(); - } - refreshLabel(); - } - } - } - - if (event.getNewValue() instanceof EAnnotation && VisualInformationPapyrusConstants.DISPLAY_NAMELABELICON.equals(((EAnnotation) event.getNewValue()).getSource())) { - refreshLabel(); - } - super.handleNotificationEvent(event); - } - - /** - * @generated - */ - @Override - protected IFigure createFigure() { - // Parent should assign one using setLabel() method - return 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.uml.diagram.composite.edit.parts; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.draw2d.ConnectionLocator; +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.Label; +import org.eclipse.draw2d.geometry.Point; +import org.eclipse.emf.common.notify.Notification; +import org.eclipse.emf.ecore.EAnnotation; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.RunnableWithResult; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gef.AccessibleEditPart; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.Request; +import org.eclipse.gef.requests.DirectEditRequest; +import org.eclipse.gef.tools.DirectEditManager; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; +import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; +import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; +import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; +import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; +import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; +import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; +import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; +import org.eclipse.gmf.runtime.notation.FontStyle; +import org.eclipse.gmf.runtime.notation.NotationPackage; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.gmf.tooling.runtime.edit.policies.DefaultLinkLabelDragPolicy; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.text.contentassist.IContentAssistProcessor; +import org.eclipse.jface.viewers.ICellEditorValidator; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.extensionpoints.editors.Activator; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; +import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; +import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; +import org.eclipse.papyrus.infra.emf.appearance.helper.AppearanceHelper; +import org.eclipse.papyrus.infra.emf.appearance.helper.VisualInformationPapyrusConstants; +import org.eclipse.papyrus.infra.gmfdiag.common.editpart.IControlParserForDirectEdit; +import org.eclipse.papyrus.infra.gmfdiag.common.editpart.PapyrusLabelEditPart; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.PapyrusLinkLabelDragPolicy; +import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; +import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; +import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; +import org.eclipse.papyrus.uml.diagram.common.util.DiagramEditPartsUtil; +import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; +import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.accessibility.AccessibleEvent; +import org.eclipse.swt.custom.BusyIndicator; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; +import org.eclipse.uml2.uml.Feature; + +/** + * @generated + */ +public class ConnectorNameEditPart extends PapyrusLabelEditPart implements ITextAwareEditPart, IControlParserForDirectEdit { + + /** + * @generated + */ + public static final int VISUAL_ID = 6050; + + /** + * @generated + */ + private DirectEditManager manager; + + /** + * @generated + */ + private IParser parser; + + /** + * @generated + */ + private List parserElements; + + /** + * @generated + */ + private String defaultText; + + /** + * direct edition mode (default, undefined, registered editor, etc.) + * + * @generated + */ + protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; + + /** + * configuration from a registered edit dialog + * + * @generated + */ + protected IDirectEditorConfiguration configuration; + /** + * @generated + */ + static { + registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.ConnectorNameEditPart.VISUAL_ID), new Point(0, -20)); + } + + /** + * @generated + */ + public ConnectorNameEditPart(View view) { + super(view); + } + + /** + * @generated + */ + @Override + protected void createDefaultEditPolicies() { + super.createDefaultEditPolicies(); + installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); + installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new DefaultLinkLabelDragPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new PapyrusLinkLabelDragPolicy()); + } + + /** + * @generated + */ + @Override + public int getKeyPoint() { + return ConnectionLocator.MIDDLE; + } + + /** + * @generated + */ + protected String getLabelTextHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getText(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getText(); + } else { + return ((Label) figure).getText(); + } + } + + /** + * @generated + */ + protected void setLabelTextHelper(IFigure figure, String text) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setText(text); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setText(text); + } else { + ((Label) figure).setText(text); + } + } + + /** + * @generated + */ + protected Image getLabelIconHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getIcon(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getIcon(); + } else { + return ((Label) figure).getIcon(); + } + } + + /** + * @generated + */ + protected void setLabelIconHelper(IFigure figure, Image icon) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setIcon(icon); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setIcon(icon); + } else { + ((Label) figure).setIcon(icon); + } + } + + /** + * @generated + */ + public void setLabel(IFigure + figure) { + unregisterVisuals(); + setFigure(figure); + defaultText = getLabelTextHelper(figure); + registerVisuals(); + refreshVisuals(); + } + + /** + * @generated + */ + @Override + protected List getModelChildren() { + return Collections.EMPTY_LIST; + } + + /** + * @generated + */ + @Override + public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { + return null; + } + + /** + * @generated + */ + @Override + public void setParser(IParser parser) { + this.parser = parser; + } + + /** + * @generated + */ + protected EObject getParserElement() { + return resolveSemanticElement(); + } + + /** + * @generated + */ + protected Image getLabelIcon() { + EObject parserElement = getParserElement(); + if (parserElement == null) { + return null; + } + List views = DiagramEditPartsUtil.findViews(parserElement, getViewer()); + for (View view : views) { + if (AppearanceHelper.showElementIcon(view)) { + return UMLElementTypes.getImage(parserElement.eClass()); + } + } + return null; + } + + /** + * @generated + */ + protected String getLabelText() { + String text = null; + EObject parserElement = getParserElement(); + if (parserElement != null && getParser() != null) { + text = getParser().getPrintString( + new EObjectAdapter(parserElement), + getParserOptions().intValue()); + } + if (text == null || text.length() == 0) { + text = defaultText; + } + return text; + } + + /** + * @generated + */ + @Override + public void setLabelText(String text) { + setLabelTextHelper(getFigure(), text); + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + @Override + public String getEditText() { + if (getParserElement() == null || getParser() == null) { + return ""; //$NON-NLS-1$ + } + return getParser().getEditString( + new EObjectAdapter(getParserElement()), + getParserOptions().intValue()); + } + + /** + * @generated + */ + protected boolean isEditable() { + return getParser() != null; + } + + /** + * @generated + */ + @Override + public ICellEditorValidator getEditTextValidator() { + return new ICellEditorValidator() { + + @Override + public String isValid(final Object value) { + if (value instanceof String) { + final EObject element = getParserElement(); + final IParser parser = getParser(); + try { + IParserEditStatus valid = + (IParserEditStatus) getEditingDomain().runExclusive( + new RunnableWithResult.Impl() { + + @Override + public void run() { + setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); + } + }); + return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); + } catch (InterruptedException ie) { + ie.printStackTrace(); + } + } + + // shouldn't get here + return null; + } + }; + } + + /** + * @generated + */ + @Override + public IContentAssistProcessor getCompletionProcessor() { + if (getParserElement() == null || getParser() == null) { + return null; + } + return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); + } + + /** + * @generated + */ + @Override + public ParserOptions getParserOptions() { + return ParserOptions.NONE; + } + + /** + * @generated + */ + @Override + public IParser getParser() { + if (parser == null) { + parser = UMLParserProvider.getParser(UMLElementTypes.Connector_4013, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.ConnectorNameEditPart.VISUAL_ID)); + } + return parser; + } + + /** + * @generated + */ + protected DirectEditManager getManager() { + if (manager == null) { + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + } + return manager; + } + + /** + * @generated + */ + protected void setManager(DirectEditManager manager) { + this.manager = manager; + } + + /** + * @generated + */ + protected void performDirectEdit() { + BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { + + @Override + public void run() { + getManager().show(); + } + }); + } + + /** + * @generated + */ + protected void performDirectEdit(Point eventLocation) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); + } + } + + /** + * @generated + */ + private void performDirectEdit(char initialCharacter) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(initialCharacter); + } else { + performDirectEdit(); + } + } + + /** + * @generated + */ + @Override + protected void performDirectEditRequest(Request request) { + + final Request theRequest = request; + + if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { + directEditionMode = getDirectEditionType(); + } + switch (directEditionMode) { + case IDirectEdition.NO_DIRECT_EDITION: + // no direct edition mode => does nothing + return; + case IDirectEdition.EXTENDED_DIRECT_EDITOR: + updateExtendedEditorConfiguration(); + if (configuration == null || configuration.getLanguage() == null) { + // Create default edit manager + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + performDefaultDirectEditorEdit(theRequest); + } else { + configuration.preEditAction(resolveSemanticElement()); + Dialog dialog = null; + if (configuration instanceof ICustomDirectEditorConfiguration) { + setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); + initializeDirectEditManager(theRequest); + return; + } else if (configuration instanceof IPopupEditorConfiguration) { + IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); + helper.showEditor(); + return; + } + else if (configuration instanceof IAdvancedEditorConfiguration) { + dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); + } else if (configuration instanceof IDirectEditorConfiguration) { + dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), + configuration); + } else { + return; + } + final Dialog finalDialog = dialog; + + if (Window.OK == dialog.open()) { + TransactionalEditingDomain domain = getEditingDomain(); + RecordingCommand command = new RecordingCommand(domain, "Edit Label") { + + @Override + protected void doExecute() { + configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); + + } + }; + domain.getCommandStack().execute(command); + } + } + break; + case IDirectEdition.DEFAULT_DIRECT_EDITOR: + initializeDirectEditManager(theRequest); + break; + default: + break; + } + } + + /** + * @generated + */ + protected void initializeDirectEditManager(final Request request) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + @Override + public void run() { + if (isActive() && isEditable()) { + if (request.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } + else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void refreshVisuals() { + super.refreshVisuals(); + refreshLabel(); + refreshFont(); + refreshFontColor(); + refreshUnderline(); + refreshStrikeThrough(); + } + + /** + * @generated + */ + protected void refreshLabel() { + EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); + if (maskLabelPolicy == null) { + maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); + } + if (maskLabelPolicy == null) { + setLabelTextHelper(getFigure(), getLabelText()); + setLabelIconHelper(getFigure(), getLabelIcon()); + } + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + protected void refreshUnderline() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); + } + if (resolveSemanticElement() instanceof Feature) { + if (((Feature) resolveSemanticElement()).isStatic()) { + ((WrappingLabel) getFigure()).setTextUnderline(true); + } + else { + ((WrappingLabel) getFigure()).setTextUnderline(false); + } + } + } + + /** + * @generated + */ + protected void refreshStrikeThrough() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); + } + } + + /** + * @generated + */ + @Override + protected void refreshFont() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null) { + FontData fontData = new FontData( + style.getFontName(), style.getFontHeight(), + (style.isBold() ? SWT.BOLD : SWT.NORMAL) | + (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); + setFont(fontData); + } + } + + /** + * @generated + */ + @Override + protected void setFontColor(Color color) { + getFigure().setForegroundColor(color); + } + + /** + * @generated + */ + @Override + protected void addSemanticListeners() { + if (getParser() instanceof ISemanticParser) { + EObject element = resolveSemanticElement(); + parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); + for (int i = 0; i < parserElements.size(); i++) { + addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ + } + } else { + super.addSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected void removeSemanticListeners() { + if (parserElements != null) { + for (int i = 0; i < parserElements.size(); i++) { + removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ + } + } else { + super.removeSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected AccessibleEditPart getAccessibleEditPart() { + if (accessibleEP == null) { + accessibleEP = new AccessibleGraphicalEditPart() { + + @Override + public void getName(AccessibleEvent e) { + e.result = getLabelTextHelper(getFigure()); + } + }; + } + return accessibleEP; + } + + /** + * @generated + */ + private View getFontStyleOwnerView() { + return getPrimaryView(); + } + + /** + * Returns the kind of associated editor for direct edition. + * + * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition + * @generated + */ + public int getDirectEditionType() { + if (checkExtendedEditor()) { + initExtendedEditorConfiguration(); + return IDirectEdition.EXTENDED_DIRECT_EDITOR; + } + if (checkDefaultEdition()) { + return IDirectEdition.DEFAULT_DIRECT_EDITOR; + } + + // not a named element. no specific editor => do nothing + return IDirectEdition.NO_DIRECT_EDITION; + } + + /** + * Checks if an extended editor is present. + * + * @return true if an extended editor is present. + * @generated + */ + protected boolean checkExtendedEditor() { + if (resolveSemanticElement() != null) { + return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); + } + return false; + } + + /** + * Checks if a default direct edition is available + * + * @return true if a default direct edition is available + * @generated + */ + protected boolean checkDefaultEdition() { + return (getParser() != null); + } + + /** + * Initializes the extended editor configuration + * + * @generated + */ + protected void initExtendedEditorConfiguration() { + if (configuration == null) { + final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("")) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); + } else { + configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); + } + } + } + + /** + * Updates the preference configuration + * + * @generated + */ + protected void updateExtendedEditorConfiguration() { + String languagePreferred = Activator.getDefault().getPreferenceStore().getString( + IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() + .eClass().getInstanceClassName()); + } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { + configuration = null; + } + } + + /** + * Performs the direct edit usually used by GMF editors. + * + * @param theRequest + * the direct edit request that starts the direct edit system + * @generated + */ + protected void performDefaultDirectEditorEdit(final Request theRequest) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + + @Override + public void run() { + if (isActive() && isEditable()) { + if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) theRequest.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { + DirectEditRequest editRequest = (DirectEditRequest) theRequest; + performDirectEdit(editRequest.getLocation()); + } else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void handleNotificationEvent(Notification event) { + Object feature = event.getFeature(); + if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { + Integer c = (Integer) event.getNewValue(); + setFontColor(DiagramColorRegistry.getInstance().getColor(c)); + } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { + refreshUnderline(); + } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { + refreshStrikeThrough(); + } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { + refreshFont(); + } else { + if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { + refreshLabel(); + } + if (getParser() instanceof ISemanticParser) { + ISemanticParser modelParser = + (ISemanticParser) getParser(); + if (modelParser.areSemanticElementsAffected(null, event)) { + removeSemanticListeners(); + if (resolveSemanticElement() != null) { + addSemanticListeners(); + } + refreshLabel(); + } + } + } + + if (event.getNewValue() instanceof EAnnotation && VisualInformationPapyrusConstants.DISPLAY_NAMELABELICON.equals(((EAnnotation) event.getNewValue()).getSource())) { + refreshLabel(); + } + super.handleNotificationEvent(event); + } + + /** + * @generated + */ + @Override + protected IFigure createFigure() { + // Parent should assign one using setLabel() method + return null; + } +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ConstraintEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ConstraintEditPart.java index 886f5ff6273..7dc64a55195 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ConstraintEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ConstraintEditPart.java @@ -23,10 +23,10 @@ import org.eclipse.gef.requests.CreateRequest; import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles; import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; -import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure; import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure; import org.eclipse.gmf.runtime.notation.View; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.IPapyrusNodeFigure; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.RoundedRectangleNodePlateFigure; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.SelectableBorderedNodeFigure; import org.eclipse.papyrus.uml.diagram.common.editparts.AbstractConstraintEditPart; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeLabelDisplayEditPolicy; @@ -198,7 +198,7 @@ public class ConstraintEditPart extends AbstractConstraintEditPart { */ @Override protected NodeFigure createNodePlate() { - DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(40, 40); + RoundedRectangleNodePlateFigure result = new RoundedRectangleNodePlateFigure(40, 40); return result; } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ConstraintEditPartCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ConstraintEditPartCN.java index 298bc883bf0..1ef2a70ad14 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ConstraintEditPartCN.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ConstraintEditPartCN.java @@ -23,10 +23,10 @@ import org.eclipse.gef.requests.CreateRequest; import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles; import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; -import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure; import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure; import org.eclipse.gmf.runtime.notation.View; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.IPapyrusNodeFigure; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.RoundedRectangleNodePlateFigure; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.SelectableBorderedNodeFigure; import org.eclipse.papyrus.uml.diagram.common.editparts.AbstractConstraintEditPart; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeLabelDisplayEditPolicy; @@ -198,7 +198,7 @@ public class ConstraintEditPartCN extends AbstractConstraintEditPart { */ @Override protected NodeFigure createNodePlate() { - DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(40, 40); + RoundedRectangleNodePlateFigure result = new RoundedRectangleNodePlateFigure(40, 40); return result; } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ConstraintNameEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ConstraintNameEditPart.java index 4b7e4711ea6..696976cf17d 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ConstraintNameEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ConstraintNameEditPart.java @@ -864,7 +864,7 @@ public class ConstraintNameEditPart extends PapyrusCompartmentEditPart implement * @generated */ protected void addOwnerElementListeners() { - addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); + addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ConstraintNameEditPartCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ConstraintNameEditPartCN.java index 77cd84fc4da..74e171e4519 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ConstraintNameEditPartCN.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ConstraintNameEditPartCN.java @@ -864,7 +864,7 @@ public class ConstraintNameEditPartCN extends PapyrusCompartmentEditPart impleme * @generated */ protected void addOwnerElementListeners() { - addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); + addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ConstraintSpecificationEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ConstraintSpecificationEditPart.java index 65b56f7e974..5e393540b53 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ConstraintSpecificationEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ConstraintSpecificationEditPart.java @@ -847,7 +847,7 @@ public class ConstraintSpecificationEditPart extends PapyrusCompartmentEditPart * @generated */ protected void addOwnerElementListeners() { - addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); + addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ConstraintSpecificationEditPartCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ConstraintSpecificationEditPartCN.java index e4a19b29154..4d54d199555 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ConstraintSpecificationEditPartCN.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ConstraintSpecificationEditPartCN.java @@ -847,7 +847,7 @@ public class ConstraintSpecificationEditPartCN extends PapyrusCompartmentEditPar * @generated */ protected void addOwnerElementListeners() { - addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); + addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DataTypeAttributeCompartmentEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DataTypeAttributeCompartmentEditPart.java index 2ad196411cc..2b2f0a0735e 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DataTypeAttributeCompartmentEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DataTypeAttributeCompartmentEditPart.java @@ -26,6 +26,7 @@ import org.eclipse.gmf.runtime.diagram.ui.editpolicies.ResizableCompartmentEditP import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.BorderDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.DuplicatePasteEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.PapyrusCreationEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.CustomDiagramDragDropEditPolicy; @@ -79,6 +80,7 @@ public class DataTypeAttributeCompartmentEditPart extends ListCompartmentEditPar installEditPolicy(DuplicatePasteEditPolicy.PASTE_ROLE, new DuplicatePasteEditPolicy()); installEditPolicy("REMOVE_ORPHAN_VIEW", new RemoveOrphanViewPolicy()); //$NON-NLS-1$ installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, new CustomDiagramDragDropEditPolicy()); + installEditPolicy(BorderDisplayEditPolicy.BORDER_DISPLAY_EDITPOLICY, new BorderDisplayEditPolicy()); } /** diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DataTypeAttributeCompartmentEditPartCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DataTypeAttributeCompartmentEditPartCN.java index ff259f05eb3..19f55266890 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DataTypeAttributeCompartmentEditPartCN.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DataTypeAttributeCompartmentEditPartCN.java @@ -26,6 +26,7 @@ import org.eclipse.gmf.runtime.diagram.ui.editpolicies.ResizableCompartmentEditP import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.BorderDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.DuplicatePasteEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.PapyrusCreationEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.CustomDiagramDragDropEditPolicy; @@ -79,6 +80,7 @@ public class DataTypeAttributeCompartmentEditPartCN extends ListCompartmentEditP installEditPolicy(DuplicatePasteEditPolicy.PASTE_ROLE, new DuplicatePasteEditPolicy()); installEditPolicy("REMOVE_ORPHAN_VIEW", new RemoveOrphanViewPolicy()); //$NON-NLS-1$ installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, new CustomDiagramDragDropEditPolicy()); + installEditPolicy(BorderDisplayEditPolicy.BORDER_DISPLAY_EDITPOLICY, new BorderDisplayEditPolicy()); } /** diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DataTypeEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DataTypeEditPart.java index df4a67c1180..417c4f7ca5a 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DataTypeEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DataTypeEditPart.java @@ -11,27 +11,38 @@ */ package org.eclipse.papyrus.uml.diagram.composite.edit.parts; +import java.util.Collections; +import java.util.List; + import org.eclipse.draw2d.IFigure; import org.eclipse.emf.common.notify.Notification; import org.eclipse.gef.EditPart; import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.GraphicalEditPart; 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.handles.MoveHandle; import org.eclipse.gef.requests.CreateRequest; import org.eclipse.gmf.runtime.diagram.core.edithelpers.CreateElementRequestAdapter; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.BorderItemSelectionEditPolicy; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles; +import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewAndElementRequest; import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; import org.eclipse.gmf.runtime.emf.type.core.IElementType; -import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure; import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure; +import org.eclipse.gmf.runtime.notation.Edge; +import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.GetChildLayoutEditPolicy; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.IPapyrusNodeFigure; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.RoundedRectangleNodePlateFigure; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.SelectableBorderedNodeFigure; -import org.eclipse.papyrus.uml.diagram.common.editparts.NamedElementEditPart; +import org.eclipse.papyrus.uml.diagram.common.editparts.RoundedCompartmentEditPart; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeNodeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.PapyrusCreationEditPolicy; @@ -39,6 +50,7 @@ import org.eclipse.papyrus.uml.diagram.common.editpolicies.QualifiedNameDisplayE import org.eclipse.papyrus.uml.diagram.common.editpolicies.ShowHideClassifierContentsEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.ShowHideCompartmentEditPolicy; import org.eclipse.papyrus.uml.diagram.common.figure.node.DataTypeFigure; +import org.eclipse.papyrus.uml.diagram.common.locator.RoundedRectangleLabelPositionLocator; import org.eclipse.papyrus.uml.diagram.composite.edit.policies.DataTypeItemSemanticEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; @@ -47,7 +59,7 @@ import org.eclipse.swt.graphics.Color; /** * @generated */ -public class DataTypeEditPart extends NamedElementEditPart { +public class DataTypeEditPart extends RoundedCompartmentEditPart { /** * @generated @@ -84,6 +96,7 @@ public class DataTypeEditPart extends NamedElementEditPart { installEditPolicy(AppliedStereotypeLabelDisplayEditPolicy.STEREOTYPE_LABEL_POLICY, new AppliedStereotypeNodeLabelDisplayEditPolicy()); installEditPolicy(ShowHideClassifierContentsEditPolicy.SHOW_HIDE_CLASSIFIER_CONTENTS_POLICY, new ShowHideClassifierContentsEditPolicy()); installEditPolicy(ShowHideCompartmentEditPolicy.SHOW_HIDE_COMPARTMENT_POLICY, new ShowHideCompartmentEditPolicy()); + installEditPolicy(EditPolicy.LAYOUT_ROLE, new GetChildLayoutEditPolicy()); // XXX need an SCR to runtime to have another abstract superclass that would let children add reasonable editpolicies // removeEditPolicy(org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles.CONNECTION_HANDLES_ROLE); } @@ -96,6 +109,20 @@ public class DataTypeEditPart extends NamedElementEditPart { @Override protected EditPolicy createChildEditPolicy(EditPart child) { + View childView = (View) child.getModel(); + switch (UMLVisualIDRegistry.getVisualID(childView)) { + case DataTypeFloatingLabelEditPart.VISUAL_ID: + return new BorderItemSelectionEditPolicy() { + + @Override + protected List createSelectionHandles() { + MoveHandle mh = new MoveHandle((GraphicalEditPart) getHost()); + mh.setBorder(null); + return Collections.singletonList(mh); + } + } + ; + } EditPolicy result = child.getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); if (result == null) { result = new NonResizableEditPolicy(); @@ -123,6 +150,19 @@ public class DataTypeEditPart extends NamedElementEditPart { **/ @Override protected void handleNotificationEvent(Notification event) { + /* + * when a node have external node labels, the methods refreshChildren() remove the EditPart corresponding to the Label from the EditPart + * Registry. After that, we can't reset the visibility to true (using the Show/Hide Label Action)! + */ + if (NotationPackage.eINSTANCE.getView_Visible().equals(event.getFeature())) { + Object notifier = event.getNotifier(); + List modelChildren = ((View) getModel()).getChildren(); + if (!(notifier instanceof Edge)) { + if (modelChildren.contains(event.getNotifier())) { + return; + } + } + } super.handleNotificationEvent(event); } @@ -225,15 +265,32 @@ public class DataTypeEditPart extends NamedElementEditPart { if (editPart instanceof DataTypeOperationCompartmentEditPart) { return getPrimaryShape().getOperationCompartmentFigure(); } + if (editPart instanceof IBorderItemEditPart) { + return getBorderedFigure().getBorderItemContainer(); + } return getContentPane(); } + /** + * @generated + */ + @Override + protected void addBorderItem(IFigure borderItemContainer, IBorderItemEditPart borderItemEditPart) { + if (borderItemEditPart instanceof DataTypeFloatingLabelEditPart) { + IBorderItemLocator locator = new RoundedRectangleLabelPositionLocator(getMainFigure()); + borderItemContainer.add(borderItemEditPart.getFigure(), locator); + } else + { + super.addBorderItem(borderItemContainer, borderItemEditPart); + } + } + /** * @generated */ @Override protected NodeFigure createNodePlate() { - DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(40, 40); + RoundedRectangleNodePlateFigure result = new RoundedRectangleNodePlateFigure(40, 40); return result; } @@ -246,7 +303,7 @@ public class DataTypeEditPart extends NamedElementEditPart { * @generated */ @Override - protected NodeFigure createNodeFigure() { + protected NodeFigure createMainFigure() { return new SelectableBorderedNodeFigure(createMainFigureWithSVG()); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DataTypeEditPartCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DataTypeEditPartCN.java index dfbf761d4f4..61ee23b44a0 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DataTypeEditPartCN.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DataTypeEditPartCN.java @@ -11,27 +11,38 @@ */ package org.eclipse.papyrus.uml.diagram.composite.edit.parts; +import java.util.Collections; +import java.util.List; + import org.eclipse.draw2d.IFigure; import org.eclipse.emf.common.notify.Notification; import org.eclipse.gef.EditPart; import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.GraphicalEditPart; 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.handles.MoveHandle; import org.eclipse.gef.requests.CreateRequest; import org.eclipse.gmf.runtime.diagram.core.edithelpers.CreateElementRequestAdapter; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.BorderItemSelectionEditPolicy; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles; +import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewAndElementRequest; import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; import org.eclipse.gmf.runtime.emf.type.core.IElementType; -import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure; import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure; +import org.eclipse.gmf.runtime.notation.Edge; +import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.GetChildLayoutEditPolicy; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.IPapyrusNodeFigure; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.RoundedRectangleNodePlateFigure; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.SelectableBorderedNodeFigure; -import org.eclipse.papyrus.uml.diagram.common.editparts.NamedElementEditPart; +import org.eclipse.papyrus.uml.diagram.common.editparts.RoundedCompartmentEditPart; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeNodeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.PapyrusCreationEditPolicy; @@ -39,6 +50,7 @@ import org.eclipse.papyrus.uml.diagram.common.editpolicies.QualifiedNameDisplayE import org.eclipse.papyrus.uml.diagram.common.editpolicies.ShowHideClassifierContentsEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.ShowHideCompartmentEditPolicy; import org.eclipse.papyrus.uml.diagram.common.figure.node.DataTypeFigure; +import org.eclipse.papyrus.uml.diagram.common.locator.RoundedRectangleLabelPositionLocator; import org.eclipse.papyrus.uml.diagram.composite.edit.policies.DataTypeItemSemanticEditPolicyCN; import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; @@ -47,7 +59,7 @@ import org.eclipse.swt.graphics.Color; /** * @generated */ -public class DataTypeEditPartCN extends NamedElementEditPart { +public class DataTypeEditPartCN extends RoundedCompartmentEditPart { /** * @generated @@ -84,6 +96,7 @@ public class DataTypeEditPartCN extends NamedElementEditPart { installEditPolicy(AppliedStereotypeLabelDisplayEditPolicy.STEREOTYPE_LABEL_POLICY, new AppliedStereotypeNodeLabelDisplayEditPolicy()); installEditPolicy(ShowHideClassifierContentsEditPolicy.SHOW_HIDE_CLASSIFIER_CONTENTS_POLICY, new ShowHideClassifierContentsEditPolicy()); installEditPolicy(ShowHideCompartmentEditPolicy.SHOW_HIDE_COMPARTMENT_POLICY, new ShowHideCompartmentEditPolicy()); + installEditPolicy(EditPolicy.LAYOUT_ROLE, new GetChildLayoutEditPolicy()); // XXX need an SCR to runtime to have another abstract superclass that would let children add reasonable editpolicies // removeEditPolicy(org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles.CONNECTION_HANDLES_ROLE); } @@ -96,6 +109,20 @@ public class DataTypeEditPartCN extends NamedElementEditPart { @Override protected EditPolicy createChildEditPolicy(EditPart child) { + View childView = (View) child.getModel(); + switch (UMLVisualIDRegistry.getVisualID(childView)) { + case DataTypeFloatingLabelEditPartCN.VISUAL_ID: + return new BorderItemSelectionEditPolicy() { + + @Override + protected List createSelectionHandles() { + MoveHandle mh = new MoveHandle((GraphicalEditPart) getHost()); + mh.setBorder(null); + return Collections.singletonList(mh); + } + } + ; + } EditPolicy result = child.getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); if (result == null) { result = new NonResizableEditPolicy(); @@ -123,6 +150,19 @@ public class DataTypeEditPartCN extends NamedElementEditPart { **/ @Override protected void handleNotificationEvent(Notification event) { + /* + * when a node have external node labels, the methods refreshChildren() remove the EditPart corresponding to the Label from the EditPart + * Registry. After that, we can't reset the visibility to true (using the Show/Hide Label Action)! + */ + if (NotationPackage.eINSTANCE.getView_Visible().equals(event.getFeature())) { + Object notifier = event.getNotifier(); + List modelChildren = ((View) getModel()).getChildren(); + if (!(notifier instanceof Edge)) { + if (modelChildren.contains(event.getNotifier())) { + return; + } + } + } super.handleNotificationEvent(event); } @@ -225,15 +265,32 @@ public class DataTypeEditPartCN extends NamedElementEditPart { if (editPart instanceof DataTypeOperationCompartmentEditPartCN) { return getPrimaryShape().getOperationCompartmentFigure(); } + if (editPart instanceof IBorderItemEditPart) { + return getBorderedFigure().getBorderItemContainer(); + } return getContentPane(); } + /** + * @generated + */ + @Override + protected void addBorderItem(IFigure borderItemContainer, IBorderItemEditPart borderItemEditPart) { + if (borderItemEditPart instanceof DataTypeFloatingLabelEditPartCN) { + IBorderItemLocator locator = new RoundedRectangleLabelPositionLocator(getMainFigure()); + borderItemContainer.add(borderItemEditPart.getFigure(), locator); + } else + { + super.addBorderItem(borderItemContainer, borderItemEditPart); + } + } + /** * @generated */ @Override protected NodeFigure createNodePlate() { - DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(40, 40); + RoundedRectangleNodePlateFigure result = new RoundedRectangleNodePlateFigure(40, 40); return result; } @@ -246,7 +303,7 @@ public class DataTypeEditPartCN extends NamedElementEditPart { * @generated */ @Override - protected NodeFigure createNodeFigure() { + protected NodeFigure createMainFigure() { return new SelectableBorderedNodeFigure(createMainFigureWithSVG()); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DataTypeFloatingLabelEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DataTypeFloatingLabelEditPart.java new file mode 100644 index 00000000000..3e2c1a0aef2 --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DataTypeFloatingLabelEditPart.java @@ -0,0 +1,860 @@ +/** + * 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.uml.diagram.composite.edit.parts; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.Label; +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.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.RunnableWithResult; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gef.AccessibleEditPart; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.Request; +import org.eclipse.gef.requests.DirectEditRequest; +import org.eclipse.gef.tools.DirectEditManager; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; +import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; +import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; +import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; +import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; +import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; +import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; +import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; +import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; +import org.eclipse.gmf.runtime.notation.FontStyle; +import org.eclipse.gmf.runtime.notation.NotationPackage; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.text.contentassist.IContentAssistProcessor; +import org.eclipse.jface.viewers.ICellEditorValidator; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.extensionpoints.editors.Activator; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; +import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; +import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.ExternalLabelPrimaryDragRoleEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.PapyrusWrappingLabel; +import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; +import org.eclipse.papyrus.uml.diagram.common.editparts.FloatingLabelEditPart; +import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; +import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; +import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; +import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.accessibility.AccessibleEvent; +import org.eclipse.swt.custom.BusyIndicator; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; +import org.eclipse.uml2.uml.Feature; + +/** + * @generated + */ +public class DataTypeFloatingLabelEditPart extends FloatingLabelEditPart + implements ITextAwareEditPart, IBorderItemEditPart +{ + + /** + * @generated + */ + public static final int VISUAL_ID = 6094; + + /** + * @generated + */ + private DirectEditManager manager; + + /** + * @generated + */ + private IParser parser; + + /** + * @generated + */ + private List parserElements; + + /** + * @generated + */ + private String defaultText; + + /** + * direct edition mode (default, undefined, registered editor, etc.) + * + * @generated + */ + protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; + + /** + * configuration from a registered edit dialog + * + * @generated + */ + protected IDirectEditorConfiguration configuration; + + + /** + * @generated + */ + static { + registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.DataTypeFloatingLabelEditPart.VISUAL_ID), new Point(0, 0)); + } + + /** + * @generated + */ + public DataTypeFloatingLabelEditPart(View view) { + super(view); + } + + /** + * @generated + */ + @Override + protected void createDefaultEditPolicies() { + super.createDefaultEditPolicies(); + installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); + installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ExternalLabelPrimaryDragRoleEditPolicy()); + } + + /** + * @generated + */ + @Override + public IBorderItemLocator getBorderItemLocator() { + IFigure parentFigure = getFigure().getParent(); + if (parentFigure != null && parentFigure.getLayoutManager() != null) { + Object constraint = parentFigure.getLayoutManager().getConstraint(getFigure()); + return (IBorderItemLocator) constraint; + } + return null; + } + + /** + * @generated + */ + @Override + public void refreshBounds() { + int x = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_X())).intValue(); + int y = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_Y())).intValue(); + int width = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Width())).intValue(); + int height = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Height())).intValue(); + getBorderItemLocator().setConstraint(new Rectangle(x, y, width, height)); + } + + + /** + * @generated + */ + protected String getLabelTextHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getText(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getText(); + } else { + return ((Label) figure).getText(); + } + } + + /** + * @generated + */ + protected void setLabelTextHelper(IFigure figure, String text) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setText(text); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setText(text); + } else { + ((Label) figure).setText(text); + } + } + + /** + * @generated + */ + protected Image getLabelIconHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getIcon(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getIcon(); + } else { + return ((Label) figure).getIcon(); + } + } + + /** + * @generated + */ + protected void setLabelIconHelper(IFigure figure, Image icon) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setIcon(icon); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setIcon(icon); + } else { + ((Label) figure).setIcon(icon); + } + } + + /** + * @generated + */ + public void setLabel(IFigure + figure) { + unregisterVisuals(); + setFigure(figure); + defaultText = getLabelTextHelper(figure); + registerVisuals(); + refreshVisuals(); + } + + /** + * @generated + */ + @Override + protected List getModelChildren() { + return Collections.EMPTY_LIST; + } + + /** + * @generated + */ + @Override + public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { + return null; + } + + /** + * @generated + */ + public void setParser(IParser parser) { + this.parser = parser; + } + + /** + * @generated + */ + protected EObject getParserElement() { + return resolveSemanticElement(); + } + + /** + * @generated + */ + protected Image getLabelIcon() { + return null; + } + + /** + * @generated + */ + protected String getLabelText() { + String text = null; + EObject parserElement = getParserElement(); + if (parserElement != null && getParser() != null) { + text = getParser().getPrintString( + new EObjectAdapter(parserElement), + getParserOptions().intValue()); + } + if (text == null || text.length() == 0) { + text = defaultText; + } + return text; + } + + /** + * @generated + */ + @Override + public void setLabelText(String text) { + setLabelTextHelper(getFigure(), text); + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + @Override + public String getEditText() { + if (getParserElement() == null || getParser() == null) { + return ""; //$NON-NLS-1$ + } + return getParser().getEditString( + new EObjectAdapter(getParserElement()), + getParserOptions().intValue()); + } + + /** + * @generated + */ + protected boolean isEditable() { + return getParser() != null; + } + + /** + * @generated + */ + @Override + public ICellEditorValidator getEditTextValidator() { + return new ICellEditorValidator() { + + @Override + public String isValid(final Object value) { + if (value instanceof String) { + final EObject element = getParserElement(); + final IParser parser = getParser(); + try { + IParserEditStatus valid = + (IParserEditStatus) getEditingDomain().runExclusive( + new RunnableWithResult.Impl() { + + @Override + public void run() { + setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); + } + }); + return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); + } catch (InterruptedException ie) { + ie.printStackTrace(); + } + } + + // shouldn't get here + return null; + } + }; + } + + /** + * @generated + */ + @Override + public IContentAssistProcessor getCompletionProcessor() { + if (getParserElement() == null || getParser() == null) { + return null; + } + return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); + } + + /** + * @generated + */ + @Override + public ParserOptions getParserOptions() { + return ParserOptions.NONE; + } + + /** + * @generated + */ + @Override + public IParser getParser() { + if (parser == null) { + parser = UMLParserProvider.getParser(UMLElementTypes.DataType_2068, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.DataTypeFloatingLabelEditPart.VISUAL_ID)); + } + return parser; + } + + /** + * @generated + */ + protected DirectEditManager getManager() { + if (manager == null) { + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + } + return manager; + } + + /** + * @generated + */ + protected void setManager(DirectEditManager manager) { + this.manager = manager; + } + + /** + * @generated + */ + protected void performDirectEdit() { + BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { + + @Override + public void run() { + getManager().show(); + } + }); + } + + /** + * @generated + */ + protected void performDirectEdit(Point eventLocation) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); + } + } + + /** + * @generated + */ + private void performDirectEdit(char initialCharacter) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(initialCharacter); + } else { + performDirectEdit(); + } + } + + /** + * @generated + */ + @Override + protected void performDirectEditRequest(Request request) { + + final Request theRequest = request; + + if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { + directEditionMode = getDirectEditionType(); + } + switch (directEditionMode) { + case IDirectEdition.NO_DIRECT_EDITION: + // no direct edition mode => does nothing + return; + case IDirectEdition.EXTENDED_DIRECT_EDITOR: + updateExtendedEditorConfiguration(); + if (configuration == null || configuration.getLanguage() == null) { + // Create default edit manager + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + performDefaultDirectEditorEdit(theRequest); + } else { + configuration.preEditAction(resolveSemanticElement()); + Dialog dialog = null; + if (configuration instanceof ICustomDirectEditorConfiguration) { + setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); + initializeDirectEditManager(theRequest); + return; + } else if (configuration instanceof IPopupEditorConfiguration) { + IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); + helper.showEditor(); + return; + } + else if (configuration instanceof IAdvancedEditorConfiguration) { + dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); + } else if (configuration instanceof IDirectEditorConfiguration) { + dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), + configuration); + } else { + return; + } + final Dialog finalDialog = dialog; + + if (Window.OK == dialog.open()) { + TransactionalEditingDomain domain = getEditingDomain(); + RecordingCommand command = new RecordingCommand(domain, "Edit Label") { + + @Override + protected void doExecute() { + configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); + + } + }; + domain.getCommandStack().execute(command); + } + } + break; + case IDirectEdition.DEFAULT_DIRECT_EDITOR: + initializeDirectEditManager(theRequest); + break; + default: + break; + } + } + + /** + * @generated + */ + protected void initializeDirectEditManager(final Request request) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + @Override + public void run() { + if (isActive() && isEditable()) { + if (request.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } + else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void refreshVisuals() { + super.refreshVisuals(); + refreshLabel(); + refreshFont(); + refreshFontColor(); + refreshUnderline(); + refreshStrikeThrough(); + } + + /** + * @generated + */ + protected void refreshLabel() { + EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); + if (maskLabelPolicy == null) { + maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); + } + if (maskLabelPolicy == null) { + View view = (View) getModel(); + if (view.isVisible()) { + setLabelTextHelper(getFigure(), getLabelText()); + setLabelIconHelper(getFigure(), getLabelIcon()); + } + else { + setLabelTextHelper(getFigure(), ""); //$NON-NLS-1$ + setLabelIconHelper(getFigure(), null); + } + } + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + protected void refreshUnderline() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); + } + if (resolveSemanticElement() instanceof Feature) { + if (((Feature) resolveSemanticElement()).isStatic()) { + ((WrappingLabel) getFigure()).setTextUnderline(true); + } + else { + ((WrappingLabel) getFigure()).setTextUnderline(false); + } + } + } + + /** + * @generated + */ + protected void refreshStrikeThrough() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); + } + } + + /** + * @generated + */ + @Override + protected void refreshFont() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null) { + FontData fontData = new FontData( + style.getFontName(), style.getFontHeight(), + (style.isBold() ? SWT.BOLD : SWT.NORMAL) | + (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); + setFont(fontData); + } + } + + /** + * @generated + */ + @Override + protected void setFontColor(Color color) { + getFigure().setForegroundColor(color); + } + + /** + * @generated + */ + @Override + protected void addSemanticListeners() { + if (getParser() instanceof ISemanticParser) { + EObject element = resolveSemanticElement(); + parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); + for (int i = 0; i < parserElements.size(); i++) { + addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ + } + } else { + super.addSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected void removeSemanticListeners() { + if (parserElements != null) { + for (int i = 0; i < parserElements.size(); i++) { + removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ + } + } else { + super.removeSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected AccessibleEditPart getAccessibleEditPart() { + if (accessibleEP == null) { + accessibleEP = new AccessibleGraphicalEditPart() { + + @Override + public void getName(AccessibleEvent e) { + e.result = getLabelTextHelper(getFigure()); + } + }; + } + return accessibleEP; + } + + /** + * @generated + */ + private View getFontStyleOwnerView() { + return getPrimaryView(); + } + + /** + * Returns the kind of associated editor for direct edition. + * + * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition + * @generated + */ + public int getDirectEditionType() { + if (checkExtendedEditor()) { + initExtendedEditorConfiguration(); + return IDirectEdition.EXTENDED_DIRECT_EDITOR; + } + if (checkDefaultEdition()) { + return IDirectEdition.DEFAULT_DIRECT_EDITOR; + } + + // not a named element. no specific editor => do nothing + return IDirectEdition.NO_DIRECT_EDITION; + } + + /** + * Checks if an extended editor is present. + * + * @return true if an extended editor is present. + * @generated + */ + protected boolean checkExtendedEditor() { + if (resolveSemanticElement() != null) { + return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); + } + return false; + } + + /** + * Checks if a default direct edition is available + * + * @return true if a default direct edition is available + * @generated + */ + protected boolean checkDefaultEdition() { + return (getParser() != null); + } + + /** + * Initializes the extended editor configuration + * + * @generated + */ + protected void initExtendedEditorConfiguration() { + if (configuration == null) { + final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("")) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); + } else { + configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); + } + } + } + + /** + * Updates the preference configuration + * + * @generated + */ + protected void updateExtendedEditorConfiguration() { + String languagePreferred = Activator.getDefault().getPreferenceStore().getString( + IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() + .eClass().getInstanceClassName()); + } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { + configuration = null; + } + } + + /** + * Performs the direct edit usually used by GMF editors. + * + * @param theRequest + * the direct edit request that starts the direct edit system + * @generated + */ + protected void performDefaultDirectEditorEdit(final Request theRequest) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + + @Override + public void run() { + if (isActive() && isEditable()) { + if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) theRequest.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { + DirectEditRequest editRequest = (DirectEditRequest) theRequest; + performDirectEdit(editRequest.getLocation()); + } else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + + /** + * @generated + */ + @Override + protected void handleNotificationEvent(Notification event) { + Object feature = event.getFeature(); + if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { + Integer c = (Integer) event.getNewValue(); + setFontColor(DiagramColorRegistry.getInstance().getColor(c)); + } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { + refreshUnderline(); + } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { + refreshStrikeThrough(); + } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { + refreshFont(); + } else { + if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { + refreshLabel(); + } + if (getParser() instanceof ISemanticParser) { + ISemanticParser modelParser = + (ISemanticParser) getParser(); + if (modelParser.areSemanticElementsAffected(null, event)) { + removeSemanticListeners(); + if (resolveSemanticElement() != null) { + addSemanticListeners(); + } + refreshLabel(); + } + } + } + super.handleNotificationEvent(event); + } + + /** + * @generated + */ + @Override + protected IFigure createFigure() { + IFigure label = createFigurePrim(); + defaultText = getLabelTextHelper(label); + return label; + } + + /** + * @generated + */ + protected IFigure createFigurePrim() { + return new PapyrusWrappingLabel(); + } + +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DataTypeFloatingLabelEditPartCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DataTypeFloatingLabelEditPartCN.java new file mode 100644 index 00000000000..82e0d29ca9f --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DataTypeFloatingLabelEditPartCN.java @@ -0,0 +1,860 @@ +/** + * 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.uml.diagram.composite.edit.parts; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.Label; +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.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.RunnableWithResult; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gef.AccessibleEditPart; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.Request; +import org.eclipse.gef.requests.DirectEditRequest; +import org.eclipse.gef.tools.DirectEditManager; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; +import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; +import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; +import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; +import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; +import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; +import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; +import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; +import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; +import org.eclipse.gmf.runtime.notation.FontStyle; +import org.eclipse.gmf.runtime.notation.NotationPackage; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.text.contentassist.IContentAssistProcessor; +import org.eclipse.jface.viewers.ICellEditorValidator; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.extensionpoints.editors.Activator; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; +import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; +import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.ExternalLabelPrimaryDragRoleEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.PapyrusWrappingLabel; +import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; +import org.eclipse.papyrus.uml.diagram.common.editparts.FloatingLabelEditPart; +import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; +import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; +import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; +import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.accessibility.AccessibleEvent; +import org.eclipse.swt.custom.BusyIndicator; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; +import org.eclipse.uml2.uml.Feature; + +/** + * @generated + */ +public class DataTypeFloatingLabelEditPartCN extends FloatingLabelEditPart + implements ITextAwareEditPart, IBorderItemEditPart +{ + + /** + * @generated + */ + public static final int VISUAL_ID = 6072; + + /** + * @generated + */ + private DirectEditManager manager; + + /** + * @generated + */ + private IParser parser; + + /** + * @generated + */ + private List parserElements; + + /** + * @generated + */ + private String defaultText; + + /** + * direct edition mode (default, undefined, registered editor, etc.) + * + * @generated + */ + protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; + + /** + * configuration from a registered edit dialog + * + * @generated + */ + protected IDirectEditorConfiguration configuration; + + + /** + * @generated + */ + static { + registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.DataTypeFloatingLabelEditPartCN.VISUAL_ID), new Point(0, 0)); + } + + /** + * @generated + */ + public DataTypeFloatingLabelEditPartCN(View view) { + super(view); + } + + /** + * @generated + */ + @Override + protected void createDefaultEditPolicies() { + super.createDefaultEditPolicies(); + installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); + installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ExternalLabelPrimaryDragRoleEditPolicy()); + } + + /** + * @generated + */ + @Override + public IBorderItemLocator getBorderItemLocator() { + IFigure parentFigure = getFigure().getParent(); + if (parentFigure != null && parentFigure.getLayoutManager() != null) { + Object constraint = parentFigure.getLayoutManager().getConstraint(getFigure()); + return (IBorderItemLocator) constraint; + } + return null; + } + + /** + * @generated + */ + @Override + public void refreshBounds() { + int x = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_X())).intValue(); + int y = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_Y())).intValue(); + int width = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Width())).intValue(); + int height = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Height())).intValue(); + getBorderItemLocator().setConstraint(new Rectangle(x, y, width, height)); + } + + + /** + * @generated + */ + protected String getLabelTextHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getText(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getText(); + } else { + return ((Label) figure).getText(); + } + } + + /** + * @generated + */ + protected void setLabelTextHelper(IFigure figure, String text) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setText(text); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setText(text); + } else { + ((Label) figure).setText(text); + } + } + + /** + * @generated + */ + protected Image getLabelIconHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getIcon(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getIcon(); + } else { + return ((Label) figure).getIcon(); + } + } + + /** + * @generated + */ + protected void setLabelIconHelper(IFigure figure, Image icon) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setIcon(icon); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setIcon(icon); + } else { + ((Label) figure).setIcon(icon); + } + } + + /** + * @generated + */ + public void setLabel(IFigure + figure) { + unregisterVisuals(); + setFigure(figure); + defaultText = getLabelTextHelper(figure); + registerVisuals(); + refreshVisuals(); + } + + /** + * @generated + */ + @Override + protected List getModelChildren() { + return Collections.EMPTY_LIST; + } + + /** + * @generated + */ + @Override + public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { + return null; + } + + /** + * @generated + */ + public void setParser(IParser parser) { + this.parser = parser; + } + + /** + * @generated + */ + protected EObject getParserElement() { + return resolveSemanticElement(); + } + + /** + * @generated + */ + protected Image getLabelIcon() { + return null; + } + + /** + * @generated + */ + protected String getLabelText() { + String text = null; + EObject parserElement = getParserElement(); + if (parserElement != null && getParser() != null) { + text = getParser().getPrintString( + new EObjectAdapter(parserElement), + getParserOptions().intValue()); + } + if (text == null || text.length() == 0) { + text = defaultText; + } + return text; + } + + /** + * @generated + */ + @Override + public void setLabelText(String text) { + setLabelTextHelper(getFigure(), text); + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + @Override + public String getEditText() { + if (getParserElement() == null || getParser() == null) { + return ""; //$NON-NLS-1$ + } + return getParser().getEditString( + new EObjectAdapter(getParserElement()), + getParserOptions().intValue()); + } + + /** + * @generated + */ + protected boolean isEditable() { + return getParser() != null; + } + + /** + * @generated + */ + @Override + public ICellEditorValidator getEditTextValidator() { + return new ICellEditorValidator() { + + @Override + public String isValid(final Object value) { + if (value instanceof String) { + final EObject element = getParserElement(); + final IParser parser = getParser(); + try { + IParserEditStatus valid = + (IParserEditStatus) getEditingDomain().runExclusive( + new RunnableWithResult.Impl() { + + @Override + public void run() { + setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); + } + }); + return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); + } catch (InterruptedException ie) { + ie.printStackTrace(); + } + } + + // shouldn't get here + return null; + } + }; + } + + /** + * @generated + */ + @Override + public IContentAssistProcessor getCompletionProcessor() { + if (getParserElement() == null || getParser() == null) { + return null; + } + return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); + } + + /** + * @generated + */ + @Override + public ParserOptions getParserOptions() { + return ParserOptions.NONE; + } + + /** + * @generated + */ + @Override + public IParser getParser() { + if (parser == null) { + parser = UMLParserProvider.getParser(UMLElementTypes.DataType_3080, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.DataTypeFloatingLabelEditPartCN.VISUAL_ID)); + } + return parser; + } + + /** + * @generated + */ + protected DirectEditManager getManager() { + if (manager == null) { + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + } + return manager; + } + + /** + * @generated + */ + protected void setManager(DirectEditManager manager) { + this.manager = manager; + } + + /** + * @generated + */ + protected void performDirectEdit() { + BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { + + @Override + public void run() { + getManager().show(); + } + }); + } + + /** + * @generated + */ + protected void performDirectEdit(Point eventLocation) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); + } + } + + /** + * @generated + */ + private void performDirectEdit(char initialCharacter) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(initialCharacter); + } else { + performDirectEdit(); + } + } + + /** + * @generated + */ + @Override + protected void performDirectEditRequest(Request request) { + + final Request theRequest = request; + + if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { + directEditionMode = getDirectEditionType(); + } + switch (directEditionMode) { + case IDirectEdition.NO_DIRECT_EDITION: + // no direct edition mode => does nothing + return; + case IDirectEdition.EXTENDED_DIRECT_EDITOR: + updateExtendedEditorConfiguration(); + if (configuration == null || configuration.getLanguage() == null) { + // Create default edit manager + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + performDefaultDirectEditorEdit(theRequest); + } else { + configuration.preEditAction(resolveSemanticElement()); + Dialog dialog = null; + if (configuration instanceof ICustomDirectEditorConfiguration) { + setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); + initializeDirectEditManager(theRequest); + return; + } else if (configuration instanceof IPopupEditorConfiguration) { + IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); + helper.showEditor(); + return; + } + else if (configuration instanceof IAdvancedEditorConfiguration) { + dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); + } else if (configuration instanceof IDirectEditorConfiguration) { + dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), + configuration); + } else { + return; + } + final Dialog finalDialog = dialog; + + if (Window.OK == dialog.open()) { + TransactionalEditingDomain domain = getEditingDomain(); + RecordingCommand command = new RecordingCommand(domain, "Edit Label") { + + @Override + protected void doExecute() { + configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); + + } + }; + domain.getCommandStack().execute(command); + } + } + break; + case IDirectEdition.DEFAULT_DIRECT_EDITOR: + initializeDirectEditManager(theRequest); + break; + default: + break; + } + } + + /** + * @generated + */ + protected void initializeDirectEditManager(final Request request) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + @Override + public void run() { + if (isActive() && isEditable()) { + if (request.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } + else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void refreshVisuals() { + super.refreshVisuals(); + refreshLabel(); + refreshFont(); + refreshFontColor(); + refreshUnderline(); + refreshStrikeThrough(); + } + + /** + * @generated + */ + protected void refreshLabel() { + EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); + if (maskLabelPolicy == null) { + maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); + } + if (maskLabelPolicy == null) { + View view = (View) getModel(); + if (view.isVisible()) { + setLabelTextHelper(getFigure(), getLabelText()); + setLabelIconHelper(getFigure(), getLabelIcon()); + } + else { + setLabelTextHelper(getFigure(), ""); //$NON-NLS-1$ + setLabelIconHelper(getFigure(), null); + } + } + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + protected void refreshUnderline() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); + } + if (resolveSemanticElement() instanceof Feature) { + if (((Feature) resolveSemanticElement()).isStatic()) { + ((WrappingLabel) getFigure()).setTextUnderline(true); + } + else { + ((WrappingLabel) getFigure()).setTextUnderline(false); + } + } + } + + /** + * @generated + */ + protected void refreshStrikeThrough() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); + } + } + + /** + * @generated + */ + @Override + protected void refreshFont() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null) { + FontData fontData = new FontData( + style.getFontName(), style.getFontHeight(), + (style.isBold() ? SWT.BOLD : SWT.NORMAL) | + (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); + setFont(fontData); + } + } + + /** + * @generated + */ + @Override + protected void setFontColor(Color color) { + getFigure().setForegroundColor(color); + } + + /** + * @generated + */ + @Override + protected void addSemanticListeners() { + if (getParser() instanceof ISemanticParser) { + EObject element = resolveSemanticElement(); + parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); + for (int i = 0; i < parserElements.size(); i++) { + addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ + } + } else { + super.addSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected void removeSemanticListeners() { + if (parserElements != null) { + for (int i = 0; i < parserElements.size(); i++) { + removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ + } + } else { + super.removeSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected AccessibleEditPart getAccessibleEditPart() { + if (accessibleEP == null) { + accessibleEP = new AccessibleGraphicalEditPart() { + + @Override + public void getName(AccessibleEvent e) { + e.result = getLabelTextHelper(getFigure()); + } + }; + } + return accessibleEP; + } + + /** + * @generated + */ + private View getFontStyleOwnerView() { + return getPrimaryView(); + } + + /** + * Returns the kind of associated editor for direct edition. + * + * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition + * @generated + */ + public int getDirectEditionType() { + if (checkExtendedEditor()) { + initExtendedEditorConfiguration(); + return IDirectEdition.EXTENDED_DIRECT_EDITOR; + } + if (checkDefaultEdition()) { + return IDirectEdition.DEFAULT_DIRECT_EDITOR; + } + + // not a named element. no specific editor => do nothing + return IDirectEdition.NO_DIRECT_EDITION; + } + + /** + * Checks if an extended editor is present. + * + * @return true if an extended editor is present. + * @generated + */ + protected boolean checkExtendedEditor() { + if (resolveSemanticElement() != null) { + return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); + } + return false; + } + + /** + * Checks if a default direct edition is available + * + * @return true if a default direct edition is available + * @generated + */ + protected boolean checkDefaultEdition() { + return (getParser() != null); + } + + /** + * Initializes the extended editor configuration + * + * @generated + */ + protected void initExtendedEditorConfiguration() { + if (configuration == null) { + final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("")) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); + } else { + configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); + } + } + } + + /** + * Updates the preference configuration + * + * @generated + */ + protected void updateExtendedEditorConfiguration() { + String languagePreferred = Activator.getDefault().getPreferenceStore().getString( + IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() + .eClass().getInstanceClassName()); + } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { + configuration = null; + } + } + + /** + * Performs the direct edit usually used by GMF editors. + * + * @param theRequest + * the direct edit request that starts the direct edit system + * @generated + */ + protected void performDefaultDirectEditorEdit(final Request theRequest) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + + @Override + public void run() { + if (isActive() && isEditable()) { + if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) theRequest.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { + DirectEditRequest editRequest = (DirectEditRequest) theRequest; + performDirectEdit(editRequest.getLocation()); + } else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + + /** + * @generated + */ + @Override + protected void handleNotificationEvent(Notification event) { + Object feature = event.getFeature(); + if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { + Integer c = (Integer) event.getNewValue(); + setFontColor(DiagramColorRegistry.getInstance().getColor(c)); + } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { + refreshUnderline(); + } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { + refreshStrikeThrough(); + } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { + refreshFont(); + } else { + if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { + refreshLabel(); + } + if (getParser() instanceof ISemanticParser) { + ISemanticParser modelParser = + (ISemanticParser) getParser(); + if (modelParser.areSemanticElementsAffected(null, event)) { + removeSemanticListeners(); + if (resolveSemanticElement() != null) { + addSemanticListeners(); + } + refreshLabel(); + } + } + } + super.handleNotificationEvent(event); + } + + /** + * @generated + */ + @Override + protected IFigure createFigure() { + IFigure label = createFigurePrim(); + defaultText = getLabelTextHelper(label); + return label; + } + + /** + * @generated + */ + protected IFigure createFigurePrim() { + return new PapyrusWrappingLabel(); + } + +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DataTypeNameEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DataTypeNameEditPart.java index 1a845f2f9c0..178f9fb4039 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DataTypeNameEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DataTypeNameEditPart.java @@ -864,7 +864,7 @@ public class DataTypeNameEditPart extends PapyrusCompartmentEditPart implements * @generated */ protected void addOwnerElementListeners() { - addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); + addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DataTypeNameEditPartCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DataTypeNameEditPartCN.java index d6aba99051b..f138924131c 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DataTypeNameEditPartCN.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DataTypeNameEditPartCN.java @@ -864,7 +864,7 @@ public class DataTypeNameEditPartCN extends PapyrusCompartmentEditPart implement * @generated */ protected void addOwnerElementListeners() { - addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); + addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DataTypeOperationCompartmentEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DataTypeOperationCompartmentEditPart.java index bc4ea1307ab..dd134687c48 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DataTypeOperationCompartmentEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DataTypeOperationCompartmentEditPart.java @@ -26,6 +26,7 @@ import org.eclipse.gmf.runtime.diagram.ui.editpolicies.ResizableCompartmentEditP import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.BorderDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.DuplicatePasteEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.PapyrusCreationEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.CustomDiagramDragDropEditPolicy; @@ -79,6 +80,7 @@ public class DataTypeOperationCompartmentEditPart extends ListCompartmentEditPar installEditPolicy(DuplicatePasteEditPolicy.PASTE_ROLE, new DuplicatePasteEditPolicy()); installEditPolicy("REMOVE_ORPHAN_VIEW", new RemoveOrphanViewPolicy()); //$NON-NLS-1$ installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, new CustomDiagramDragDropEditPolicy()); + installEditPolicy(BorderDisplayEditPolicy.BORDER_DISPLAY_EDITPOLICY, new BorderDisplayEditPolicy()); } /** diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DataTypeOperationCompartmentEditPartCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DataTypeOperationCompartmentEditPartCN.java index 969183c270b..641bd5190f1 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DataTypeOperationCompartmentEditPartCN.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DataTypeOperationCompartmentEditPartCN.java @@ -26,6 +26,7 @@ import org.eclipse.gmf.runtime.diagram.ui.editpolicies.ResizableCompartmentEditP import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.BorderDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.DuplicatePasteEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.PapyrusCreationEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.CustomDiagramDragDropEditPolicy; @@ -79,6 +80,7 @@ public class DataTypeOperationCompartmentEditPartCN extends ListCompartmentEditP installEditPolicy(DuplicatePasteEditPolicy.PASTE_ROLE, new DuplicatePasteEditPolicy()); installEditPolicy("REMOVE_ORPHAN_VIEW", new RemoveOrphanViewPolicy()); //$NON-NLS-1$ installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, new CustomDiagramDragDropEditPolicy()); + installEditPolicy(BorderDisplayEditPolicy.BORDER_DISPLAY_EDITPOLICY, new BorderDisplayEditPolicy()); } /** diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DependencyAppliedStereotypeEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DependencyAppliedStereotypeEditPart.java index 173e4795922..13dde21aa72 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DependencyAppliedStereotypeEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DependencyAppliedStereotypeEditPart.java @@ -1,820 +1,815 @@ -/** - * 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.uml.diagram.composite.edit.parts; - -import java.util.Collections; -import java.util.List; - -import org.eclipse.draw2d.ConnectionLocator; -import org.eclipse.draw2d.IFigure; -import org.eclipse.draw2d.Label; -import org.eclipse.draw2d.geometry.Point; -import org.eclipse.emf.common.notify.Notification; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.transaction.RecordingCommand; -import org.eclipse.emf.transaction.RunnableWithResult; -import org.eclipse.emf.transaction.TransactionalEditingDomain; -import org.eclipse.gef.AccessibleEditPart; -import org.eclipse.gef.EditPolicy; -import org.eclipse.gef.Request; -import org.eclipse.gef.requests.DirectEditRequest; -import org.eclipse.gef.tools.DirectEditManager; -import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; -import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; -import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; -import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; -import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; -import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; -import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; -import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; -import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; -import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; -import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; -import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; -import org.eclipse.gmf.runtime.notation.FontStyle; -import org.eclipse.gmf.runtime.notation.NotationPackage; -import org.eclipse.gmf.runtime.notation.View; -import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.jface.text.contentassist.IContentAssistProcessor; -import org.eclipse.jface.viewers.ICellEditorValidator; -import org.eclipse.jface.window.Window; -import org.eclipse.papyrus.extensionpoints.editors.Activator; -import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; -import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; -import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; -import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; -import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; -import org.eclipse.papyrus.infra.gmfdiag.common.editpart.IControlParserForDirectEdit; -import org.eclipse.papyrus.infra.gmfdiag.common.editpart.PapyrusLabelEditPart; -import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; -import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; -import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.PapyrusLinkLabelDragPolicy; -import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; -import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; -import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; -import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; -import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; -import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; -import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; -import org.eclipse.swt.SWT; -import org.eclipse.swt.accessibility.AccessibleEvent; -import org.eclipse.swt.custom.BusyIndicator; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.FontData; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.widgets.Display; -import org.eclipse.ui.PlatformUI; -import org.eclipse.uml2.uml.Feature; - -/** - * @generated - */ -public class DependencyAppliedStereotypeEditPart extends PapyrusLabelEditPart implements ITextAwareEditPart, IControlParserForDirectEdit { - - /** - * @generated - */ - public static final int VISUAL_ID = 6023; - - /** - * @generated - */ - private DirectEditManager manager; - - /** - * @generated - */ - private IParser parser; - - /** - * @generated - */ - private List parserElements; - - /** - * @generated - */ - private String defaultText; - - /** - * direct edition mode (default, undefined, registered editor, etc.) - * - * @generated - */ - protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; - - /** - * configuration from a registered edit dialog - * - * @generated - */ - protected IDirectEditorConfiguration configuration; - /** - * @generated - */ - static { - registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.DependencyAppliedStereotypeEditPart.VISUAL_ID), new Point(0, 60)); - } - - /** - * @generated - */ - public DependencyAppliedStereotypeEditPart(View view) { - super(view); - } - - /** - * @generated - */ - @Override - protected void createDefaultEditPolicies() { - super.createDefaultEditPolicies(); - installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); - installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); - installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new PapyrusLinkLabelDragPolicy()); - } - - /** - * @generated - */ - @Override - public int getKeyPoint() { - return ConnectionLocator.MIDDLE; - } - - /** - * @generated - */ - protected String getLabelTextHelper(IFigure figure) { - if (figure instanceof WrappingLabel) { - return ((WrappingLabel) figure).getText(); - } else if (figure instanceof ILabelFigure) { - return ((ILabelFigure) figure).getText(); - } else { - return ((Label) figure).getText(); - } - } - - /** - * @generated - */ - protected void setLabelTextHelper(IFigure figure, String text) { - if (figure instanceof WrappingLabel) { - ((WrappingLabel) figure).setText(text); - } else if (figure instanceof ILabelFigure) { - ((ILabelFigure) figure).setText(text); - } else { - ((Label) figure).setText(text); - } - } - - /** - * @generated - */ - protected Image getLabelIconHelper(IFigure figure) { - if (figure instanceof WrappingLabel) { - return ((WrappingLabel) figure).getIcon(); - } else if (figure instanceof ILabelFigure) { - return ((ILabelFigure) figure).getIcon(); - } else { - return ((Label) figure).getIcon(); - } - } - - /** - * @generated - */ - protected void setLabelIconHelper(IFigure figure, Image icon) { - if (figure instanceof WrappingLabel) { - ((WrappingLabel) figure).setIcon(icon); - } else if (figure instanceof ILabelFigure) { - ((ILabelFigure) figure).setIcon(icon); - } else { - ((Label) figure).setIcon(icon); - } - } - - /** - * @generated - */ - public void setLabel(IFigure - figure) { - unregisterVisuals(); - setFigure(figure); - defaultText = getLabelTextHelper(figure); - registerVisuals(); - refreshVisuals(); - } - - /** - * @generated - */ - @Override - protected List getModelChildren() { - return Collections.EMPTY_LIST; - } - - /** - * @generated - */ - @Override - public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { - return null; - } - - /** - * @generated - */ - @Override - public void setParser(IParser parser) { - this.parser = parser; - } - - /** - * @generated - */ - protected EObject getParserElement() { - return resolveSemanticElement(); - } - - /** - * @generated - */ - protected Image getLabelIcon() { - return null; - } - - /** - * @generated - */ - protected String getLabelText() { - String text = null; - EObject parserElement = getParserElement(); - if (parserElement != null && getParser() != null) { - text = getParser().getPrintString( - new EObjectAdapter(parserElement), - getParserOptions().intValue()); - } - if (text == null || text.length() == 0) { - text = defaultText; - } - return text; - } - - /** - * @generated - */ - @Override - public void setLabelText(String text) { - setLabelTextHelper(getFigure(), text); - Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); - if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); - } - Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); - if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); - } - } - - /** - * @generated - */ - @Override - public String getEditText() { - if (getParserElement() == null || getParser() == null) { - return ""; //$NON-NLS-1$ - } - return getParser().getEditString( - new EObjectAdapter(getParserElement()), - getParserOptions().intValue()); - } - - /** - * @generated - */ - protected boolean isEditable() { - return false; - } - - /** - * @generated - */ - @Override - public ICellEditorValidator getEditTextValidator() { - return new ICellEditorValidator() { - - @Override - public String isValid(final Object value) { - if (value instanceof String) { - final EObject element = getParserElement(); - final IParser parser = getParser(); - try { - IParserEditStatus valid = - (IParserEditStatus) getEditingDomain().runExclusive( - new RunnableWithResult.Impl() { - - @Override - public void run() { - setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); - } - }); - return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); - } catch (InterruptedException ie) { - ie.printStackTrace(); - } - } - - // shouldn't get here - return null; - } - }; - } - - /** - * @generated - */ - @Override - public IContentAssistProcessor getCompletionProcessor() { - if (getParserElement() == null || getParser() == null) { - return null; - } - return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); - } - - /** - * @generated - */ - @Override - public ParserOptions getParserOptions() { - return ParserOptions.NONE; - } - - /** - * @generated - */ - @Override - public IParser getParser() { - if (parser == null) { - parser = UMLParserProvider.getParser(UMLElementTypes.Dependency_4010, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.DependencyAppliedStereotypeEditPart.VISUAL_ID)); - } - return parser; - } - - /** - * @generated - */ - protected DirectEditManager getManager() { - if (manager == null) { - setManager(new MultilineLabelDirectEditManager(this, - MultilineLabelDirectEditManager.getTextCellEditorClass(this), - UMLEditPartFactory.getTextCellEditorLocator(this))); - } - return manager; - } - - /** - * @generated - */ - protected void setManager(DirectEditManager manager) { - this.manager = manager; - } - - /** - * @generated - */ - protected void performDirectEdit() { - BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { - - @Override - public void run() { - getManager().show(); - } - }); - } - - /** - * @generated - */ - protected void performDirectEdit(Point eventLocation) { - if (getManager() instanceof TextDirectEditManager) { - ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); - } - } - - /** - * @generated - */ - private void performDirectEdit(char initialCharacter) { - if (getManager() instanceof TextDirectEditManager) { - ((TextDirectEditManager) getManager()).show(initialCharacter); - } else { - performDirectEdit(); - } - } - - /** - * @generated - */ - @Override - protected void performDirectEditRequest(Request request) { - - final Request theRequest = request; - - if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { - directEditionMode = getDirectEditionType(); - } - switch (directEditionMode) { - case IDirectEdition.NO_DIRECT_EDITION: - // no direct edition mode => does nothing - return; - case IDirectEdition.EXTENDED_DIRECT_EDITOR: - updateExtendedEditorConfiguration(); - if (configuration == null || configuration.getLanguage() == null) { - // Create default edit manager - setManager(new MultilineLabelDirectEditManager(this, - MultilineLabelDirectEditManager.getTextCellEditorClass(this), - UMLEditPartFactory.getTextCellEditorLocator(this))); - performDefaultDirectEditorEdit(theRequest); - } else { - configuration.preEditAction(resolveSemanticElement()); - Dialog dialog = null; - if (configuration instanceof ICustomDirectEditorConfiguration) { - setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); - initializeDirectEditManager(theRequest); - return; - } else if (configuration instanceof IPopupEditorConfiguration) { - IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); - helper.showEditor(); - return; - } - else if (configuration instanceof IAdvancedEditorConfiguration) { - dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); - } else if (configuration instanceof IDirectEditorConfiguration) { - dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), - configuration); - } else { - return; - } - final Dialog finalDialog = dialog; - - if (Window.OK == dialog.open()) { - TransactionalEditingDomain domain = getEditingDomain(); - RecordingCommand command = new RecordingCommand(domain, "Edit Label") { - - @Override - protected void doExecute() { - configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); - - } - }; - domain.getCommandStack().execute(command); - } - } - break; - case IDirectEdition.DEFAULT_DIRECT_EDITOR: - initializeDirectEditManager(theRequest); - break; - default: - break; - } - } - - /** - * @generated - */ - protected void initializeDirectEditManager(final Request request) { - // initialize the direct edit manager - try { - getEditingDomain().runExclusive(new Runnable() { - @Override - public void run() { - if (isActive() && isEditable()) { - if (request.getExtendedData().get( - RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { - Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); - performDirectEdit(initialChar.charValue()); - } - else { - performDirectEdit(); - } - } - } - }); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - - /** - * @generated - */ - @Override - protected void refreshVisuals() { - super.refreshVisuals(); - refreshLabel(); - refreshFont(); - refreshFontColor(); - refreshUnderline(); - refreshStrikeThrough(); - } - - /** - * @generated - */ - protected void refreshLabel() { - EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); - if (maskLabelPolicy == null) { - maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); - } - if (maskLabelPolicy == null) { - View view = (View) getModel(); - if (view.isVisible()) { - setLabelTextHelper(getFigure(), getLabelText()); - setLabelIconHelper(getFigure(), getLabelIcon()); - } - else { - setLabelTextHelper(getFigure(), ""); //$NON-NLS-1$ - setLabelIconHelper(getFigure(), null); - } - } - Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); - if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); - } - Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); - if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); - } - } - - /** - * @generated - */ - protected void refreshUnderline() { - FontStyle style = - (FontStyle) getFontStyleOwnerView().getStyle( - NotationPackage.eINSTANCE.getFontStyle()); - if (style != null && getFigure() instanceof WrappingLabel) { - ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); - } - if (resolveSemanticElement() instanceof Feature) { - if (((Feature) resolveSemanticElement()).isStatic()) { - ((WrappingLabel) getFigure()).setTextUnderline(true); - } - else { - ((WrappingLabel) getFigure()).setTextUnderline(false); - } - } - } - - /** - * @generated - */ - protected void refreshStrikeThrough() { - FontStyle style = - (FontStyle) getFontStyleOwnerView().getStyle( - NotationPackage.eINSTANCE.getFontStyle()); - if (style != null && getFigure() instanceof WrappingLabel) { - ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); - } - } - - /** - * @generated - */ - @Override - protected void refreshFont() { - FontStyle style = - (FontStyle) getFontStyleOwnerView().getStyle( - NotationPackage.eINSTANCE.getFontStyle()); - if (style != null) { - FontData fontData = new FontData( - style.getFontName(), style.getFontHeight(), - (style.isBold() ? SWT.BOLD : SWT.NORMAL) | - (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); - setFont(fontData); - } - } - - /** - * @generated - */ - @Override - protected void setFontColor(Color color) { - getFigure().setForegroundColor(color); - } - - /** - * @generated - */ - @Override - protected void addSemanticListeners() { - if (getParser() instanceof ISemanticParser) { - EObject element = resolveSemanticElement(); - parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); - for (int i = 0; i < parserElements.size(); i++) { - addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ - } - } else { - super.addSemanticListeners(); - } - } - - /** - * @generated - */ - @Override - protected void removeSemanticListeners() { - if (parserElements != null) { - for (int i = 0; i < parserElements.size(); i++) { - removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ - } - } else { - super.removeSemanticListeners(); - } - } - - /** - * @generated - */ - @Override - protected AccessibleEditPart getAccessibleEditPart() { - if (accessibleEP == null) { - accessibleEP = new AccessibleGraphicalEditPart() { - - @Override - public void getName(AccessibleEvent e) { - e.result = getLabelTextHelper(getFigure()); - } - }; - } - return accessibleEP; - } - - /** - * @generated - */ - private View getFontStyleOwnerView() { - return getPrimaryView(); - } - - /** - * Returns the kind of associated editor for direct edition. - * - * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition - * @generated - */ - public int getDirectEditionType() { - // The label is read-only (defined in GMFGen model) - return IDirectEdition.NO_DIRECT_EDITION; - } - - /** - * Checks if an extended editor is present. - * - * @return true if an extended editor is present. - * @generated - */ - protected boolean checkExtendedEditor() { - if (resolveSemanticElement() != null) { - return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); - } - return false; - } - - /** - * Checks if a default direct edition is available - * - * @return true if a default direct edition is available - * @generated - */ - protected boolean checkDefaultEdition() { - return (getParser() != null); - } - - /** - * Initializes the extended editor configuration - * - * @generated - */ - protected void initExtendedEditorConfiguration() { - if (configuration == null) { - final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); - if (languagePreferred != null && !languagePreferred.equals("")) { - configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); - } else { - configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); - } - } - } - - /** - * Updates the preference configuration - * - * @generated - */ - protected void updateExtendedEditorConfiguration() { - String languagePreferred = Activator.getDefault().getPreferenceStore().getString( - IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); - if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { - configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() - .eClass().getInstanceClassName()); - } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { - configuration = null; - } - } - - /** - * Performs the direct edit usually used by GMF editors. - * - * @param theRequest - * the direct edit request that starts the direct edit system - * @generated - */ - protected void performDefaultDirectEditorEdit(final Request theRequest) { - // initialize the direct edit manager - try { - getEditingDomain().runExclusive(new Runnable() { - - @Override - public void run() { - if (isActive() && isEditable()) { - if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { - Character initialChar = (Character) theRequest.getExtendedData().get( - RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); - performDirectEdit(initialChar.charValue()); - } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { - DirectEditRequest editRequest = (DirectEditRequest) theRequest; - performDirectEdit(editRequest.getLocation()); - } else { - performDirectEdit(); - } - } - } - }); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - - /** - * @generated - */ - @Override - protected void handleNotificationEvent(Notification event) { - Object feature = event.getFeature(); - if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { - Integer c = (Integer) event.getNewValue(); - setFontColor(DiagramColorRegistry.getInstance().getColor(c)); - } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { - refreshUnderline(); - } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { - refreshStrikeThrough(); - } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || - NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || - NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || - NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { - refreshFont(); - } else { - if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { - refreshLabel(); - } - if (getParser() instanceof ISemanticParser) { - ISemanticParser modelParser = - (ISemanticParser) getParser(); - if (modelParser.areSemanticElementsAffected(null, event)) { - removeSemanticListeners(); - if (resolveSemanticElement() != null) { - addSemanticListeners(); - } - refreshLabel(); - } - } - } - - super.handleNotificationEvent(event); - } - - /** - * @generated - */ - @Override - protected IFigure createFigure() { - // Parent should assign one using setLabel() method - return 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.uml.diagram.composite.edit.parts; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.draw2d.ConnectionLocator; +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.Label; +import org.eclipse.draw2d.geometry.Point; +import org.eclipse.emf.common.notify.Notification; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.RunnableWithResult; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gef.AccessibleEditPart; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.Request; +import org.eclipse.gef.requests.DirectEditRequest; +import org.eclipse.gef.tools.DirectEditManager; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; +import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; +import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; +import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; +import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; +import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; +import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; +import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; +import org.eclipse.gmf.runtime.notation.FontStyle; +import org.eclipse.gmf.runtime.notation.NotationPackage; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.gmf.tooling.runtime.edit.policies.DefaultLinkLabelDragPolicy; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.text.contentassist.IContentAssistProcessor; +import org.eclipse.jface.viewers.ICellEditorValidator; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.extensionpoints.editors.Activator; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; +import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; +import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; +import org.eclipse.papyrus.infra.gmfdiag.common.editpart.IControlParserForDirectEdit; +import org.eclipse.papyrus.infra.gmfdiag.common.editpart.PapyrusLabelEditPart; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.PapyrusLinkLabelDragPolicy; +import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; +import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; +import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; +import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; +import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.accessibility.AccessibleEvent; +import org.eclipse.swt.custom.BusyIndicator; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; +import org.eclipse.uml2.uml.Feature; + +/** + * @generated + */ +public class DependencyAppliedStereotypeEditPart extends PapyrusLabelEditPart implements ITextAwareEditPart, IControlParserForDirectEdit { + + /** + * @generated + */ + public static final int VISUAL_ID = 6023; + + /** + * @generated + */ + private DirectEditManager manager; + + /** + * @generated + */ + private IParser parser; + + /** + * @generated + */ + private List parserElements; + + /** + * @generated + */ + private String defaultText; + + /** + * direct edition mode (default, undefined, registered editor, etc.) + * + * @generated + */ + protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; + + /** + * configuration from a registered edit dialog + * + * @generated + */ + protected IDirectEditorConfiguration configuration; + /** + * @generated + */ + static { + registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.DependencyAppliedStereotypeEditPart.VISUAL_ID), new Point(0, 60)); + } + + /** + * @generated + */ + public DependencyAppliedStereotypeEditPart(View view) { + super(view); + } + + /** + * @generated + */ + @Override + protected void createDefaultEditPolicies() { + super.createDefaultEditPolicies(); + installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); + installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new DefaultLinkLabelDragPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new PapyrusLinkLabelDragPolicy()); + } + + /** + * @generated + */ + @Override + public int getKeyPoint() { + return ConnectionLocator.MIDDLE; + } + + /** + * @generated + */ + protected String getLabelTextHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getText(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getText(); + } else { + return ((Label) figure).getText(); + } + } + + /** + * @generated + */ + protected void setLabelTextHelper(IFigure figure, String text) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setText(text); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setText(text); + } else { + ((Label) figure).setText(text); + } + } + + /** + * @generated + */ + protected Image getLabelIconHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getIcon(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getIcon(); + } else { + return ((Label) figure).getIcon(); + } + } + + /** + * @generated + */ + protected void setLabelIconHelper(IFigure figure, Image icon) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setIcon(icon); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setIcon(icon); + } else { + ((Label) figure).setIcon(icon); + } + } + + /** + * @generated + */ + public void setLabel(IFigure + figure) { + unregisterVisuals(); + setFigure(figure); + defaultText = getLabelTextHelper(figure); + registerVisuals(); + refreshVisuals(); + } + + /** + * @generated + */ + @Override + protected List getModelChildren() { + return Collections.EMPTY_LIST; + } + + /** + * @generated + */ + @Override + public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { + return null; + } + + /** + * @generated + */ + @Override + public void setParser(IParser parser) { + this.parser = parser; + } + + /** + * @generated + */ + protected EObject getParserElement() { + return resolveSemanticElement(); + } + + /** + * @generated + */ + protected Image getLabelIcon() { + return null; + } + + /** + * @generated + */ + protected String getLabelText() { + String text = null; + EObject parserElement = getParserElement(); + if (parserElement != null && getParser() != null) { + text = getParser().getPrintString( + new EObjectAdapter(parserElement), + getParserOptions().intValue()); + } + if (text == null || text.length() == 0) { + text = defaultText; + } + return text; + } + + /** + * @generated + */ + @Override + public void setLabelText(String text) { + setLabelTextHelper(getFigure(), text); + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + @Override + public String getEditText() { + if (getParserElement() == null || getParser() == null) { + return ""; //$NON-NLS-1$ + } + return getParser().getEditString( + new EObjectAdapter(getParserElement()), + getParserOptions().intValue()); + } + + /** + * @generated + */ + protected boolean isEditable() { + return false; + } + + /** + * @generated + */ + @Override + public ICellEditorValidator getEditTextValidator() { + return new ICellEditorValidator() { + + @Override + public String isValid(final Object value) { + if (value instanceof String) { + final EObject element = getParserElement(); + final IParser parser = getParser(); + try { + IParserEditStatus valid = + (IParserEditStatus) getEditingDomain().runExclusive( + new RunnableWithResult.Impl() { + + @Override + public void run() { + setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); + } + }); + return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); + } catch (InterruptedException ie) { + ie.printStackTrace(); + } + } + + // shouldn't get here + return null; + } + }; + } + + /** + * @generated + */ + @Override + public IContentAssistProcessor getCompletionProcessor() { + if (getParserElement() == null || getParser() == null) { + return null; + } + return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); + } + + /** + * @generated + */ + @Override + public ParserOptions getParserOptions() { + return ParserOptions.NONE; + } + + /** + * @generated + */ + @Override + public IParser getParser() { + if (parser == null) { + parser = UMLParserProvider.getParser(UMLElementTypes.Dependency_4010, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.DependencyAppliedStereotypeEditPart.VISUAL_ID)); + } + return parser; + } + + /** + * @generated + */ + protected DirectEditManager getManager() { + if (manager == null) { + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + } + return manager; + } + + /** + * @generated + */ + protected void setManager(DirectEditManager manager) { + this.manager = manager; + } + + /** + * @generated + */ + protected void performDirectEdit() { + BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { + + @Override + public void run() { + getManager().show(); + } + }); + } + + /** + * @generated + */ + protected void performDirectEdit(Point eventLocation) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); + } + } + + /** + * @generated + */ + private void performDirectEdit(char initialCharacter) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(initialCharacter); + } else { + performDirectEdit(); + } + } + + /** + * @generated + */ + @Override + protected void performDirectEditRequest(Request request) { + + final Request theRequest = request; + + if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { + directEditionMode = getDirectEditionType(); + } + switch (directEditionMode) { + case IDirectEdition.NO_DIRECT_EDITION: + // no direct edition mode => does nothing + return; + case IDirectEdition.EXTENDED_DIRECT_EDITOR: + updateExtendedEditorConfiguration(); + if (configuration == null || configuration.getLanguage() == null) { + // Create default edit manager + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + performDefaultDirectEditorEdit(theRequest); + } else { + configuration.preEditAction(resolveSemanticElement()); + Dialog dialog = null; + if (configuration instanceof ICustomDirectEditorConfiguration) { + setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); + initializeDirectEditManager(theRequest); + return; + } else if (configuration instanceof IPopupEditorConfiguration) { + IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); + helper.showEditor(); + return; + } + else if (configuration instanceof IAdvancedEditorConfiguration) { + dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); + } else if (configuration instanceof IDirectEditorConfiguration) { + dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), + configuration); + } else { + return; + } + final Dialog finalDialog = dialog; + + if (Window.OK == dialog.open()) { + TransactionalEditingDomain domain = getEditingDomain(); + RecordingCommand command = new RecordingCommand(domain, "Edit Label") { + + @Override + protected void doExecute() { + configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); + + } + }; + domain.getCommandStack().execute(command); + } + } + break; + case IDirectEdition.DEFAULT_DIRECT_EDITOR: + initializeDirectEditManager(theRequest); + break; + default: + break; + } + } + + /** + * @generated + */ + protected void initializeDirectEditManager(final Request request) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + @Override + public void run() { + if (isActive() && isEditable()) { + if (request.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } + else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void refreshVisuals() { + super.refreshVisuals(); + refreshLabel(); + refreshFont(); + refreshFontColor(); + refreshUnderline(); + refreshStrikeThrough(); + } + + /** + * @generated + */ + protected void refreshLabel() { + EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); + if (maskLabelPolicy == null) { + maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); + } + if (maskLabelPolicy == null) { + setLabelTextHelper(getFigure(), getLabelText()); + setLabelIconHelper(getFigure(), getLabelIcon()); + } + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + protected void refreshUnderline() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); + } + if (resolveSemanticElement() instanceof Feature) { + if (((Feature) resolveSemanticElement()).isStatic()) { + ((WrappingLabel) getFigure()).setTextUnderline(true); + } + else { + ((WrappingLabel) getFigure()).setTextUnderline(false); + } + } + } + + /** + * @generated + */ + protected void refreshStrikeThrough() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); + } + } + + /** + * @generated + */ + @Override + protected void refreshFont() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null) { + FontData fontData = new FontData( + style.getFontName(), style.getFontHeight(), + (style.isBold() ? SWT.BOLD : SWT.NORMAL) | + (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); + setFont(fontData); + } + } + + /** + * @generated + */ + @Override + protected void setFontColor(Color color) { + getFigure().setForegroundColor(color); + } + + /** + * @generated + */ + @Override + protected void addSemanticListeners() { + if (getParser() instanceof ISemanticParser) { + EObject element = resolveSemanticElement(); + parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); + for (int i = 0; i < parserElements.size(); i++) { + addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ + } + } else { + super.addSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected void removeSemanticListeners() { + if (parserElements != null) { + for (int i = 0; i < parserElements.size(); i++) { + removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ + } + } else { + super.removeSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected AccessibleEditPart getAccessibleEditPart() { + if (accessibleEP == null) { + accessibleEP = new AccessibleGraphicalEditPart() { + + @Override + public void getName(AccessibleEvent e) { + e.result = getLabelTextHelper(getFigure()); + } + }; + } + return accessibleEP; + } + + /** + * @generated + */ + private View getFontStyleOwnerView() { + return getPrimaryView(); + } + + /** + * Returns the kind of associated editor for direct edition. + * + * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition + * @generated + */ + public int getDirectEditionType() { + // The label is read-only (defined in GMFGen model) + return IDirectEdition.NO_DIRECT_EDITION; + } + + /** + * Checks if an extended editor is present. + * + * @return true if an extended editor is present. + * @generated + */ + protected boolean checkExtendedEditor() { + if (resolveSemanticElement() != null) { + return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); + } + return false; + } + + /** + * Checks if a default direct edition is available + * + * @return true if a default direct edition is available + * @generated + */ + protected boolean checkDefaultEdition() { + return (getParser() != null); + } + + /** + * Initializes the extended editor configuration + * + * @generated + */ + protected void initExtendedEditorConfiguration() { + if (configuration == null) { + final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("")) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); + } else { + configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); + } + } + } + + /** + * Updates the preference configuration + * + * @generated + */ + protected void updateExtendedEditorConfiguration() { + String languagePreferred = Activator.getDefault().getPreferenceStore().getString( + IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() + .eClass().getInstanceClassName()); + } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { + configuration = null; + } + } + + /** + * Performs the direct edit usually used by GMF editors. + * + * @param theRequest + * the direct edit request that starts the direct edit system + * @generated + */ + protected void performDefaultDirectEditorEdit(final Request theRequest) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + + @Override + public void run() { + if (isActive() && isEditable()) { + if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) theRequest.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { + DirectEditRequest editRequest = (DirectEditRequest) theRequest; + performDirectEdit(editRequest.getLocation()); + } else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void handleNotificationEvent(Notification event) { + Object feature = event.getFeature(); + if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { + Integer c = (Integer) event.getNewValue(); + setFontColor(DiagramColorRegistry.getInstance().getColor(c)); + } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { + refreshUnderline(); + } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { + refreshStrikeThrough(); + } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { + refreshFont(); + } else { + if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { + refreshLabel(); + } + if (getParser() instanceof ISemanticParser) { + ISemanticParser modelParser = + (ISemanticParser) getParser(); + if (modelParser.areSemanticElementsAffected(null, event)) { + removeSemanticListeners(); + if (resolveSemanticElement() != null) { + addSemanticListeners(); + } + refreshLabel(); + } + } + } + + super.handleNotificationEvent(event); + } + + /** + * @generated + */ + @Override + protected IFigure createFigure() { + // Parent should assign one using setLabel() method + return null; + } +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DependencyNameEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DependencyNameEditPart.java index 746472bf595..a07313f373a 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DependencyNameEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DependencyNameEditPart.java @@ -1,828 +1,823 @@ -/** - * 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.uml.diagram.composite.edit.parts; - -import java.util.Collections; -import java.util.List; - -import org.eclipse.draw2d.ConnectionLocator; -import org.eclipse.draw2d.IFigure; -import org.eclipse.draw2d.Label; -import org.eclipse.draw2d.geometry.Point; -import org.eclipse.emf.common.notify.Notification; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.transaction.RecordingCommand; -import org.eclipse.emf.transaction.RunnableWithResult; -import org.eclipse.emf.transaction.TransactionalEditingDomain; -import org.eclipse.gef.AccessibleEditPart; -import org.eclipse.gef.EditPolicy; -import org.eclipse.gef.Request; -import org.eclipse.gef.requests.DirectEditRequest; -import org.eclipse.gef.tools.DirectEditManager; -import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; -import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; -import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; -import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; -import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; -import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; -import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; -import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; -import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; -import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; -import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; -import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; -import org.eclipse.gmf.runtime.notation.FontStyle; -import org.eclipse.gmf.runtime.notation.NotationPackage; -import org.eclipse.gmf.runtime.notation.View; -import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.jface.text.contentassist.IContentAssistProcessor; -import org.eclipse.jface.viewers.ICellEditorValidator; -import org.eclipse.jface.window.Window; -import org.eclipse.papyrus.extensionpoints.editors.Activator; -import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; -import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; -import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; -import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; -import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; -import org.eclipse.papyrus.infra.gmfdiag.common.editpart.IControlParserForDirectEdit; -import org.eclipse.papyrus.infra.gmfdiag.common.editpart.PapyrusLabelEditPart; -import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; -import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; -import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.PapyrusLinkLabelDragPolicy; -import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; -import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; -import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; -import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; -import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; -import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; -import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; -import org.eclipse.swt.SWT; -import org.eclipse.swt.accessibility.AccessibleEvent; -import org.eclipse.swt.custom.BusyIndicator; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.FontData; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.widgets.Display; -import org.eclipse.ui.PlatformUI; -import org.eclipse.uml2.uml.Feature; - -/** - * @generated - */ -public class DependencyNameEditPart extends PapyrusLabelEditPart implements ITextAwareEditPart, IControlParserForDirectEdit { - - /** - * @generated - */ - public static final int VISUAL_ID = 6009; - - /** - * @generated - */ - private DirectEditManager manager; - - /** - * @generated - */ - private IParser parser; - - /** - * @generated - */ - private List parserElements; - - /** - * @generated - */ - private String defaultText; - - /** - * direct edition mode (default, undefined, registered editor, etc.) - * - * @generated - */ - protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; - - /** - * configuration from a registered edit dialog - * - * @generated - */ - protected IDirectEditorConfiguration configuration; - /** - * @generated - */ - static { - registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.DependencyNameEditPart.VISUAL_ID), new Point(0, 60)); - } - - /** - * @generated - */ - public DependencyNameEditPart(View view) { - super(view); - } - - /** - * @generated - */ - @Override - protected void createDefaultEditPolicies() { - super.createDefaultEditPolicies(); - installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); - installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); - installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new PapyrusLinkLabelDragPolicy()); - } - - /** - * @generated - */ - @Override - public int getKeyPoint() { - return ConnectionLocator.MIDDLE; - } - - /** - * @generated - */ - protected String getLabelTextHelper(IFigure figure) { - if (figure instanceof WrappingLabel) { - return ((WrappingLabel) figure).getText(); - } else if (figure instanceof ILabelFigure) { - return ((ILabelFigure) figure).getText(); - } else { - return ((Label) figure).getText(); - } - } - - /** - * @generated - */ - protected void setLabelTextHelper(IFigure figure, String text) { - if (figure instanceof WrappingLabel) { - ((WrappingLabel) figure).setText(text); - } else if (figure instanceof ILabelFigure) { - ((ILabelFigure) figure).setText(text); - } else { - ((Label) figure).setText(text); - } - } - - /** - * @generated - */ - protected Image getLabelIconHelper(IFigure figure) { - if (figure instanceof WrappingLabel) { - return ((WrappingLabel) figure).getIcon(); - } else if (figure instanceof ILabelFigure) { - return ((ILabelFigure) figure).getIcon(); - } else { - return ((Label) figure).getIcon(); - } - } - - /** - * @generated - */ - protected void setLabelIconHelper(IFigure figure, Image icon) { - if (figure instanceof WrappingLabel) { - ((WrappingLabel) figure).setIcon(icon); - } else if (figure instanceof ILabelFigure) { - ((ILabelFigure) figure).setIcon(icon); - } else { - ((Label) figure).setIcon(icon); - } - } - - /** - * @generated - */ - public void setLabel(IFigure - figure) { - unregisterVisuals(); - setFigure(figure); - defaultText = getLabelTextHelper(figure); - registerVisuals(); - refreshVisuals(); - } - - /** - * @generated - */ - @Override - protected List getModelChildren() { - return Collections.EMPTY_LIST; - } - - /** - * @generated - */ - @Override - public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { - return null; - } - - /** - * @generated - */ - @Override - public void setParser(IParser parser) { - this.parser = parser; - } - - /** - * @generated - */ - protected EObject getParserElement() { - return resolveSemanticElement(); - } - - /** - * @generated - */ - protected Image getLabelIcon() { - return null; - } - - /** - * @generated - */ - protected String getLabelText() { - String text = null; - EObject parserElement = getParserElement(); - if (parserElement != null && getParser() != null) { - text = getParser().getPrintString( - new EObjectAdapter(parserElement), - getParserOptions().intValue()); - } - if (text == null || text.length() == 0) { - text = defaultText; - } - return text; - } - - /** - * @generated - */ - @Override - public void setLabelText(String text) { - setLabelTextHelper(getFigure(), text); - Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); - if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); - } - Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); - if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); - } - } - - /** - * @generated - */ - @Override - public String getEditText() { - if (getParserElement() == null || getParser() == null) { - return ""; //$NON-NLS-1$ - } - return getParser().getEditString( - new EObjectAdapter(getParserElement()), - getParserOptions().intValue()); - } - - /** - * @generated - */ - protected boolean isEditable() { - return getParser() != null; - } - - /** - * @generated - */ - @Override - public ICellEditorValidator getEditTextValidator() { - return new ICellEditorValidator() { - - @Override - public String isValid(final Object value) { - if (value instanceof String) { - final EObject element = getParserElement(); - final IParser parser = getParser(); - try { - IParserEditStatus valid = - (IParserEditStatus) getEditingDomain().runExclusive( - new RunnableWithResult.Impl() { - - @Override - public void run() { - setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); - } - }); - return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); - } catch (InterruptedException ie) { - ie.printStackTrace(); - } - } - - // shouldn't get here - return null; - } - }; - } - - /** - * @generated - */ - @Override - public IContentAssistProcessor getCompletionProcessor() { - if (getParserElement() == null || getParser() == null) { - return null; - } - return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); - } - - /** - * @generated - */ - @Override - public ParserOptions getParserOptions() { - return ParserOptions.NONE; - } - - /** - * @generated - */ - @Override - public IParser getParser() { - if (parser == null) { - parser = UMLParserProvider.getParser(UMLElementTypes.Dependency_4010, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.DependencyNameEditPart.VISUAL_ID)); - } - return parser; - } - - /** - * @generated - */ - protected DirectEditManager getManager() { - if (manager == null) { - setManager(new MultilineLabelDirectEditManager(this, - MultilineLabelDirectEditManager.getTextCellEditorClass(this), - UMLEditPartFactory.getTextCellEditorLocator(this))); - } - return manager; - } - - /** - * @generated - */ - protected void setManager(DirectEditManager manager) { - this.manager = manager; - } - - /** - * @generated - */ - protected void performDirectEdit() { - BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { - - @Override - public void run() { - getManager().show(); - } - }); - } - - /** - * @generated - */ - protected void performDirectEdit(Point eventLocation) { - if (getManager() instanceof TextDirectEditManager) { - ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); - } - } - - /** - * @generated - */ - private void performDirectEdit(char initialCharacter) { - if (getManager() instanceof TextDirectEditManager) { - ((TextDirectEditManager) getManager()).show(initialCharacter); - } else { - performDirectEdit(); - } - } - - /** - * @generated - */ - @Override - protected void performDirectEditRequest(Request request) { - - final Request theRequest = request; - - if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { - directEditionMode = getDirectEditionType(); - } - switch (directEditionMode) { - case IDirectEdition.NO_DIRECT_EDITION: - // no direct edition mode => does nothing - return; - case IDirectEdition.EXTENDED_DIRECT_EDITOR: - updateExtendedEditorConfiguration(); - if (configuration == null || configuration.getLanguage() == null) { - // Create default edit manager - setManager(new MultilineLabelDirectEditManager(this, - MultilineLabelDirectEditManager.getTextCellEditorClass(this), - UMLEditPartFactory.getTextCellEditorLocator(this))); - performDefaultDirectEditorEdit(theRequest); - } else { - configuration.preEditAction(resolveSemanticElement()); - Dialog dialog = null; - if (configuration instanceof ICustomDirectEditorConfiguration) { - setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); - initializeDirectEditManager(theRequest); - return; - } else if (configuration instanceof IPopupEditorConfiguration) { - IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); - helper.showEditor(); - return; - } - else if (configuration instanceof IAdvancedEditorConfiguration) { - dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); - } else if (configuration instanceof IDirectEditorConfiguration) { - dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), - configuration); - } else { - return; - } - final Dialog finalDialog = dialog; - - if (Window.OK == dialog.open()) { - TransactionalEditingDomain domain = getEditingDomain(); - RecordingCommand command = new RecordingCommand(domain, "Edit Label") { - - @Override - protected void doExecute() { - configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); - - } - }; - domain.getCommandStack().execute(command); - } - } - break; - case IDirectEdition.DEFAULT_DIRECT_EDITOR: - initializeDirectEditManager(theRequest); - break; - default: - break; - } - } - - /** - * @generated - */ - protected void initializeDirectEditManager(final Request request) { - // initialize the direct edit manager - try { - getEditingDomain().runExclusive(new Runnable() { - @Override - public void run() { - if (isActive() && isEditable()) { - if (request.getExtendedData().get( - RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { - Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); - performDirectEdit(initialChar.charValue()); - } - else { - performDirectEdit(); - } - } - } - }); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - - /** - * @generated - */ - @Override - protected void refreshVisuals() { - super.refreshVisuals(); - refreshLabel(); - refreshFont(); - refreshFontColor(); - refreshUnderline(); - refreshStrikeThrough(); - } - - /** - * @generated - */ - protected void refreshLabel() { - EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); - if (maskLabelPolicy == null) { - maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); - } - if (maskLabelPolicy == null) { - View view = (View) getModel(); - if (view.isVisible()) { - setLabelTextHelper(getFigure(), getLabelText()); - setLabelIconHelper(getFigure(), getLabelIcon()); - } - else { - setLabelTextHelper(getFigure(), ""); //$NON-NLS-1$ - setLabelIconHelper(getFigure(), null); - } - } - Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); - if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); - } - Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); - if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); - } - } - - /** - * @generated - */ - protected void refreshUnderline() { - FontStyle style = - (FontStyle) getFontStyleOwnerView().getStyle( - NotationPackage.eINSTANCE.getFontStyle()); - if (style != null && getFigure() instanceof WrappingLabel) { - ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); - } - if (resolveSemanticElement() instanceof Feature) { - if (((Feature) resolveSemanticElement()).isStatic()) { - ((WrappingLabel) getFigure()).setTextUnderline(true); - } - else { - ((WrappingLabel) getFigure()).setTextUnderline(false); - } - } - } - - /** - * @generated - */ - protected void refreshStrikeThrough() { - FontStyle style = - (FontStyle) getFontStyleOwnerView().getStyle( - NotationPackage.eINSTANCE.getFontStyle()); - if (style != null && getFigure() instanceof WrappingLabel) { - ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); - } - } - - /** - * @generated - */ - @Override - protected void refreshFont() { - FontStyle style = - (FontStyle) getFontStyleOwnerView().getStyle( - NotationPackage.eINSTANCE.getFontStyle()); - if (style != null) { - FontData fontData = new FontData( - style.getFontName(), style.getFontHeight(), - (style.isBold() ? SWT.BOLD : SWT.NORMAL) | - (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); - setFont(fontData); - } - } - - /** - * @generated - */ - @Override - protected void setFontColor(Color color) { - getFigure().setForegroundColor(color); - } - - /** - * @generated - */ - @Override - protected void addSemanticListeners() { - if (getParser() instanceof ISemanticParser) { - EObject element = resolveSemanticElement(); - parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); - for (int i = 0; i < parserElements.size(); i++) { - addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ - } - } else { - super.addSemanticListeners(); - } - } - - /** - * @generated - */ - @Override - protected void removeSemanticListeners() { - if (parserElements != null) { - for (int i = 0; i < parserElements.size(); i++) { - removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ - } - } else { - super.removeSemanticListeners(); - } - } - - /** - * @generated - */ - @Override - protected AccessibleEditPart getAccessibleEditPart() { - if (accessibleEP == null) { - accessibleEP = new AccessibleGraphicalEditPart() { - - @Override - public void getName(AccessibleEvent e) { - e.result = getLabelTextHelper(getFigure()); - } - }; - } - return accessibleEP; - } - - /** - * @generated - */ - private View getFontStyleOwnerView() { - return getPrimaryView(); - } - - /** - * Returns the kind of associated editor for direct edition. - * - * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition - * @generated - */ - public int getDirectEditionType() { - if (checkExtendedEditor()) { - initExtendedEditorConfiguration(); - return IDirectEdition.EXTENDED_DIRECT_EDITOR; - } - if (checkDefaultEdition()) { - return IDirectEdition.DEFAULT_DIRECT_EDITOR; - } - - // not a named element. no specific editor => do nothing - return IDirectEdition.NO_DIRECT_EDITION; - } - - /** - * Checks if an extended editor is present. - * - * @return true if an extended editor is present. - * @generated - */ - protected boolean checkExtendedEditor() { - if (resolveSemanticElement() != null) { - return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); - } - return false; - } - - /** - * Checks if a default direct edition is available - * - * @return true if a default direct edition is available - * @generated - */ - protected boolean checkDefaultEdition() { - return (getParser() != null); - } - - /** - * Initializes the extended editor configuration - * - * @generated - */ - protected void initExtendedEditorConfiguration() { - if (configuration == null) { - final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); - if (languagePreferred != null && !languagePreferred.equals("")) { - configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); - } else { - configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); - } - } - } - - /** - * Updates the preference configuration - * - * @generated - */ - protected void updateExtendedEditorConfiguration() { - String languagePreferred = Activator.getDefault().getPreferenceStore().getString( - IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); - if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { - configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() - .eClass().getInstanceClassName()); - } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { - configuration = null; - } - } - - /** - * Performs the direct edit usually used by GMF editors. - * - * @param theRequest - * the direct edit request that starts the direct edit system - * @generated - */ - protected void performDefaultDirectEditorEdit(final Request theRequest) { - // initialize the direct edit manager - try { - getEditingDomain().runExclusive(new Runnable() { - - @Override - public void run() { - if (isActive() && isEditable()) { - if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { - Character initialChar = (Character) theRequest.getExtendedData().get( - RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); - performDirectEdit(initialChar.charValue()); - } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { - DirectEditRequest editRequest = (DirectEditRequest) theRequest; - performDirectEdit(editRequest.getLocation()); - } else { - performDirectEdit(); - } - } - } - }); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - - /** - * @generated - */ - @Override - protected void handleNotificationEvent(Notification event) { - Object feature = event.getFeature(); - if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { - Integer c = (Integer) event.getNewValue(); - setFontColor(DiagramColorRegistry.getInstance().getColor(c)); - } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { - refreshUnderline(); - } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { - refreshStrikeThrough(); - } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || - NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || - NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || - NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { - refreshFont(); - } else { - if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { - refreshLabel(); - } - if (getParser() instanceof ISemanticParser) { - ISemanticParser modelParser = - (ISemanticParser) getParser(); - if (modelParser.areSemanticElementsAffected(null, event)) { - removeSemanticListeners(); - if (resolveSemanticElement() != null) { - addSemanticListeners(); - } - refreshLabel(); - } - } - } - - super.handleNotificationEvent(event); - } - - /** - * @generated - */ - @Override - protected IFigure createFigure() { - // Parent should assign one using setLabel() method - return 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.uml.diagram.composite.edit.parts; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.draw2d.ConnectionLocator; +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.Label; +import org.eclipse.draw2d.geometry.Point; +import org.eclipse.emf.common.notify.Notification; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.RunnableWithResult; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gef.AccessibleEditPart; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.Request; +import org.eclipse.gef.requests.DirectEditRequest; +import org.eclipse.gef.tools.DirectEditManager; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; +import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; +import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; +import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; +import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; +import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; +import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; +import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; +import org.eclipse.gmf.runtime.notation.FontStyle; +import org.eclipse.gmf.runtime.notation.NotationPackage; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.gmf.tooling.runtime.edit.policies.DefaultLinkLabelDragPolicy; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.text.contentassist.IContentAssistProcessor; +import org.eclipse.jface.viewers.ICellEditorValidator; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.extensionpoints.editors.Activator; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; +import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; +import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; +import org.eclipse.papyrus.infra.gmfdiag.common.editpart.IControlParserForDirectEdit; +import org.eclipse.papyrus.infra.gmfdiag.common.editpart.PapyrusLabelEditPart; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.PapyrusLinkLabelDragPolicy; +import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; +import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; +import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; +import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; +import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.accessibility.AccessibleEvent; +import org.eclipse.swt.custom.BusyIndicator; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; +import org.eclipse.uml2.uml.Feature; + +/** + * @generated + */ +public class DependencyNameEditPart extends PapyrusLabelEditPart implements ITextAwareEditPart, IControlParserForDirectEdit { + + /** + * @generated + */ + public static final int VISUAL_ID = 6009; + + /** + * @generated + */ + private DirectEditManager manager; + + /** + * @generated + */ + private IParser parser; + + /** + * @generated + */ + private List parserElements; + + /** + * @generated + */ + private String defaultText; + + /** + * direct edition mode (default, undefined, registered editor, etc.) + * + * @generated + */ + protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; + + /** + * configuration from a registered edit dialog + * + * @generated + */ + protected IDirectEditorConfiguration configuration; + /** + * @generated + */ + static { + registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.DependencyNameEditPart.VISUAL_ID), new Point(0, 60)); + } + + /** + * @generated + */ + public DependencyNameEditPart(View view) { + super(view); + } + + /** + * @generated + */ + @Override + protected void createDefaultEditPolicies() { + super.createDefaultEditPolicies(); + installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); + installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new DefaultLinkLabelDragPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new PapyrusLinkLabelDragPolicy()); + } + + /** + * @generated + */ + @Override + public int getKeyPoint() { + return ConnectionLocator.MIDDLE; + } + + /** + * @generated + */ + protected String getLabelTextHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getText(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getText(); + } else { + return ((Label) figure).getText(); + } + } + + /** + * @generated + */ + protected void setLabelTextHelper(IFigure figure, String text) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setText(text); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setText(text); + } else { + ((Label) figure).setText(text); + } + } + + /** + * @generated + */ + protected Image getLabelIconHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getIcon(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getIcon(); + } else { + return ((Label) figure).getIcon(); + } + } + + /** + * @generated + */ + protected void setLabelIconHelper(IFigure figure, Image icon) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setIcon(icon); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setIcon(icon); + } else { + ((Label) figure).setIcon(icon); + } + } + + /** + * @generated + */ + public void setLabel(IFigure + figure) { + unregisterVisuals(); + setFigure(figure); + defaultText = getLabelTextHelper(figure); + registerVisuals(); + refreshVisuals(); + } + + /** + * @generated + */ + @Override + protected List getModelChildren() { + return Collections.EMPTY_LIST; + } + + /** + * @generated + */ + @Override + public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { + return null; + } + + /** + * @generated + */ + @Override + public void setParser(IParser parser) { + this.parser = parser; + } + + /** + * @generated + */ + protected EObject getParserElement() { + return resolveSemanticElement(); + } + + /** + * @generated + */ + protected Image getLabelIcon() { + return null; + } + + /** + * @generated + */ + protected String getLabelText() { + String text = null; + EObject parserElement = getParserElement(); + if (parserElement != null && getParser() != null) { + text = getParser().getPrintString( + new EObjectAdapter(parserElement), + getParserOptions().intValue()); + } + if (text == null || text.length() == 0) { + text = defaultText; + } + return text; + } + + /** + * @generated + */ + @Override + public void setLabelText(String text) { + setLabelTextHelper(getFigure(), text); + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + @Override + public String getEditText() { + if (getParserElement() == null || getParser() == null) { + return ""; //$NON-NLS-1$ + } + return getParser().getEditString( + new EObjectAdapter(getParserElement()), + getParserOptions().intValue()); + } + + /** + * @generated + */ + protected boolean isEditable() { + return getParser() != null; + } + + /** + * @generated + */ + @Override + public ICellEditorValidator getEditTextValidator() { + return new ICellEditorValidator() { + + @Override + public String isValid(final Object value) { + if (value instanceof String) { + final EObject element = getParserElement(); + final IParser parser = getParser(); + try { + IParserEditStatus valid = + (IParserEditStatus) getEditingDomain().runExclusive( + new RunnableWithResult.Impl() { + + @Override + public void run() { + setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); + } + }); + return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); + } catch (InterruptedException ie) { + ie.printStackTrace(); + } + } + + // shouldn't get here + return null; + } + }; + } + + /** + * @generated + */ + @Override + public IContentAssistProcessor getCompletionProcessor() { + if (getParserElement() == null || getParser() == null) { + return null; + } + return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); + } + + /** + * @generated + */ + @Override + public ParserOptions getParserOptions() { + return ParserOptions.NONE; + } + + /** + * @generated + */ + @Override + public IParser getParser() { + if (parser == null) { + parser = UMLParserProvider.getParser(UMLElementTypes.Dependency_4010, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.DependencyNameEditPart.VISUAL_ID)); + } + return parser; + } + + /** + * @generated + */ + protected DirectEditManager getManager() { + if (manager == null) { + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + } + return manager; + } + + /** + * @generated + */ + protected void setManager(DirectEditManager manager) { + this.manager = manager; + } + + /** + * @generated + */ + protected void performDirectEdit() { + BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { + + @Override + public void run() { + getManager().show(); + } + }); + } + + /** + * @generated + */ + protected void performDirectEdit(Point eventLocation) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); + } + } + + /** + * @generated + */ + private void performDirectEdit(char initialCharacter) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(initialCharacter); + } else { + performDirectEdit(); + } + } + + /** + * @generated + */ + @Override + protected void performDirectEditRequest(Request request) { + + final Request theRequest = request; + + if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { + directEditionMode = getDirectEditionType(); + } + switch (directEditionMode) { + case IDirectEdition.NO_DIRECT_EDITION: + // no direct edition mode => does nothing + return; + case IDirectEdition.EXTENDED_DIRECT_EDITOR: + updateExtendedEditorConfiguration(); + if (configuration == null || configuration.getLanguage() == null) { + // Create default edit manager + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + performDefaultDirectEditorEdit(theRequest); + } else { + configuration.preEditAction(resolveSemanticElement()); + Dialog dialog = null; + if (configuration instanceof ICustomDirectEditorConfiguration) { + setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); + initializeDirectEditManager(theRequest); + return; + } else if (configuration instanceof IPopupEditorConfiguration) { + IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); + helper.showEditor(); + return; + } + else if (configuration instanceof IAdvancedEditorConfiguration) { + dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); + } else if (configuration instanceof IDirectEditorConfiguration) { + dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), + configuration); + } else { + return; + } + final Dialog finalDialog = dialog; + + if (Window.OK == dialog.open()) { + TransactionalEditingDomain domain = getEditingDomain(); + RecordingCommand command = new RecordingCommand(domain, "Edit Label") { + + @Override + protected void doExecute() { + configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); + + } + }; + domain.getCommandStack().execute(command); + } + } + break; + case IDirectEdition.DEFAULT_DIRECT_EDITOR: + initializeDirectEditManager(theRequest); + break; + default: + break; + } + } + + /** + * @generated + */ + protected void initializeDirectEditManager(final Request request) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + @Override + public void run() { + if (isActive() && isEditable()) { + if (request.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } + else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void refreshVisuals() { + super.refreshVisuals(); + refreshLabel(); + refreshFont(); + refreshFontColor(); + refreshUnderline(); + refreshStrikeThrough(); + } + + /** + * @generated + */ + protected void refreshLabel() { + EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); + if (maskLabelPolicy == null) { + maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); + } + if (maskLabelPolicy == null) { + setLabelTextHelper(getFigure(), getLabelText()); + setLabelIconHelper(getFigure(), getLabelIcon()); + } + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + protected void refreshUnderline() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); + } + if (resolveSemanticElement() instanceof Feature) { + if (((Feature) resolveSemanticElement()).isStatic()) { + ((WrappingLabel) getFigure()).setTextUnderline(true); + } + else { + ((WrappingLabel) getFigure()).setTextUnderline(false); + } + } + } + + /** + * @generated + */ + protected void refreshStrikeThrough() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); + } + } + + /** + * @generated + */ + @Override + protected void refreshFont() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null) { + FontData fontData = new FontData( + style.getFontName(), style.getFontHeight(), + (style.isBold() ? SWT.BOLD : SWT.NORMAL) | + (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); + setFont(fontData); + } + } + + /** + * @generated + */ + @Override + protected void setFontColor(Color color) { + getFigure().setForegroundColor(color); + } + + /** + * @generated + */ + @Override + protected void addSemanticListeners() { + if (getParser() instanceof ISemanticParser) { + EObject element = resolveSemanticElement(); + parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); + for (int i = 0; i < parserElements.size(); i++) { + addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ + } + } else { + super.addSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected void removeSemanticListeners() { + if (parserElements != null) { + for (int i = 0; i < parserElements.size(); i++) { + removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ + } + } else { + super.removeSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected AccessibleEditPart getAccessibleEditPart() { + if (accessibleEP == null) { + accessibleEP = new AccessibleGraphicalEditPart() { + + @Override + public void getName(AccessibleEvent e) { + e.result = getLabelTextHelper(getFigure()); + } + }; + } + return accessibleEP; + } + + /** + * @generated + */ + private View getFontStyleOwnerView() { + return getPrimaryView(); + } + + /** + * Returns the kind of associated editor for direct edition. + * + * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition + * @generated + */ + public int getDirectEditionType() { + if (checkExtendedEditor()) { + initExtendedEditorConfiguration(); + return IDirectEdition.EXTENDED_DIRECT_EDITOR; + } + if (checkDefaultEdition()) { + return IDirectEdition.DEFAULT_DIRECT_EDITOR; + } + + // not a named element. no specific editor => do nothing + return IDirectEdition.NO_DIRECT_EDITION; + } + + /** + * Checks if an extended editor is present. + * + * @return true if an extended editor is present. + * @generated + */ + protected boolean checkExtendedEditor() { + if (resolveSemanticElement() != null) { + return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); + } + return false; + } + + /** + * Checks if a default direct edition is available + * + * @return true if a default direct edition is available + * @generated + */ + protected boolean checkDefaultEdition() { + return (getParser() != null); + } + + /** + * Initializes the extended editor configuration + * + * @generated + */ + protected void initExtendedEditorConfiguration() { + if (configuration == null) { + final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("")) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); + } else { + configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); + } + } + } + + /** + * Updates the preference configuration + * + * @generated + */ + protected void updateExtendedEditorConfiguration() { + String languagePreferred = Activator.getDefault().getPreferenceStore().getString( + IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() + .eClass().getInstanceClassName()); + } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { + configuration = null; + } + } + + /** + * Performs the direct edit usually used by GMF editors. + * + * @param theRequest + * the direct edit request that starts the direct edit system + * @generated + */ + protected void performDefaultDirectEditorEdit(final Request theRequest) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + + @Override + public void run() { + if (isActive() && isEditable()) { + if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) theRequest.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { + DirectEditRequest editRequest = (DirectEditRequest) theRequest; + performDirectEdit(editRequest.getLocation()); + } else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void handleNotificationEvent(Notification event) { + Object feature = event.getFeature(); + if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { + Integer c = (Integer) event.getNewValue(); + setFontColor(DiagramColorRegistry.getInstance().getColor(c)); + } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { + refreshUnderline(); + } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { + refreshStrikeThrough(); + } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { + refreshFont(); + } else { + if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { + refreshLabel(); + } + if (getParser() instanceof ISemanticParser) { + ISemanticParser modelParser = + (ISemanticParser) getParser(); + if (modelParser.areSemanticElementsAffected(null, event)) { + removeSemanticListeners(); + if (resolveSemanticElement() != null) { + addSemanticListeners(); + } + refreshLabel(); + } + } + } + + super.handleNotificationEvent(event); + } + + /** + * @generated + */ + @Override + protected IFigure createFigure() { + // Parent should assign one using setLabel() method + return null; + } +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DeploymentAppliedStereotypeEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DeploymentAppliedStereotypeEditPart.java index 9915fd3f991..8ea8dcc087a 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DeploymentAppliedStereotypeEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DeploymentAppliedStereotypeEditPart.java @@ -1,820 +1,815 @@ -/** - * 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.uml.diagram.composite.edit.parts; - -import java.util.Collections; -import java.util.List; - -import org.eclipse.draw2d.ConnectionLocator; -import org.eclipse.draw2d.IFigure; -import org.eclipse.draw2d.Label; -import org.eclipse.draw2d.geometry.Point; -import org.eclipse.emf.common.notify.Notification; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.transaction.RecordingCommand; -import org.eclipse.emf.transaction.RunnableWithResult; -import org.eclipse.emf.transaction.TransactionalEditingDomain; -import org.eclipse.gef.AccessibleEditPart; -import org.eclipse.gef.EditPolicy; -import org.eclipse.gef.Request; -import org.eclipse.gef.requests.DirectEditRequest; -import org.eclipse.gef.tools.DirectEditManager; -import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; -import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; -import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; -import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; -import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; -import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; -import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; -import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; -import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; -import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; -import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; -import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; -import org.eclipse.gmf.runtime.notation.FontStyle; -import org.eclipse.gmf.runtime.notation.NotationPackage; -import org.eclipse.gmf.runtime.notation.View; -import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.jface.text.contentassist.IContentAssistProcessor; -import org.eclipse.jface.viewers.ICellEditorValidator; -import org.eclipse.jface.window.Window; -import org.eclipse.papyrus.extensionpoints.editors.Activator; -import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; -import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; -import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; -import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; -import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; -import org.eclipse.papyrus.infra.gmfdiag.common.editpart.IControlParserForDirectEdit; -import org.eclipse.papyrus.infra.gmfdiag.common.editpart.PapyrusLabelEditPart; -import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; -import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; -import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.PapyrusLinkLabelDragPolicy; -import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; -import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; -import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; -import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; -import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; -import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; -import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; -import org.eclipse.swt.SWT; -import org.eclipse.swt.accessibility.AccessibleEvent; -import org.eclipse.swt.custom.BusyIndicator; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.FontData; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.widgets.Display; -import org.eclipse.ui.PlatformUI; -import org.eclipse.uml2.uml.Feature; - -/** - * @generated - */ -public class DeploymentAppliedStereotypeEditPart extends PapyrusLabelEditPart implements ITextAwareEditPart, IControlParserForDirectEdit { - - /** - * @generated - */ - public static final int VISUAL_ID = 6022; - - /** - * @generated - */ - private DirectEditManager manager; - - /** - * @generated - */ - private IParser parser; - - /** - * @generated - */ - private List parserElements; - - /** - * @generated - */ - private String defaultText; - - /** - * direct edition mode (default, undefined, registered editor, etc.) - * - * @generated - */ - protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; - - /** - * configuration from a registered edit dialog - * - * @generated - */ - protected IDirectEditorConfiguration configuration; - /** - * @generated - */ - static { - registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.DeploymentAppliedStereotypeEditPart.VISUAL_ID), new Point(0, 30)); - } - - /** - * @generated - */ - public DeploymentAppliedStereotypeEditPart(View view) { - super(view); - } - - /** - * @generated - */ - @Override - protected void createDefaultEditPolicies() { - super.createDefaultEditPolicies(); - installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); - installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); - installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new PapyrusLinkLabelDragPolicy()); - } - - /** - * @generated - */ - @Override - public int getKeyPoint() { - return ConnectionLocator.MIDDLE; - } - - /** - * @generated - */ - protected String getLabelTextHelper(IFigure figure) { - if (figure instanceof WrappingLabel) { - return ((WrappingLabel) figure).getText(); - } else if (figure instanceof ILabelFigure) { - return ((ILabelFigure) figure).getText(); - } else { - return ((Label) figure).getText(); - } - } - - /** - * @generated - */ - protected void setLabelTextHelper(IFigure figure, String text) { - if (figure instanceof WrappingLabel) { - ((WrappingLabel) figure).setText(text); - } else if (figure instanceof ILabelFigure) { - ((ILabelFigure) figure).setText(text); - } else { - ((Label) figure).setText(text); - } - } - - /** - * @generated - */ - protected Image getLabelIconHelper(IFigure figure) { - if (figure instanceof WrappingLabel) { - return ((WrappingLabel) figure).getIcon(); - } else if (figure instanceof ILabelFigure) { - return ((ILabelFigure) figure).getIcon(); - } else { - return ((Label) figure).getIcon(); - } - } - - /** - * @generated - */ - protected void setLabelIconHelper(IFigure figure, Image icon) { - if (figure instanceof WrappingLabel) { - ((WrappingLabel) figure).setIcon(icon); - } else if (figure instanceof ILabelFigure) { - ((ILabelFigure) figure).setIcon(icon); - } else { - ((Label) figure).setIcon(icon); - } - } - - /** - * @generated - */ - public void setLabel(IFigure - figure) { - unregisterVisuals(); - setFigure(figure); - defaultText = getLabelTextHelper(figure); - registerVisuals(); - refreshVisuals(); - } - - /** - * @generated - */ - @Override - protected List getModelChildren() { - return Collections.EMPTY_LIST; - } - - /** - * @generated - */ - @Override - public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { - return null; - } - - /** - * @generated - */ - @Override - public void setParser(IParser parser) { - this.parser = parser; - } - - /** - * @generated - */ - protected EObject getParserElement() { - return resolveSemanticElement(); - } - - /** - * @generated - */ - protected Image getLabelIcon() { - return null; - } - - /** - * @generated - */ - protected String getLabelText() { - String text = null; - EObject parserElement = getParserElement(); - if (parserElement != null && getParser() != null) { - text = getParser().getPrintString( - new EObjectAdapter(parserElement), - getParserOptions().intValue()); - } - if (text == null || text.length() == 0) { - text = defaultText; - } - return text; - } - - /** - * @generated - */ - @Override - public void setLabelText(String text) { - setLabelTextHelper(getFigure(), text); - Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); - if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); - } - Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); - if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); - } - } - - /** - * @generated - */ - @Override - public String getEditText() { - if (getParserElement() == null || getParser() == null) { - return ""; //$NON-NLS-1$ - } - return getParser().getEditString( - new EObjectAdapter(getParserElement()), - getParserOptions().intValue()); - } - - /** - * @generated - */ - protected boolean isEditable() { - return false; - } - - /** - * @generated - */ - @Override - public ICellEditorValidator getEditTextValidator() { - return new ICellEditorValidator() { - - @Override - public String isValid(final Object value) { - if (value instanceof String) { - final EObject element = getParserElement(); - final IParser parser = getParser(); - try { - IParserEditStatus valid = - (IParserEditStatus) getEditingDomain().runExclusive( - new RunnableWithResult.Impl() { - - @Override - public void run() { - setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); - } - }); - return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); - } catch (InterruptedException ie) { - ie.printStackTrace(); - } - } - - // shouldn't get here - return null; - } - }; - } - - /** - * @generated - */ - @Override - public IContentAssistProcessor getCompletionProcessor() { - if (getParserElement() == null || getParser() == null) { - return null; - } - return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); - } - - /** - * @generated - */ - @Override - public ParserOptions getParserOptions() { - return ParserOptions.NONE; - } - - /** - * @generated - */ - @Override - public IParser getParser() { - if (parser == null) { - parser = UMLParserProvider.getParser(UMLElementTypes.Deployment_4009, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.DeploymentAppliedStereotypeEditPart.VISUAL_ID)); - } - return parser; - } - - /** - * @generated - */ - protected DirectEditManager getManager() { - if (manager == null) { - setManager(new MultilineLabelDirectEditManager(this, - MultilineLabelDirectEditManager.getTextCellEditorClass(this), - UMLEditPartFactory.getTextCellEditorLocator(this))); - } - return manager; - } - - /** - * @generated - */ - protected void setManager(DirectEditManager manager) { - this.manager = manager; - } - - /** - * @generated - */ - protected void performDirectEdit() { - BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { - - @Override - public void run() { - getManager().show(); - } - }); - } - - /** - * @generated - */ - protected void performDirectEdit(Point eventLocation) { - if (getManager() instanceof TextDirectEditManager) { - ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); - } - } - - /** - * @generated - */ - private void performDirectEdit(char initialCharacter) { - if (getManager() instanceof TextDirectEditManager) { - ((TextDirectEditManager) getManager()).show(initialCharacter); - } else { - performDirectEdit(); - } - } - - /** - * @generated - */ - @Override - protected void performDirectEditRequest(Request request) { - - final Request theRequest = request; - - if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { - directEditionMode = getDirectEditionType(); - } - switch (directEditionMode) { - case IDirectEdition.NO_DIRECT_EDITION: - // no direct edition mode => does nothing - return; - case IDirectEdition.EXTENDED_DIRECT_EDITOR: - updateExtendedEditorConfiguration(); - if (configuration == null || configuration.getLanguage() == null) { - // Create default edit manager - setManager(new MultilineLabelDirectEditManager(this, - MultilineLabelDirectEditManager.getTextCellEditorClass(this), - UMLEditPartFactory.getTextCellEditorLocator(this))); - performDefaultDirectEditorEdit(theRequest); - } else { - configuration.preEditAction(resolveSemanticElement()); - Dialog dialog = null; - if (configuration instanceof ICustomDirectEditorConfiguration) { - setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); - initializeDirectEditManager(theRequest); - return; - } else if (configuration instanceof IPopupEditorConfiguration) { - IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); - helper.showEditor(); - return; - } - else if (configuration instanceof IAdvancedEditorConfiguration) { - dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); - } else if (configuration instanceof IDirectEditorConfiguration) { - dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), - configuration); - } else { - return; - } - final Dialog finalDialog = dialog; - - if (Window.OK == dialog.open()) { - TransactionalEditingDomain domain = getEditingDomain(); - RecordingCommand command = new RecordingCommand(domain, "Edit Label") { - - @Override - protected void doExecute() { - configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); - - } - }; - domain.getCommandStack().execute(command); - } - } - break; - case IDirectEdition.DEFAULT_DIRECT_EDITOR: - initializeDirectEditManager(theRequest); - break; - default: - break; - } - } - - /** - * @generated - */ - protected void initializeDirectEditManager(final Request request) { - // initialize the direct edit manager - try { - getEditingDomain().runExclusive(new Runnable() { - @Override - public void run() { - if (isActive() && isEditable()) { - if (request.getExtendedData().get( - RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { - Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); - performDirectEdit(initialChar.charValue()); - } - else { - performDirectEdit(); - } - } - } - }); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - - /** - * @generated - */ - @Override - protected void refreshVisuals() { - super.refreshVisuals(); - refreshLabel(); - refreshFont(); - refreshFontColor(); - refreshUnderline(); - refreshStrikeThrough(); - } - - /** - * @generated - */ - protected void refreshLabel() { - EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); - if (maskLabelPolicy == null) { - maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); - } - if (maskLabelPolicy == null) { - View view = (View) getModel(); - if (view.isVisible()) { - setLabelTextHelper(getFigure(), getLabelText()); - setLabelIconHelper(getFigure(), getLabelIcon()); - } - else { - setLabelTextHelper(getFigure(), ""); //$NON-NLS-1$ - setLabelIconHelper(getFigure(), null); - } - } - Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); - if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); - } - Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); - if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); - } - } - - /** - * @generated - */ - protected void refreshUnderline() { - FontStyle style = - (FontStyle) getFontStyleOwnerView().getStyle( - NotationPackage.eINSTANCE.getFontStyle()); - if (style != null && getFigure() instanceof WrappingLabel) { - ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); - } - if (resolveSemanticElement() instanceof Feature) { - if (((Feature) resolveSemanticElement()).isStatic()) { - ((WrappingLabel) getFigure()).setTextUnderline(true); - } - else { - ((WrappingLabel) getFigure()).setTextUnderline(false); - } - } - } - - /** - * @generated - */ - protected void refreshStrikeThrough() { - FontStyle style = - (FontStyle) getFontStyleOwnerView().getStyle( - NotationPackage.eINSTANCE.getFontStyle()); - if (style != null && getFigure() instanceof WrappingLabel) { - ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); - } - } - - /** - * @generated - */ - @Override - protected void refreshFont() { - FontStyle style = - (FontStyle) getFontStyleOwnerView().getStyle( - NotationPackage.eINSTANCE.getFontStyle()); - if (style != null) { - FontData fontData = new FontData( - style.getFontName(), style.getFontHeight(), - (style.isBold() ? SWT.BOLD : SWT.NORMAL) | - (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); - setFont(fontData); - } - } - - /** - * @generated - */ - @Override - protected void setFontColor(Color color) { - getFigure().setForegroundColor(color); - } - - /** - * @generated - */ - @Override - protected void addSemanticListeners() { - if (getParser() instanceof ISemanticParser) { - EObject element = resolveSemanticElement(); - parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); - for (int i = 0; i < parserElements.size(); i++) { - addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ - } - } else { - super.addSemanticListeners(); - } - } - - /** - * @generated - */ - @Override - protected void removeSemanticListeners() { - if (parserElements != null) { - for (int i = 0; i < parserElements.size(); i++) { - removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ - } - } else { - super.removeSemanticListeners(); - } - } - - /** - * @generated - */ - @Override - protected AccessibleEditPart getAccessibleEditPart() { - if (accessibleEP == null) { - accessibleEP = new AccessibleGraphicalEditPart() { - - @Override - public void getName(AccessibleEvent e) { - e.result = getLabelTextHelper(getFigure()); - } - }; - } - return accessibleEP; - } - - /** - * @generated - */ - private View getFontStyleOwnerView() { - return getPrimaryView(); - } - - /** - * Returns the kind of associated editor for direct edition. - * - * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition - * @generated - */ - public int getDirectEditionType() { - // The label is read-only (defined in GMFGen model) - return IDirectEdition.NO_DIRECT_EDITION; - } - - /** - * Checks if an extended editor is present. - * - * @return true if an extended editor is present. - * @generated - */ - protected boolean checkExtendedEditor() { - if (resolveSemanticElement() != null) { - return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); - } - return false; - } - - /** - * Checks if a default direct edition is available - * - * @return true if a default direct edition is available - * @generated - */ - protected boolean checkDefaultEdition() { - return (getParser() != null); - } - - /** - * Initializes the extended editor configuration - * - * @generated - */ - protected void initExtendedEditorConfiguration() { - if (configuration == null) { - final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); - if (languagePreferred != null && !languagePreferred.equals("")) { - configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); - } else { - configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); - } - } - } - - /** - * Updates the preference configuration - * - * @generated - */ - protected void updateExtendedEditorConfiguration() { - String languagePreferred = Activator.getDefault().getPreferenceStore().getString( - IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); - if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { - configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() - .eClass().getInstanceClassName()); - } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { - configuration = null; - } - } - - /** - * Performs the direct edit usually used by GMF editors. - * - * @param theRequest - * the direct edit request that starts the direct edit system - * @generated - */ - protected void performDefaultDirectEditorEdit(final Request theRequest) { - // initialize the direct edit manager - try { - getEditingDomain().runExclusive(new Runnable() { - - @Override - public void run() { - if (isActive() && isEditable()) { - if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { - Character initialChar = (Character) theRequest.getExtendedData().get( - RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); - performDirectEdit(initialChar.charValue()); - } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { - DirectEditRequest editRequest = (DirectEditRequest) theRequest; - performDirectEdit(editRequest.getLocation()); - } else { - performDirectEdit(); - } - } - } - }); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - - /** - * @generated - */ - @Override - protected void handleNotificationEvent(Notification event) { - Object feature = event.getFeature(); - if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { - Integer c = (Integer) event.getNewValue(); - setFontColor(DiagramColorRegistry.getInstance().getColor(c)); - } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { - refreshUnderline(); - } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { - refreshStrikeThrough(); - } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || - NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || - NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || - NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { - refreshFont(); - } else { - if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { - refreshLabel(); - } - if (getParser() instanceof ISemanticParser) { - ISemanticParser modelParser = - (ISemanticParser) getParser(); - if (modelParser.areSemanticElementsAffected(null, event)) { - removeSemanticListeners(); - if (resolveSemanticElement() != null) { - addSemanticListeners(); - } - refreshLabel(); - } - } - } - - super.handleNotificationEvent(event); - } - - /** - * @generated - */ - @Override - protected IFigure createFigure() { - // Parent should assign one using setLabel() method - return 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.uml.diagram.composite.edit.parts; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.draw2d.ConnectionLocator; +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.Label; +import org.eclipse.draw2d.geometry.Point; +import org.eclipse.emf.common.notify.Notification; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.RunnableWithResult; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gef.AccessibleEditPart; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.Request; +import org.eclipse.gef.requests.DirectEditRequest; +import org.eclipse.gef.tools.DirectEditManager; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; +import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; +import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; +import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; +import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; +import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; +import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; +import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; +import org.eclipse.gmf.runtime.notation.FontStyle; +import org.eclipse.gmf.runtime.notation.NotationPackage; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.gmf.tooling.runtime.edit.policies.DefaultLinkLabelDragPolicy; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.text.contentassist.IContentAssistProcessor; +import org.eclipse.jface.viewers.ICellEditorValidator; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.extensionpoints.editors.Activator; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; +import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; +import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; +import org.eclipse.papyrus.infra.gmfdiag.common.editpart.IControlParserForDirectEdit; +import org.eclipse.papyrus.infra.gmfdiag.common.editpart.PapyrusLabelEditPart; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.PapyrusLinkLabelDragPolicy; +import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; +import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; +import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; +import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; +import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.accessibility.AccessibleEvent; +import org.eclipse.swt.custom.BusyIndicator; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; +import org.eclipse.uml2.uml.Feature; + +/** + * @generated + */ +public class DeploymentAppliedStereotypeEditPart extends PapyrusLabelEditPart implements ITextAwareEditPart, IControlParserForDirectEdit { + + /** + * @generated + */ + public static final int VISUAL_ID = 6022; + + /** + * @generated + */ + private DirectEditManager manager; + + /** + * @generated + */ + private IParser parser; + + /** + * @generated + */ + private List parserElements; + + /** + * @generated + */ + private String defaultText; + + /** + * direct edition mode (default, undefined, registered editor, etc.) + * + * @generated + */ + protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; + + /** + * configuration from a registered edit dialog + * + * @generated + */ + protected IDirectEditorConfiguration configuration; + /** + * @generated + */ + static { + registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.DeploymentAppliedStereotypeEditPart.VISUAL_ID), new Point(0, 30)); + } + + /** + * @generated + */ + public DeploymentAppliedStereotypeEditPart(View view) { + super(view); + } + + /** + * @generated + */ + @Override + protected void createDefaultEditPolicies() { + super.createDefaultEditPolicies(); + installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); + installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new DefaultLinkLabelDragPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new PapyrusLinkLabelDragPolicy()); + } + + /** + * @generated + */ + @Override + public int getKeyPoint() { + return ConnectionLocator.MIDDLE; + } + + /** + * @generated + */ + protected String getLabelTextHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getText(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getText(); + } else { + return ((Label) figure).getText(); + } + } + + /** + * @generated + */ + protected void setLabelTextHelper(IFigure figure, String text) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setText(text); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setText(text); + } else { + ((Label) figure).setText(text); + } + } + + /** + * @generated + */ + protected Image getLabelIconHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getIcon(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getIcon(); + } else { + return ((Label) figure).getIcon(); + } + } + + /** + * @generated + */ + protected void setLabelIconHelper(IFigure figure, Image icon) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setIcon(icon); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setIcon(icon); + } else { + ((Label) figure).setIcon(icon); + } + } + + /** + * @generated + */ + public void setLabel(IFigure + figure) { + unregisterVisuals(); + setFigure(figure); + defaultText = getLabelTextHelper(figure); + registerVisuals(); + refreshVisuals(); + } + + /** + * @generated + */ + @Override + protected List getModelChildren() { + return Collections.EMPTY_LIST; + } + + /** + * @generated + */ + @Override + public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { + return null; + } + + /** + * @generated + */ + @Override + public void setParser(IParser parser) { + this.parser = parser; + } + + /** + * @generated + */ + protected EObject getParserElement() { + return resolveSemanticElement(); + } + + /** + * @generated + */ + protected Image getLabelIcon() { + return null; + } + + /** + * @generated + */ + protected String getLabelText() { + String text = null; + EObject parserElement = getParserElement(); + if (parserElement != null && getParser() != null) { + text = getParser().getPrintString( + new EObjectAdapter(parserElement), + getParserOptions().intValue()); + } + if (text == null || text.length() == 0) { + text = defaultText; + } + return text; + } + + /** + * @generated + */ + @Override + public void setLabelText(String text) { + setLabelTextHelper(getFigure(), text); + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + @Override + public String getEditText() { + if (getParserElement() == null || getParser() == null) { + return ""; //$NON-NLS-1$ + } + return getParser().getEditString( + new EObjectAdapter(getParserElement()), + getParserOptions().intValue()); + } + + /** + * @generated + */ + protected boolean isEditable() { + return false; + } + + /** + * @generated + */ + @Override + public ICellEditorValidator getEditTextValidator() { + return new ICellEditorValidator() { + + @Override + public String isValid(final Object value) { + if (value instanceof String) { + final EObject element = getParserElement(); + final IParser parser = getParser(); + try { + IParserEditStatus valid = + (IParserEditStatus) getEditingDomain().runExclusive( + new RunnableWithResult.Impl() { + + @Override + public void run() { + setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); + } + }); + return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); + } catch (InterruptedException ie) { + ie.printStackTrace(); + } + } + + // shouldn't get here + return null; + } + }; + } + + /** + * @generated + */ + @Override + public IContentAssistProcessor getCompletionProcessor() { + if (getParserElement() == null || getParser() == null) { + return null; + } + return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); + } + + /** + * @generated + */ + @Override + public ParserOptions getParserOptions() { + return ParserOptions.NONE; + } + + /** + * @generated + */ + @Override + public IParser getParser() { + if (parser == null) { + parser = UMLParserProvider.getParser(UMLElementTypes.Deployment_4009, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.DeploymentAppliedStereotypeEditPart.VISUAL_ID)); + } + return parser; + } + + /** + * @generated + */ + protected DirectEditManager getManager() { + if (manager == null) { + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + } + return manager; + } + + /** + * @generated + */ + protected void setManager(DirectEditManager manager) { + this.manager = manager; + } + + /** + * @generated + */ + protected void performDirectEdit() { + BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { + + @Override + public void run() { + getManager().show(); + } + }); + } + + /** + * @generated + */ + protected void performDirectEdit(Point eventLocation) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); + } + } + + /** + * @generated + */ + private void performDirectEdit(char initialCharacter) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(initialCharacter); + } else { + performDirectEdit(); + } + } + + /** + * @generated + */ + @Override + protected void performDirectEditRequest(Request request) { + + final Request theRequest = request; + + if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { + directEditionMode = getDirectEditionType(); + } + switch (directEditionMode) { + case IDirectEdition.NO_DIRECT_EDITION: + // no direct edition mode => does nothing + return; + case IDirectEdition.EXTENDED_DIRECT_EDITOR: + updateExtendedEditorConfiguration(); + if (configuration == null || configuration.getLanguage() == null) { + // Create default edit manager + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + performDefaultDirectEditorEdit(theRequest); + } else { + configuration.preEditAction(resolveSemanticElement()); + Dialog dialog = null; + if (configuration instanceof ICustomDirectEditorConfiguration) { + setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); + initializeDirectEditManager(theRequest); + return; + } else if (configuration instanceof IPopupEditorConfiguration) { + IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); + helper.showEditor(); + return; + } + else if (configuration instanceof IAdvancedEditorConfiguration) { + dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); + } else if (configuration instanceof IDirectEditorConfiguration) { + dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), + configuration); + } else { + return; + } + final Dialog finalDialog = dialog; + + if (Window.OK == dialog.open()) { + TransactionalEditingDomain domain = getEditingDomain(); + RecordingCommand command = new RecordingCommand(domain, "Edit Label") { + + @Override + protected void doExecute() { + configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); + + } + }; + domain.getCommandStack().execute(command); + } + } + break; + case IDirectEdition.DEFAULT_DIRECT_EDITOR: + initializeDirectEditManager(theRequest); + break; + default: + break; + } + } + + /** + * @generated + */ + protected void initializeDirectEditManager(final Request request) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + @Override + public void run() { + if (isActive() && isEditable()) { + if (request.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } + else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void refreshVisuals() { + super.refreshVisuals(); + refreshLabel(); + refreshFont(); + refreshFontColor(); + refreshUnderline(); + refreshStrikeThrough(); + } + + /** + * @generated + */ + protected void refreshLabel() { + EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); + if (maskLabelPolicy == null) { + maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); + } + if (maskLabelPolicy == null) { + setLabelTextHelper(getFigure(), getLabelText()); + setLabelIconHelper(getFigure(), getLabelIcon()); + } + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + protected void refreshUnderline() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); + } + if (resolveSemanticElement() instanceof Feature) { + if (((Feature) resolveSemanticElement()).isStatic()) { + ((WrappingLabel) getFigure()).setTextUnderline(true); + } + else { + ((WrappingLabel) getFigure()).setTextUnderline(false); + } + } + } + + /** + * @generated + */ + protected void refreshStrikeThrough() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); + } + } + + /** + * @generated + */ + @Override + protected void refreshFont() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null) { + FontData fontData = new FontData( + style.getFontName(), style.getFontHeight(), + (style.isBold() ? SWT.BOLD : SWT.NORMAL) | + (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); + setFont(fontData); + } + } + + /** + * @generated + */ + @Override + protected void setFontColor(Color color) { + getFigure().setForegroundColor(color); + } + + /** + * @generated + */ + @Override + protected void addSemanticListeners() { + if (getParser() instanceof ISemanticParser) { + EObject element = resolveSemanticElement(); + parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); + for (int i = 0; i < parserElements.size(); i++) { + addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ + } + } else { + super.addSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected void removeSemanticListeners() { + if (parserElements != null) { + for (int i = 0; i < parserElements.size(); i++) { + removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ + } + } else { + super.removeSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected AccessibleEditPart getAccessibleEditPart() { + if (accessibleEP == null) { + accessibleEP = new AccessibleGraphicalEditPart() { + + @Override + public void getName(AccessibleEvent e) { + e.result = getLabelTextHelper(getFigure()); + } + }; + } + return accessibleEP; + } + + /** + * @generated + */ + private View getFontStyleOwnerView() { + return getPrimaryView(); + } + + /** + * Returns the kind of associated editor for direct edition. + * + * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition + * @generated + */ + public int getDirectEditionType() { + // The label is read-only (defined in GMFGen model) + return IDirectEdition.NO_DIRECT_EDITION; + } + + /** + * Checks if an extended editor is present. + * + * @return true if an extended editor is present. + * @generated + */ + protected boolean checkExtendedEditor() { + if (resolveSemanticElement() != null) { + return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); + } + return false; + } + + /** + * Checks if a default direct edition is available + * + * @return true if a default direct edition is available + * @generated + */ + protected boolean checkDefaultEdition() { + return (getParser() != null); + } + + /** + * Initializes the extended editor configuration + * + * @generated + */ + protected void initExtendedEditorConfiguration() { + if (configuration == null) { + final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("")) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); + } else { + configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); + } + } + } + + /** + * Updates the preference configuration + * + * @generated + */ + protected void updateExtendedEditorConfiguration() { + String languagePreferred = Activator.getDefault().getPreferenceStore().getString( + IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() + .eClass().getInstanceClassName()); + } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { + configuration = null; + } + } + + /** + * Performs the direct edit usually used by GMF editors. + * + * @param theRequest + * the direct edit request that starts the direct edit system + * @generated + */ + protected void performDefaultDirectEditorEdit(final Request theRequest) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + + @Override + public void run() { + if (isActive() && isEditable()) { + if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) theRequest.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { + DirectEditRequest editRequest = (DirectEditRequest) theRequest; + performDirectEdit(editRequest.getLocation()); + } else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void handleNotificationEvent(Notification event) { + Object feature = event.getFeature(); + if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { + Integer c = (Integer) event.getNewValue(); + setFontColor(DiagramColorRegistry.getInstance().getColor(c)); + } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { + refreshUnderline(); + } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { + refreshStrikeThrough(); + } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { + refreshFont(); + } else { + if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { + refreshLabel(); + } + if (getParser() instanceof ISemanticParser) { + ISemanticParser modelParser = + (ISemanticParser) getParser(); + if (modelParser.areSemanticElementsAffected(null, event)) { + removeSemanticListeners(); + if (resolveSemanticElement() != null) { + addSemanticListeners(); + } + refreshLabel(); + } + } + } + + super.handleNotificationEvent(event); + } + + /** + * @generated + */ + @Override + protected IFigure createFigure() { + // Parent should assign one using setLabel() method + return null; + } +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DeploymentNameEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DeploymentNameEditPart.java index a2d8bf22d50..a3aa6fc3f37 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DeploymentNameEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DeploymentNameEditPart.java @@ -1,828 +1,823 @@ -/** - * 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.uml.diagram.composite.edit.parts; - -import java.util.Collections; -import java.util.List; - -import org.eclipse.draw2d.ConnectionLocator; -import org.eclipse.draw2d.IFigure; -import org.eclipse.draw2d.Label; -import org.eclipse.draw2d.geometry.Point; -import org.eclipse.emf.common.notify.Notification; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.transaction.RecordingCommand; -import org.eclipse.emf.transaction.RunnableWithResult; -import org.eclipse.emf.transaction.TransactionalEditingDomain; -import org.eclipse.gef.AccessibleEditPart; -import org.eclipse.gef.EditPolicy; -import org.eclipse.gef.Request; -import org.eclipse.gef.requests.DirectEditRequest; -import org.eclipse.gef.tools.DirectEditManager; -import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; -import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; -import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; -import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; -import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; -import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; -import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; -import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; -import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; -import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; -import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; -import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; -import org.eclipse.gmf.runtime.notation.FontStyle; -import org.eclipse.gmf.runtime.notation.NotationPackage; -import org.eclipse.gmf.runtime.notation.View; -import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.jface.text.contentassist.IContentAssistProcessor; -import org.eclipse.jface.viewers.ICellEditorValidator; -import org.eclipse.jface.window.Window; -import org.eclipse.papyrus.extensionpoints.editors.Activator; -import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; -import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; -import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; -import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; -import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; -import org.eclipse.papyrus.infra.gmfdiag.common.editpart.IControlParserForDirectEdit; -import org.eclipse.papyrus.infra.gmfdiag.common.editpart.PapyrusLabelEditPart; -import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; -import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; -import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.PapyrusLinkLabelDragPolicy; -import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; -import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; -import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; -import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; -import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; -import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; -import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; -import org.eclipse.swt.SWT; -import org.eclipse.swt.accessibility.AccessibleEvent; -import org.eclipse.swt.custom.BusyIndicator; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.FontData; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.widgets.Display; -import org.eclipse.ui.PlatformUI; -import org.eclipse.uml2.uml.Feature; - -/** - * @generated - */ -public class DeploymentNameEditPart extends PapyrusLabelEditPart implements ITextAwareEditPart, IControlParserForDirectEdit { - - /** - * @generated - */ - public static final int VISUAL_ID = 6008; - - /** - * @generated - */ - private DirectEditManager manager; - - /** - * @generated - */ - private IParser parser; - - /** - * @generated - */ - private List parserElements; - - /** - * @generated - */ - private String defaultText; - - /** - * direct edition mode (default, undefined, registered editor, etc.) - * - * @generated - */ - protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; - - /** - * configuration from a registered edit dialog - * - * @generated - */ - protected IDirectEditorConfiguration configuration; - /** - * @generated - */ - static { - registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.DeploymentNameEditPart.VISUAL_ID), new Point(0, 60)); - } - - /** - * @generated - */ - public DeploymentNameEditPart(View view) { - super(view); - } - - /** - * @generated - */ - @Override - protected void createDefaultEditPolicies() { - super.createDefaultEditPolicies(); - installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); - installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); - installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new PapyrusLinkLabelDragPolicy()); - } - - /** - * @generated - */ - @Override - public int getKeyPoint() { - return ConnectionLocator.MIDDLE; - } - - /** - * @generated - */ - protected String getLabelTextHelper(IFigure figure) { - if (figure instanceof WrappingLabel) { - return ((WrappingLabel) figure).getText(); - } else if (figure instanceof ILabelFigure) { - return ((ILabelFigure) figure).getText(); - } else { - return ((Label) figure).getText(); - } - } - - /** - * @generated - */ - protected void setLabelTextHelper(IFigure figure, String text) { - if (figure instanceof WrappingLabel) { - ((WrappingLabel) figure).setText(text); - } else if (figure instanceof ILabelFigure) { - ((ILabelFigure) figure).setText(text); - } else { - ((Label) figure).setText(text); - } - } - - /** - * @generated - */ - protected Image getLabelIconHelper(IFigure figure) { - if (figure instanceof WrappingLabel) { - return ((WrappingLabel) figure).getIcon(); - } else if (figure instanceof ILabelFigure) { - return ((ILabelFigure) figure).getIcon(); - } else { - return ((Label) figure).getIcon(); - } - } - - /** - * @generated - */ - protected void setLabelIconHelper(IFigure figure, Image icon) { - if (figure instanceof WrappingLabel) { - ((WrappingLabel) figure).setIcon(icon); - } else if (figure instanceof ILabelFigure) { - ((ILabelFigure) figure).setIcon(icon); - } else { - ((Label) figure).setIcon(icon); - } - } - - /** - * @generated - */ - public void setLabel(IFigure - figure) { - unregisterVisuals(); - setFigure(figure); - defaultText = getLabelTextHelper(figure); - registerVisuals(); - refreshVisuals(); - } - - /** - * @generated - */ - @Override - protected List getModelChildren() { - return Collections.EMPTY_LIST; - } - - /** - * @generated - */ - @Override - public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { - return null; - } - - /** - * @generated - */ - @Override - public void setParser(IParser parser) { - this.parser = parser; - } - - /** - * @generated - */ - protected EObject getParserElement() { - return resolveSemanticElement(); - } - - /** - * @generated - */ - protected Image getLabelIcon() { - return null; - } - - /** - * @generated - */ - protected String getLabelText() { - String text = null; - EObject parserElement = getParserElement(); - if (parserElement != null && getParser() != null) { - text = getParser().getPrintString( - new EObjectAdapter(parserElement), - getParserOptions().intValue()); - } - if (text == null || text.length() == 0) { - text = defaultText; - } - return text; - } - - /** - * @generated - */ - @Override - public void setLabelText(String text) { - setLabelTextHelper(getFigure(), text); - Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); - if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); - } - Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); - if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); - } - } - - /** - * @generated - */ - @Override - public String getEditText() { - if (getParserElement() == null || getParser() == null) { - return ""; //$NON-NLS-1$ - } - return getParser().getEditString( - new EObjectAdapter(getParserElement()), - getParserOptions().intValue()); - } - - /** - * @generated - */ - protected boolean isEditable() { - return getParser() != null; - } - - /** - * @generated - */ - @Override - public ICellEditorValidator getEditTextValidator() { - return new ICellEditorValidator() { - - @Override - public String isValid(final Object value) { - if (value instanceof String) { - final EObject element = getParserElement(); - final IParser parser = getParser(); - try { - IParserEditStatus valid = - (IParserEditStatus) getEditingDomain().runExclusive( - new RunnableWithResult.Impl() { - - @Override - public void run() { - setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); - } - }); - return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); - } catch (InterruptedException ie) { - ie.printStackTrace(); - } - } - - // shouldn't get here - return null; - } - }; - } - - /** - * @generated - */ - @Override - public IContentAssistProcessor getCompletionProcessor() { - if (getParserElement() == null || getParser() == null) { - return null; - } - return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); - } - - /** - * @generated - */ - @Override - public ParserOptions getParserOptions() { - return ParserOptions.NONE; - } - - /** - * @generated - */ - @Override - public IParser getParser() { - if (parser == null) { - parser = UMLParserProvider.getParser(UMLElementTypes.Deployment_4009, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.DeploymentNameEditPart.VISUAL_ID)); - } - return parser; - } - - /** - * @generated - */ - protected DirectEditManager getManager() { - if (manager == null) { - setManager(new MultilineLabelDirectEditManager(this, - MultilineLabelDirectEditManager.getTextCellEditorClass(this), - UMLEditPartFactory.getTextCellEditorLocator(this))); - } - return manager; - } - - /** - * @generated - */ - protected void setManager(DirectEditManager manager) { - this.manager = manager; - } - - /** - * @generated - */ - protected void performDirectEdit() { - BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { - - @Override - public void run() { - getManager().show(); - } - }); - } - - /** - * @generated - */ - protected void performDirectEdit(Point eventLocation) { - if (getManager() instanceof TextDirectEditManager) { - ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); - } - } - - /** - * @generated - */ - private void performDirectEdit(char initialCharacter) { - if (getManager() instanceof TextDirectEditManager) { - ((TextDirectEditManager) getManager()).show(initialCharacter); - } else { - performDirectEdit(); - } - } - - /** - * @generated - */ - @Override - protected void performDirectEditRequest(Request request) { - - final Request theRequest = request; - - if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { - directEditionMode = getDirectEditionType(); - } - switch (directEditionMode) { - case IDirectEdition.NO_DIRECT_EDITION: - // no direct edition mode => does nothing - return; - case IDirectEdition.EXTENDED_DIRECT_EDITOR: - updateExtendedEditorConfiguration(); - if (configuration == null || configuration.getLanguage() == null) { - // Create default edit manager - setManager(new MultilineLabelDirectEditManager(this, - MultilineLabelDirectEditManager.getTextCellEditorClass(this), - UMLEditPartFactory.getTextCellEditorLocator(this))); - performDefaultDirectEditorEdit(theRequest); - } else { - configuration.preEditAction(resolveSemanticElement()); - Dialog dialog = null; - if (configuration instanceof ICustomDirectEditorConfiguration) { - setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); - initializeDirectEditManager(theRequest); - return; - } else if (configuration instanceof IPopupEditorConfiguration) { - IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); - helper.showEditor(); - return; - } - else if (configuration instanceof IAdvancedEditorConfiguration) { - dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); - } else if (configuration instanceof IDirectEditorConfiguration) { - dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), - configuration); - } else { - return; - } - final Dialog finalDialog = dialog; - - if (Window.OK == dialog.open()) { - TransactionalEditingDomain domain = getEditingDomain(); - RecordingCommand command = new RecordingCommand(domain, "Edit Label") { - - @Override - protected void doExecute() { - configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); - - } - }; - domain.getCommandStack().execute(command); - } - } - break; - case IDirectEdition.DEFAULT_DIRECT_EDITOR: - initializeDirectEditManager(theRequest); - break; - default: - break; - } - } - - /** - * @generated - */ - protected void initializeDirectEditManager(final Request request) { - // initialize the direct edit manager - try { - getEditingDomain().runExclusive(new Runnable() { - @Override - public void run() { - if (isActive() && isEditable()) { - if (request.getExtendedData().get( - RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { - Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); - performDirectEdit(initialChar.charValue()); - } - else { - performDirectEdit(); - } - } - } - }); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - - /** - * @generated - */ - @Override - protected void refreshVisuals() { - super.refreshVisuals(); - refreshLabel(); - refreshFont(); - refreshFontColor(); - refreshUnderline(); - refreshStrikeThrough(); - } - - /** - * @generated - */ - protected void refreshLabel() { - EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); - if (maskLabelPolicy == null) { - maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); - } - if (maskLabelPolicy == null) { - View view = (View) getModel(); - if (view.isVisible()) { - setLabelTextHelper(getFigure(), getLabelText()); - setLabelIconHelper(getFigure(), getLabelIcon()); - } - else { - setLabelTextHelper(getFigure(), ""); //$NON-NLS-1$ - setLabelIconHelper(getFigure(), null); - } - } - Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); - if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); - } - Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); - if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); - } - } - - /** - * @generated - */ - protected void refreshUnderline() { - FontStyle style = - (FontStyle) getFontStyleOwnerView().getStyle( - NotationPackage.eINSTANCE.getFontStyle()); - if (style != null && getFigure() instanceof WrappingLabel) { - ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); - } - if (resolveSemanticElement() instanceof Feature) { - if (((Feature) resolveSemanticElement()).isStatic()) { - ((WrappingLabel) getFigure()).setTextUnderline(true); - } - else { - ((WrappingLabel) getFigure()).setTextUnderline(false); - } - } - } - - /** - * @generated - */ - protected void refreshStrikeThrough() { - FontStyle style = - (FontStyle) getFontStyleOwnerView().getStyle( - NotationPackage.eINSTANCE.getFontStyle()); - if (style != null && getFigure() instanceof WrappingLabel) { - ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); - } - } - - /** - * @generated - */ - @Override - protected void refreshFont() { - FontStyle style = - (FontStyle) getFontStyleOwnerView().getStyle( - NotationPackage.eINSTANCE.getFontStyle()); - if (style != null) { - FontData fontData = new FontData( - style.getFontName(), style.getFontHeight(), - (style.isBold() ? SWT.BOLD : SWT.NORMAL) | - (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); - setFont(fontData); - } - } - - /** - * @generated - */ - @Override - protected void setFontColor(Color color) { - getFigure().setForegroundColor(color); - } - - /** - * @generated - */ - @Override - protected void addSemanticListeners() { - if (getParser() instanceof ISemanticParser) { - EObject element = resolveSemanticElement(); - parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); - for (int i = 0; i < parserElements.size(); i++) { - addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ - } - } else { - super.addSemanticListeners(); - } - } - - /** - * @generated - */ - @Override - protected void removeSemanticListeners() { - if (parserElements != null) { - for (int i = 0; i < parserElements.size(); i++) { - removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ - } - } else { - super.removeSemanticListeners(); - } - } - - /** - * @generated - */ - @Override - protected AccessibleEditPart getAccessibleEditPart() { - if (accessibleEP == null) { - accessibleEP = new AccessibleGraphicalEditPart() { - - @Override - public void getName(AccessibleEvent e) { - e.result = getLabelTextHelper(getFigure()); - } - }; - } - return accessibleEP; - } - - /** - * @generated - */ - private View getFontStyleOwnerView() { - return getPrimaryView(); - } - - /** - * Returns the kind of associated editor for direct edition. - * - * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition - * @generated - */ - public int getDirectEditionType() { - if (checkExtendedEditor()) { - initExtendedEditorConfiguration(); - return IDirectEdition.EXTENDED_DIRECT_EDITOR; - } - if (checkDefaultEdition()) { - return IDirectEdition.DEFAULT_DIRECT_EDITOR; - } - - // not a named element. no specific editor => do nothing - return IDirectEdition.NO_DIRECT_EDITION; - } - - /** - * Checks if an extended editor is present. - * - * @return true if an extended editor is present. - * @generated - */ - protected boolean checkExtendedEditor() { - if (resolveSemanticElement() != null) { - return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); - } - return false; - } - - /** - * Checks if a default direct edition is available - * - * @return true if a default direct edition is available - * @generated - */ - protected boolean checkDefaultEdition() { - return (getParser() != null); - } - - /** - * Initializes the extended editor configuration - * - * @generated - */ - protected void initExtendedEditorConfiguration() { - if (configuration == null) { - final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); - if (languagePreferred != null && !languagePreferred.equals("")) { - configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); - } else { - configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); - } - } - } - - /** - * Updates the preference configuration - * - * @generated - */ - protected void updateExtendedEditorConfiguration() { - String languagePreferred = Activator.getDefault().getPreferenceStore().getString( - IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); - if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { - configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() - .eClass().getInstanceClassName()); - } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { - configuration = null; - } - } - - /** - * Performs the direct edit usually used by GMF editors. - * - * @param theRequest - * the direct edit request that starts the direct edit system - * @generated - */ - protected void performDefaultDirectEditorEdit(final Request theRequest) { - // initialize the direct edit manager - try { - getEditingDomain().runExclusive(new Runnable() { - - @Override - public void run() { - if (isActive() && isEditable()) { - if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { - Character initialChar = (Character) theRequest.getExtendedData().get( - RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); - performDirectEdit(initialChar.charValue()); - } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { - DirectEditRequest editRequest = (DirectEditRequest) theRequest; - performDirectEdit(editRequest.getLocation()); - } else { - performDirectEdit(); - } - } - } - }); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - - /** - * @generated - */ - @Override - protected void handleNotificationEvent(Notification event) { - Object feature = event.getFeature(); - if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { - Integer c = (Integer) event.getNewValue(); - setFontColor(DiagramColorRegistry.getInstance().getColor(c)); - } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { - refreshUnderline(); - } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { - refreshStrikeThrough(); - } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || - NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || - NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || - NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { - refreshFont(); - } else { - if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { - refreshLabel(); - } - if (getParser() instanceof ISemanticParser) { - ISemanticParser modelParser = - (ISemanticParser) getParser(); - if (modelParser.areSemanticElementsAffected(null, event)) { - removeSemanticListeners(); - if (resolveSemanticElement() != null) { - addSemanticListeners(); - } - refreshLabel(); - } - } - } - - super.handleNotificationEvent(event); - } - - /** - * @generated - */ - @Override - protected IFigure createFigure() { - // Parent should assign one using setLabel() method - return 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.uml.diagram.composite.edit.parts; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.draw2d.ConnectionLocator; +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.Label; +import org.eclipse.draw2d.geometry.Point; +import org.eclipse.emf.common.notify.Notification; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.RunnableWithResult; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gef.AccessibleEditPart; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.Request; +import org.eclipse.gef.requests.DirectEditRequest; +import org.eclipse.gef.tools.DirectEditManager; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; +import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; +import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; +import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; +import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; +import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; +import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; +import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; +import org.eclipse.gmf.runtime.notation.FontStyle; +import org.eclipse.gmf.runtime.notation.NotationPackage; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.gmf.tooling.runtime.edit.policies.DefaultLinkLabelDragPolicy; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.text.contentassist.IContentAssistProcessor; +import org.eclipse.jface.viewers.ICellEditorValidator; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.extensionpoints.editors.Activator; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; +import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; +import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; +import org.eclipse.papyrus.infra.gmfdiag.common.editpart.IControlParserForDirectEdit; +import org.eclipse.papyrus.infra.gmfdiag.common.editpart.PapyrusLabelEditPart; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.PapyrusLinkLabelDragPolicy; +import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; +import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; +import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; +import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; +import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.accessibility.AccessibleEvent; +import org.eclipse.swt.custom.BusyIndicator; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; +import org.eclipse.uml2.uml.Feature; + +/** + * @generated + */ +public class DeploymentNameEditPart extends PapyrusLabelEditPart implements ITextAwareEditPart, IControlParserForDirectEdit { + + /** + * @generated + */ + public static final int VISUAL_ID = 6008; + + /** + * @generated + */ + private DirectEditManager manager; + + /** + * @generated + */ + private IParser parser; + + /** + * @generated + */ + private List parserElements; + + /** + * @generated + */ + private String defaultText; + + /** + * direct edition mode (default, undefined, registered editor, etc.) + * + * @generated + */ + protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; + + /** + * configuration from a registered edit dialog + * + * @generated + */ + protected IDirectEditorConfiguration configuration; + /** + * @generated + */ + static { + registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.DeploymentNameEditPart.VISUAL_ID), new Point(0, 60)); + } + + /** + * @generated + */ + public DeploymentNameEditPart(View view) { + super(view); + } + + /** + * @generated + */ + @Override + protected void createDefaultEditPolicies() { + super.createDefaultEditPolicies(); + installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); + installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new DefaultLinkLabelDragPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new PapyrusLinkLabelDragPolicy()); + } + + /** + * @generated + */ + @Override + public int getKeyPoint() { + return ConnectionLocator.MIDDLE; + } + + /** + * @generated + */ + protected String getLabelTextHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getText(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getText(); + } else { + return ((Label) figure).getText(); + } + } + + /** + * @generated + */ + protected void setLabelTextHelper(IFigure figure, String text) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setText(text); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setText(text); + } else { + ((Label) figure).setText(text); + } + } + + /** + * @generated + */ + protected Image getLabelIconHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getIcon(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getIcon(); + } else { + return ((Label) figure).getIcon(); + } + } + + /** + * @generated + */ + protected void setLabelIconHelper(IFigure figure, Image icon) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setIcon(icon); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setIcon(icon); + } else { + ((Label) figure).setIcon(icon); + } + } + + /** + * @generated + */ + public void setLabel(IFigure + figure) { + unregisterVisuals(); + setFigure(figure); + defaultText = getLabelTextHelper(figure); + registerVisuals(); + refreshVisuals(); + } + + /** + * @generated + */ + @Override + protected List getModelChildren() { + return Collections.EMPTY_LIST; + } + + /** + * @generated + */ + @Override + public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { + return null; + } + + /** + * @generated + */ + @Override + public void setParser(IParser parser) { + this.parser = parser; + } + + /** + * @generated + */ + protected EObject getParserElement() { + return resolveSemanticElement(); + } + + /** + * @generated + */ + protected Image getLabelIcon() { + return null; + } + + /** + * @generated + */ + protected String getLabelText() { + String text = null; + EObject parserElement = getParserElement(); + if (parserElement != null && getParser() != null) { + text = getParser().getPrintString( + new EObjectAdapter(parserElement), + getParserOptions().intValue()); + } + if (text == null || text.length() == 0) { + text = defaultText; + } + return text; + } + + /** + * @generated + */ + @Override + public void setLabelText(String text) { + setLabelTextHelper(getFigure(), text); + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + @Override + public String getEditText() { + if (getParserElement() == null || getParser() == null) { + return ""; //$NON-NLS-1$ + } + return getParser().getEditString( + new EObjectAdapter(getParserElement()), + getParserOptions().intValue()); + } + + /** + * @generated + */ + protected boolean isEditable() { + return getParser() != null; + } + + /** + * @generated + */ + @Override + public ICellEditorValidator getEditTextValidator() { + return new ICellEditorValidator() { + + @Override + public String isValid(final Object value) { + if (value instanceof String) { + final EObject element = getParserElement(); + final IParser parser = getParser(); + try { + IParserEditStatus valid = + (IParserEditStatus) getEditingDomain().runExclusive( + new RunnableWithResult.Impl() { + + @Override + public void run() { + setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); + } + }); + return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); + } catch (InterruptedException ie) { + ie.printStackTrace(); + } + } + + // shouldn't get here + return null; + } + }; + } + + /** + * @generated + */ + @Override + public IContentAssistProcessor getCompletionProcessor() { + if (getParserElement() == null || getParser() == null) { + return null; + } + return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); + } + + /** + * @generated + */ + @Override + public ParserOptions getParserOptions() { + return ParserOptions.NONE; + } + + /** + * @generated + */ + @Override + public IParser getParser() { + if (parser == null) { + parser = UMLParserProvider.getParser(UMLElementTypes.Deployment_4009, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.DeploymentNameEditPart.VISUAL_ID)); + } + return parser; + } + + /** + * @generated + */ + protected DirectEditManager getManager() { + if (manager == null) { + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + } + return manager; + } + + /** + * @generated + */ + protected void setManager(DirectEditManager manager) { + this.manager = manager; + } + + /** + * @generated + */ + protected void performDirectEdit() { + BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { + + @Override + public void run() { + getManager().show(); + } + }); + } + + /** + * @generated + */ + protected void performDirectEdit(Point eventLocation) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); + } + } + + /** + * @generated + */ + private void performDirectEdit(char initialCharacter) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(initialCharacter); + } else { + performDirectEdit(); + } + } + + /** + * @generated + */ + @Override + protected void performDirectEditRequest(Request request) { + + final Request theRequest = request; + + if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { + directEditionMode = getDirectEditionType(); + } + switch (directEditionMode) { + case IDirectEdition.NO_DIRECT_EDITION: + // no direct edition mode => does nothing + return; + case IDirectEdition.EXTENDED_DIRECT_EDITOR: + updateExtendedEditorConfiguration(); + if (configuration == null || configuration.getLanguage() == null) { + // Create default edit manager + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + performDefaultDirectEditorEdit(theRequest); + } else { + configuration.preEditAction(resolveSemanticElement()); + Dialog dialog = null; + if (configuration instanceof ICustomDirectEditorConfiguration) { + setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); + initializeDirectEditManager(theRequest); + return; + } else if (configuration instanceof IPopupEditorConfiguration) { + IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); + helper.showEditor(); + return; + } + else if (configuration instanceof IAdvancedEditorConfiguration) { + dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); + } else if (configuration instanceof IDirectEditorConfiguration) { + dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), + configuration); + } else { + return; + } + final Dialog finalDialog = dialog; + + if (Window.OK == dialog.open()) { + TransactionalEditingDomain domain = getEditingDomain(); + RecordingCommand command = new RecordingCommand(domain, "Edit Label") { + + @Override + protected void doExecute() { + configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); + + } + }; + domain.getCommandStack().execute(command); + } + } + break; + case IDirectEdition.DEFAULT_DIRECT_EDITOR: + initializeDirectEditManager(theRequest); + break; + default: + break; + } + } + + /** + * @generated + */ + protected void initializeDirectEditManager(final Request request) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + @Override + public void run() { + if (isActive() && isEditable()) { + if (request.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } + else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void refreshVisuals() { + super.refreshVisuals(); + refreshLabel(); + refreshFont(); + refreshFontColor(); + refreshUnderline(); + refreshStrikeThrough(); + } + + /** + * @generated + */ + protected void refreshLabel() { + EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); + if (maskLabelPolicy == null) { + maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); + } + if (maskLabelPolicy == null) { + setLabelTextHelper(getFigure(), getLabelText()); + setLabelIconHelper(getFigure(), getLabelIcon()); + } + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + protected void refreshUnderline() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); + } + if (resolveSemanticElement() instanceof Feature) { + if (((Feature) resolveSemanticElement()).isStatic()) { + ((WrappingLabel) getFigure()).setTextUnderline(true); + } + else { + ((WrappingLabel) getFigure()).setTextUnderline(false); + } + } + } + + /** + * @generated + */ + protected void refreshStrikeThrough() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); + } + } + + /** + * @generated + */ + @Override + protected void refreshFont() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null) { + FontData fontData = new FontData( + style.getFontName(), style.getFontHeight(), + (style.isBold() ? SWT.BOLD : SWT.NORMAL) | + (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); + setFont(fontData); + } + } + + /** + * @generated + */ + @Override + protected void setFontColor(Color color) { + getFigure().setForegroundColor(color); + } + + /** + * @generated + */ + @Override + protected void addSemanticListeners() { + if (getParser() instanceof ISemanticParser) { + EObject element = resolveSemanticElement(); + parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); + for (int i = 0; i < parserElements.size(); i++) { + addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ + } + } else { + super.addSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected void removeSemanticListeners() { + if (parserElements != null) { + for (int i = 0; i < parserElements.size(); i++) { + removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ + } + } else { + super.removeSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected AccessibleEditPart getAccessibleEditPart() { + if (accessibleEP == null) { + accessibleEP = new AccessibleGraphicalEditPart() { + + @Override + public void getName(AccessibleEvent e) { + e.result = getLabelTextHelper(getFigure()); + } + }; + } + return accessibleEP; + } + + /** + * @generated + */ + private View getFontStyleOwnerView() { + return getPrimaryView(); + } + + /** + * Returns the kind of associated editor for direct edition. + * + * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition + * @generated + */ + public int getDirectEditionType() { + if (checkExtendedEditor()) { + initExtendedEditorConfiguration(); + return IDirectEdition.EXTENDED_DIRECT_EDITOR; + } + if (checkDefaultEdition()) { + return IDirectEdition.DEFAULT_DIRECT_EDITOR; + } + + // not a named element. no specific editor => do nothing + return IDirectEdition.NO_DIRECT_EDITION; + } + + /** + * Checks if an extended editor is present. + * + * @return true if an extended editor is present. + * @generated + */ + protected boolean checkExtendedEditor() { + if (resolveSemanticElement() != null) { + return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); + } + return false; + } + + /** + * Checks if a default direct edition is available + * + * @return true if a default direct edition is available + * @generated + */ + protected boolean checkDefaultEdition() { + return (getParser() != null); + } + + /** + * Initializes the extended editor configuration + * + * @generated + */ + protected void initExtendedEditorConfiguration() { + if (configuration == null) { + final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("")) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); + } else { + configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); + } + } + } + + /** + * Updates the preference configuration + * + * @generated + */ + protected void updateExtendedEditorConfiguration() { + String languagePreferred = Activator.getDefault().getPreferenceStore().getString( + IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() + .eClass().getInstanceClassName()); + } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { + configuration = null; + } + } + + /** + * Performs the direct edit usually used by GMF editors. + * + * @param theRequest + * the direct edit request that starts the direct edit system + * @generated + */ + protected void performDefaultDirectEditorEdit(final Request theRequest) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + + @Override + public void run() { + if (isActive() && isEditable()) { + if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) theRequest.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { + DirectEditRequest editRequest = (DirectEditRequest) theRequest; + performDirectEdit(editRequest.getLocation()); + } else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void handleNotificationEvent(Notification event) { + Object feature = event.getFeature(); + if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { + Integer c = (Integer) event.getNewValue(); + setFontColor(DiagramColorRegistry.getInstance().getColor(c)); + } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { + refreshUnderline(); + } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { + refreshStrikeThrough(); + } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { + refreshFont(); + } else { + if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { + refreshLabel(); + } + if (getParser() instanceof ISemanticParser) { + ISemanticParser modelParser = + (ISemanticParser) getParser(); + if (modelParser.areSemanticElementsAffected(null, event)) { + removeSemanticListeners(); + if (resolveSemanticElement() != null) { + addSemanticListeners(); + } + refreshLabel(); + } + } + } + + super.handleNotificationEvent(event); + } + + /** + * @generated + */ + @Override + protected IFigure createFigure() { + // Parent should assign one using setLabel() method + return null; + } +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DeploymentSpecificationEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DeploymentSpecificationEditPart.java index 9c5896b27b2..0b5463c0fe9 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DeploymentSpecificationEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DeploymentSpecificationEditPart.java @@ -11,27 +11,40 @@ */ package org.eclipse.papyrus.uml.diagram.composite.edit.parts; +import java.util.Collections; +import java.util.List; + import org.eclipse.draw2d.IFigure; +import org.eclipse.emf.common.notify.Notification; import org.eclipse.gef.EditPart; import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.GraphicalEditPart; 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.handles.MoveHandle; import org.eclipse.gef.requests.CreateRequest; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.BorderItemSelectionEditPolicy; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles; +import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; -import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure; import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure; +import org.eclipse.gmf.runtime.notation.Edge; +import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.gmf.runtime.notation.View; -import org.eclipse.papyrus.infra.gmfdiag.common.editpart.NodeEditPart; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.GetChildLayoutEditPolicy; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.IPapyrusNodeFigure; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.RoundedRectangleNodePlateFigure; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.SelectableBorderedNodeFigure; +import org.eclipse.papyrus.uml.diagram.common.editparts.RoundedCompartmentEditPart; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeNodeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.QualifiedNameDisplayEditPolicy; -import org.eclipse.papyrus.uml.diagram.common.figure.node.NodeNamedElementFigure; +import org.eclipse.papyrus.uml.diagram.common.figure.node.RoundedCompartmentFigure; +import org.eclipse.papyrus.uml.diagram.common.locator.RoundedRectangleLabelPositionLocator; import org.eclipse.papyrus.uml.diagram.composite.edit.policies.DeploymentSpecificationItemSemanticEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; import org.eclipse.swt.graphics.Color; @@ -39,7 +52,7 @@ import org.eclipse.swt.graphics.Color; /** * @generated */ -public class DeploymentSpecificationEditPart extends NodeEditPart { +public class DeploymentSpecificationEditPart extends RoundedCompartmentEditPart { /** * @generated @@ -73,6 +86,7 @@ public class DeploymentSpecificationEditPart extends NodeEditPart { installEditPolicy(EditPolicy.LAYOUT_ROLE, createLayoutEditPolicy()); installEditPolicy(QualifiedNameDisplayEditPolicy.QUALIFIED_NAME_POLICY, new QualifiedNameDisplayEditPolicy()); installEditPolicy(AppliedStereotypeLabelDisplayEditPolicy.STEREOTYPE_LABEL_POLICY, new AppliedStereotypeNodeLabelDisplayEditPolicy()); + installEditPolicy(EditPolicy.LAYOUT_ROLE, new GetChildLayoutEditPolicy()); // XXX need an SCR to runtime to have another abstract superclass that would let children add reasonable editpolicies // removeEditPolicy(org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles.CONNECTION_HANDLES_ROLE); } @@ -85,6 +99,20 @@ public class DeploymentSpecificationEditPart extends NodeEditPart { @Override protected EditPolicy createChildEditPolicy(EditPart child) { + View childView = (View) child.getModel(); + switch (UMLVisualIDRegistry.getVisualID(childView)) { + case DeploymentSpecificationFloatingLabelEditPart.VISUAL_ID: + return new BorderItemSelectionEditPolicy() { + + @Override + protected List createSelectionHandles() { + MoveHandle mh = new MoveHandle((GraphicalEditPart) getHost()); + mh.setBorder(null); + return Collections.singletonList(mh); + } + } + ; + } EditPolicy result = child.getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); if (result == null) { result = new NonResizableEditPolicy(); @@ -105,12 +133,36 @@ public class DeploymentSpecificationEditPart extends NodeEditPart { return lep; } + /** + * Papyrus codeGen + * + * @generated + **/ + @Override + protected void handleNotificationEvent(Notification event) { + /* + * when a node have external node labels, the methods refreshChildren() remove the EditPart corresponding to the Label from the EditPart + * Registry. After that, we can't reset the visibility to true (using the Show/Hide Label Action)! + */ + if (NotationPackage.eINSTANCE.getView_Visible().equals(event.getFeature())) { + Object notifier = event.getNotifier(); + List modelChildren = ((View) getModel()).getChildren(); + if (!(notifier instanceof Edge)) { + if (modelChildren.contains(event.getNotifier())) { + return; + } + } + } + super.handleNotificationEvent(event); + + } + /** * @generated */ @Override protected IFigure createNodeShape() { - return primaryShape = new NodeNamedElementFigure(); + return primaryShape = new RoundedCompartmentFigure(); } /** @@ -119,8 +171,8 @@ public class DeploymentSpecificationEditPart extends NodeEditPart { * @generated */ @Override - public NodeNamedElementFigure getPrimaryShape() { - return (NodeNamedElementFigure) primaryShape; + public RoundedCompartmentFigure getPrimaryShape() { + return (RoundedCompartmentFigure) primaryShape; } /** @@ -173,15 +225,32 @@ public class DeploymentSpecificationEditPart extends NodeEditPart { */ @Override protected IFigure getContentPaneFor(IGraphicalEditPart editPart) { + if (editPart instanceof IBorderItemEditPart) { + return getBorderedFigure().getBorderItemContainer(); + } return getContentPane(); } + /** + * @generated + */ + @Override + protected void addBorderItem(IFigure borderItemContainer, IBorderItemEditPart borderItemEditPart) { + if (borderItemEditPart instanceof DeploymentSpecificationFloatingLabelEditPart) { + IBorderItemLocator locator = new RoundedRectangleLabelPositionLocator(getMainFigure()); + borderItemContainer.add(borderItemEditPart.getFigure(), locator); + } else + { + super.addBorderItem(borderItemContainer, borderItemEditPart); + } + } + /** * @generated */ @Override protected NodeFigure createNodePlate() { - DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(40, 40); + RoundedRectangleNodePlateFigure result = new RoundedRectangleNodePlateFigure(40, 40); return result; } @@ -194,7 +263,7 @@ public class DeploymentSpecificationEditPart extends NodeEditPart { * @generated */ @Override - protected NodeFigure createNodeFigure() { + protected NodeFigure createMainFigure() { return new SelectableBorderedNodeFigure(createMainFigureWithSVG()); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DeploymentSpecificationEditPartCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DeploymentSpecificationEditPartCN.java index 9604e3e5053..57bd8d511f7 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DeploymentSpecificationEditPartCN.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DeploymentSpecificationEditPartCN.java @@ -11,27 +11,40 @@ */ package org.eclipse.papyrus.uml.diagram.composite.edit.parts; +import java.util.Collections; +import java.util.List; + import org.eclipse.draw2d.IFigure; +import org.eclipse.emf.common.notify.Notification; import org.eclipse.gef.EditPart; import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.GraphicalEditPart; 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.handles.MoveHandle; import org.eclipse.gef.requests.CreateRequest; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.BorderItemSelectionEditPolicy; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles; +import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; -import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure; import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure; +import org.eclipse.gmf.runtime.notation.Edge; +import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.gmf.runtime.notation.View; -import org.eclipse.papyrus.infra.gmfdiag.common.editpart.NodeEditPart; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.GetChildLayoutEditPolicy; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.IPapyrusNodeFigure; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.RoundedRectangleNodePlateFigure; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.SelectableBorderedNodeFigure; +import org.eclipse.papyrus.uml.diagram.common.editparts.RoundedCompartmentEditPart; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeNodeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.QualifiedNameDisplayEditPolicy; -import org.eclipse.papyrus.uml.diagram.common.figure.node.NodeNamedElementFigure; +import org.eclipse.papyrus.uml.diagram.common.figure.node.RoundedCompartmentFigure; +import org.eclipse.papyrus.uml.diagram.common.locator.RoundedRectangleLabelPositionLocator; import org.eclipse.papyrus.uml.diagram.composite.edit.policies.DeploymentSpecificationItemSemanticEditPolicyCN; import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; import org.eclipse.swt.graphics.Color; @@ -39,7 +52,7 @@ import org.eclipse.swt.graphics.Color; /** * @generated */ -public class DeploymentSpecificationEditPartCN extends NodeEditPart { +public class DeploymentSpecificationEditPartCN extends RoundedCompartmentEditPart { /** * @generated @@ -73,6 +86,7 @@ public class DeploymentSpecificationEditPartCN extends NodeEditPart { installEditPolicy(EditPolicy.LAYOUT_ROLE, createLayoutEditPolicy()); installEditPolicy(QualifiedNameDisplayEditPolicy.QUALIFIED_NAME_POLICY, new QualifiedNameDisplayEditPolicy()); installEditPolicy(AppliedStereotypeLabelDisplayEditPolicy.STEREOTYPE_LABEL_POLICY, new AppliedStereotypeNodeLabelDisplayEditPolicy()); + installEditPolicy(EditPolicy.LAYOUT_ROLE, new GetChildLayoutEditPolicy()); // XXX need an SCR to runtime to have another abstract superclass that would let children add reasonable editpolicies // removeEditPolicy(org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles.CONNECTION_HANDLES_ROLE); } @@ -85,6 +99,20 @@ public class DeploymentSpecificationEditPartCN extends NodeEditPart { @Override protected EditPolicy createChildEditPolicy(EditPart child) { + View childView = (View) child.getModel(); + switch (UMLVisualIDRegistry.getVisualID(childView)) { + case DeploymentSpecificationFloatingLabelEditPartCN.VISUAL_ID: + return new BorderItemSelectionEditPolicy() { + + @Override + protected List createSelectionHandles() { + MoveHandle mh = new MoveHandle((GraphicalEditPart) getHost()); + mh.setBorder(null); + return Collections.singletonList(mh); + } + } + ; + } EditPolicy result = child.getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); if (result == null) { result = new NonResizableEditPolicy(); @@ -105,12 +133,36 @@ public class DeploymentSpecificationEditPartCN extends NodeEditPart { return lep; } + /** + * Papyrus codeGen + * + * @generated + **/ + @Override + protected void handleNotificationEvent(Notification event) { + /* + * when a node have external node labels, the methods refreshChildren() remove the EditPart corresponding to the Label from the EditPart + * Registry. After that, we can't reset the visibility to true (using the Show/Hide Label Action)! + */ + if (NotationPackage.eINSTANCE.getView_Visible().equals(event.getFeature())) { + Object notifier = event.getNotifier(); + List modelChildren = ((View) getModel()).getChildren(); + if (!(notifier instanceof Edge)) { + if (modelChildren.contains(event.getNotifier())) { + return; + } + } + } + super.handleNotificationEvent(event); + + } + /** * @generated */ @Override protected IFigure createNodeShape() { - return primaryShape = new NodeNamedElementFigure(); + return primaryShape = new RoundedCompartmentFigure(); } /** @@ -119,8 +171,8 @@ public class DeploymentSpecificationEditPartCN extends NodeEditPart { * @generated */ @Override - public NodeNamedElementFigure getPrimaryShape() { - return (NodeNamedElementFigure) primaryShape; + public RoundedCompartmentFigure getPrimaryShape() { + return (RoundedCompartmentFigure) primaryShape; } /** @@ -173,15 +225,32 @@ public class DeploymentSpecificationEditPartCN extends NodeEditPart { */ @Override protected IFigure getContentPaneFor(IGraphicalEditPart editPart) { + if (editPart instanceof IBorderItemEditPart) { + return getBorderedFigure().getBorderItemContainer(); + } return getContentPane(); } + /** + * @generated + */ + @Override + protected void addBorderItem(IFigure borderItemContainer, IBorderItemEditPart borderItemEditPart) { + if (borderItemEditPart instanceof DeploymentSpecificationFloatingLabelEditPartCN) { + IBorderItemLocator locator = new RoundedRectangleLabelPositionLocator(getMainFigure()); + borderItemContainer.add(borderItemEditPart.getFigure(), locator); + } else + { + super.addBorderItem(borderItemContainer, borderItemEditPart); + } + } + /** * @generated */ @Override protected NodeFigure createNodePlate() { - DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(40, 40); + RoundedRectangleNodePlateFigure result = new RoundedRectangleNodePlateFigure(40, 40); return result; } @@ -194,7 +263,7 @@ public class DeploymentSpecificationEditPartCN extends NodeEditPart { * @generated */ @Override - protected NodeFigure createNodeFigure() { + protected NodeFigure createMainFigure() { return new SelectableBorderedNodeFigure(createMainFigureWithSVG()); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DeploymentSpecificationFloatingLabelEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DeploymentSpecificationFloatingLabelEditPart.java new file mode 100644 index 00000000000..eda33a0119e --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DeploymentSpecificationFloatingLabelEditPart.java @@ -0,0 +1,860 @@ +/** + * 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.uml.diagram.composite.edit.parts; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.Label; +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.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.RunnableWithResult; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gef.AccessibleEditPart; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.Request; +import org.eclipse.gef.requests.DirectEditRequest; +import org.eclipse.gef.tools.DirectEditManager; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; +import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; +import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; +import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; +import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; +import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; +import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; +import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; +import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; +import org.eclipse.gmf.runtime.notation.FontStyle; +import org.eclipse.gmf.runtime.notation.NotationPackage; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.text.contentassist.IContentAssistProcessor; +import org.eclipse.jface.viewers.ICellEditorValidator; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.extensionpoints.editors.Activator; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; +import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; +import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.ExternalLabelPrimaryDragRoleEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.PapyrusWrappingLabel; +import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; +import org.eclipse.papyrus.uml.diagram.common.editparts.FloatingLabelEditPart; +import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; +import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; +import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; +import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.accessibility.AccessibleEvent; +import org.eclipse.swt.custom.BusyIndicator; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; +import org.eclipse.uml2.uml.Feature; + +/** + * @generated + */ +public class DeploymentSpecificationFloatingLabelEditPart extends FloatingLabelEditPart + implements ITextAwareEditPart, IBorderItemEditPart +{ + + /** + * @generated + */ + public static final int VISUAL_ID = 6096; + + /** + * @generated + */ + private DirectEditManager manager; + + /** + * @generated + */ + private IParser parser; + + /** + * @generated + */ + private List parserElements; + + /** + * @generated + */ + private String defaultText; + + /** + * direct edition mode (default, undefined, registered editor, etc.) + * + * @generated + */ + protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; + + /** + * configuration from a registered edit dialog + * + * @generated + */ + protected IDirectEditorConfiguration configuration; + + + /** + * @generated + */ + static { + registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.DeploymentSpecificationFloatingLabelEditPart.VISUAL_ID), new Point(0, 0)); + } + + /** + * @generated + */ + public DeploymentSpecificationFloatingLabelEditPart(View view) { + super(view); + } + + /** + * @generated + */ + @Override + protected void createDefaultEditPolicies() { + super.createDefaultEditPolicies(); + installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); + installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ExternalLabelPrimaryDragRoleEditPolicy()); + } + + /** + * @generated + */ + @Override + public IBorderItemLocator getBorderItemLocator() { + IFigure parentFigure = getFigure().getParent(); + if (parentFigure != null && parentFigure.getLayoutManager() != null) { + Object constraint = parentFigure.getLayoutManager().getConstraint(getFigure()); + return (IBorderItemLocator) constraint; + } + return null; + } + + /** + * @generated + */ + @Override + public void refreshBounds() { + int x = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_X())).intValue(); + int y = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_Y())).intValue(); + int width = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Width())).intValue(); + int height = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Height())).intValue(); + getBorderItemLocator().setConstraint(new Rectangle(x, y, width, height)); + } + + + /** + * @generated + */ + protected String getLabelTextHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getText(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getText(); + } else { + return ((Label) figure).getText(); + } + } + + /** + * @generated + */ + protected void setLabelTextHelper(IFigure figure, String text) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setText(text); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setText(text); + } else { + ((Label) figure).setText(text); + } + } + + /** + * @generated + */ + protected Image getLabelIconHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getIcon(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getIcon(); + } else { + return ((Label) figure).getIcon(); + } + } + + /** + * @generated + */ + protected void setLabelIconHelper(IFigure figure, Image icon) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setIcon(icon); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setIcon(icon); + } else { + ((Label) figure).setIcon(icon); + } + } + + /** + * @generated + */ + public void setLabel(IFigure + figure) { + unregisterVisuals(); + setFigure(figure); + defaultText = getLabelTextHelper(figure); + registerVisuals(); + refreshVisuals(); + } + + /** + * @generated + */ + @Override + protected List getModelChildren() { + return Collections.EMPTY_LIST; + } + + /** + * @generated + */ + @Override + public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { + return null; + } + + /** + * @generated + */ + public void setParser(IParser parser) { + this.parser = parser; + } + + /** + * @generated + */ + protected EObject getParserElement() { + return resolveSemanticElement(); + } + + /** + * @generated + */ + protected Image getLabelIcon() { + return null; + } + + /** + * @generated + */ + protected String getLabelText() { + String text = null; + EObject parserElement = getParserElement(); + if (parserElement != null && getParser() != null) { + text = getParser().getPrintString( + new EObjectAdapter(parserElement), + getParserOptions().intValue()); + } + if (text == null || text.length() == 0) { + text = defaultText; + } + return text; + } + + /** + * @generated + */ + @Override + public void setLabelText(String text) { + setLabelTextHelper(getFigure(), text); + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + @Override + public String getEditText() { + if (getParserElement() == null || getParser() == null) { + return ""; //$NON-NLS-1$ + } + return getParser().getEditString( + new EObjectAdapter(getParserElement()), + getParserOptions().intValue()); + } + + /** + * @generated + */ + protected boolean isEditable() { + return getParser() != null; + } + + /** + * @generated + */ + @Override + public ICellEditorValidator getEditTextValidator() { + return new ICellEditorValidator() { + + @Override + public String isValid(final Object value) { + if (value instanceof String) { + final EObject element = getParserElement(); + final IParser parser = getParser(); + try { + IParserEditStatus valid = + (IParserEditStatus) getEditingDomain().runExclusive( + new RunnableWithResult.Impl() { + + @Override + public void run() { + setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); + } + }); + return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); + } catch (InterruptedException ie) { + ie.printStackTrace(); + } + } + + // shouldn't get here + return null; + } + }; + } + + /** + * @generated + */ + @Override + public IContentAssistProcessor getCompletionProcessor() { + if (getParserElement() == null || getParser() == null) { + return null; + } + return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); + } + + /** + * @generated + */ + @Override + public ParserOptions getParserOptions() { + return ParserOptions.NONE; + } + + /** + * @generated + */ + @Override + public IParser getParser() { + if (parser == null) { + parser = UMLParserProvider.getParser(UMLElementTypes.DeploymentSpecification_2078, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.DeploymentSpecificationFloatingLabelEditPart.VISUAL_ID)); + } + return parser; + } + + /** + * @generated + */ + protected DirectEditManager getManager() { + if (manager == null) { + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + } + return manager; + } + + /** + * @generated + */ + protected void setManager(DirectEditManager manager) { + this.manager = manager; + } + + /** + * @generated + */ + protected void performDirectEdit() { + BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { + + @Override + public void run() { + getManager().show(); + } + }); + } + + /** + * @generated + */ + protected void performDirectEdit(Point eventLocation) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); + } + } + + /** + * @generated + */ + private void performDirectEdit(char initialCharacter) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(initialCharacter); + } else { + performDirectEdit(); + } + } + + /** + * @generated + */ + @Override + protected void performDirectEditRequest(Request request) { + + final Request theRequest = request; + + if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { + directEditionMode = getDirectEditionType(); + } + switch (directEditionMode) { + case IDirectEdition.NO_DIRECT_EDITION: + // no direct edition mode => does nothing + return; + case IDirectEdition.EXTENDED_DIRECT_EDITOR: + updateExtendedEditorConfiguration(); + if (configuration == null || configuration.getLanguage() == null) { + // Create default edit manager + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + performDefaultDirectEditorEdit(theRequest); + } else { + configuration.preEditAction(resolveSemanticElement()); + Dialog dialog = null; + if (configuration instanceof ICustomDirectEditorConfiguration) { + setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); + initializeDirectEditManager(theRequest); + return; + } else if (configuration instanceof IPopupEditorConfiguration) { + IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); + helper.showEditor(); + return; + } + else if (configuration instanceof IAdvancedEditorConfiguration) { + dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); + } else if (configuration instanceof IDirectEditorConfiguration) { + dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), + configuration); + } else { + return; + } + final Dialog finalDialog = dialog; + + if (Window.OK == dialog.open()) { + TransactionalEditingDomain domain = getEditingDomain(); + RecordingCommand command = new RecordingCommand(domain, "Edit Label") { + + @Override + protected void doExecute() { + configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); + + } + }; + domain.getCommandStack().execute(command); + } + } + break; + case IDirectEdition.DEFAULT_DIRECT_EDITOR: + initializeDirectEditManager(theRequest); + break; + default: + break; + } + } + + /** + * @generated + */ + protected void initializeDirectEditManager(final Request request) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + @Override + public void run() { + if (isActive() && isEditable()) { + if (request.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } + else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void refreshVisuals() { + super.refreshVisuals(); + refreshLabel(); + refreshFont(); + refreshFontColor(); + refreshUnderline(); + refreshStrikeThrough(); + } + + /** + * @generated + */ + protected void refreshLabel() { + EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); + if (maskLabelPolicy == null) { + maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); + } + if (maskLabelPolicy == null) { + View view = (View) getModel(); + if (view.isVisible()) { + setLabelTextHelper(getFigure(), getLabelText()); + setLabelIconHelper(getFigure(), getLabelIcon()); + } + else { + setLabelTextHelper(getFigure(), ""); //$NON-NLS-1$ + setLabelIconHelper(getFigure(), null); + } + } + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + protected void refreshUnderline() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); + } + if (resolveSemanticElement() instanceof Feature) { + if (((Feature) resolveSemanticElement()).isStatic()) { + ((WrappingLabel) getFigure()).setTextUnderline(true); + } + else { + ((WrappingLabel) getFigure()).setTextUnderline(false); + } + } + } + + /** + * @generated + */ + protected void refreshStrikeThrough() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); + } + } + + /** + * @generated + */ + @Override + protected void refreshFont() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null) { + FontData fontData = new FontData( + style.getFontName(), style.getFontHeight(), + (style.isBold() ? SWT.BOLD : SWT.NORMAL) | + (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); + setFont(fontData); + } + } + + /** + * @generated + */ + @Override + protected void setFontColor(Color color) { + getFigure().setForegroundColor(color); + } + + /** + * @generated + */ + @Override + protected void addSemanticListeners() { + if (getParser() instanceof ISemanticParser) { + EObject element = resolveSemanticElement(); + parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); + for (int i = 0; i < parserElements.size(); i++) { + addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ + } + } else { + super.addSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected void removeSemanticListeners() { + if (parserElements != null) { + for (int i = 0; i < parserElements.size(); i++) { + removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ + } + } else { + super.removeSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected AccessibleEditPart getAccessibleEditPart() { + if (accessibleEP == null) { + accessibleEP = new AccessibleGraphicalEditPart() { + + @Override + public void getName(AccessibleEvent e) { + e.result = getLabelTextHelper(getFigure()); + } + }; + } + return accessibleEP; + } + + /** + * @generated + */ + private View getFontStyleOwnerView() { + return getPrimaryView(); + } + + /** + * Returns the kind of associated editor for direct edition. + * + * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition + * @generated + */ + public int getDirectEditionType() { + if (checkExtendedEditor()) { + initExtendedEditorConfiguration(); + return IDirectEdition.EXTENDED_DIRECT_EDITOR; + } + if (checkDefaultEdition()) { + return IDirectEdition.DEFAULT_DIRECT_EDITOR; + } + + // not a named element. no specific editor => do nothing + return IDirectEdition.NO_DIRECT_EDITION; + } + + /** + * Checks if an extended editor is present. + * + * @return true if an extended editor is present. + * @generated + */ + protected boolean checkExtendedEditor() { + if (resolveSemanticElement() != null) { + return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); + } + return false; + } + + /** + * Checks if a default direct edition is available + * + * @return true if a default direct edition is available + * @generated + */ + protected boolean checkDefaultEdition() { + return (getParser() != null); + } + + /** + * Initializes the extended editor configuration + * + * @generated + */ + protected void initExtendedEditorConfiguration() { + if (configuration == null) { + final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("")) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); + } else { + configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); + } + } + } + + /** + * Updates the preference configuration + * + * @generated + */ + protected void updateExtendedEditorConfiguration() { + String languagePreferred = Activator.getDefault().getPreferenceStore().getString( + IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() + .eClass().getInstanceClassName()); + } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { + configuration = null; + } + } + + /** + * Performs the direct edit usually used by GMF editors. + * + * @param theRequest + * the direct edit request that starts the direct edit system + * @generated + */ + protected void performDefaultDirectEditorEdit(final Request theRequest) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + + @Override + public void run() { + if (isActive() && isEditable()) { + if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) theRequest.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { + DirectEditRequest editRequest = (DirectEditRequest) theRequest; + performDirectEdit(editRequest.getLocation()); + } else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + + /** + * @generated + */ + @Override + protected void handleNotificationEvent(Notification event) { + Object feature = event.getFeature(); + if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { + Integer c = (Integer) event.getNewValue(); + setFontColor(DiagramColorRegistry.getInstance().getColor(c)); + } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { + refreshUnderline(); + } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { + refreshStrikeThrough(); + } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { + refreshFont(); + } else { + if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { + refreshLabel(); + } + if (getParser() instanceof ISemanticParser) { + ISemanticParser modelParser = + (ISemanticParser) getParser(); + if (modelParser.areSemanticElementsAffected(null, event)) { + removeSemanticListeners(); + if (resolveSemanticElement() != null) { + addSemanticListeners(); + } + refreshLabel(); + } + } + } + super.handleNotificationEvent(event); + } + + /** + * @generated + */ + @Override + protected IFigure createFigure() { + IFigure label = createFigurePrim(); + defaultText = getLabelTextHelper(label); + return label; + } + + /** + * @generated + */ + protected IFigure createFigurePrim() { + return new PapyrusWrappingLabel(); + } + +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DeploymentSpecificationFloatingLabelEditPartCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DeploymentSpecificationFloatingLabelEditPartCN.java new file mode 100644 index 00000000000..bdd11e2b97d --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DeploymentSpecificationFloatingLabelEditPartCN.java @@ -0,0 +1,860 @@ +/** + * 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.uml.diagram.composite.edit.parts; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.Label; +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.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.RunnableWithResult; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gef.AccessibleEditPart; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.Request; +import org.eclipse.gef.requests.DirectEditRequest; +import org.eclipse.gef.tools.DirectEditManager; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; +import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; +import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; +import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; +import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; +import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; +import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; +import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; +import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; +import org.eclipse.gmf.runtime.notation.FontStyle; +import org.eclipse.gmf.runtime.notation.NotationPackage; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.text.contentassist.IContentAssistProcessor; +import org.eclipse.jface.viewers.ICellEditorValidator; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.extensionpoints.editors.Activator; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; +import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; +import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.ExternalLabelPrimaryDragRoleEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.PapyrusWrappingLabel; +import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; +import org.eclipse.papyrus.uml.diagram.common.editparts.FloatingLabelEditPart; +import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; +import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; +import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; +import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.accessibility.AccessibleEvent; +import org.eclipse.swt.custom.BusyIndicator; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; +import org.eclipse.uml2.uml.Feature; + +/** + * @generated + */ +public class DeploymentSpecificationFloatingLabelEditPartCN extends FloatingLabelEditPart + implements ITextAwareEditPart, IBorderItemEditPart +{ + + /** + * @generated + */ + public static final int VISUAL_ID = 6074; + + /** + * @generated + */ + private DirectEditManager manager; + + /** + * @generated + */ + private IParser parser; + + /** + * @generated + */ + private List parserElements; + + /** + * @generated + */ + private String defaultText; + + /** + * direct edition mode (default, undefined, registered editor, etc.) + * + * @generated + */ + protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; + + /** + * configuration from a registered edit dialog + * + * @generated + */ + protected IDirectEditorConfiguration configuration; + + + /** + * @generated + */ + static { + registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.DeploymentSpecificationFloatingLabelEditPartCN.VISUAL_ID), new Point(0, 0)); + } + + /** + * @generated + */ + public DeploymentSpecificationFloatingLabelEditPartCN(View view) { + super(view); + } + + /** + * @generated + */ + @Override + protected void createDefaultEditPolicies() { + super.createDefaultEditPolicies(); + installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); + installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ExternalLabelPrimaryDragRoleEditPolicy()); + } + + /** + * @generated + */ + @Override + public IBorderItemLocator getBorderItemLocator() { + IFigure parentFigure = getFigure().getParent(); + if (parentFigure != null && parentFigure.getLayoutManager() != null) { + Object constraint = parentFigure.getLayoutManager().getConstraint(getFigure()); + return (IBorderItemLocator) constraint; + } + return null; + } + + /** + * @generated + */ + @Override + public void refreshBounds() { + int x = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_X())).intValue(); + int y = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_Y())).intValue(); + int width = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Width())).intValue(); + int height = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Height())).intValue(); + getBorderItemLocator().setConstraint(new Rectangle(x, y, width, height)); + } + + + /** + * @generated + */ + protected String getLabelTextHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getText(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getText(); + } else { + return ((Label) figure).getText(); + } + } + + /** + * @generated + */ + protected void setLabelTextHelper(IFigure figure, String text) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setText(text); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setText(text); + } else { + ((Label) figure).setText(text); + } + } + + /** + * @generated + */ + protected Image getLabelIconHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getIcon(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getIcon(); + } else { + return ((Label) figure).getIcon(); + } + } + + /** + * @generated + */ + protected void setLabelIconHelper(IFigure figure, Image icon) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setIcon(icon); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setIcon(icon); + } else { + ((Label) figure).setIcon(icon); + } + } + + /** + * @generated + */ + public void setLabel(IFigure + figure) { + unregisterVisuals(); + setFigure(figure); + defaultText = getLabelTextHelper(figure); + registerVisuals(); + refreshVisuals(); + } + + /** + * @generated + */ + @Override + protected List getModelChildren() { + return Collections.EMPTY_LIST; + } + + /** + * @generated + */ + @Override + public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { + return null; + } + + /** + * @generated + */ + public void setParser(IParser parser) { + this.parser = parser; + } + + /** + * @generated + */ + protected EObject getParserElement() { + return resolveSemanticElement(); + } + + /** + * @generated + */ + protected Image getLabelIcon() { + return null; + } + + /** + * @generated + */ + protected String getLabelText() { + String text = null; + EObject parserElement = getParserElement(); + if (parserElement != null && getParser() != null) { + text = getParser().getPrintString( + new EObjectAdapter(parserElement), + getParserOptions().intValue()); + } + if (text == null || text.length() == 0) { + text = defaultText; + } + return text; + } + + /** + * @generated + */ + @Override + public void setLabelText(String text) { + setLabelTextHelper(getFigure(), text); + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + @Override + public String getEditText() { + if (getParserElement() == null || getParser() == null) { + return ""; //$NON-NLS-1$ + } + return getParser().getEditString( + new EObjectAdapter(getParserElement()), + getParserOptions().intValue()); + } + + /** + * @generated + */ + protected boolean isEditable() { + return getParser() != null; + } + + /** + * @generated + */ + @Override + public ICellEditorValidator getEditTextValidator() { + return new ICellEditorValidator() { + + @Override + public String isValid(final Object value) { + if (value instanceof String) { + final EObject element = getParserElement(); + final IParser parser = getParser(); + try { + IParserEditStatus valid = + (IParserEditStatus) getEditingDomain().runExclusive( + new RunnableWithResult.Impl() { + + @Override + public void run() { + setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); + } + }); + return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); + } catch (InterruptedException ie) { + ie.printStackTrace(); + } + } + + // shouldn't get here + return null; + } + }; + } + + /** + * @generated + */ + @Override + public IContentAssistProcessor getCompletionProcessor() { + if (getParserElement() == null || getParser() == null) { + return null; + } + return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); + } + + /** + * @generated + */ + @Override + public ParserOptions getParserOptions() { + return ParserOptions.NONE; + } + + /** + * @generated + */ + @Override + public IParser getParser() { + if (parser == null) { + parser = UMLParserProvider.getParser(UMLElementTypes.DeploymentSpecification_3092, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.DeploymentSpecificationFloatingLabelEditPartCN.VISUAL_ID)); + } + return parser; + } + + /** + * @generated + */ + protected DirectEditManager getManager() { + if (manager == null) { + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + } + return manager; + } + + /** + * @generated + */ + protected void setManager(DirectEditManager manager) { + this.manager = manager; + } + + /** + * @generated + */ + protected void performDirectEdit() { + BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { + + @Override + public void run() { + getManager().show(); + } + }); + } + + /** + * @generated + */ + protected void performDirectEdit(Point eventLocation) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); + } + } + + /** + * @generated + */ + private void performDirectEdit(char initialCharacter) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(initialCharacter); + } else { + performDirectEdit(); + } + } + + /** + * @generated + */ + @Override + protected void performDirectEditRequest(Request request) { + + final Request theRequest = request; + + if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { + directEditionMode = getDirectEditionType(); + } + switch (directEditionMode) { + case IDirectEdition.NO_DIRECT_EDITION: + // no direct edition mode => does nothing + return; + case IDirectEdition.EXTENDED_DIRECT_EDITOR: + updateExtendedEditorConfiguration(); + if (configuration == null || configuration.getLanguage() == null) { + // Create default edit manager + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + performDefaultDirectEditorEdit(theRequest); + } else { + configuration.preEditAction(resolveSemanticElement()); + Dialog dialog = null; + if (configuration instanceof ICustomDirectEditorConfiguration) { + setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); + initializeDirectEditManager(theRequest); + return; + } else if (configuration instanceof IPopupEditorConfiguration) { + IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); + helper.showEditor(); + return; + } + else if (configuration instanceof IAdvancedEditorConfiguration) { + dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); + } else if (configuration instanceof IDirectEditorConfiguration) { + dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), + configuration); + } else { + return; + } + final Dialog finalDialog = dialog; + + if (Window.OK == dialog.open()) { + TransactionalEditingDomain domain = getEditingDomain(); + RecordingCommand command = new RecordingCommand(domain, "Edit Label") { + + @Override + protected void doExecute() { + configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); + + } + }; + domain.getCommandStack().execute(command); + } + } + break; + case IDirectEdition.DEFAULT_DIRECT_EDITOR: + initializeDirectEditManager(theRequest); + break; + default: + break; + } + } + + /** + * @generated + */ + protected void initializeDirectEditManager(final Request request) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + @Override + public void run() { + if (isActive() && isEditable()) { + if (request.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } + else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void refreshVisuals() { + super.refreshVisuals(); + refreshLabel(); + refreshFont(); + refreshFontColor(); + refreshUnderline(); + refreshStrikeThrough(); + } + + /** + * @generated + */ + protected void refreshLabel() { + EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); + if (maskLabelPolicy == null) { + maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); + } + if (maskLabelPolicy == null) { + View view = (View) getModel(); + if (view.isVisible()) { + setLabelTextHelper(getFigure(), getLabelText()); + setLabelIconHelper(getFigure(), getLabelIcon()); + } + else { + setLabelTextHelper(getFigure(), ""); //$NON-NLS-1$ + setLabelIconHelper(getFigure(), null); + } + } + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + protected void refreshUnderline() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); + } + if (resolveSemanticElement() instanceof Feature) { + if (((Feature) resolveSemanticElement()).isStatic()) { + ((WrappingLabel) getFigure()).setTextUnderline(true); + } + else { + ((WrappingLabel) getFigure()).setTextUnderline(false); + } + } + } + + /** + * @generated + */ + protected void refreshStrikeThrough() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); + } + } + + /** + * @generated + */ + @Override + protected void refreshFont() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null) { + FontData fontData = new FontData( + style.getFontName(), style.getFontHeight(), + (style.isBold() ? SWT.BOLD : SWT.NORMAL) | + (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); + setFont(fontData); + } + } + + /** + * @generated + */ + @Override + protected void setFontColor(Color color) { + getFigure().setForegroundColor(color); + } + + /** + * @generated + */ + @Override + protected void addSemanticListeners() { + if (getParser() instanceof ISemanticParser) { + EObject element = resolveSemanticElement(); + parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); + for (int i = 0; i < parserElements.size(); i++) { + addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ + } + } else { + super.addSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected void removeSemanticListeners() { + if (parserElements != null) { + for (int i = 0; i < parserElements.size(); i++) { + removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ + } + } else { + super.removeSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected AccessibleEditPart getAccessibleEditPart() { + if (accessibleEP == null) { + accessibleEP = new AccessibleGraphicalEditPart() { + + @Override + public void getName(AccessibleEvent e) { + e.result = getLabelTextHelper(getFigure()); + } + }; + } + return accessibleEP; + } + + /** + * @generated + */ + private View getFontStyleOwnerView() { + return getPrimaryView(); + } + + /** + * Returns the kind of associated editor for direct edition. + * + * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition + * @generated + */ + public int getDirectEditionType() { + if (checkExtendedEditor()) { + initExtendedEditorConfiguration(); + return IDirectEdition.EXTENDED_DIRECT_EDITOR; + } + if (checkDefaultEdition()) { + return IDirectEdition.DEFAULT_DIRECT_EDITOR; + } + + // not a named element. no specific editor => do nothing + return IDirectEdition.NO_DIRECT_EDITION; + } + + /** + * Checks if an extended editor is present. + * + * @return true if an extended editor is present. + * @generated + */ + protected boolean checkExtendedEditor() { + if (resolveSemanticElement() != null) { + return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); + } + return false; + } + + /** + * Checks if a default direct edition is available + * + * @return true if a default direct edition is available + * @generated + */ + protected boolean checkDefaultEdition() { + return (getParser() != null); + } + + /** + * Initializes the extended editor configuration + * + * @generated + */ + protected void initExtendedEditorConfiguration() { + if (configuration == null) { + final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("")) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); + } else { + configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); + } + } + } + + /** + * Updates the preference configuration + * + * @generated + */ + protected void updateExtendedEditorConfiguration() { + String languagePreferred = Activator.getDefault().getPreferenceStore().getString( + IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() + .eClass().getInstanceClassName()); + } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { + configuration = null; + } + } + + /** + * Performs the direct edit usually used by GMF editors. + * + * @param theRequest + * the direct edit request that starts the direct edit system + * @generated + */ + protected void performDefaultDirectEditorEdit(final Request theRequest) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + + @Override + public void run() { + if (isActive() && isEditable()) { + if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) theRequest.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { + DirectEditRequest editRequest = (DirectEditRequest) theRequest; + performDirectEdit(editRequest.getLocation()); + } else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + + /** + * @generated + */ + @Override + protected void handleNotificationEvent(Notification event) { + Object feature = event.getFeature(); + if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { + Integer c = (Integer) event.getNewValue(); + setFontColor(DiagramColorRegistry.getInstance().getColor(c)); + } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { + refreshUnderline(); + } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { + refreshStrikeThrough(); + } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { + refreshFont(); + } else { + if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { + refreshLabel(); + } + if (getParser() instanceof ISemanticParser) { + ISemanticParser modelParser = + (ISemanticParser) getParser(); + if (modelParser.areSemanticElementsAffected(null, event)) { + removeSemanticListeners(); + if (resolveSemanticElement() != null) { + addSemanticListeners(); + } + refreshLabel(); + } + } + } + super.handleNotificationEvent(event); + } + + /** + * @generated + */ + @Override + protected IFigure createFigure() { + IFigure label = createFigurePrim(); + defaultText = getLabelTextHelper(label); + return label; + } + + /** + * @generated + */ + protected IFigure createFigurePrim() { + return new PapyrusWrappingLabel(); + } + +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DeploymentSpecificationNameEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DeploymentSpecificationNameEditPart.java index c12208ece57..3a2a3fc58cd 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DeploymentSpecificationNameEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DeploymentSpecificationNameEditPart.java @@ -864,7 +864,7 @@ public class DeploymentSpecificationNameEditPart extends PapyrusCompartmentEditP * @generated */ protected void addOwnerElementListeners() { - addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); + addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DeploymentSpecificationNameEditPartCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DeploymentSpecificationNameEditPartCN.java index abace2c77c5..70a08172c8b 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DeploymentSpecificationNameEditPartCN.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DeploymentSpecificationNameEditPartCN.java @@ -864,7 +864,7 @@ public class DeploymentSpecificationNameEditPartCN extends PapyrusCompartmentEdi * @generated */ protected void addOwnerElementListeners() { - addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); + addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DeviceCompositeCompartmentEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DeviceCompositeCompartmentEditPart.java index cc11d61169c..17fa46ed0a1 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DeviceCompositeCompartmentEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DeviceCompositeCompartmentEditPart.java @@ -26,6 +26,7 @@ import org.eclipse.gmf.runtime.diagram.ui.editpolicies.ResizableCompartmentEditP import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.BorderDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.CustomContainerEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.DuplicatePasteEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.PapyrusCreationEditPolicy; @@ -75,6 +76,7 @@ public class DeviceCompositeCompartmentEditPart extends ShapeCompartmentEditPart installEditPolicy(EditPolicy.GRAPHICAL_NODE_ROLE, new CustomContainerEditPolicy()); installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, new CustomDiagramDragDropEditPolicy()); installEditPolicy(EditPolicyRoles.CREATION_ROLE, new PortInCompartmentCreationEditPolicy()); + installEditPolicy(BorderDisplayEditPolicy.BORDER_DISPLAY_EDITPOLICY, new BorderDisplayEditPolicy()); } /** diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DeviceCompositeCompartmentEditPartCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DeviceCompositeCompartmentEditPartCN.java index 10e4db0bf97..cee56bd49f3 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DeviceCompositeCompartmentEditPartCN.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DeviceCompositeCompartmentEditPartCN.java @@ -26,6 +26,7 @@ import org.eclipse.gmf.runtime.diagram.ui.editpolicies.ResizableCompartmentEditP import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.BorderDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.CustomContainerEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.DuplicatePasteEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.PapyrusCreationEditPolicy; @@ -75,6 +76,7 @@ public class DeviceCompositeCompartmentEditPartCN extends ShapeCompartmentEditPa installEditPolicy(EditPolicy.GRAPHICAL_NODE_ROLE, new CustomContainerEditPolicy()); installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, new CustomDiagramDragDropEditPolicy()); installEditPolicy(EditPolicyRoles.CREATION_ROLE, new PortInCompartmentCreationEditPolicy()); + installEditPolicy(BorderDisplayEditPolicy.BORDER_DISPLAY_EDITPOLICY, new BorderDisplayEditPolicy()); } /** diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DeviceCompositeEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DeviceCompositeEditPart.java index 3d8f61679fe..0f1c749db13 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DeviceCompositeEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DeviceCompositeEditPart.java @@ -11,28 +11,37 @@ */ package org.eclipse.papyrus.uml.diagram.composite.edit.parts; +import java.util.Collections; +import java.util.List; + import org.eclipse.draw2d.IFigure; import org.eclipse.draw2d.PositionConstants; import org.eclipse.emf.common.notify.Notification; import org.eclipse.gef.EditPart; import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.GraphicalEditPart; 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.handles.MoveHandle; import org.eclipse.gef.requests.CreateRequest; import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.BorderItemSelectionEditPolicy; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.DragDropEditPolicy; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles; import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; -import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure; import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure; +import org.eclipse.gmf.runtime.notation.Edge; +import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.GetChildLayoutEditPolicy; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.IPapyrusNodeFigure; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.RoundedRectangleNodePlateFigure; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.SelectableBorderedNodeFigure; -import org.eclipse.papyrus.uml.diagram.common.editparts.NamedElementEditPart; +import org.eclipse.papyrus.uml.diagram.common.editparts.RoundedCompartmentEditPart; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AffixedNodeAlignmentEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeNodeLabelDisplayEditPolicy; @@ -41,11 +50,11 @@ import org.eclipse.papyrus.uml.diagram.common.editpolicies.PapyrusCreationEditPo import org.eclipse.papyrus.uml.diagram.common.editpolicies.QualifiedNameDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.ShowHideClassifierContentsEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.ShowHideCompartmentEditPolicy; +import org.eclipse.papyrus.uml.diagram.common.locator.RoundedRectangleLabelPositionLocator; import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.CustomDiagramDragDropEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.RemoveOrphanViewPolicy; import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.StructuredClassifierLayoutEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.custom.figures.DeviceCompositeFigure; -import org.eclipse.papyrus.uml.diagram.composite.custom.locators.PortPositionLocator; import org.eclipse.papyrus.uml.diagram.composite.edit.policies.DeviceCompositeItemSemanticEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; import org.eclipse.swt.graphics.Color; @@ -53,7 +62,7 @@ import org.eclipse.swt.graphics.Color; /** * @generated */ -public class DeviceCompositeEditPart extends NamedElementEditPart { +public class DeviceCompositeEditPart extends RoundedCompartmentEditPart { /** * @generated @@ -95,6 +104,7 @@ public class DeviceCompositeEditPart extends NamedElementEditPart { installEditPolicy(ShowHideCompartmentEditPolicy.SHOW_HIDE_COMPARTMENT_POLICY, new ShowHideCompartmentEditPolicy()); installEditPolicy(AffixedNodeAlignmentEditPolicy.AFFIXED_CHILD_ALIGNMENT_ROLE, new AffixedNodeAlignmentEditPolicy()); installEditPolicy("REMOVE_ORPHAN_VIEW", new RemoveOrphanViewPolicy()); //$NON-NLS-1$ + installEditPolicy(EditPolicy.LAYOUT_ROLE, new GetChildLayoutEditPolicy()); // XXX need an SCR to runtime to have another abstract superclass that would let children add reasonable editpolicies // removeEditPolicy(org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles.CONNECTION_HANDLES_ROLE); } @@ -109,6 +119,17 @@ public class DeviceCompositeEditPart extends NamedElementEditPart { protected EditPolicy createChildEditPolicy(EditPart child) { View childView = (View) child.getModel(); switch (UMLVisualIDRegistry.getVisualID(childView)) { + case DeviceCompositeFloatingLabelEditPart.VISUAL_ID: + return new BorderItemSelectionEditPolicy() { + + @Override + protected List createSelectionHandles() { + MoveHandle mh = new MoveHandle((GraphicalEditPart) getHost()); + mh.setBorder(null); + return Collections.singletonList(mh); + } + } + ; case PortEditPart.VISUAL_ID: return new BorderItemResizableEditPolicy(); } @@ -139,6 +160,19 @@ public class DeviceCompositeEditPart extends NamedElementEditPart { **/ @Override protected void handleNotificationEvent(Notification event) { + /* + * when a node have external node labels, the methods refreshChildren() remove the EditPart corresponding to the Label from the EditPart + * Registry. After that, we can't reset the visibility to true (using the Show/Hide Label Action)! + */ + if (NotationPackage.eINSTANCE.getView_Visible().equals(event.getFeature())) { + Object notifier = event.getNotifier(); + List modelChildren = ((View) getModel()).getChildren(); + if (!(notifier instanceof Edge)) { + if (modelChildren.contains(event.getNotifier())) { + return; + } + } + } super.handleNotificationEvent(event); } @@ -180,9 +214,9 @@ public class DeviceCompositeEditPart extends NamedElementEditPart { - //Papyrus Gencode :Affixed Port locator + // Papyrus Gencode :Affixed Port locator if (childEditPart instanceof PortEditPart) { - IBorderItemLocator locator = new PortPositionLocator(getMainFigure(), PositionConstants.NONE); + IBorderItemLocator locator = new org.eclipse.papyrus.uml.diagram.common.locator.PortPositionLocator(getMainFigure(), PositionConstants.NONE); getBorderedFigure().getBorderItemContainer().add(((PortEditPart) childEditPart).getFigure(), locator); return true; } @@ -246,12 +280,26 @@ public class DeviceCompositeEditPart extends NamedElementEditPart { return getContentPane(); } + /** + * @generated + */ + @Override + protected void addBorderItem(IFigure borderItemContainer, IBorderItemEditPart borderItemEditPart) { + if (borderItemEditPart instanceof DeviceCompositeFloatingLabelEditPart) { + IBorderItemLocator locator = new RoundedRectangleLabelPositionLocator(getMainFigure()); + borderItemContainer.add(borderItemEditPart.getFigure(), locator); + } else + { + super.addBorderItem(borderItemContainer, borderItemEditPart); + } + } + /** * @generated */ @Override protected NodeFigure createNodePlate() { - DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(40, 40); + RoundedRectangleNodePlateFigure result = new RoundedRectangleNodePlateFigure(40, 40); return result; } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DeviceCompositeEditPartCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DeviceCompositeEditPartCN.java index 730ebefd883..b5e3aae511d 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DeviceCompositeEditPartCN.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DeviceCompositeEditPartCN.java @@ -11,28 +11,37 @@ */ package org.eclipse.papyrus.uml.diagram.composite.edit.parts; +import java.util.Collections; +import java.util.List; + import org.eclipse.draw2d.IFigure; import org.eclipse.draw2d.PositionConstants; import org.eclipse.emf.common.notify.Notification; import org.eclipse.gef.EditPart; import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.GraphicalEditPart; 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.handles.MoveHandle; import org.eclipse.gef.requests.CreateRequest; import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.BorderItemSelectionEditPolicy; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.DragDropEditPolicy; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles; import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; -import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure; import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure; +import org.eclipse.gmf.runtime.notation.Edge; +import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.GetChildLayoutEditPolicy; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.IPapyrusNodeFigure; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.RoundedRectangleNodePlateFigure; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.SelectableBorderedNodeFigure; -import org.eclipse.papyrus.uml.diagram.common.editparts.NamedElementEditPart; +import org.eclipse.papyrus.uml.diagram.common.editparts.RoundedCompartmentEditPart; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AffixedNodeAlignmentEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeNodeLabelDisplayEditPolicy; @@ -41,11 +50,11 @@ import org.eclipse.papyrus.uml.diagram.common.editpolicies.PapyrusCreationEditPo import org.eclipse.papyrus.uml.diagram.common.editpolicies.QualifiedNameDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.ShowHideClassifierContentsEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.ShowHideCompartmentEditPolicy; +import org.eclipse.papyrus.uml.diagram.common.locator.RoundedRectangleLabelPositionLocator; import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.CustomDiagramDragDropEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.RemoveOrphanViewPolicy; import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.StructuredClassifierLayoutEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.custom.figures.DeviceCompositeFigure; -import org.eclipse.papyrus.uml.diagram.composite.custom.locators.PortPositionLocator; import org.eclipse.papyrus.uml.diagram.composite.edit.policies.DeviceCompositeItemSemanticEditPolicyCN; import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; import org.eclipse.swt.graphics.Color; @@ -53,7 +62,7 @@ import org.eclipse.swt.graphics.Color; /** * @generated */ -public class DeviceCompositeEditPartCN extends NamedElementEditPart { +public class DeviceCompositeEditPartCN extends RoundedCompartmentEditPart { /** * @generated @@ -95,6 +104,7 @@ public class DeviceCompositeEditPartCN extends NamedElementEditPart { installEditPolicy(ShowHideCompartmentEditPolicy.SHOW_HIDE_COMPARTMENT_POLICY, new ShowHideCompartmentEditPolicy()); installEditPolicy(AffixedNodeAlignmentEditPolicy.AFFIXED_CHILD_ALIGNMENT_ROLE, new AffixedNodeAlignmentEditPolicy()); installEditPolicy("REMOVE_ORPHAN_VIEW", new RemoveOrphanViewPolicy()); //$NON-NLS-1$ + installEditPolicy(EditPolicy.LAYOUT_ROLE, new GetChildLayoutEditPolicy()); // XXX need an SCR to runtime to have another abstract superclass that would let children add reasonable editpolicies // removeEditPolicy(org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles.CONNECTION_HANDLES_ROLE); } @@ -109,6 +119,17 @@ public class DeviceCompositeEditPartCN extends NamedElementEditPart { protected EditPolicy createChildEditPolicy(EditPart child) { View childView = (View) child.getModel(); switch (UMLVisualIDRegistry.getVisualID(childView)) { + case DeviceCompositeFloatingLabelEditPartCN.VISUAL_ID: + return new BorderItemSelectionEditPolicy() { + + @Override + protected List createSelectionHandles() { + MoveHandle mh = new MoveHandle((GraphicalEditPart) getHost()); + mh.setBorder(null); + return Collections.singletonList(mh); + } + } + ; case PortEditPart.VISUAL_ID: return new BorderItemResizableEditPolicy(); } @@ -139,6 +160,19 @@ public class DeviceCompositeEditPartCN extends NamedElementEditPart { **/ @Override protected void handleNotificationEvent(Notification event) { + /* + * when a node have external node labels, the methods refreshChildren() remove the EditPart corresponding to the Label from the EditPart + * Registry. After that, we can't reset the visibility to true (using the Show/Hide Label Action)! + */ + if (NotationPackage.eINSTANCE.getView_Visible().equals(event.getFeature())) { + Object notifier = event.getNotifier(); + List modelChildren = ((View) getModel()).getChildren(); + if (!(notifier instanceof Edge)) { + if (modelChildren.contains(event.getNotifier())) { + return; + } + } + } super.handleNotificationEvent(event); } @@ -180,9 +214,9 @@ public class DeviceCompositeEditPartCN extends NamedElementEditPart { - //Papyrus Gencode :Affixed Port locator + // Papyrus Gencode :Affixed Port locator if (childEditPart instanceof PortEditPart) { - IBorderItemLocator locator = new PortPositionLocator(getMainFigure(), PositionConstants.NONE); + IBorderItemLocator locator = new org.eclipse.papyrus.uml.diagram.common.locator.PortPositionLocator(getMainFigure(), PositionConstants.NONE); getBorderedFigure().getBorderItemContainer().add(((PortEditPart) childEditPart).getFigure(), locator); return true; } @@ -246,12 +280,26 @@ public class DeviceCompositeEditPartCN extends NamedElementEditPart { return getContentPane(); } + /** + * @generated + */ + @Override + protected void addBorderItem(IFigure borderItemContainer, IBorderItemEditPart borderItemEditPart) { + if (borderItemEditPart instanceof DeviceCompositeFloatingLabelEditPartCN) { + IBorderItemLocator locator = new RoundedRectangleLabelPositionLocator(getMainFigure()); + borderItemContainer.add(borderItemEditPart.getFigure(), locator); + } else + { + super.addBorderItem(borderItemContainer, borderItemEditPart); + } + } + /** * @generated */ @Override protected NodeFigure createNodePlate() { - DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(40, 40); + RoundedRectangleNodePlateFigure result = new RoundedRectangleNodePlateFigure(40, 40); return result; } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DeviceCompositeFloatingLabelEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DeviceCompositeFloatingLabelEditPart.java new file mode 100644 index 00000000000..cb2ca303fc6 --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DeviceCompositeFloatingLabelEditPart.java @@ -0,0 +1,860 @@ +/** + * 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.uml.diagram.composite.edit.parts; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.Label; +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.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.RunnableWithResult; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gef.AccessibleEditPart; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.Request; +import org.eclipse.gef.requests.DirectEditRequest; +import org.eclipse.gef.tools.DirectEditManager; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; +import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; +import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; +import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; +import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; +import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; +import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; +import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; +import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; +import org.eclipse.gmf.runtime.notation.FontStyle; +import org.eclipse.gmf.runtime.notation.NotationPackage; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.text.contentassist.IContentAssistProcessor; +import org.eclipse.jface.viewers.ICellEditorValidator; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.extensionpoints.editors.Activator; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; +import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; +import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.ExternalLabelPrimaryDragRoleEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.PapyrusWrappingLabel; +import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; +import org.eclipse.papyrus.uml.diagram.common.editparts.FloatingLabelEditPart; +import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; +import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; +import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; +import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.accessibility.AccessibleEvent; +import org.eclipse.swt.custom.BusyIndicator; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; +import org.eclipse.uml2.uml.Feature; + +/** + * @generated + */ +public class DeviceCompositeFloatingLabelEditPart extends FloatingLabelEditPart + implements ITextAwareEditPart, IBorderItemEditPart +{ + + /** + * @generated + */ + public static final int VISUAL_ID = 6086; + + /** + * @generated + */ + private DirectEditManager manager; + + /** + * @generated + */ + private IParser parser; + + /** + * @generated + */ + private List parserElements; + + /** + * @generated + */ + private String defaultText; + + /** + * direct edition mode (default, undefined, registered editor, etc.) + * + * @generated + */ + protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; + + /** + * configuration from a registered edit dialog + * + * @generated + */ + protected IDirectEditorConfiguration configuration; + + + /** + * @generated + */ + static { + registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.DeviceCompositeFloatingLabelEditPart.VISUAL_ID), new Point(0, 0)); + } + + /** + * @generated + */ + public DeviceCompositeFloatingLabelEditPart(View view) { + super(view); + } + + /** + * @generated + */ + @Override + protected void createDefaultEditPolicies() { + super.createDefaultEditPolicies(); + installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); + installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ExternalLabelPrimaryDragRoleEditPolicy()); + } + + /** + * @generated + */ + @Override + public IBorderItemLocator getBorderItemLocator() { + IFigure parentFigure = getFigure().getParent(); + if (parentFigure != null && parentFigure.getLayoutManager() != null) { + Object constraint = parentFigure.getLayoutManager().getConstraint(getFigure()); + return (IBorderItemLocator) constraint; + } + return null; + } + + /** + * @generated + */ + @Override + public void refreshBounds() { + int x = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_X())).intValue(); + int y = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_Y())).intValue(); + int width = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Width())).intValue(); + int height = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Height())).intValue(); + getBorderItemLocator().setConstraint(new Rectangle(x, y, width, height)); + } + + + /** + * @generated + */ + protected String getLabelTextHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getText(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getText(); + } else { + return ((Label) figure).getText(); + } + } + + /** + * @generated + */ + protected void setLabelTextHelper(IFigure figure, String text) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setText(text); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setText(text); + } else { + ((Label) figure).setText(text); + } + } + + /** + * @generated + */ + protected Image getLabelIconHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getIcon(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getIcon(); + } else { + return ((Label) figure).getIcon(); + } + } + + /** + * @generated + */ + protected void setLabelIconHelper(IFigure figure, Image icon) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setIcon(icon); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setIcon(icon); + } else { + ((Label) figure).setIcon(icon); + } + } + + /** + * @generated + */ + public void setLabel(IFigure + figure) { + unregisterVisuals(); + setFigure(figure); + defaultText = getLabelTextHelper(figure); + registerVisuals(); + refreshVisuals(); + } + + /** + * @generated + */ + @Override + protected List getModelChildren() { + return Collections.EMPTY_LIST; + } + + /** + * @generated + */ + @Override + public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { + return null; + } + + /** + * @generated + */ + public void setParser(IParser parser) { + this.parser = parser; + } + + /** + * @generated + */ + protected EObject getParserElement() { + return resolveSemanticElement(); + } + + /** + * @generated + */ + protected Image getLabelIcon() { + return null; + } + + /** + * @generated + */ + protected String getLabelText() { + String text = null; + EObject parserElement = getParserElement(); + if (parserElement != null && getParser() != null) { + text = getParser().getPrintString( + new EObjectAdapter(parserElement), + getParserOptions().intValue()); + } + if (text == null || text.length() == 0) { + text = defaultText; + } + return text; + } + + /** + * @generated + */ + @Override + public void setLabelText(String text) { + setLabelTextHelper(getFigure(), text); + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + @Override + public String getEditText() { + if (getParserElement() == null || getParser() == null) { + return ""; //$NON-NLS-1$ + } + return getParser().getEditString( + new EObjectAdapter(getParserElement()), + getParserOptions().intValue()); + } + + /** + * @generated + */ + protected boolean isEditable() { + return getParser() != null; + } + + /** + * @generated + */ + @Override + public ICellEditorValidator getEditTextValidator() { + return new ICellEditorValidator() { + + @Override + public String isValid(final Object value) { + if (value instanceof String) { + final EObject element = getParserElement(); + final IParser parser = getParser(); + try { + IParserEditStatus valid = + (IParserEditStatus) getEditingDomain().runExclusive( + new RunnableWithResult.Impl() { + + @Override + public void run() { + setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); + } + }); + return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); + } catch (InterruptedException ie) { + ie.printStackTrace(); + } + } + + // shouldn't get here + return null; + } + }; + } + + /** + * @generated + */ + @Override + public IContentAssistProcessor getCompletionProcessor() { + if (getParserElement() == null || getParser() == null) { + return null; + } + return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); + } + + /** + * @generated + */ + @Override + public ParserOptions getParserOptions() { + return ParserOptions.NONE; + } + + /** + * @generated + */ + @Override + public IParser getParser() { + if (parser == null) { + parser = UMLParserProvider.getParser(UMLElementTypes.Device_2070, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.DeviceCompositeFloatingLabelEditPart.VISUAL_ID)); + } + return parser; + } + + /** + * @generated + */ + protected DirectEditManager getManager() { + if (manager == null) { + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + } + return manager; + } + + /** + * @generated + */ + protected void setManager(DirectEditManager manager) { + this.manager = manager; + } + + /** + * @generated + */ + protected void performDirectEdit() { + BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { + + @Override + public void run() { + getManager().show(); + } + }); + } + + /** + * @generated + */ + protected void performDirectEdit(Point eventLocation) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); + } + } + + /** + * @generated + */ + private void performDirectEdit(char initialCharacter) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(initialCharacter); + } else { + performDirectEdit(); + } + } + + /** + * @generated + */ + @Override + protected void performDirectEditRequest(Request request) { + + final Request theRequest = request; + + if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { + directEditionMode = getDirectEditionType(); + } + switch (directEditionMode) { + case IDirectEdition.NO_DIRECT_EDITION: + // no direct edition mode => does nothing + return; + case IDirectEdition.EXTENDED_DIRECT_EDITOR: + updateExtendedEditorConfiguration(); + if (configuration == null || configuration.getLanguage() == null) { + // Create default edit manager + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + performDefaultDirectEditorEdit(theRequest); + } else { + configuration.preEditAction(resolveSemanticElement()); + Dialog dialog = null; + if (configuration instanceof ICustomDirectEditorConfiguration) { + setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); + initializeDirectEditManager(theRequest); + return; + } else if (configuration instanceof IPopupEditorConfiguration) { + IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); + helper.showEditor(); + return; + } + else if (configuration instanceof IAdvancedEditorConfiguration) { + dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); + } else if (configuration instanceof IDirectEditorConfiguration) { + dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), + configuration); + } else { + return; + } + final Dialog finalDialog = dialog; + + if (Window.OK == dialog.open()) { + TransactionalEditingDomain domain = getEditingDomain(); + RecordingCommand command = new RecordingCommand(domain, "Edit Label") { + + @Override + protected void doExecute() { + configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); + + } + }; + domain.getCommandStack().execute(command); + } + } + break; + case IDirectEdition.DEFAULT_DIRECT_EDITOR: + initializeDirectEditManager(theRequest); + break; + default: + break; + } + } + + /** + * @generated + */ + protected void initializeDirectEditManager(final Request request) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + @Override + public void run() { + if (isActive() && isEditable()) { + if (request.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } + else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void refreshVisuals() { + super.refreshVisuals(); + refreshLabel(); + refreshFont(); + refreshFontColor(); + refreshUnderline(); + refreshStrikeThrough(); + } + + /** + * @generated + */ + protected void refreshLabel() { + EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); + if (maskLabelPolicy == null) { + maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); + } + if (maskLabelPolicy == null) { + View view = (View) getModel(); + if (view.isVisible()) { + setLabelTextHelper(getFigure(), getLabelText()); + setLabelIconHelper(getFigure(), getLabelIcon()); + } + else { + setLabelTextHelper(getFigure(), ""); //$NON-NLS-1$ + setLabelIconHelper(getFigure(), null); + } + } + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + protected void refreshUnderline() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); + } + if (resolveSemanticElement() instanceof Feature) { + if (((Feature) resolveSemanticElement()).isStatic()) { + ((WrappingLabel) getFigure()).setTextUnderline(true); + } + else { + ((WrappingLabel) getFigure()).setTextUnderline(false); + } + } + } + + /** + * @generated + */ + protected void refreshStrikeThrough() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); + } + } + + /** + * @generated + */ + @Override + protected void refreshFont() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null) { + FontData fontData = new FontData( + style.getFontName(), style.getFontHeight(), + (style.isBold() ? SWT.BOLD : SWT.NORMAL) | + (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); + setFont(fontData); + } + } + + /** + * @generated + */ + @Override + protected void setFontColor(Color color) { + getFigure().setForegroundColor(color); + } + + /** + * @generated + */ + @Override + protected void addSemanticListeners() { + if (getParser() instanceof ISemanticParser) { + EObject element = resolveSemanticElement(); + parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); + for (int i = 0; i < parserElements.size(); i++) { + addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ + } + } else { + super.addSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected void removeSemanticListeners() { + if (parserElements != null) { + for (int i = 0; i < parserElements.size(); i++) { + removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ + } + } else { + super.removeSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected AccessibleEditPart getAccessibleEditPart() { + if (accessibleEP == null) { + accessibleEP = new AccessibleGraphicalEditPart() { + + @Override + public void getName(AccessibleEvent e) { + e.result = getLabelTextHelper(getFigure()); + } + }; + } + return accessibleEP; + } + + /** + * @generated + */ + private View getFontStyleOwnerView() { + return getPrimaryView(); + } + + /** + * Returns the kind of associated editor for direct edition. + * + * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition + * @generated + */ + public int getDirectEditionType() { + if (checkExtendedEditor()) { + initExtendedEditorConfiguration(); + return IDirectEdition.EXTENDED_DIRECT_EDITOR; + } + if (checkDefaultEdition()) { + return IDirectEdition.DEFAULT_DIRECT_EDITOR; + } + + // not a named element. no specific editor => do nothing + return IDirectEdition.NO_DIRECT_EDITION; + } + + /** + * Checks if an extended editor is present. + * + * @return true if an extended editor is present. + * @generated + */ + protected boolean checkExtendedEditor() { + if (resolveSemanticElement() != null) { + return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); + } + return false; + } + + /** + * Checks if a default direct edition is available + * + * @return true if a default direct edition is available + * @generated + */ + protected boolean checkDefaultEdition() { + return (getParser() != null); + } + + /** + * Initializes the extended editor configuration + * + * @generated + */ + protected void initExtendedEditorConfiguration() { + if (configuration == null) { + final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("")) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); + } else { + configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); + } + } + } + + /** + * Updates the preference configuration + * + * @generated + */ + protected void updateExtendedEditorConfiguration() { + String languagePreferred = Activator.getDefault().getPreferenceStore().getString( + IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() + .eClass().getInstanceClassName()); + } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { + configuration = null; + } + } + + /** + * Performs the direct edit usually used by GMF editors. + * + * @param theRequest + * the direct edit request that starts the direct edit system + * @generated + */ + protected void performDefaultDirectEditorEdit(final Request theRequest) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + + @Override + public void run() { + if (isActive() && isEditable()) { + if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) theRequest.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { + DirectEditRequest editRequest = (DirectEditRequest) theRequest; + performDirectEdit(editRequest.getLocation()); + } else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + + /** + * @generated + */ + @Override + protected void handleNotificationEvent(Notification event) { + Object feature = event.getFeature(); + if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { + Integer c = (Integer) event.getNewValue(); + setFontColor(DiagramColorRegistry.getInstance().getColor(c)); + } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { + refreshUnderline(); + } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { + refreshStrikeThrough(); + } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { + refreshFont(); + } else { + if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { + refreshLabel(); + } + if (getParser() instanceof ISemanticParser) { + ISemanticParser modelParser = + (ISemanticParser) getParser(); + if (modelParser.areSemanticElementsAffected(null, event)) { + removeSemanticListeners(); + if (resolveSemanticElement() != null) { + addSemanticListeners(); + } + refreshLabel(); + } + } + } + super.handleNotificationEvent(event); + } + + /** + * @generated + */ + @Override + protected IFigure createFigure() { + IFigure label = createFigurePrim(); + defaultText = getLabelTextHelper(label); + return label; + } + + /** + * @generated + */ + protected IFigure createFigurePrim() { + return new PapyrusWrappingLabel(); + } + +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DeviceCompositeFloatingLabelEditPartCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DeviceCompositeFloatingLabelEditPartCN.java new file mode 100644 index 00000000000..622e59a00ab --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DeviceCompositeFloatingLabelEditPartCN.java @@ -0,0 +1,860 @@ +/** + * 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.uml.diagram.composite.edit.parts; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.Label; +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.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.RunnableWithResult; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gef.AccessibleEditPart; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.Request; +import org.eclipse.gef.requests.DirectEditRequest; +import org.eclipse.gef.tools.DirectEditManager; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; +import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; +import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; +import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; +import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; +import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; +import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; +import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; +import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; +import org.eclipse.gmf.runtime.notation.FontStyle; +import org.eclipse.gmf.runtime.notation.NotationPackage; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.text.contentassist.IContentAssistProcessor; +import org.eclipse.jface.viewers.ICellEditorValidator; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.extensionpoints.editors.Activator; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; +import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; +import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.ExternalLabelPrimaryDragRoleEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.PapyrusWrappingLabel; +import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; +import org.eclipse.papyrus.uml.diagram.common.editparts.FloatingLabelEditPart; +import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; +import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; +import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; +import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.accessibility.AccessibleEvent; +import org.eclipse.swt.custom.BusyIndicator; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; +import org.eclipse.uml2.uml.Feature; + +/** + * @generated + */ +public class DeviceCompositeFloatingLabelEditPartCN extends FloatingLabelEditPart + implements ITextAwareEditPart, IBorderItemEditPart +{ + + /** + * @generated + */ + public static final int VISUAL_ID = 6064; + + /** + * @generated + */ + private DirectEditManager manager; + + /** + * @generated + */ + private IParser parser; + + /** + * @generated + */ + private List parserElements; + + /** + * @generated + */ + private String defaultText; + + /** + * direct edition mode (default, undefined, registered editor, etc.) + * + * @generated + */ + protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; + + /** + * configuration from a registered edit dialog + * + * @generated + */ + protected IDirectEditorConfiguration configuration; + + + /** + * @generated + */ + static { + registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.DeviceCompositeFloatingLabelEditPartCN.VISUAL_ID), new Point(0, 0)); + } + + /** + * @generated + */ + public DeviceCompositeFloatingLabelEditPartCN(View view) { + super(view); + } + + /** + * @generated + */ + @Override + protected void createDefaultEditPolicies() { + super.createDefaultEditPolicies(); + installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); + installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ExternalLabelPrimaryDragRoleEditPolicy()); + } + + /** + * @generated + */ + @Override + public IBorderItemLocator getBorderItemLocator() { + IFigure parentFigure = getFigure().getParent(); + if (parentFigure != null && parentFigure.getLayoutManager() != null) { + Object constraint = parentFigure.getLayoutManager().getConstraint(getFigure()); + return (IBorderItemLocator) constraint; + } + return null; + } + + /** + * @generated + */ + @Override + public void refreshBounds() { + int x = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_X())).intValue(); + int y = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_Y())).intValue(); + int width = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Width())).intValue(); + int height = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Height())).intValue(); + getBorderItemLocator().setConstraint(new Rectangle(x, y, width, height)); + } + + + /** + * @generated + */ + protected String getLabelTextHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getText(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getText(); + } else { + return ((Label) figure).getText(); + } + } + + /** + * @generated + */ + protected void setLabelTextHelper(IFigure figure, String text) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setText(text); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setText(text); + } else { + ((Label) figure).setText(text); + } + } + + /** + * @generated + */ + protected Image getLabelIconHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getIcon(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getIcon(); + } else { + return ((Label) figure).getIcon(); + } + } + + /** + * @generated + */ + protected void setLabelIconHelper(IFigure figure, Image icon) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setIcon(icon); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setIcon(icon); + } else { + ((Label) figure).setIcon(icon); + } + } + + /** + * @generated + */ + public void setLabel(IFigure + figure) { + unregisterVisuals(); + setFigure(figure); + defaultText = getLabelTextHelper(figure); + registerVisuals(); + refreshVisuals(); + } + + /** + * @generated + */ + @Override + protected List getModelChildren() { + return Collections.EMPTY_LIST; + } + + /** + * @generated + */ + @Override + public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { + return null; + } + + /** + * @generated + */ + public void setParser(IParser parser) { + this.parser = parser; + } + + /** + * @generated + */ + protected EObject getParserElement() { + return resolveSemanticElement(); + } + + /** + * @generated + */ + protected Image getLabelIcon() { + return null; + } + + /** + * @generated + */ + protected String getLabelText() { + String text = null; + EObject parserElement = getParserElement(); + if (parserElement != null && getParser() != null) { + text = getParser().getPrintString( + new EObjectAdapter(parserElement), + getParserOptions().intValue()); + } + if (text == null || text.length() == 0) { + text = defaultText; + } + return text; + } + + /** + * @generated + */ + @Override + public void setLabelText(String text) { + setLabelTextHelper(getFigure(), text); + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + @Override + public String getEditText() { + if (getParserElement() == null || getParser() == null) { + return ""; //$NON-NLS-1$ + } + return getParser().getEditString( + new EObjectAdapter(getParserElement()), + getParserOptions().intValue()); + } + + /** + * @generated + */ + protected boolean isEditable() { + return getParser() != null; + } + + /** + * @generated + */ + @Override + public ICellEditorValidator getEditTextValidator() { + return new ICellEditorValidator() { + + @Override + public String isValid(final Object value) { + if (value instanceof String) { + final EObject element = getParserElement(); + final IParser parser = getParser(); + try { + IParserEditStatus valid = + (IParserEditStatus) getEditingDomain().runExclusive( + new RunnableWithResult.Impl() { + + @Override + public void run() { + setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); + } + }); + return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); + } catch (InterruptedException ie) { + ie.printStackTrace(); + } + } + + // shouldn't get here + return null; + } + }; + } + + /** + * @generated + */ + @Override + public IContentAssistProcessor getCompletionProcessor() { + if (getParserElement() == null || getParser() == null) { + return null; + } + return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); + } + + /** + * @generated + */ + @Override + public ParserOptions getParserOptions() { + return ParserOptions.NONE; + } + + /** + * @generated + */ + @Override + public IParser getParser() { + if (parser == null) { + parser = UMLParserProvider.getParser(UMLElementTypes.Device_3082, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.DeviceCompositeFloatingLabelEditPartCN.VISUAL_ID)); + } + return parser; + } + + /** + * @generated + */ + protected DirectEditManager getManager() { + if (manager == null) { + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + } + return manager; + } + + /** + * @generated + */ + protected void setManager(DirectEditManager manager) { + this.manager = manager; + } + + /** + * @generated + */ + protected void performDirectEdit() { + BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { + + @Override + public void run() { + getManager().show(); + } + }); + } + + /** + * @generated + */ + protected void performDirectEdit(Point eventLocation) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); + } + } + + /** + * @generated + */ + private void performDirectEdit(char initialCharacter) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(initialCharacter); + } else { + performDirectEdit(); + } + } + + /** + * @generated + */ + @Override + protected void performDirectEditRequest(Request request) { + + final Request theRequest = request; + + if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { + directEditionMode = getDirectEditionType(); + } + switch (directEditionMode) { + case IDirectEdition.NO_DIRECT_EDITION: + // no direct edition mode => does nothing + return; + case IDirectEdition.EXTENDED_DIRECT_EDITOR: + updateExtendedEditorConfiguration(); + if (configuration == null || configuration.getLanguage() == null) { + // Create default edit manager + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + performDefaultDirectEditorEdit(theRequest); + } else { + configuration.preEditAction(resolveSemanticElement()); + Dialog dialog = null; + if (configuration instanceof ICustomDirectEditorConfiguration) { + setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); + initializeDirectEditManager(theRequest); + return; + } else if (configuration instanceof IPopupEditorConfiguration) { + IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); + helper.showEditor(); + return; + } + else if (configuration instanceof IAdvancedEditorConfiguration) { + dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); + } else if (configuration instanceof IDirectEditorConfiguration) { + dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), + configuration); + } else { + return; + } + final Dialog finalDialog = dialog; + + if (Window.OK == dialog.open()) { + TransactionalEditingDomain domain = getEditingDomain(); + RecordingCommand command = new RecordingCommand(domain, "Edit Label") { + + @Override + protected void doExecute() { + configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); + + } + }; + domain.getCommandStack().execute(command); + } + } + break; + case IDirectEdition.DEFAULT_DIRECT_EDITOR: + initializeDirectEditManager(theRequest); + break; + default: + break; + } + } + + /** + * @generated + */ + protected void initializeDirectEditManager(final Request request) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + @Override + public void run() { + if (isActive() && isEditable()) { + if (request.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } + else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void refreshVisuals() { + super.refreshVisuals(); + refreshLabel(); + refreshFont(); + refreshFontColor(); + refreshUnderline(); + refreshStrikeThrough(); + } + + /** + * @generated + */ + protected void refreshLabel() { + EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); + if (maskLabelPolicy == null) { + maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); + } + if (maskLabelPolicy == null) { + View view = (View) getModel(); + if (view.isVisible()) { + setLabelTextHelper(getFigure(), getLabelText()); + setLabelIconHelper(getFigure(), getLabelIcon()); + } + else { + setLabelTextHelper(getFigure(), ""); //$NON-NLS-1$ + setLabelIconHelper(getFigure(), null); + } + } + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + protected void refreshUnderline() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); + } + if (resolveSemanticElement() instanceof Feature) { + if (((Feature) resolveSemanticElement()).isStatic()) { + ((WrappingLabel) getFigure()).setTextUnderline(true); + } + else { + ((WrappingLabel) getFigure()).setTextUnderline(false); + } + } + } + + /** + * @generated + */ + protected void refreshStrikeThrough() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); + } + } + + /** + * @generated + */ + @Override + protected void refreshFont() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null) { + FontData fontData = new FontData( + style.getFontName(), style.getFontHeight(), + (style.isBold() ? SWT.BOLD : SWT.NORMAL) | + (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); + setFont(fontData); + } + } + + /** + * @generated + */ + @Override + protected void setFontColor(Color color) { + getFigure().setForegroundColor(color); + } + + /** + * @generated + */ + @Override + protected void addSemanticListeners() { + if (getParser() instanceof ISemanticParser) { + EObject element = resolveSemanticElement(); + parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); + for (int i = 0; i < parserElements.size(); i++) { + addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ + } + } else { + super.addSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected void removeSemanticListeners() { + if (parserElements != null) { + for (int i = 0; i < parserElements.size(); i++) { + removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ + } + } else { + super.removeSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected AccessibleEditPart getAccessibleEditPart() { + if (accessibleEP == null) { + accessibleEP = new AccessibleGraphicalEditPart() { + + @Override + public void getName(AccessibleEvent e) { + e.result = getLabelTextHelper(getFigure()); + } + }; + } + return accessibleEP; + } + + /** + * @generated + */ + private View getFontStyleOwnerView() { + return getPrimaryView(); + } + + /** + * Returns the kind of associated editor for direct edition. + * + * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition + * @generated + */ + public int getDirectEditionType() { + if (checkExtendedEditor()) { + initExtendedEditorConfiguration(); + return IDirectEdition.EXTENDED_DIRECT_EDITOR; + } + if (checkDefaultEdition()) { + return IDirectEdition.DEFAULT_DIRECT_EDITOR; + } + + // not a named element. no specific editor => do nothing + return IDirectEdition.NO_DIRECT_EDITION; + } + + /** + * Checks if an extended editor is present. + * + * @return true if an extended editor is present. + * @generated + */ + protected boolean checkExtendedEditor() { + if (resolveSemanticElement() != null) { + return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); + } + return false; + } + + /** + * Checks if a default direct edition is available + * + * @return true if a default direct edition is available + * @generated + */ + protected boolean checkDefaultEdition() { + return (getParser() != null); + } + + /** + * Initializes the extended editor configuration + * + * @generated + */ + protected void initExtendedEditorConfiguration() { + if (configuration == null) { + final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("")) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); + } else { + configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); + } + } + } + + /** + * Updates the preference configuration + * + * @generated + */ + protected void updateExtendedEditorConfiguration() { + String languagePreferred = Activator.getDefault().getPreferenceStore().getString( + IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() + .eClass().getInstanceClassName()); + } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { + configuration = null; + } + } + + /** + * Performs the direct edit usually used by GMF editors. + * + * @param theRequest + * the direct edit request that starts the direct edit system + * @generated + */ + protected void performDefaultDirectEditorEdit(final Request theRequest) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + + @Override + public void run() { + if (isActive() && isEditable()) { + if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) theRequest.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { + DirectEditRequest editRequest = (DirectEditRequest) theRequest; + performDirectEdit(editRequest.getLocation()); + } else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + + /** + * @generated + */ + @Override + protected void handleNotificationEvent(Notification event) { + Object feature = event.getFeature(); + if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { + Integer c = (Integer) event.getNewValue(); + setFontColor(DiagramColorRegistry.getInstance().getColor(c)); + } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { + refreshUnderline(); + } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { + refreshStrikeThrough(); + } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { + refreshFont(); + } else { + if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { + refreshLabel(); + } + if (getParser() instanceof ISemanticParser) { + ISemanticParser modelParser = + (ISemanticParser) getParser(); + if (modelParser.areSemanticElementsAffected(null, event)) { + removeSemanticListeners(); + if (resolveSemanticElement() != null) { + addSemanticListeners(); + } + refreshLabel(); + } + } + } + super.handleNotificationEvent(event); + } + + /** + * @generated + */ + @Override + protected IFigure createFigure() { + IFigure label = createFigurePrim(); + defaultText = getLabelTextHelper(label); + return label; + } + + /** + * @generated + */ + protected IFigure createFigurePrim() { + return new PapyrusWrappingLabel(); + } + +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DeviceCompositeNameEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DeviceCompositeNameEditPart.java index 51906b6b045..daadd40f3ee 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DeviceCompositeNameEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DeviceCompositeNameEditPart.java @@ -864,7 +864,7 @@ public class DeviceCompositeNameEditPart extends PapyrusCompartmentEditPart impl * @generated */ protected void addOwnerElementListeners() { - addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); + addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DeviceCompositeNameEditPartCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DeviceCompositeNameEditPartCN.java index 1ba2c212207..5439c16058d 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DeviceCompositeNameEditPartCN.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DeviceCompositeNameEditPartCN.java @@ -864,7 +864,7 @@ public class DeviceCompositeNameEditPartCN extends PapyrusCompartmentEditPart im * @generated */ protected void addOwnerElementListeners() { - addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); + addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DurationConstraintEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DurationConstraintEditPart.java index 0e458ba62a1..b138bb51f75 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DurationConstraintEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DurationConstraintEditPart.java @@ -23,10 +23,10 @@ import org.eclipse.gef.requests.CreateRequest; import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles; import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; -import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure; import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure; import org.eclipse.gmf.runtime.notation.View; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.IPapyrusNodeFigure; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.RoundedRectangleNodePlateFigure; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.SelectableBorderedNodeFigure; import org.eclipse.papyrus.uml.diagram.common.editparts.AbstractConstraintEditPart; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeLabelDisplayEditPolicy; @@ -198,7 +198,7 @@ public class DurationConstraintEditPart extends AbstractConstraintEditPart { */ @Override protected NodeFigure createNodePlate() { - DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(40, 40); + RoundedRectangleNodePlateFigure result = new RoundedRectangleNodePlateFigure(40, 40); return result; } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DurationConstraintEditPartCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DurationConstraintEditPartCN.java index 8cd28e93afc..b47f86c8c0b 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DurationConstraintEditPartCN.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DurationConstraintEditPartCN.java @@ -23,10 +23,10 @@ import org.eclipse.gef.requests.CreateRequest; import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles; import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; -import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure; import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure; import org.eclipse.gmf.runtime.notation.View; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.IPapyrusNodeFigure; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.RoundedRectangleNodePlateFigure; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.SelectableBorderedNodeFigure; import org.eclipse.papyrus.uml.diagram.common.editparts.AbstractConstraintEditPart; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeLabelDisplayEditPolicy; @@ -198,7 +198,7 @@ public class DurationConstraintEditPartCN extends AbstractConstraintEditPart { */ @Override protected NodeFigure createNodePlate() { - DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(40, 40); + RoundedRectangleNodePlateFigure result = new RoundedRectangleNodePlateFigure(40, 40); return result; } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DurationConstraintNameEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DurationConstraintNameEditPart.java index 4a953fdb3da..dfde29809e1 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DurationConstraintNameEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DurationConstraintNameEditPart.java @@ -864,7 +864,7 @@ public class DurationConstraintNameEditPart extends PapyrusCompartmentEditPart i * @generated */ protected void addOwnerElementListeners() { - addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); + addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DurationConstraintNameEditPartCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DurationConstraintNameEditPartCN.java index 28836517fe3..1b59ba8c50d 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DurationConstraintNameEditPartCN.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DurationConstraintNameEditPartCN.java @@ -864,7 +864,7 @@ public class DurationConstraintNameEditPartCN extends PapyrusCompartmentEditPart * @generated */ protected void addOwnerElementListeners() { - addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); + addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DurationConstraintSpecificationEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DurationConstraintSpecificationEditPart.java index bdcd9383ed0..fb596bc2a00 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DurationConstraintSpecificationEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DurationConstraintSpecificationEditPart.java @@ -847,7 +847,7 @@ public class DurationConstraintSpecificationEditPart extends PapyrusCompartmentE * @generated */ protected void addOwnerElementListeners() { - addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); + addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DurationConstraintSpecificationEditPartCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DurationConstraintSpecificationEditPartCN.java index 4b3ea48bb88..83238ad4931 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DurationConstraintSpecificationEditPartCN.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DurationConstraintSpecificationEditPartCN.java @@ -847,7 +847,7 @@ public class DurationConstraintSpecificationEditPartCN extends PapyrusCompartmen * @generated */ protected void addOwnerElementListeners() { - addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); + addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DurationEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DurationEditPart.java index 3ff43b8b7d9..0e88e957014 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DurationEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DurationEditPart.java @@ -11,27 +11,40 @@ */ package org.eclipse.papyrus.uml.diagram.composite.edit.parts; +import java.util.Collections; +import java.util.List; + import org.eclipse.draw2d.IFigure; +import org.eclipse.emf.common.notify.Notification; import org.eclipse.gef.EditPart; import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.GraphicalEditPart; 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.handles.MoveHandle; import org.eclipse.gef.requests.CreateRequest; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.BorderItemSelectionEditPolicy; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles; +import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; -import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure; import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure; +import org.eclipse.gmf.runtime.notation.Edge; +import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.gmf.runtime.notation.View; -import org.eclipse.papyrus.infra.gmfdiag.common.editpart.NodeEditPart; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.GetChildLayoutEditPolicy; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.IPapyrusNodeFigure; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.RoundedRectangleNodePlateFigure; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.SelectableBorderedNodeFigure; +import org.eclipse.papyrus.uml.diagram.common.editparts.RoundedCompartmentEditPart; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeNodeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.QualifiedNameDisplayEditPolicy; -import org.eclipse.papyrus.uml.diagram.common.figure.node.NodeNamedElementFigure; +import org.eclipse.papyrus.uml.diagram.common.figure.node.RoundedCompartmentFigure; +import org.eclipse.papyrus.uml.diagram.common.locator.RoundedRectangleLabelPositionLocator; import org.eclipse.papyrus.uml.diagram.composite.edit.policies.DurationItemSemanticEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; import org.eclipse.swt.graphics.Color; @@ -39,7 +52,7 @@ import org.eclipse.swt.graphics.Color; /** * @generated */ -public class DurationEditPart extends NodeEditPart { +public class DurationEditPart extends RoundedCompartmentEditPart { /** * @generated @@ -73,6 +86,7 @@ public class DurationEditPart extends NodeEditPart { installEditPolicy(EditPolicy.LAYOUT_ROLE, createLayoutEditPolicy()); installEditPolicy(QualifiedNameDisplayEditPolicy.QUALIFIED_NAME_POLICY, new QualifiedNameDisplayEditPolicy()); installEditPolicy(AppliedStereotypeLabelDisplayEditPolicy.STEREOTYPE_LABEL_POLICY, new AppliedStereotypeNodeLabelDisplayEditPolicy()); + installEditPolicy(EditPolicy.LAYOUT_ROLE, new GetChildLayoutEditPolicy()); // XXX need an SCR to runtime to have another abstract superclass that would let children add reasonable editpolicies // removeEditPolicy(org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles.CONNECTION_HANDLES_ROLE); } @@ -85,6 +99,20 @@ public class DurationEditPart extends NodeEditPart { @Override protected EditPolicy createChildEditPolicy(EditPart child) { + View childView = (View) child.getModel(); + switch (UMLVisualIDRegistry.getVisualID(childView)) { + case DurationFloatingLabelEditPart.VISUAL_ID: + return new BorderItemSelectionEditPolicy() { + + @Override + protected List createSelectionHandles() { + MoveHandle mh = new MoveHandle((GraphicalEditPart) getHost()); + mh.setBorder(null); + return Collections.singletonList(mh); + } + } + ; + } EditPolicy result = child.getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); if (result == null) { result = new NonResizableEditPolicy(); @@ -105,12 +133,36 @@ public class DurationEditPart extends NodeEditPart { return lep; } + /** + * Papyrus codeGen + * + * @generated + **/ + @Override + protected void handleNotificationEvent(Notification event) { + /* + * when a node have external node labels, the methods refreshChildren() remove the EditPart corresponding to the Label from the EditPart + * Registry. After that, we can't reset the visibility to true (using the Show/Hide Label Action)! + */ + if (NotationPackage.eINSTANCE.getView_Visible().equals(event.getFeature())) { + Object notifier = event.getNotifier(); + List modelChildren = ((View) getModel()).getChildren(); + if (!(notifier instanceof Edge)) { + if (modelChildren.contains(event.getNotifier())) { + return; + } + } + } + super.handleNotificationEvent(event); + + } + /** * @generated */ @Override protected IFigure createNodeShape() { - return primaryShape = new NodeNamedElementFigure(); + return primaryShape = new RoundedCompartmentFigure(); } /** @@ -119,8 +171,8 @@ public class DurationEditPart extends NodeEditPart { * @generated */ @Override - public NodeNamedElementFigure getPrimaryShape() { - return (NodeNamedElementFigure) primaryShape; + public RoundedCompartmentFigure getPrimaryShape() { + return (RoundedCompartmentFigure) primaryShape; } /** @@ -173,15 +225,32 @@ public class DurationEditPart extends NodeEditPart { */ @Override protected IFigure getContentPaneFor(IGraphicalEditPart editPart) { + if (editPart instanceof IBorderItemEditPart) { + return getBorderedFigure().getBorderItemContainer(); + } return getContentPane(); } + /** + * @generated + */ + @Override + protected void addBorderItem(IFigure borderItemContainer, IBorderItemEditPart borderItemEditPart) { + if (borderItemEditPart instanceof DurationFloatingLabelEditPart) { + IBorderItemLocator locator = new RoundedRectangleLabelPositionLocator(getMainFigure()); + borderItemContainer.add(borderItemEditPart.getFigure(), locator); + } else + { + super.addBorderItem(borderItemContainer, borderItemEditPart); + } + } + /** * @generated */ @Override protected NodeFigure createNodePlate() { - DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(40, 40); + RoundedRectangleNodePlateFigure result = new RoundedRectangleNodePlateFigure(40, 40); return result; } @@ -194,7 +263,7 @@ public class DurationEditPart extends NodeEditPart { * @generated */ @Override - protected NodeFigure createNodeFigure() { + protected NodeFigure createMainFigure() { return new SelectableBorderedNodeFigure(createMainFigureWithSVG()); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DurationFloatingLabelEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DurationFloatingLabelEditPart.java new file mode 100644 index 00000000000..8a215b40d8b --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DurationFloatingLabelEditPart.java @@ -0,0 +1,860 @@ +/** + * 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.uml.diagram.composite.edit.parts; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.Label; +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.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.RunnableWithResult; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gef.AccessibleEditPart; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.Request; +import org.eclipse.gef.requests.DirectEditRequest; +import org.eclipse.gef.tools.DirectEditManager; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; +import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; +import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; +import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; +import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; +import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; +import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; +import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; +import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; +import org.eclipse.gmf.runtime.notation.FontStyle; +import org.eclipse.gmf.runtime.notation.NotationPackage; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.text.contentassist.IContentAssistProcessor; +import org.eclipse.jface.viewers.ICellEditorValidator; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.extensionpoints.editors.Activator; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; +import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; +import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.ExternalLabelPrimaryDragRoleEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.PapyrusWrappingLabel; +import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; +import org.eclipse.papyrus.uml.diagram.common.editparts.FloatingLabelEditPart; +import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; +import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; +import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; +import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.accessibility.AccessibleEvent; +import org.eclipse.swt.custom.BusyIndicator; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; +import org.eclipse.uml2.uml.Feature; + +/** + * @generated + */ +public class DurationFloatingLabelEditPart extends FloatingLabelEditPart + implements ITextAwareEditPart, IBorderItemEditPart +{ + + /** + * @generated + */ + public static final int VISUAL_ID = 6115; + + /** + * @generated + */ + private DirectEditManager manager; + + /** + * @generated + */ + private IParser parser; + + /** + * @generated + */ + private List parserElements; + + /** + * @generated + */ + private String defaultText; + + /** + * direct edition mode (default, undefined, registered editor, etc.) + * + * @generated + */ + protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; + + /** + * configuration from a registered edit dialog + * + * @generated + */ + protected IDirectEditorConfiguration configuration; + + + /** + * @generated + */ + static { + registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.DurationFloatingLabelEditPart.VISUAL_ID), new Point(0, 0)); + } + + /** + * @generated + */ + public DurationFloatingLabelEditPart(View view) { + super(view); + } + + /** + * @generated + */ + @Override + protected void createDefaultEditPolicies() { + super.createDefaultEditPolicies(); + installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); + installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ExternalLabelPrimaryDragRoleEditPolicy()); + } + + /** + * @generated + */ + @Override + public IBorderItemLocator getBorderItemLocator() { + IFigure parentFigure = getFigure().getParent(); + if (parentFigure != null && parentFigure.getLayoutManager() != null) { + Object constraint = parentFigure.getLayoutManager().getConstraint(getFigure()); + return (IBorderItemLocator) constraint; + } + return null; + } + + /** + * @generated + */ + @Override + public void refreshBounds() { + int x = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_X())).intValue(); + int y = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_Y())).intValue(); + int width = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Width())).intValue(); + int height = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Height())).intValue(); + getBorderItemLocator().setConstraint(new Rectangle(x, y, width, height)); + } + + + /** + * @generated + */ + protected String getLabelTextHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getText(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getText(); + } else { + return ((Label) figure).getText(); + } + } + + /** + * @generated + */ + protected void setLabelTextHelper(IFigure figure, String text) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setText(text); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setText(text); + } else { + ((Label) figure).setText(text); + } + } + + /** + * @generated + */ + protected Image getLabelIconHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getIcon(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getIcon(); + } else { + return ((Label) figure).getIcon(); + } + } + + /** + * @generated + */ + protected void setLabelIconHelper(IFigure figure, Image icon) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setIcon(icon); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setIcon(icon); + } else { + ((Label) figure).setIcon(icon); + } + } + + /** + * @generated + */ + public void setLabel(IFigure + figure) { + unregisterVisuals(); + setFigure(figure); + defaultText = getLabelTextHelper(figure); + registerVisuals(); + refreshVisuals(); + } + + /** + * @generated + */ + @Override + protected List getModelChildren() { + return Collections.EMPTY_LIST; + } + + /** + * @generated + */ + @Override + public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { + return null; + } + + /** + * @generated + */ + public void setParser(IParser parser) { + this.parser = parser; + } + + /** + * @generated + */ + protected EObject getParserElement() { + return resolveSemanticElement(); + } + + /** + * @generated + */ + protected Image getLabelIcon() { + return null; + } + + /** + * @generated + */ + protected String getLabelText() { + String text = null; + EObject parserElement = getParserElement(); + if (parserElement != null && getParser() != null) { + text = getParser().getPrintString( + new EObjectAdapter(parserElement), + getParserOptions().intValue()); + } + if (text == null || text.length() == 0) { + text = defaultText; + } + return text; + } + + /** + * @generated + */ + @Override + public void setLabelText(String text) { + setLabelTextHelper(getFigure(), text); + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + @Override + public String getEditText() { + if (getParserElement() == null || getParser() == null) { + return ""; //$NON-NLS-1$ + } + return getParser().getEditString( + new EObjectAdapter(getParserElement()), + getParserOptions().intValue()); + } + + /** + * @generated + */ + protected boolean isEditable() { + return getParser() != null; + } + + /** + * @generated + */ + @Override + public ICellEditorValidator getEditTextValidator() { + return new ICellEditorValidator() { + + @Override + public String isValid(final Object value) { + if (value instanceof String) { + final EObject element = getParserElement(); + final IParser parser = getParser(); + try { + IParserEditStatus valid = + (IParserEditStatus) getEditingDomain().runExclusive( + new RunnableWithResult.Impl() { + + @Override + public void run() { + setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); + } + }); + return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); + } catch (InterruptedException ie) { + ie.printStackTrace(); + } + } + + // shouldn't get here + return null; + } + }; + } + + /** + * @generated + */ + @Override + public IContentAssistProcessor getCompletionProcessor() { + if (getParserElement() == null || getParser() == null) { + return null; + } + return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); + } + + /** + * @generated + */ + @Override + public ParserOptions getParserOptions() { + return ParserOptions.NONE; + } + + /** + * @generated + */ + @Override + public IParser getParser() { + if (parser == null) { + parser = UMLParserProvider.getParser(UMLElementTypes.Duration_2104, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.DurationFloatingLabelEditPart.VISUAL_ID)); + } + return parser; + } + + /** + * @generated + */ + protected DirectEditManager getManager() { + if (manager == null) { + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + } + return manager; + } + + /** + * @generated + */ + protected void setManager(DirectEditManager manager) { + this.manager = manager; + } + + /** + * @generated + */ + protected void performDirectEdit() { + BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { + + @Override + public void run() { + getManager().show(); + } + }); + } + + /** + * @generated + */ + protected void performDirectEdit(Point eventLocation) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); + } + } + + /** + * @generated + */ + private void performDirectEdit(char initialCharacter) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(initialCharacter); + } else { + performDirectEdit(); + } + } + + /** + * @generated + */ + @Override + protected void performDirectEditRequest(Request request) { + + final Request theRequest = request; + + if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { + directEditionMode = getDirectEditionType(); + } + switch (directEditionMode) { + case IDirectEdition.NO_DIRECT_EDITION: + // no direct edition mode => does nothing + return; + case IDirectEdition.EXTENDED_DIRECT_EDITOR: + updateExtendedEditorConfiguration(); + if (configuration == null || configuration.getLanguage() == null) { + // Create default edit manager + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + performDefaultDirectEditorEdit(theRequest); + } else { + configuration.preEditAction(resolveSemanticElement()); + Dialog dialog = null; + if (configuration instanceof ICustomDirectEditorConfiguration) { + setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); + initializeDirectEditManager(theRequest); + return; + } else if (configuration instanceof IPopupEditorConfiguration) { + IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); + helper.showEditor(); + return; + } + else if (configuration instanceof IAdvancedEditorConfiguration) { + dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); + } else if (configuration instanceof IDirectEditorConfiguration) { + dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), + configuration); + } else { + return; + } + final Dialog finalDialog = dialog; + + if (Window.OK == dialog.open()) { + TransactionalEditingDomain domain = getEditingDomain(); + RecordingCommand command = new RecordingCommand(domain, "Edit Label") { + + @Override + protected void doExecute() { + configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); + + } + }; + domain.getCommandStack().execute(command); + } + } + break; + case IDirectEdition.DEFAULT_DIRECT_EDITOR: + initializeDirectEditManager(theRequest); + break; + default: + break; + } + } + + /** + * @generated + */ + protected void initializeDirectEditManager(final Request request) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + @Override + public void run() { + if (isActive() && isEditable()) { + if (request.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } + else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void refreshVisuals() { + super.refreshVisuals(); + refreshLabel(); + refreshFont(); + refreshFontColor(); + refreshUnderline(); + refreshStrikeThrough(); + } + + /** + * @generated + */ + protected void refreshLabel() { + EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); + if (maskLabelPolicy == null) { + maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); + } + if (maskLabelPolicy == null) { + View view = (View) getModel(); + if (view.isVisible()) { + setLabelTextHelper(getFigure(), getLabelText()); + setLabelIconHelper(getFigure(), getLabelIcon()); + } + else { + setLabelTextHelper(getFigure(), ""); //$NON-NLS-1$ + setLabelIconHelper(getFigure(), null); + } + } + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + protected void refreshUnderline() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); + } + if (resolveSemanticElement() instanceof Feature) { + if (((Feature) resolveSemanticElement()).isStatic()) { + ((WrappingLabel) getFigure()).setTextUnderline(true); + } + else { + ((WrappingLabel) getFigure()).setTextUnderline(false); + } + } + } + + /** + * @generated + */ + protected void refreshStrikeThrough() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); + } + } + + /** + * @generated + */ + @Override + protected void refreshFont() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null) { + FontData fontData = new FontData( + style.getFontName(), style.getFontHeight(), + (style.isBold() ? SWT.BOLD : SWT.NORMAL) | + (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); + setFont(fontData); + } + } + + /** + * @generated + */ + @Override + protected void setFontColor(Color color) { + getFigure().setForegroundColor(color); + } + + /** + * @generated + */ + @Override + protected void addSemanticListeners() { + if (getParser() instanceof ISemanticParser) { + EObject element = resolveSemanticElement(); + parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); + for (int i = 0; i < parserElements.size(); i++) { + addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ + } + } else { + super.addSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected void removeSemanticListeners() { + if (parserElements != null) { + for (int i = 0; i < parserElements.size(); i++) { + removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ + } + } else { + super.removeSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected AccessibleEditPart getAccessibleEditPart() { + if (accessibleEP == null) { + accessibleEP = new AccessibleGraphicalEditPart() { + + @Override + public void getName(AccessibleEvent e) { + e.result = getLabelTextHelper(getFigure()); + } + }; + } + return accessibleEP; + } + + /** + * @generated + */ + private View getFontStyleOwnerView() { + return getPrimaryView(); + } + + /** + * Returns the kind of associated editor for direct edition. + * + * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition + * @generated + */ + public int getDirectEditionType() { + if (checkExtendedEditor()) { + initExtendedEditorConfiguration(); + return IDirectEdition.EXTENDED_DIRECT_EDITOR; + } + if (checkDefaultEdition()) { + return IDirectEdition.DEFAULT_DIRECT_EDITOR; + } + + // not a named element. no specific editor => do nothing + return IDirectEdition.NO_DIRECT_EDITION; + } + + /** + * Checks if an extended editor is present. + * + * @return true if an extended editor is present. + * @generated + */ + protected boolean checkExtendedEditor() { + if (resolveSemanticElement() != null) { + return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); + } + return false; + } + + /** + * Checks if a default direct edition is available + * + * @return true if a default direct edition is available + * @generated + */ + protected boolean checkDefaultEdition() { + return (getParser() != null); + } + + /** + * Initializes the extended editor configuration + * + * @generated + */ + protected void initExtendedEditorConfiguration() { + if (configuration == null) { + final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("")) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); + } else { + configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); + } + } + } + + /** + * Updates the preference configuration + * + * @generated + */ + protected void updateExtendedEditorConfiguration() { + String languagePreferred = Activator.getDefault().getPreferenceStore().getString( + IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() + .eClass().getInstanceClassName()); + } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { + configuration = null; + } + } + + /** + * Performs the direct edit usually used by GMF editors. + * + * @param theRequest + * the direct edit request that starts the direct edit system + * @generated + */ + protected void performDefaultDirectEditorEdit(final Request theRequest) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + + @Override + public void run() { + if (isActive() && isEditable()) { + if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) theRequest.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { + DirectEditRequest editRequest = (DirectEditRequest) theRequest; + performDirectEdit(editRequest.getLocation()); + } else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + + /** + * @generated + */ + @Override + protected void handleNotificationEvent(Notification event) { + Object feature = event.getFeature(); + if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { + Integer c = (Integer) event.getNewValue(); + setFontColor(DiagramColorRegistry.getInstance().getColor(c)); + } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { + refreshUnderline(); + } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { + refreshStrikeThrough(); + } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { + refreshFont(); + } else { + if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { + refreshLabel(); + } + if (getParser() instanceof ISemanticParser) { + ISemanticParser modelParser = + (ISemanticParser) getParser(); + if (modelParser.areSemanticElementsAffected(null, event)) { + removeSemanticListeners(); + if (resolveSemanticElement() != null) { + addSemanticListeners(); + } + refreshLabel(); + } + } + } + super.handleNotificationEvent(event); + } + + /** + * @generated + */ + @Override + protected IFigure createFigure() { + IFigure label = createFigurePrim(); + defaultText = getLabelTextHelper(label); + return label; + } + + /** + * @generated + */ + protected IFigure createFigurePrim() { + return new PapyrusWrappingLabel(); + } + +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DurationIntervalEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DurationIntervalEditPart.java index 2a26642b3c8..a20c516d2a6 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DurationIntervalEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DurationIntervalEditPart.java @@ -11,27 +11,40 @@ */ package org.eclipse.papyrus.uml.diagram.composite.edit.parts; +import java.util.Collections; +import java.util.List; + import org.eclipse.draw2d.IFigure; +import org.eclipse.emf.common.notify.Notification; import org.eclipse.gef.EditPart; import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.GraphicalEditPart; 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.handles.MoveHandle; import org.eclipse.gef.requests.CreateRequest; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.BorderItemSelectionEditPolicy; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles; +import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; -import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure; import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure; +import org.eclipse.gmf.runtime.notation.Edge; +import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.gmf.runtime.notation.View; -import org.eclipse.papyrus.infra.gmfdiag.common.editpart.NodeEditPart; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.GetChildLayoutEditPolicy; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.IPapyrusNodeFigure; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.RoundedRectangleNodePlateFigure; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.SelectableBorderedNodeFigure; +import org.eclipse.papyrus.uml.diagram.common.editparts.RoundedCompartmentEditPart; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeNodeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.QualifiedNameDisplayEditPolicy; -import org.eclipse.papyrus.uml.diagram.common.figure.node.NodeNamedElementFigure; +import org.eclipse.papyrus.uml.diagram.common.figure.node.RoundedCompartmentFigure; +import org.eclipse.papyrus.uml.diagram.common.locator.RoundedRectangleLabelPositionLocator; import org.eclipse.papyrus.uml.diagram.composite.edit.policies.DurationIntervalItemSemanticEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; import org.eclipse.swt.graphics.Color; @@ -39,7 +52,7 @@ import org.eclipse.swt.graphics.Color; /** * @generated */ -public class DurationIntervalEditPart extends NodeEditPart { +public class DurationIntervalEditPart extends RoundedCompartmentEditPart { /** * @generated @@ -73,6 +86,7 @@ public class DurationIntervalEditPart extends NodeEditPart { installEditPolicy(EditPolicy.LAYOUT_ROLE, createLayoutEditPolicy()); installEditPolicy(QualifiedNameDisplayEditPolicy.QUALIFIED_NAME_POLICY, new QualifiedNameDisplayEditPolicy()); installEditPolicy(AppliedStereotypeLabelDisplayEditPolicy.STEREOTYPE_LABEL_POLICY, new AppliedStereotypeNodeLabelDisplayEditPolicy()); + installEditPolicy(EditPolicy.LAYOUT_ROLE, new GetChildLayoutEditPolicy()); // XXX need an SCR to runtime to have another abstract superclass that would let children add reasonable editpolicies // removeEditPolicy(org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles.CONNECTION_HANDLES_ROLE); } @@ -85,6 +99,20 @@ public class DurationIntervalEditPart extends NodeEditPart { @Override protected EditPolicy createChildEditPolicy(EditPart child) { + View childView = (View) child.getModel(); + switch (UMLVisualIDRegistry.getVisualID(childView)) { + case DurationIntervalFloatingLabelEditPart.VISUAL_ID: + return new BorderItemSelectionEditPolicy() { + + @Override + protected List createSelectionHandles() { + MoveHandle mh = new MoveHandle((GraphicalEditPart) getHost()); + mh.setBorder(null); + return Collections.singletonList(mh); + } + } + ; + } EditPolicy result = child.getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); if (result == null) { result = new NonResizableEditPolicy(); @@ -105,12 +133,36 @@ public class DurationIntervalEditPart extends NodeEditPart { return lep; } + /** + * Papyrus codeGen + * + * @generated + **/ + @Override + protected void handleNotificationEvent(Notification event) { + /* + * when a node have external node labels, the methods refreshChildren() remove the EditPart corresponding to the Label from the EditPart + * Registry. After that, we can't reset the visibility to true (using the Show/Hide Label Action)! + */ + if (NotationPackage.eINSTANCE.getView_Visible().equals(event.getFeature())) { + Object notifier = event.getNotifier(); + List modelChildren = ((View) getModel()).getChildren(); + if (!(notifier instanceof Edge)) { + if (modelChildren.contains(event.getNotifier())) { + return; + } + } + } + super.handleNotificationEvent(event); + + } + /** * @generated */ @Override protected IFigure createNodeShape() { - return primaryShape = new NodeNamedElementFigure(); + return primaryShape = new RoundedCompartmentFigure(); } /** @@ -119,8 +171,8 @@ public class DurationIntervalEditPart extends NodeEditPart { * @generated */ @Override - public NodeNamedElementFigure getPrimaryShape() { - return (NodeNamedElementFigure) primaryShape; + public RoundedCompartmentFigure getPrimaryShape() { + return (RoundedCompartmentFigure) primaryShape; } /** @@ -173,15 +225,32 @@ public class DurationIntervalEditPart extends NodeEditPart { */ @Override protected IFigure getContentPaneFor(IGraphicalEditPart editPart) { + if (editPart instanceof IBorderItemEditPart) { + return getBorderedFigure().getBorderItemContainer(); + } return getContentPane(); } + /** + * @generated + */ + @Override + protected void addBorderItem(IFigure borderItemContainer, IBorderItemEditPart borderItemEditPart) { + if (borderItemEditPart instanceof DurationIntervalFloatingLabelEditPart) { + IBorderItemLocator locator = new RoundedRectangleLabelPositionLocator(getMainFigure()); + borderItemContainer.add(borderItemEditPart.getFigure(), locator); + } else + { + super.addBorderItem(borderItemContainer, borderItemEditPart); + } + } + /** * @generated */ @Override protected NodeFigure createNodePlate() { - DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(40, 40); + RoundedRectangleNodePlateFigure result = new RoundedRectangleNodePlateFigure(40, 40); return result; } @@ -194,7 +263,7 @@ public class DurationIntervalEditPart extends NodeEditPart { * @generated */ @Override - protected NodeFigure createNodeFigure() { + protected NodeFigure createMainFigure() { return new SelectableBorderedNodeFigure(createMainFigureWithSVG()); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DurationIntervalFloatingLabelEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DurationIntervalFloatingLabelEditPart.java new file mode 100644 index 00000000000..ed7084771c2 --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DurationIntervalFloatingLabelEditPart.java @@ -0,0 +1,860 @@ +/** + * 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.uml.diagram.composite.edit.parts; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.Label; +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.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.RunnableWithResult; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gef.AccessibleEditPart; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.Request; +import org.eclipse.gef.requests.DirectEditRequest; +import org.eclipse.gef.tools.DirectEditManager; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; +import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; +import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; +import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; +import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; +import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; +import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; +import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; +import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; +import org.eclipse.gmf.runtime.notation.FontStyle; +import org.eclipse.gmf.runtime.notation.NotationPackage; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.text.contentassist.IContentAssistProcessor; +import org.eclipse.jface.viewers.ICellEditorValidator; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.extensionpoints.editors.Activator; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; +import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; +import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.ExternalLabelPrimaryDragRoleEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.PapyrusWrappingLabel; +import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; +import org.eclipse.papyrus.uml.diagram.common.editparts.FloatingLabelEditPart; +import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; +import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; +import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; +import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.accessibility.AccessibleEvent; +import org.eclipse.swt.custom.BusyIndicator; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; +import org.eclipse.uml2.uml.Feature; + +/** + * @generated + */ +public class DurationIntervalFloatingLabelEditPart extends FloatingLabelEditPart + implements ITextAwareEditPart, IBorderItemEditPart +{ + + /** + * @generated + */ + public static final int VISUAL_ID = 6117; + + /** + * @generated + */ + private DirectEditManager manager; + + /** + * @generated + */ + private IParser parser; + + /** + * @generated + */ + private List parserElements; + + /** + * @generated + */ + private String defaultText; + + /** + * direct edition mode (default, undefined, registered editor, etc.) + * + * @generated + */ + protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; + + /** + * configuration from a registered edit dialog + * + * @generated + */ + protected IDirectEditorConfiguration configuration; + + + /** + * @generated + */ + static { + registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.DurationIntervalFloatingLabelEditPart.VISUAL_ID), new Point(0, 0)); + } + + /** + * @generated + */ + public DurationIntervalFloatingLabelEditPart(View view) { + super(view); + } + + /** + * @generated + */ + @Override + protected void createDefaultEditPolicies() { + super.createDefaultEditPolicies(); + installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); + installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ExternalLabelPrimaryDragRoleEditPolicy()); + } + + /** + * @generated + */ + @Override + public IBorderItemLocator getBorderItemLocator() { + IFigure parentFigure = getFigure().getParent(); + if (parentFigure != null && parentFigure.getLayoutManager() != null) { + Object constraint = parentFigure.getLayoutManager().getConstraint(getFigure()); + return (IBorderItemLocator) constraint; + } + return null; + } + + /** + * @generated + */ + @Override + public void refreshBounds() { + int x = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_X())).intValue(); + int y = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_Y())).intValue(); + int width = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Width())).intValue(); + int height = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Height())).intValue(); + getBorderItemLocator().setConstraint(new Rectangle(x, y, width, height)); + } + + + /** + * @generated + */ + protected String getLabelTextHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getText(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getText(); + } else { + return ((Label) figure).getText(); + } + } + + /** + * @generated + */ + protected void setLabelTextHelper(IFigure figure, String text) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setText(text); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setText(text); + } else { + ((Label) figure).setText(text); + } + } + + /** + * @generated + */ + protected Image getLabelIconHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getIcon(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getIcon(); + } else { + return ((Label) figure).getIcon(); + } + } + + /** + * @generated + */ + protected void setLabelIconHelper(IFigure figure, Image icon) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setIcon(icon); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setIcon(icon); + } else { + ((Label) figure).setIcon(icon); + } + } + + /** + * @generated + */ + public void setLabel(IFigure + figure) { + unregisterVisuals(); + setFigure(figure); + defaultText = getLabelTextHelper(figure); + registerVisuals(); + refreshVisuals(); + } + + /** + * @generated + */ + @Override + protected List getModelChildren() { + return Collections.EMPTY_LIST; + } + + /** + * @generated + */ + @Override + public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { + return null; + } + + /** + * @generated + */ + public void setParser(IParser parser) { + this.parser = parser; + } + + /** + * @generated + */ + protected EObject getParserElement() { + return resolveSemanticElement(); + } + + /** + * @generated + */ + protected Image getLabelIcon() { + return null; + } + + /** + * @generated + */ + protected String getLabelText() { + String text = null; + EObject parserElement = getParserElement(); + if (parserElement != null && getParser() != null) { + text = getParser().getPrintString( + new EObjectAdapter(parserElement), + getParserOptions().intValue()); + } + if (text == null || text.length() == 0) { + text = defaultText; + } + return text; + } + + /** + * @generated + */ + @Override + public void setLabelText(String text) { + setLabelTextHelper(getFigure(), text); + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + @Override + public String getEditText() { + if (getParserElement() == null || getParser() == null) { + return ""; //$NON-NLS-1$ + } + return getParser().getEditString( + new EObjectAdapter(getParserElement()), + getParserOptions().intValue()); + } + + /** + * @generated + */ + protected boolean isEditable() { + return getParser() != null; + } + + /** + * @generated + */ + @Override + public ICellEditorValidator getEditTextValidator() { + return new ICellEditorValidator() { + + @Override + public String isValid(final Object value) { + if (value instanceof String) { + final EObject element = getParserElement(); + final IParser parser = getParser(); + try { + IParserEditStatus valid = + (IParserEditStatus) getEditingDomain().runExclusive( + new RunnableWithResult.Impl() { + + @Override + public void run() { + setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); + } + }); + return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); + } catch (InterruptedException ie) { + ie.printStackTrace(); + } + } + + // shouldn't get here + return null; + } + }; + } + + /** + * @generated + */ + @Override + public IContentAssistProcessor getCompletionProcessor() { + if (getParserElement() == null || getParser() == null) { + return null; + } + return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); + } + + /** + * @generated + */ + @Override + public ParserOptions getParserOptions() { + return ParserOptions.NONE; + } + + /** + * @generated + */ + @Override + public IParser getParser() { + if (parser == null) { + parser = UMLParserProvider.getParser(UMLElementTypes.DurationInterval_2106, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.DurationIntervalFloatingLabelEditPart.VISUAL_ID)); + } + return parser; + } + + /** + * @generated + */ + protected DirectEditManager getManager() { + if (manager == null) { + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + } + return manager; + } + + /** + * @generated + */ + protected void setManager(DirectEditManager manager) { + this.manager = manager; + } + + /** + * @generated + */ + protected void performDirectEdit() { + BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { + + @Override + public void run() { + getManager().show(); + } + }); + } + + /** + * @generated + */ + protected void performDirectEdit(Point eventLocation) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); + } + } + + /** + * @generated + */ + private void performDirectEdit(char initialCharacter) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(initialCharacter); + } else { + performDirectEdit(); + } + } + + /** + * @generated + */ + @Override + protected void performDirectEditRequest(Request request) { + + final Request theRequest = request; + + if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { + directEditionMode = getDirectEditionType(); + } + switch (directEditionMode) { + case IDirectEdition.NO_DIRECT_EDITION: + // no direct edition mode => does nothing + return; + case IDirectEdition.EXTENDED_DIRECT_EDITOR: + updateExtendedEditorConfiguration(); + if (configuration == null || configuration.getLanguage() == null) { + // Create default edit manager + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + performDefaultDirectEditorEdit(theRequest); + } else { + configuration.preEditAction(resolveSemanticElement()); + Dialog dialog = null; + if (configuration instanceof ICustomDirectEditorConfiguration) { + setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); + initializeDirectEditManager(theRequest); + return; + } else if (configuration instanceof IPopupEditorConfiguration) { + IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); + helper.showEditor(); + return; + } + else if (configuration instanceof IAdvancedEditorConfiguration) { + dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); + } else if (configuration instanceof IDirectEditorConfiguration) { + dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), + configuration); + } else { + return; + } + final Dialog finalDialog = dialog; + + if (Window.OK == dialog.open()) { + TransactionalEditingDomain domain = getEditingDomain(); + RecordingCommand command = new RecordingCommand(domain, "Edit Label") { + + @Override + protected void doExecute() { + configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); + + } + }; + domain.getCommandStack().execute(command); + } + } + break; + case IDirectEdition.DEFAULT_DIRECT_EDITOR: + initializeDirectEditManager(theRequest); + break; + default: + break; + } + } + + /** + * @generated + */ + protected void initializeDirectEditManager(final Request request) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + @Override + public void run() { + if (isActive() && isEditable()) { + if (request.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } + else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void refreshVisuals() { + super.refreshVisuals(); + refreshLabel(); + refreshFont(); + refreshFontColor(); + refreshUnderline(); + refreshStrikeThrough(); + } + + /** + * @generated + */ + protected void refreshLabel() { + EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); + if (maskLabelPolicy == null) { + maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); + } + if (maskLabelPolicy == null) { + View view = (View) getModel(); + if (view.isVisible()) { + setLabelTextHelper(getFigure(), getLabelText()); + setLabelIconHelper(getFigure(), getLabelIcon()); + } + else { + setLabelTextHelper(getFigure(), ""); //$NON-NLS-1$ + setLabelIconHelper(getFigure(), null); + } + } + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + protected void refreshUnderline() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); + } + if (resolveSemanticElement() instanceof Feature) { + if (((Feature) resolveSemanticElement()).isStatic()) { + ((WrappingLabel) getFigure()).setTextUnderline(true); + } + else { + ((WrappingLabel) getFigure()).setTextUnderline(false); + } + } + } + + /** + * @generated + */ + protected void refreshStrikeThrough() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); + } + } + + /** + * @generated + */ + @Override + protected void refreshFont() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null) { + FontData fontData = new FontData( + style.getFontName(), style.getFontHeight(), + (style.isBold() ? SWT.BOLD : SWT.NORMAL) | + (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); + setFont(fontData); + } + } + + /** + * @generated + */ + @Override + protected void setFontColor(Color color) { + getFigure().setForegroundColor(color); + } + + /** + * @generated + */ + @Override + protected void addSemanticListeners() { + if (getParser() instanceof ISemanticParser) { + EObject element = resolveSemanticElement(); + parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); + for (int i = 0; i < parserElements.size(); i++) { + addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ + } + } else { + super.addSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected void removeSemanticListeners() { + if (parserElements != null) { + for (int i = 0; i < parserElements.size(); i++) { + removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ + } + } else { + super.removeSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected AccessibleEditPart getAccessibleEditPart() { + if (accessibleEP == null) { + accessibleEP = new AccessibleGraphicalEditPart() { + + @Override + public void getName(AccessibleEvent e) { + e.result = getLabelTextHelper(getFigure()); + } + }; + } + return accessibleEP; + } + + /** + * @generated + */ + private View getFontStyleOwnerView() { + return getPrimaryView(); + } + + /** + * Returns the kind of associated editor for direct edition. + * + * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition + * @generated + */ + public int getDirectEditionType() { + if (checkExtendedEditor()) { + initExtendedEditorConfiguration(); + return IDirectEdition.EXTENDED_DIRECT_EDITOR; + } + if (checkDefaultEdition()) { + return IDirectEdition.DEFAULT_DIRECT_EDITOR; + } + + // not a named element. no specific editor => do nothing + return IDirectEdition.NO_DIRECT_EDITION; + } + + /** + * Checks if an extended editor is present. + * + * @return true if an extended editor is present. + * @generated + */ + protected boolean checkExtendedEditor() { + if (resolveSemanticElement() != null) { + return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); + } + return false; + } + + /** + * Checks if a default direct edition is available + * + * @return true if a default direct edition is available + * @generated + */ + protected boolean checkDefaultEdition() { + return (getParser() != null); + } + + /** + * Initializes the extended editor configuration + * + * @generated + */ + protected void initExtendedEditorConfiguration() { + if (configuration == null) { + final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("")) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); + } else { + configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); + } + } + } + + /** + * Updates the preference configuration + * + * @generated + */ + protected void updateExtendedEditorConfiguration() { + String languagePreferred = Activator.getDefault().getPreferenceStore().getString( + IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() + .eClass().getInstanceClassName()); + } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { + configuration = null; + } + } + + /** + * Performs the direct edit usually used by GMF editors. + * + * @param theRequest + * the direct edit request that starts the direct edit system + * @generated + */ + protected void performDefaultDirectEditorEdit(final Request theRequest) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + + @Override + public void run() { + if (isActive() && isEditable()) { + if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) theRequest.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { + DirectEditRequest editRequest = (DirectEditRequest) theRequest; + performDirectEdit(editRequest.getLocation()); + } else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + + /** + * @generated + */ + @Override + protected void handleNotificationEvent(Notification event) { + Object feature = event.getFeature(); + if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { + Integer c = (Integer) event.getNewValue(); + setFontColor(DiagramColorRegistry.getInstance().getColor(c)); + } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { + refreshUnderline(); + } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { + refreshStrikeThrough(); + } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { + refreshFont(); + } else { + if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { + refreshLabel(); + } + if (getParser() instanceof ISemanticParser) { + ISemanticParser modelParser = + (ISemanticParser) getParser(); + if (modelParser.areSemanticElementsAffected(null, event)) { + removeSemanticListeners(); + if (resolveSemanticElement() != null) { + addSemanticListeners(); + } + refreshLabel(); + } + } + } + super.handleNotificationEvent(event); + } + + /** + * @generated + */ + @Override + protected IFigure createFigure() { + IFigure label = createFigurePrim(); + defaultText = getLabelTextHelper(label); + return label; + } + + /** + * @generated + */ + protected IFigure createFigurePrim() { + return new PapyrusWrappingLabel(); + } + +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DurationIntervalNameEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DurationIntervalNameEditPart.java index 8800f289818..1897b014c5a 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DurationIntervalNameEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DurationIntervalNameEditPart.java @@ -864,7 +864,7 @@ public class DurationIntervalNameEditPart extends PapyrusCompartmentEditPart imp * @generated */ protected void addOwnerElementListeners() { - addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); + addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DurationNameEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DurationNameEditPart.java index 11e30fd76f0..e1d877b34ba 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DurationNameEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DurationNameEditPart.java @@ -864,7 +864,7 @@ public class DurationNameEditPart extends PapyrusCompartmentEditPart implements * @generated */ protected void addOwnerElementListeners() { - addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); + addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DurationObservationEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DurationObservationEditPart.java index 684287b7069..d5b7acca4eb 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DurationObservationEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DurationObservationEditPart.java @@ -29,22 +29,23 @@ import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.BorderItemSelectionEditPolicy; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles; import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; -import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure; import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure; import org.eclipse.gmf.runtime.notation.Edge; import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.gmf.runtime.notation.View; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.IPapyrusNodeFigure; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.RoundedRectangleNodePlateFigure; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.SelectableBorderedNodeFigure; +import org.eclipse.papyrus.uml.diagram.common.editparts.RoundedCompartmentEditPart; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeIconlDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.QualifiedNameDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.ShowHideLabelEditPolicy; +import org.eclipse.papyrus.uml.diagram.common.figure.node.RoundedCompartmentFigure; import org.eclipse.papyrus.uml.diagram.common.locator.ExternalLabelPositionLocator; -import org.eclipse.papyrus.uml.diagram.composite.custom.edit.parts.AbstractObservationEditPart; +import org.eclipse.papyrus.uml.diagram.common.locator.RoundedRectangleLabelPositionLocator; import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.CustomDiagramDragDropEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.ObservationLayoutEditPolicy; -import org.eclipse.papyrus.uml.diagram.composite.custom.figures.DurationObservationNodeFigure; import org.eclipse.papyrus.uml.diagram.composite.edit.policies.DurationObservationItemSemanticEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; import org.eclipse.swt.graphics.Color; @@ -52,7 +53,7 @@ import org.eclipse.swt.graphics.Color; /** * @generated */ -public class DurationObservationEditPart extends AbstractObservationEditPart { +public class DurationObservationEditPart extends RoundedCompartmentEditPart { /** * @generated @@ -165,7 +166,7 @@ public class DurationObservationEditPart extends AbstractObservationEditPart { */ @Override protected IFigure createNodeShape() { - return primaryShape = new DurationObservationNodeFigure(); + return primaryShape = new RoundedCompartmentFigure(); } /** @@ -174,8 +175,8 @@ public class DurationObservationEditPart extends AbstractObservationEditPart { * @generated */ @Override - public DurationObservationNodeFigure getPrimaryShape() { - return (DurationObservationNodeFigure) primaryShape; + public RoundedCompartmentFigure getPrimaryShape() { + return (RoundedCompartmentFigure) primaryShape; } /** @@ -184,7 +185,7 @@ public class DurationObservationEditPart extends AbstractObservationEditPart { @Override protected void addBorderItem(IFigure borderItemContainer, IBorderItemEditPart borderItemEditPart) { if (borderItemEditPart instanceof DurationObservationNameEditPart) { - IBorderItemLocator locator = new ExternalLabelPositionLocator(getMainFigure()); + IBorderItemLocator locator = new RoundedRectangleLabelPositionLocator(getMainFigure()); borderItemContainer.add(borderItemEditPart.getFigure(), locator); } else if (borderItemEditPart instanceof DurationObservationStereotypeLabelEditPart) { IBorderItemLocator locator = new ExternalLabelPositionLocator(getMainFigure()); @@ -200,7 +201,7 @@ public class DurationObservationEditPart extends AbstractObservationEditPart { */ @Override protected NodeFigure createNodePlate() { - DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(40, 40); + RoundedRectangleNodePlateFigure result = new RoundedRectangleNodePlateFigure(20, 20); return result; } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DurationObservationNameEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DurationObservationNameEditPart.java index 3fb0be0edad..aa04ba29fad 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DurationObservationNameEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DurationObservationNameEditPart.java @@ -59,11 +59,12 @@ import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; -import org.eclipse.papyrus.infra.gmfdiag.common.editpart.PapyrusLabelEditPart; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.ExternalLabelPrimaryDragRoleEditPolicy; import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.PapyrusWrappingLabel; import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; +import org.eclipse.papyrus.uml.diagram.common.editparts.FloatingLabelEditPart; import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; @@ -83,7 +84,7 @@ import org.eclipse.uml2.uml.Feature; /** * @generated */ -public class DurationObservationNameEditPart extends PapyrusLabelEditPart implements ITextAwareEditPart, IBorderItemEditPart { +public class DurationObservationNameEditPart extends FloatingLabelEditPart implements ITextAwareEditPart, IBorderItemEditPart { /** * @generated @@ -145,6 +146,7 @@ public class DurationObservationNameEditPart extends PapyrusLabelEditPart implem super.createDefaultEditPolicies(); installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ExternalLabelPrimaryDragRoleEditPolicy()); } /** diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DurationObservationStereotypeLabelEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DurationObservationStereotypeLabelEditPart.java index 3827807d4c5..418a8f27c9c 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DurationObservationStereotypeLabelEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/DurationObservationStereotypeLabelEditPart.java @@ -59,6 +59,7 @@ import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.ExternalLabelPrimaryDragRoleEditPolicy; import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; @@ -148,6 +149,7 @@ public class DurationObservationStereotypeLabelEditPart extends AbstractLabelEdi installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); installEditPolicy(AppliedStereotypeLabelDisplayEditPolicy.STEREOTYPE_LABEL_POLICY, new AppliedStereotypeExternalNodeEditPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ExternalLabelPrimaryDragRoleEditPolicy()); } /** diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/EnumerationEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/EnumerationEditPart.java index 4c929d124e5..01fc12f4395 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/EnumerationEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/EnumerationEditPart.java @@ -11,28 +11,39 @@ */ package org.eclipse.papyrus.uml.diagram.composite.edit.parts; +import java.util.Collections; +import java.util.List; + import org.eclipse.draw2d.IFigure; import org.eclipse.emf.common.notify.Notification; import org.eclipse.gef.EditPart; import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.GraphicalEditPart; 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.handles.MoveHandle; import org.eclipse.gef.requests.CreateRequest; import org.eclipse.gmf.runtime.diagram.core.edithelpers.CreateElementRequestAdapter; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.BorderItemSelectionEditPolicy; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.DragDropEditPolicy; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles; +import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewAndElementRequest; import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; import org.eclipse.gmf.runtime.emf.type.core.IElementType; -import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure; import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure; +import org.eclipse.gmf.runtime.notation.Edge; +import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.GetChildLayoutEditPolicy; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.IPapyrusNodeFigure; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.RoundedRectangleNodePlateFigure; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.SelectableBorderedNodeFigure; -import org.eclipse.papyrus.uml.diagram.common.editparts.NamedElementEditPart; +import org.eclipse.papyrus.uml.diagram.common.editparts.RoundedCompartmentEditPart; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeNodeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.PapyrusCreationEditPolicy; @@ -40,6 +51,7 @@ import org.eclipse.papyrus.uml.diagram.common.editpolicies.QualifiedNameDisplayE import org.eclipse.papyrus.uml.diagram.common.editpolicies.ShowHideClassifierContentsEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.ShowHideCompartmentEditPolicy; import org.eclipse.papyrus.uml.diagram.common.figure.node.EnumerationFigure; +import org.eclipse.papyrus.uml.diagram.common.locator.RoundedRectangleLabelPositionLocator; import org.eclipse.papyrus.uml.diagram.composite.edit.policies.EnumerationItemSemanticEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; @@ -48,7 +60,7 @@ import org.eclipse.swt.graphics.Color; /** * @generated */ -public class EnumerationEditPart extends NamedElementEditPart { +public class EnumerationEditPart extends RoundedCompartmentEditPart { /** * @generated @@ -86,6 +98,7 @@ public class EnumerationEditPart extends NamedElementEditPart { installEditPolicy(AppliedStereotypeLabelDisplayEditPolicy.STEREOTYPE_LABEL_POLICY, new AppliedStereotypeNodeLabelDisplayEditPolicy()); installEditPolicy(ShowHideClassifierContentsEditPolicy.SHOW_HIDE_CLASSIFIER_CONTENTS_POLICY, new ShowHideClassifierContentsEditPolicy()); installEditPolicy(ShowHideCompartmentEditPolicy.SHOW_HIDE_COMPARTMENT_POLICY, new ShowHideCompartmentEditPolicy()); + installEditPolicy(EditPolicy.LAYOUT_ROLE, new GetChildLayoutEditPolicy()); // XXX need an SCR to runtime to have another abstract superclass that would let children add reasonable editpolicies // removeEditPolicy(org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles.CONNECTION_HANDLES_ROLE); } @@ -98,6 +111,20 @@ public class EnumerationEditPart extends NamedElementEditPart { @Override protected EditPolicy createChildEditPolicy(EditPart child) { + View childView = (View) child.getModel(); + switch (UMLVisualIDRegistry.getVisualID(childView)) { + case EnumerationFloatingLabelEditPart.VISUAL_ID: + return new BorderItemSelectionEditPolicy() { + + @Override + protected List createSelectionHandles() { + MoveHandle mh = new MoveHandle((GraphicalEditPart) getHost()); + mh.setBorder(null); + return Collections.singletonList(mh); + } + } + ; + } EditPolicy result = child.getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); if (result == null) { result = new NonResizableEditPolicy(); @@ -125,6 +152,19 @@ public class EnumerationEditPart extends NamedElementEditPart { **/ @Override protected void handleNotificationEvent(Notification event) { + /* + * when a node have external node labels, the methods refreshChildren() remove the EditPart corresponding to the Label from the EditPart + * Registry. After that, we can't reset the visibility to true (using the Show/Hide Label Action)! + */ + if (NotationPackage.eINSTANCE.getView_Visible().equals(event.getFeature())) { + Object notifier = event.getNotifier(); + List modelChildren = ((View) getModel()).getChildren(); + if (!(notifier instanceof Edge)) { + if (modelChildren.contains(event.getNotifier())) { + return; + } + } + } super.handleNotificationEvent(event); } @@ -212,15 +252,32 @@ public class EnumerationEditPart extends NamedElementEditPart { if (editPart instanceof EnumerationEnumerationLiteralCompartmentEditPart) { return getPrimaryShape().getEnumerationLiteralCompartmentFigure(); } + if (editPart instanceof IBorderItemEditPart) { + return getBorderedFigure().getBorderItemContainer(); + } return getContentPane(); } + /** + * @generated + */ + @Override + protected void addBorderItem(IFigure borderItemContainer, IBorderItemEditPart borderItemEditPart) { + if (borderItemEditPart instanceof EnumerationFloatingLabelEditPart) { + IBorderItemLocator locator = new RoundedRectangleLabelPositionLocator(getMainFigure()); + borderItemContainer.add(borderItemEditPart.getFigure(), locator); + } else + { + super.addBorderItem(borderItemContainer, borderItemEditPart); + } + } + /** * @generated */ @Override protected NodeFigure createNodePlate() { - DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(40, 40); + RoundedRectangleNodePlateFigure result = new RoundedRectangleNodePlateFigure(40, 40); return result; } @@ -233,7 +290,7 @@ public class EnumerationEditPart extends NamedElementEditPart { * @generated */ @Override - protected NodeFigure createNodeFigure() { + protected NodeFigure createMainFigure() { return new SelectableBorderedNodeFigure(createMainFigureWithSVG()); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/EnumerationEditPartCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/EnumerationEditPartCN.java index 2664aba9213..222755bd98c 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/EnumerationEditPartCN.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/EnumerationEditPartCN.java @@ -11,28 +11,39 @@ */ package org.eclipse.papyrus.uml.diagram.composite.edit.parts; +import java.util.Collections; +import java.util.List; + import org.eclipse.draw2d.IFigure; import org.eclipse.emf.common.notify.Notification; import org.eclipse.gef.EditPart; import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.GraphicalEditPart; 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.handles.MoveHandle; import org.eclipse.gef.requests.CreateRequest; import org.eclipse.gmf.runtime.diagram.core.edithelpers.CreateElementRequestAdapter; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.BorderItemSelectionEditPolicy; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.DragDropEditPolicy; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles; +import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewAndElementRequest; import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; import org.eclipse.gmf.runtime.emf.type.core.IElementType; -import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure; import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure; +import org.eclipse.gmf.runtime.notation.Edge; +import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.GetChildLayoutEditPolicy; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.IPapyrusNodeFigure; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.RoundedRectangleNodePlateFigure; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.SelectableBorderedNodeFigure; -import org.eclipse.papyrus.uml.diagram.common.editparts.NamedElementEditPart; +import org.eclipse.papyrus.uml.diagram.common.editparts.RoundedCompartmentEditPart; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeNodeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.PapyrusCreationEditPolicy; @@ -40,6 +51,7 @@ import org.eclipse.papyrus.uml.diagram.common.editpolicies.QualifiedNameDisplayE import org.eclipse.papyrus.uml.diagram.common.editpolicies.ShowHideClassifierContentsEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.ShowHideCompartmentEditPolicy; import org.eclipse.papyrus.uml.diagram.common.figure.node.EnumerationFigure; +import org.eclipse.papyrus.uml.diagram.common.locator.RoundedRectangleLabelPositionLocator; import org.eclipse.papyrus.uml.diagram.composite.edit.policies.EnumerationItemSemanticEditPolicyCN; import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; @@ -48,7 +60,7 @@ import org.eclipse.swt.graphics.Color; /** * @generated */ -public class EnumerationEditPartCN extends NamedElementEditPart { +public class EnumerationEditPartCN extends RoundedCompartmentEditPart { /** * @generated @@ -86,6 +98,7 @@ public class EnumerationEditPartCN extends NamedElementEditPart { installEditPolicy(AppliedStereotypeLabelDisplayEditPolicy.STEREOTYPE_LABEL_POLICY, new AppliedStereotypeNodeLabelDisplayEditPolicy()); installEditPolicy(ShowHideClassifierContentsEditPolicy.SHOW_HIDE_CLASSIFIER_CONTENTS_POLICY, new ShowHideClassifierContentsEditPolicy()); installEditPolicy(ShowHideCompartmentEditPolicy.SHOW_HIDE_COMPARTMENT_POLICY, new ShowHideCompartmentEditPolicy()); + installEditPolicy(EditPolicy.LAYOUT_ROLE, new GetChildLayoutEditPolicy()); // XXX need an SCR to runtime to have another abstract superclass that would let children add reasonable editpolicies // removeEditPolicy(org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles.CONNECTION_HANDLES_ROLE); } @@ -98,6 +111,20 @@ public class EnumerationEditPartCN extends NamedElementEditPart { @Override protected EditPolicy createChildEditPolicy(EditPart child) { + View childView = (View) child.getModel(); + switch (UMLVisualIDRegistry.getVisualID(childView)) { + case EnumerationFloatingLabelEditPartCN.VISUAL_ID: + return new BorderItemSelectionEditPolicy() { + + @Override + protected List createSelectionHandles() { + MoveHandle mh = new MoveHandle((GraphicalEditPart) getHost()); + mh.setBorder(null); + return Collections.singletonList(mh); + } + } + ; + } EditPolicy result = child.getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); if (result == null) { result = new NonResizableEditPolicy(); @@ -125,6 +152,19 @@ public class EnumerationEditPartCN extends NamedElementEditPart { **/ @Override protected void handleNotificationEvent(Notification event) { + /* + * when a node have external node labels, the methods refreshChildren() remove the EditPart corresponding to the Label from the EditPart + * Registry. After that, we can't reset the visibility to true (using the Show/Hide Label Action)! + */ + if (NotationPackage.eINSTANCE.getView_Visible().equals(event.getFeature())) { + Object notifier = event.getNotifier(); + List modelChildren = ((View) getModel()).getChildren(); + if (!(notifier instanceof Edge)) { + if (modelChildren.contains(event.getNotifier())) { + return; + } + } + } super.handleNotificationEvent(event); } @@ -212,15 +252,32 @@ public class EnumerationEditPartCN extends NamedElementEditPart { if (editPart instanceof EnumerationEnumerationLiteralCompartmentEditPartCN) { return getPrimaryShape().getEnumerationLiteralCompartmentFigure(); } + if (editPart instanceof IBorderItemEditPart) { + return getBorderedFigure().getBorderItemContainer(); + } return getContentPane(); } + /** + * @generated + */ + @Override + protected void addBorderItem(IFigure borderItemContainer, IBorderItemEditPart borderItemEditPart) { + if (borderItemEditPart instanceof EnumerationFloatingLabelEditPartCN) { + IBorderItemLocator locator = new RoundedRectangleLabelPositionLocator(getMainFigure()); + borderItemContainer.add(borderItemEditPart.getFigure(), locator); + } else + { + super.addBorderItem(borderItemContainer, borderItemEditPart); + } + } + /** * @generated */ @Override protected NodeFigure createNodePlate() { - DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(40, 40); + RoundedRectangleNodePlateFigure result = new RoundedRectangleNodePlateFigure(40, 40); return result; } @@ -233,7 +290,7 @@ public class EnumerationEditPartCN extends NamedElementEditPart { * @generated */ @Override - protected NodeFigure createNodeFigure() { + protected NodeFigure createMainFigure() { return new SelectableBorderedNodeFigure(createMainFigureWithSVG()); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/EnumerationEnumerationLiteralCompartmentEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/EnumerationEnumerationLiteralCompartmentEditPart.java index 16b4cf40e5e..d3e77147cbb 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/EnumerationEnumerationLiteralCompartmentEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/EnumerationEnumerationLiteralCompartmentEditPart.java @@ -26,6 +26,7 @@ import org.eclipse.gmf.runtime.diagram.ui.editpolicies.ResizableCompartmentEditP import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.BorderDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.DuplicatePasteEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.PapyrusCreationEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.CustomDiagramDragDropEditPolicy; @@ -79,6 +80,7 @@ public class EnumerationEnumerationLiteralCompartmentEditPart extends ListCompar installEditPolicy(DuplicatePasteEditPolicy.PASTE_ROLE, new DuplicatePasteEditPolicy()); installEditPolicy("REMOVE_ORPHAN_VIEW", new RemoveOrphanViewPolicy()); //$NON-NLS-1$ installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, new CustomDiagramDragDropEditPolicy()); + installEditPolicy(BorderDisplayEditPolicy.BORDER_DISPLAY_EDITPOLICY, new BorderDisplayEditPolicy()); } /** diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/EnumerationEnumerationLiteralCompartmentEditPartCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/EnumerationEnumerationLiteralCompartmentEditPartCN.java index 56aceab8dc5..236b9c55d75 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/EnumerationEnumerationLiteralCompartmentEditPartCN.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/EnumerationEnumerationLiteralCompartmentEditPartCN.java @@ -26,6 +26,7 @@ import org.eclipse.gmf.runtime.diagram.ui.editpolicies.ResizableCompartmentEditP import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.BorderDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.DuplicatePasteEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.PapyrusCreationEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.CustomDiagramDragDropEditPolicy; @@ -79,6 +80,7 @@ public class EnumerationEnumerationLiteralCompartmentEditPartCN extends ListComp installEditPolicy(DuplicatePasteEditPolicy.PASTE_ROLE, new DuplicatePasteEditPolicy()); installEditPolicy("REMOVE_ORPHAN_VIEW", new RemoveOrphanViewPolicy()); //$NON-NLS-1$ installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, new CustomDiagramDragDropEditPolicy()); + installEditPolicy(BorderDisplayEditPolicy.BORDER_DISPLAY_EDITPOLICY, new BorderDisplayEditPolicy()); } /** diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/EnumerationFloatingLabelEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/EnumerationFloatingLabelEditPart.java new file mode 100644 index 00000000000..776391a75da --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/EnumerationFloatingLabelEditPart.java @@ -0,0 +1,860 @@ +/** + * 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.uml.diagram.composite.edit.parts; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.Label; +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.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.RunnableWithResult; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gef.AccessibleEditPart; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.Request; +import org.eclipse.gef.requests.DirectEditRequest; +import org.eclipse.gef.tools.DirectEditManager; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; +import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; +import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; +import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; +import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; +import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; +import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; +import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; +import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; +import org.eclipse.gmf.runtime.notation.FontStyle; +import org.eclipse.gmf.runtime.notation.NotationPackage; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.text.contentassist.IContentAssistProcessor; +import org.eclipse.jface.viewers.ICellEditorValidator; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.extensionpoints.editors.Activator; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; +import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; +import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.ExternalLabelPrimaryDragRoleEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.PapyrusWrappingLabel; +import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; +import org.eclipse.papyrus.uml.diagram.common.editparts.FloatingLabelEditPart; +import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; +import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; +import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; +import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.accessibility.AccessibleEvent; +import org.eclipse.swt.custom.BusyIndicator; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; +import org.eclipse.uml2.uml.Feature; + +/** + * @generated + */ +public class EnumerationFloatingLabelEditPart extends FloatingLabelEditPart + implements ITextAwareEditPart, IBorderItemEditPart +{ + + /** + * @generated + */ + public static final int VISUAL_ID = 6093; + + /** + * @generated + */ + private DirectEditManager manager; + + /** + * @generated + */ + private IParser parser; + + /** + * @generated + */ + private List parserElements; + + /** + * @generated + */ + private String defaultText; + + /** + * direct edition mode (default, undefined, registered editor, etc.) + * + * @generated + */ + protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; + + /** + * configuration from a registered edit dialog + * + * @generated + */ + protected IDirectEditorConfiguration configuration; + + + /** + * @generated + */ + static { + registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.EnumerationFloatingLabelEditPart.VISUAL_ID), new Point(0, 0)); + } + + /** + * @generated + */ + public EnumerationFloatingLabelEditPart(View view) { + super(view); + } + + /** + * @generated + */ + @Override + protected void createDefaultEditPolicies() { + super.createDefaultEditPolicies(); + installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); + installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ExternalLabelPrimaryDragRoleEditPolicy()); + } + + /** + * @generated + */ + @Override + public IBorderItemLocator getBorderItemLocator() { + IFigure parentFigure = getFigure().getParent(); + if (parentFigure != null && parentFigure.getLayoutManager() != null) { + Object constraint = parentFigure.getLayoutManager().getConstraint(getFigure()); + return (IBorderItemLocator) constraint; + } + return null; + } + + /** + * @generated + */ + @Override + public void refreshBounds() { + int x = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_X())).intValue(); + int y = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_Y())).intValue(); + int width = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Width())).intValue(); + int height = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Height())).intValue(); + getBorderItemLocator().setConstraint(new Rectangle(x, y, width, height)); + } + + + /** + * @generated + */ + protected String getLabelTextHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getText(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getText(); + } else { + return ((Label) figure).getText(); + } + } + + /** + * @generated + */ + protected void setLabelTextHelper(IFigure figure, String text) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setText(text); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setText(text); + } else { + ((Label) figure).setText(text); + } + } + + /** + * @generated + */ + protected Image getLabelIconHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getIcon(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getIcon(); + } else { + return ((Label) figure).getIcon(); + } + } + + /** + * @generated + */ + protected void setLabelIconHelper(IFigure figure, Image icon) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setIcon(icon); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setIcon(icon); + } else { + ((Label) figure).setIcon(icon); + } + } + + /** + * @generated + */ + public void setLabel(IFigure + figure) { + unregisterVisuals(); + setFigure(figure); + defaultText = getLabelTextHelper(figure); + registerVisuals(); + refreshVisuals(); + } + + /** + * @generated + */ + @Override + protected List getModelChildren() { + return Collections.EMPTY_LIST; + } + + /** + * @generated + */ + @Override + public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { + return null; + } + + /** + * @generated + */ + public void setParser(IParser parser) { + this.parser = parser; + } + + /** + * @generated + */ + protected EObject getParserElement() { + return resolveSemanticElement(); + } + + /** + * @generated + */ + protected Image getLabelIcon() { + return null; + } + + /** + * @generated + */ + protected String getLabelText() { + String text = null; + EObject parserElement = getParserElement(); + if (parserElement != null && getParser() != null) { + text = getParser().getPrintString( + new EObjectAdapter(parserElement), + getParserOptions().intValue()); + } + if (text == null || text.length() == 0) { + text = defaultText; + } + return text; + } + + /** + * @generated + */ + @Override + public void setLabelText(String text) { + setLabelTextHelper(getFigure(), text); + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + @Override + public String getEditText() { + if (getParserElement() == null || getParser() == null) { + return ""; //$NON-NLS-1$ + } + return getParser().getEditString( + new EObjectAdapter(getParserElement()), + getParserOptions().intValue()); + } + + /** + * @generated + */ + protected boolean isEditable() { + return getParser() != null; + } + + /** + * @generated + */ + @Override + public ICellEditorValidator getEditTextValidator() { + return new ICellEditorValidator() { + + @Override + public String isValid(final Object value) { + if (value instanceof String) { + final EObject element = getParserElement(); + final IParser parser = getParser(); + try { + IParserEditStatus valid = + (IParserEditStatus) getEditingDomain().runExclusive( + new RunnableWithResult.Impl() { + + @Override + public void run() { + setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); + } + }); + return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); + } catch (InterruptedException ie) { + ie.printStackTrace(); + } + } + + // shouldn't get here + return null; + } + }; + } + + /** + * @generated + */ + @Override + public IContentAssistProcessor getCompletionProcessor() { + if (getParserElement() == null || getParser() == null) { + return null; + } + return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); + } + + /** + * @generated + */ + @Override + public ParserOptions getParserOptions() { + return ParserOptions.NONE; + } + + /** + * @generated + */ + @Override + public IParser getParser() { + if (parser == null) { + parser = UMLParserProvider.getParser(UMLElementTypes.Enumeration_2067, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.EnumerationFloatingLabelEditPart.VISUAL_ID)); + } + return parser; + } + + /** + * @generated + */ + protected DirectEditManager getManager() { + if (manager == null) { + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + } + return manager; + } + + /** + * @generated + */ + protected void setManager(DirectEditManager manager) { + this.manager = manager; + } + + /** + * @generated + */ + protected void performDirectEdit() { + BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { + + @Override + public void run() { + getManager().show(); + } + }); + } + + /** + * @generated + */ + protected void performDirectEdit(Point eventLocation) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); + } + } + + /** + * @generated + */ + private void performDirectEdit(char initialCharacter) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(initialCharacter); + } else { + performDirectEdit(); + } + } + + /** + * @generated + */ + @Override + protected void performDirectEditRequest(Request request) { + + final Request theRequest = request; + + if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { + directEditionMode = getDirectEditionType(); + } + switch (directEditionMode) { + case IDirectEdition.NO_DIRECT_EDITION: + // no direct edition mode => does nothing + return; + case IDirectEdition.EXTENDED_DIRECT_EDITOR: + updateExtendedEditorConfiguration(); + if (configuration == null || configuration.getLanguage() == null) { + // Create default edit manager + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + performDefaultDirectEditorEdit(theRequest); + } else { + configuration.preEditAction(resolveSemanticElement()); + Dialog dialog = null; + if (configuration instanceof ICustomDirectEditorConfiguration) { + setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); + initializeDirectEditManager(theRequest); + return; + } else if (configuration instanceof IPopupEditorConfiguration) { + IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); + helper.showEditor(); + return; + } + else if (configuration instanceof IAdvancedEditorConfiguration) { + dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); + } else if (configuration instanceof IDirectEditorConfiguration) { + dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), + configuration); + } else { + return; + } + final Dialog finalDialog = dialog; + + if (Window.OK == dialog.open()) { + TransactionalEditingDomain domain = getEditingDomain(); + RecordingCommand command = new RecordingCommand(domain, "Edit Label") { + + @Override + protected void doExecute() { + configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); + + } + }; + domain.getCommandStack().execute(command); + } + } + break; + case IDirectEdition.DEFAULT_DIRECT_EDITOR: + initializeDirectEditManager(theRequest); + break; + default: + break; + } + } + + /** + * @generated + */ + protected void initializeDirectEditManager(final Request request) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + @Override + public void run() { + if (isActive() && isEditable()) { + if (request.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } + else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void refreshVisuals() { + super.refreshVisuals(); + refreshLabel(); + refreshFont(); + refreshFontColor(); + refreshUnderline(); + refreshStrikeThrough(); + } + + /** + * @generated + */ + protected void refreshLabel() { + EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); + if (maskLabelPolicy == null) { + maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); + } + if (maskLabelPolicy == null) { + View view = (View) getModel(); + if (view.isVisible()) { + setLabelTextHelper(getFigure(), getLabelText()); + setLabelIconHelper(getFigure(), getLabelIcon()); + } + else { + setLabelTextHelper(getFigure(), ""); //$NON-NLS-1$ + setLabelIconHelper(getFigure(), null); + } + } + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + protected void refreshUnderline() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); + } + if (resolveSemanticElement() instanceof Feature) { + if (((Feature) resolveSemanticElement()).isStatic()) { + ((WrappingLabel) getFigure()).setTextUnderline(true); + } + else { + ((WrappingLabel) getFigure()).setTextUnderline(false); + } + } + } + + /** + * @generated + */ + protected void refreshStrikeThrough() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); + } + } + + /** + * @generated + */ + @Override + protected void refreshFont() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null) { + FontData fontData = new FontData( + style.getFontName(), style.getFontHeight(), + (style.isBold() ? SWT.BOLD : SWT.NORMAL) | + (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); + setFont(fontData); + } + } + + /** + * @generated + */ + @Override + protected void setFontColor(Color color) { + getFigure().setForegroundColor(color); + } + + /** + * @generated + */ + @Override + protected void addSemanticListeners() { + if (getParser() instanceof ISemanticParser) { + EObject element = resolveSemanticElement(); + parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); + for (int i = 0; i < parserElements.size(); i++) { + addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ + } + } else { + super.addSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected void removeSemanticListeners() { + if (parserElements != null) { + for (int i = 0; i < parserElements.size(); i++) { + removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ + } + } else { + super.removeSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected AccessibleEditPart getAccessibleEditPart() { + if (accessibleEP == null) { + accessibleEP = new AccessibleGraphicalEditPart() { + + @Override + public void getName(AccessibleEvent e) { + e.result = getLabelTextHelper(getFigure()); + } + }; + } + return accessibleEP; + } + + /** + * @generated + */ + private View getFontStyleOwnerView() { + return getPrimaryView(); + } + + /** + * Returns the kind of associated editor for direct edition. + * + * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition + * @generated + */ + public int getDirectEditionType() { + if (checkExtendedEditor()) { + initExtendedEditorConfiguration(); + return IDirectEdition.EXTENDED_DIRECT_EDITOR; + } + if (checkDefaultEdition()) { + return IDirectEdition.DEFAULT_DIRECT_EDITOR; + } + + // not a named element. no specific editor => do nothing + return IDirectEdition.NO_DIRECT_EDITION; + } + + /** + * Checks if an extended editor is present. + * + * @return true if an extended editor is present. + * @generated + */ + protected boolean checkExtendedEditor() { + if (resolveSemanticElement() != null) { + return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); + } + return false; + } + + /** + * Checks if a default direct edition is available + * + * @return true if a default direct edition is available + * @generated + */ + protected boolean checkDefaultEdition() { + return (getParser() != null); + } + + /** + * Initializes the extended editor configuration + * + * @generated + */ + protected void initExtendedEditorConfiguration() { + if (configuration == null) { + final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("")) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); + } else { + configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); + } + } + } + + /** + * Updates the preference configuration + * + * @generated + */ + protected void updateExtendedEditorConfiguration() { + String languagePreferred = Activator.getDefault().getPreferenceStore().getString( + IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() + .eClass().getInstanceClassName()); + } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { + configuration = null; + } + } + + /** + * Performs the direct edit usually used by GMF editors. + * + * @param theRequest + * the direct edit request that starts the direct edit system + * @generated + */ + protected void performDefaultDirectEditorEdit(final Request theRequest) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + + @Override + public void run() { + if (isActive() && isEditable()) { + if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) theRequest.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { + DirectEditRequest editRequest = (DirectEditRequest) theRequest; + performDirectEdit(editRequest.getLocation()); + } else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + + /** + * @generated + */ + @Override + protected void handleNotificationEvent(Notification event) { + Object feature = event.getFeature(); + if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { + Integer c = (Integer) event.getNewValue(); + setFontColor(DiagramColorRegistry.getInstance().getColor(c)); + } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { + refreshUnderline(); + } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { + refreshStrikeThrough(); + } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { + refreshFont(); + } else { + if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { + refreshLabel(); + } + if (getParser() instanceof ISemanticParser) { + ISemanticParser modelParser = + (ISemanticParser) getParser(); + if (modelParser.areSemanticElementsAffected(null, event)) { + removeSemanticListeners(); + if (resolveSemanticElement() != null) { + addSemanticListeners(); + } + refreshLabel(); + } + } + } + super.handleNotificationEvent(event); + } + + /** + * @generated + */ + @Override + protected IFigure createFigure() { + IFigure label = createFigurePrim(); + defaultText = getLabelTextHelper(label); + return label; + } + + /** + * @generated + */ + protected IFigure createFigurePrim() { + return new PapyrusWrappingLabel(); + } + +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/EnumerationFloatingLabelEditPartCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/EnumerationFloatingLabelEditPartCN.java new file mode 100644 index 00000000000..dab5d5b9655 --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/EnumerationFloatingLabelEditPartCN.java @@ -0,0 +1,860 @@ +/** + * 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.uml.diagram.composite.edit.parts; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.Label; +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.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.RunnableWithResult; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gef.AccessibleEditPart; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.Request; +import org.eclipse.gef.requests.DirectEditRequest; +import org.eclipse.gef.tools.DirectEditManager; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; +import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; +import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; +import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; +import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; +import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; +import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; +import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; +import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; +import org.eclipse.gmf.runtime.notation.FontStyle; +import org.eclipse.gmf.runtime.notation.NotationPackage; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.text.contentassist.IContentAssistProcessor; +import org.eclipse.jface.viewers.ICellEditorValidator; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.extensionpoints.editors.Activator; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; +import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; +import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.ExternalLabelPrimaryDragRoleEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.PapyrusWrappingLabel; +import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; +import org.eclipse.papyrus.uml.diagram.common.editparts.FloatingLabelEditPart; +import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; +import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; +import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; +import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.accessibility.AccessibleEvent; +import org.eclipse.swt.custom.BusyIndicator; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; +import org.eclipse.uml2.uml.Feature; + +/** + * @generated + */ +public class EnumerationFloatingLabelEditPartCN extends FloatingLabelEditPart + implements ITextAwareEditPart, IBorderItemEditPart +{ + + /** + * @generated + */ + public static final int VISUAL_ID = 6071; + + /** + * @generated + */ + private DirectEditManager manager; + + /** + * @generated + */ + private IParser parser; + + /** + * @generated + */ + private List parserElements; + + /** + * @generated + */ + private String defaultText; + + /** + * direct edition mode (default, undefined, registered editor, etc.) + * + * @generated + */ + protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; + + /** + * configuration from a registered edit dialog + * + * @generated + */ + protected IDirectEditorConfiguration configuration; + + + /** + * @generated + */ + static { + registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.EnumerationFloatingLabelEditPartCN.VISUAL_ID), new Point(0, 0)); + } + + /** + * @generated + */ + public EnumerationFloatingLabelEditPartCN(View view) { + super(view); + } + + /** + * @generated + */ + @Override + protected void createDefaultEditPolicies() { + super.createDefaultEditPolicies(); + installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); + installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ExternalLabelPrimaryDragRoleEditPolicy()); + } + + /** + * @generated + */ + @Override + public IBorderItemLocator getBorderItemLocator() { + IFigure parentFigure = getFigure().getParent(); + if (parentFigure != null && parentFigure.getLayoutManager() != null) { + Object constraint = parentFigure.getLayoutManager().getConstraint(getFigure()); + return (IBorderItemLocator) constraint; + } + return null; + } + + /** + * @generated + */ + @Override + public void refreshBounds() { + int x = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_X())).intValue(); + int y = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_Y())).intValue(); + int width = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Width())).intValue(); + int height = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Height())).intValue(); + getBorderItemLocator().setConstraint(new Rectangle(x, y, width, height)); + } + + + /** + * @generated + */ + protected String getLabelTextHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getText(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getText(); + } else { + return ((Label) figure).getText(); + } + } + + /** + * @generated + */ + protected void setLabelTextHelper(IFigure figure, String text) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setText(text); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setText(text); + } else { + ((Label) figure).setText(text); + } + } + + /** + * @generated + */ + protected Image getLabelIconHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getIcon(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getIcon(); + } else { + return ((Label) figure).getIcon(); + } + } + + /** + * @generated + */ + protected void setLabelIconHelper(IFigure figure, Image icon) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setIcon(icon); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setIcon(icon); + } else { + ((Label) figure).setIcon(icon); + } + } + + /** + * @generated + */ + public void setLabel(IFigure + figure) { + unregisterVisuals(); + setFigure(figure); + defaultText = getLabelTextHelper(figure); + registerVisuals(); + refreshVisuals(); + } + + /** + * @generated + */ + @Override + protected List getModelChildren() { + return Collections.EMPTY_LIST; + } + + /** + * @generated + */ + @Override + public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { + return null; + } + + /** + * @generated + */ + public void setParser(IParser parser) { + this.parser = parser; + } + + /** + * @generated + */ + protected EObject getParserElement() { + return resolveSemanticElement(); + } + + /** + * @generated + */ + protected Image getLabelIcon() { + return null; + } + + /** + * @generated + */ + protected String getLabelText() { + String text = null; + EObject parserElement = getParserElement(); + if (parserElement != null && getParser() != null) { + text = getParser().getPrintString( + new EObjectAdapter(parserElement), + getParserOptions().intValue()); + } + if (text == null || text.length() == 0) { + text = defaultText; + } + return text; + } + + /** + * @generated + */ + @Override + public void setLabelText(String text) { + setLabelTextHelper(getFigure(), text); + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + @Override + public String getEditText() { + if (getParserElement() == null || getParser() == null) { + return ""; //$NON-NLS-1$ + } + return getParser().getEditString( + new EObjectAdapter(getParserElement()), + getParserOptions().intValue()); + } + + /** + * @generated + */ + protected boolean isEditable() { + return getParser() != null; + } + + /** + * @generated + */ + @Override + public ICellEditorValidator getEditTextValidator() { + return new ICellEditorValidator() { + + @Override + public String isValid(final Object value) { + if (value instanceof String) { + final EObject element = getParserElement(); + final IParser parser = getParser(); + try { + IParserEditStatus valid = + (IParserEditStatus) getEditingDomain().runExclusive( + new RunnableWithResult.Impl() { + + @Override + public void run() { + setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); + } + }); + return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); + } catch (InterruptedException ie) { + ie.printStackTrace(); + } + } + + // shouldn't get here + return null; + } + }; + } + + /** + * @generated + */ + @Override + public IContentAssistProcessor getCompletionProcessor() { + if (getParserElement() == null || getParser() == null) { + return null; + } + return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); + } + + /** + * @generated + */ + @Override + public ParserOptions getParserOptions() { + return ParserOptions.NONE; + } + + /** + * @generated + */ + @Override + public IParser getParser() { + if (parser == null) { + parser = UMLParserProvider.getParser(UMLElementTypes.Enumeration_3079, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.EnumerationFloatingLabelEditPartCN.VISUAL_ID)); + } + return parser; + } + + /** + * @generated + */ + protected DirectEditManager getManager() { + if (manager == null) { + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + } + return manager; + } + + /** + * @generated + */ + protected void setManager(DirectEditManager manager) { + this.manager = manager; + } + + /** + * @generated + */ + protected void performDirectEdit() { + BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { + + @Override + public void run() { + getManager().show(); + } + }); + } + + /** + * @generated + */ + protected void performDirectEdit(Point eventLocation) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); + } + } + + /** + * @generated + */ + private void performDirectEdit(char initialCharacter) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(initialCharacter); + } else { + performDirectEdit(); + } + } + + /** + * @generated + */ + @Override + protected void performDirectEditRequest(Request request) { + + final Request theRequest = request; + + if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { + directEditionMode = getDirectEditionType(); + } + switch (directEditionMode) { + case IDirectEdition.NO_DIRECT_EDITION: + // no direct edition mode => does nothing + return; + case IDirectEdition.EXTENDED_DIRECT_EDITOR: + updateExtendedEditorConfiguration(); + if (configuration == null || configuration.getLanguage() == null) { + // Create default edit manager + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + performDefaultDirectEditorEdit(theRequest); + } else { + configuration.preEditAction(resolveSemanticElement()); + Dialog dialog = null; + if (configuration instanceof ICustomDirectEditorConfiguration) { + setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); + initializeDirectEditManager(theRequest); + return; + } else if (configuration instanceof IPopupEditorConfiguration) { + IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); + helper.showEditor(); + return; + } + else if (configuration instanceof IAdvancedEditorConfiguration) { + dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); + } else if (configuration instanceof IDirectEditorConfiguration) { + dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), + configuration); + } else { + return; + } + final Dialog finalDialog = dialog; + + if (Window.OK == dialog.open()) { + TransactionalEditingDomain domain = getEditingDomain(); + RecordingCommand command = new RecordingCommand(domain, "Edit Label") { + + @Override + protected void doExecute() { + configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); + + } + }; + domain.getCommandStack().execute(command); + } + } + break; + case IDirectEdition.DEFAULT_DIRECT_EDITOR: + initializeDirectEditManager(theRequest); + break; + default: + break; + } + } + + /** + * @generated + */ + protected void initializeDirectEditManager(final Request request) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + @Override + public void run() { + if (isActive() && isEditable()) { + if (request.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } + else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void refreshVisuals() { + super.refreshVisuals(); + refreshLabel(); + refreshFont(); + refreshFontColor(); + refreshUnderline(); + refreshStrikeThrough(); + } + + /** + * @generated + */ + protected void refreshLabel() { + EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); + if (maskLabelPolicy == null) { + maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); + } + if (maskLabelPolicy == null) { + View view = (View) getModel(); + if (view.isVisible()) { + setLabelTextHelper(getFigure(), getLabelText()); + setLabelIconHelper(getFigure(), getLabelIcon()); + } + else { + setLabelTextHelper(getFigure(), ""); //$NON-NLS-1$ + setLabelIconHelper(getFigure(), null); + } + } + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + protected void refreshUnderline() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); + } + if (resolveSemanticElement() instanceof Feature) { + if (((Feature) resolveSemanticElement()).isStatic()) { + ((WrappingLabel) getFigure()).setTextUnderline(true); + } + else { + ((WrappingLabel) getFigure()).setTextUnderline(false); + } + } + } + + /** + * @generated + */ + protected void refreshStrikeThrough() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); + } + } + + /** + * @generated + */ + @Override + protected void refreshFont() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null) { + FontData fontData = new FontData( + style.getFontName(), style.getFontHeight(), + (style.isBold() ? SWT.BOLD : SWT.NORMAL) | + (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); + setFont(fontData); + } + } + + /** + * @generated + */ + @Override + protected void setFontColor(Color color) { + getFigure().setForegroundColor(color); + } + + /** + * @generated + */ + @Override + protected void addSemanticListeners() { + if (getParser() instanceof ISemanticParser) { + EObject element = resolveSemanticElement(); + parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); + for (int i = 0; i < parserElements.size(); i++) { + addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ + } + } else { + super.addSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected void removeSemanticListeners() { + if (parserElements != null) { + for (int i = 0; i < parserElements.size(); i++) { + removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ + } + } else { + super.removeSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected AccessibleEditPart getAccessibleEditPart() { + if (accessibleEP == null) { + accessibleEP = new AccessibleGraphicalEditPart() { + + @Override + public void getName(AccessibleEvent e) { + e.result = getLabelTextHelper(getFigure()); + } + }; + } + return accessibleEP; + } + + /** + * @generated + */ + private View getFontStyleOwnerView() { + return getPrimaryView(); + } + + /** + * Returns the kind of associated editor for direct edition. + * + * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition + * @generated + */ + public int getDirectEditionType() { + if (checkExtendedEditor()) { + initExtendedEditorConfiguration(); + return IDirectEdition.EXTENDED_DIRECT_EDITOR; + } + if (checkDefaultEdition()) { + return IDirectEdition.DEFAULT_DIRECT_EDITOR; + } + + // not a named element. no specific editor => do nothing + return IDirectEdition.NO_DIRECT_EDITION; + } + + /** + * Checks if an extended editor is present. + * + * @return true if an extended editor is present. + * @generated + */ + protected boolean checkExtendedEditor() { + if (resolveSemanticElement() != null) { + return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); + } + return false; + } + + /** + * Checks if a default direct edition is available + * + * @return true if a default direct edition is available + * @generated + */ + protected boolean checkDefaultEdition() { + return (getParser() != null); + } + + /** + * Initializes the extended editor configuration + * + * @generated + */ + protected void initExtendedEditorConfiguration() { + if (configuration == null) { + final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("")) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); + } else { + configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); + } + } + } + + /** + * Updates the preference configuration + * + * @generated + */ + protected void updateExtendedEditorConfiguration() { + String languagePreferred = Activator.getDefault().getPreferenceStore().getString( + IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() + .eClass().getInstanceClassName()); + } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { + configuration = null; + } + } + + /** + * Performs the direct edit usually used by GMF editors. + * + * @param theRequest + * the direct edit request that starts the direct edit system + * @generated + */ + protected void performDefaultDirectEditorEdit(final Request theRequest) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + + @Override + public void run() { + if (isActive() && isEditable()) { + if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) theRequest.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { + DirectEditRequest editRequest = (DirectEditRequest) theRequest; + performDirectEdit(editRequest.getLocation()); + } else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + + /** + * @generated + */ + @Override + protected void handleNotificationEvent(Notification event) { + Object feature = event.getFeature(); + if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { + Integer c = (Integer) event.getNewValue(); + setFontColor(DiagramColorRegistry.getInstance().getColor(c)); + } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { + refreshUnderline(); + } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { + refreshStrikeThrough(); + } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { + refreshFont(); + } else { + if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { + refreshLabel(); + } + if (getParser() instanceof ISemanticParser) { + ISemanticParser modelParser = + (ISemanticParser) getParser(); + if (modelParser.areSemanticElementsAffected(null, event)) { + removeSemanticListeners(); + if (resolveSemanticElement() != null) { + addSemanticListeners(); + } + refreshLabel(); + } + } + } + super.handleNotificationEvent(event); + } + + /** + * @generated + */ + @Override + protected IFigure createFigure() { + IFigure label = createFigurePrim(); + defaultText = getLabelTextHelper(label); + return label; + } + + /** + * @generated + */ + protected IFigure createFigurePrim() { + return new PapyrusWrappingLabel(); + } + +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/EnumerationNameEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/EnumerationNameEditPart.java index d1d9f3e9867..6453fbeab9f 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/EnumerationNameEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/EnumerationNameEditPart.java @@ -864,7 +864,7 @@ public class EnumerationNameEditPart extends PapyrusCompartmentEditPart implemen * @generated */ protected void addOwnerElementListeners() { - addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); + addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/EnumerationNameEditPartCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/EnumerationNameEditPartCN.java index aee074d372b..235e5b5fc96 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/EnumerationNameEditPartCN.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/EnumerationNameEditPartCN.java @@ -864,7 +864,7 @@ public class EnumerationNameEditPartCN extends PapyrusCompartmentEditPart implem * @generated */ protected void addOwnerElementListeners() { - addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); + addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ExecutionEnvironmentCompositeCompartmentEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ExecutionEnvironmentCompositeCompartmentEditPart.java index 2e8be0c4179..f8bf73ed81c 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ExecutionEnvironmentCompositeCompartmentEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ExecutionEnvironmentCompositeCompartmentEditPart.java @@ -26,6 +26,7 @@ import org.eclipse.gmf.runtime.diagram.ui.editpolicies.ResizableCompartmentEditP import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.BorderDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.CustomContainerEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.DuplicatePasteEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.PapyrusCreationEditPolicy; @@ -75,6 +76,7 @@ public class ExecutionEnvironmentCompositeCompartmentEditPart extends ShapeCompa installEditPolicy(EditPolicy.GRAPHICAL_NODE_ROLE, new CustomContainerEditPolicy()); installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, new CustomDiagramDragDropEditPolicy()); installEditPolicy(EditPolicyRoles.CREATION_ROLE, new PortInCompartmentCreationEditPolicy()); + installEditPolicy(BorderDisplayEditPolicy.BORDER_DISPLAY_EDITPOLICY, new BorderDisplayEditPolicy()); } /** diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ExecutionEnvironmentCompositeCompartmentEditPartCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ExecutionEnvironmentCompositeCompartmentEditPartCN.java index eaefbc9b464..0eba78eeca3 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ExecutionEnvironmentCompositeCompartmentEditPartCN.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ExecutionEnvironmentCompositeCompartmentEditPartCN.java @@ -26,6 +26,7 @@ import org.eclipse.gmf.runtime.diagram.ui.editpolicies.ResizableCompartmentEditP import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.BorderDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.CustomContainerEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.DuplicatePasteEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.PapyrusCreationEditPolicy; @@ -75,6 +76,7 @@ public class ExecutionEnvironmentCompositeCompartmentEditPartCN extends ShapeCom installEditPolicy(EditPolicy.GRAPHICAL_NODE_ROLE, new CustomContainerEditPolicy()); installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, new CustomDiagramDragDropEditPolicy()); installEditPolicy(EditPolicyRoles.CREATION_ROLE, new PortInCompartmentCreationEditPolicy()); + installEditPolicy(BorderDisplayEditPolicy.BORDER_DISPLAY_EDITPOLICY, new BorderDisplayEditPolicy()); } /** diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ExecutionEnvironmentCompositeEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ExecutionEnvironmentCompositeEditPart.java index b05f3a77e75..402656d4f47 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ExecutionEnvironmentCompositeEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ExecutionEnvironmentCompositeEditPart.java @@ -11,28 +11,37 @@ */ package org.eclipse.papyrus.uml.diagram.composite.edit.parts; +import java.util.Collections; +import java.util.List; + import org.eclipse.draw2d.IFigure; import org.eclipse.draw2d.PositionConstants; import org.eclipse.emf.common.notify.Notification; import org.eclipse.gef.EditPart; import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.GraphicalEditPart; 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.handles.MoveHandle; import org.eclipse.gef.requests.CreateRequest; import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.BorderItemSelectionEditPolicy; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.DragDropEditPolicy; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles; import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; -import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure; import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure; +import org.eclipse.gmf.runtime.notation.Edge; +import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.GetChildLayoutEditPolicy; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.IPapyrusNodeFigure; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.RoundedRectangleNodePlateFigure; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.SelectableBorderedNodeFigure; -import org.eclipse.papyrus.uml.diagram.common.editparts.NamedElementEditPart; +import org.eclipse.papyrus.uml.diagram.common.editparts.RoundedCompartmentEditPart; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AffixedNodeAlignmentEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeNodeLabelDisplayEditPolicy; @@ -41,11 +50,11 @@ import org.eclipse.papyrus.uml.diagram.common.editpolicies.PapyrusCreationEditPo import org.eclipse.papyrus.uml.diagram.common.editpolicies.QualifiedNameDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.ShowHideClassifierContentsEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.ShowHideCompartmentEditPolicy; +import org.eclipse.papyrus.uml.diagram.common.locator.RoundedRectangleLabelPositionLocator; import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.CustomDiagramDragDropEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.RemoveOrphanViewPolicy; import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.StructuredClassifierLayoutEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.custom.figures.ExecutionEnvironmentCompositeFigure; -import org.eclipse.papyrus.uml.diagram.composite.custom.locators.PortPositionLocator; import org.eclipse.papyrus.uml.diagram.composite.edit.policies.ExecutionEnvironmentCompositeItemSemanticEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; import org.eclipse.swt.graphics.Color; @@ -53,7 +62,7 @@ import org.eclipse.swt.graphics.Color; /** * @generated */ -public class ExecutionEnvironmentCompositeEditPart extends NamedElementEditPart { +public class ExecutionEnvironmentCompositeEditPart extends RoundedCompartmentEditPart { /** * @generated @@ -95,6 +104,7 @@ public class ExecutionEnvironmentCompositeEditPart extends NamedElementEditPart installEditPolicy(ShowHideCompartmentEditPolicy.SHOW_HIDE_COMPARTMENT_POLICY, new ShowHideCompartmentEditPolicy()); installEditPolicy(AffixedNodeAlignmentEditPolicy.AFFIXED_CHILD_ALIGNMENT_ROLE, new AffixedNodeAlignmentEditPolicy()); installEditPolicy("REMOVE_ORPHAN_VIEW", new RemoveOrphanViewPolicy()); //$NON-NLS-1$ + installEditPolicy(EditPolicy.LAYOUT_ROLE, new GetChildLayoutEditPolicy()); // XXX need an SCR to runtime to have another abstract superclass that would let children add reasonable editpolicies // removeEditPolicy(org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles.CONNECTION_HANDLES_ROLE); } @@ -109,6 +119,17 @@ public class ExecutionEnvironmentCompositeEditPart extends NamedElementEditPart protected EditPolicy createChildEditPolicy(EditPart child) { View childView = (View) child.getModel(); switch (UMLVisualIDRegistry.getVisualID(childView)) { + case ExecutionEnvironmentCompositeFloatingLabelEditPart.VISUAL_ID: + return new BorderItemSelectionEditPolicy() { + + @Override + protected List createSelectionHandles() { + MoveHandle mh = new MoveHandle((GraphicalEditPart) getHost()); + mh.setBorder(null); + return Collections.singletonList(mh); + } + } + ; case PortEditPart.VISUAL_ID: return new BorderItemResizableEditPolicy(); } @@ -139,6 +160,19 @@ public class ExecutionEnvironmentCompositeEditPart extends NamedElementEditPart **/ @Override protected void handleNotificationEvent(Notification event) { + /* + * when a node have external node labels, the methods refreshChildren() remove the EditPart corresponding to the Label from the EditPart + * Registry. After that, we can't reset the visibility to true (using the Show/Hide Label Action)! + */ + if (NotationPackage.eINSTANCE.getView_Visible().equals(event.getFeature())) { + Object notifier = event.getNotifier(); + List modelChildren = ((View) getModel()).getChildren(); + if (!(notifier instanceof Edge)) { + if (modelChildren.contains(event.getNotifier())) { + return; + } + } + } super.handleNotificationEvent(event); } @@ -180,9 +214,9 @@ public class ExecutionEnvironmentCompositeEditPart extends NamedElementEditPart - //Papyrus Gencode :Affixed Port locator + // Papyrus Gencode :Affixed Port locator if (childEditPart instanceof PortEditPart) { - IBorderItemLocator locator = new PortPositionLocator(getMainFigure(), PositionConstants.NONE); + IBorderItemLocator locator = new org.eclipse.papyrus.uml.diagram.common.locator.PortPositionLocator(getMainFigure(), PositionConstants.NONE); getBorderedFigure().getBorderItemContainer().add(((PortEditPart) childEditPart).getFigure(), locator); return true; } @@ -246,12 +280,26 @@ public class ExecutionEnvironmentCompositeEditPart extends NamedElementEditPart return getContentPane(); } + /** + * @generated + */ + @Override + protected void addBorderItem(IFigure borderItemContainer, IBorderItemEditPart borderItemEditPart) { + if (borderItemEditPart instanceof ExecutionEnvironmentCompositeFloatingLabelEditPart) { + IBorderItemLocator locator = new RoundedRectangleLabelPositionLocator(getMainFigure()); + borderItemContainer.add(borderItemEditPart.getFigure(), locator); + } else + { + super.addBorderItem(borderItemContainer, borderItemEditPart); + } + } + /** * @generated */ @Override protected NodeFigure createNodePlate() { - DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(40, 40); + RoundedRectangleNodePlateFigure result = new RoundedRectangleNodePlateFigure(40, 40); return result; } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ExecutionEnvironmentCompositeEditPartCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ExecutionEnvironmentCompositeEditPartCN.java index 60f070ebe8d..695a278fec3 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ExecutionEnvironmentCompositeEditPartCN.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ExecutionEnvironmentCompositeEditPartCN.java @@ -11,28 +11,37 @@ */ package org.eclipse.papyrus.uml.diagram.composite.edit.parts; +import java.util.Collections; +import java.util.List; + import org.eclipse.draw2d.IFigure; import org.eclipse.draw2d.PositionConstants; import org.eclipse.emf.common.notify.Notification; import org.eclipse.gef.EditPart; import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.GraphicalEditPart; 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.handles.MoveHandle; import org.eclipse.gef.requests.CreateRequest; import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.BorderItemSelectionEditPolicy; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.DragDropEditPolicy; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles; import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; -import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure; import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure; +import org.eclipse.gmf.runtime.notation.Edge; +import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.GetChildLayoutEditPolicy; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.IPapyrusNodeFigure; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.RoundedRectangleNodePlateFigure; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.SelectableBorderedNodeFigure; -import org.eclipse.papyrus.uml.diagram.common.editparts.NamedElementEditPart; +import org.eclipse.papyrus.uml.diagram.common.editparts.RoundedCompartmentEditPart; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AffixedNodeAlignmentEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeNodeLabelDisplayEditPolicy; @@ -41,11 +50,11 @@ import org.eclipse.papyrus.uml.diagram.common.editpolicies.PapyrusCreationEditPo import org.eclipse.papyrus.uml.diagram.common.editpolicies.QualifiedNameDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.ShowHideClassifierContentsEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.ShowHideCompartmentEditPolicy; +import org.eclipse.papyrus.uml.diagram.common.locator.RoundedRectangleLabelPositionLocator; import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.CustomDiagramDragDropEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.RemoveOrphanViewPolicy; import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.StructuredClassifierLayoutEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.custom.figures.ExecutionEnvironmentCompositeFigure; -import org.eclipse.papyrus.uml.diagram.composite.custom.locators.PortPositionLocator; import org.eclipse.papyrus.uml.diagram.composite.edit.policies.ExecutionEnvironmentCompositeItemSemanticEditPolicyCN; import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; import org.eclipse.swt.graphics.Color; @@ -53,7 +62,7 @@ import org.eclipse.swt.graphics.Color; /** * @generated */ -public class ExecutionEnvironmentCompositeEditPartCN extends NamedElementEditPart { +public class ExecutionEnvironmentCompositeEditPartCN extends RoundedCompartmentEditPart { /** * @generated @@ -95,6 +104,7 @@ public class ExecutionEnvironmentCompositeEditPartCN extends NamedElementEditPar installEditPolicy(ShowHideCompartmentEditPolicy.SHOW_HIDE_COMPARTMENT_POLICY, new ShowHideCompartmentEditPolicy()); installEditPolicy(AffixedNodeAlignmentEditPolicy.AFFIXED_CHILD_ALIGNMENT_ROLE, new AffixedNodeAlignmentEditPolicy()); installEditPolicy("REMOVE_ORPHAN_VIEW", new RemoveOrphanViewPolicy()); //$NON-NLS-1$ + installEditPolicy(EditPolicy.LAYOUT_ROLE, new GetChildLayoutEditPolicy()); // XXX need an SCR to runtime to have another abstract superclass that would let children add reasonable editpolicies // removeEditPolicy(org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles.CONNECTION_HANDLES_ROLE); } @@ -109,6 +119,17 @@ public class ExecutionEnvironmentCompositeEditPartCN extends NamedElementEditPar protected EditPolicy createChildEditPolicy(EditPart child) { View childView = (View) child.getModel(); switch (UMLVisualIDRegistry.getVisualID(childView)) { + case ExecutionEnvironmentCompositeFloatingLabelEditPartCN.VISUAL_ID: + return new BorderItemSelectionEditPolicy() { + + @Override + protected List createSelectionHandles() { + MoveHandle mh = new MoveHandle((GraphicalEditPart) getHost()); + mh.setBorder(null); + return Collections.singletonList(mh); + } + } + ; case PortEditPart.VISUAL_ID: return new BorderItemResizableEditPolicy(); } @@ -139,6 +160,19 @@ public class ExecutionEnvironmentCompositeEditPartCN extends NamedElementEditPar **/ @Override protected void handleNotificationEvent(Notification event) { + /* + * when a node have external node labels, the methods refreshChildren() remove the EditPart corresponding to the Label from the EditPart + * Registry. After that, we can't reset the visibility to true (using the Show/Hide Label Action)! + */ + if (NotationPackage.eINSTANCE.getView_Visible().equals(event.getFeature())) { + Object notifier = event.getNotifier(); + List modelChildren = ((View) getModel()).getChildren(); + if (!(notifier instanceof Edge)) { + if (modelChildren.contains(event.getNotifier())) { + return; + } + } + } super.handleNotificationEvent(event); } @@ -180,9 +214,9 @@ public class ExecutionEnvironmentCompositeEditPartCN extends NamedElementEditPar - //Papyrus Gencode :Affixed Port locator + // Papyrus Gencode :Affixed Port locator if (childEditPart instanceof PortEditPart) { - IBorderItemLocator locator = new PortPositionLocator(getMainFigure(), PositionConstants.NONE); + IBorderItemLocator locator = new org.eclipse.papyrus.uml.diagram.common.locator.PortPositionLocator(getMainFigure(), PositionConstants.NONE); getBorderedFigure().getBorderItemContainer().add(((PortEditPart) childEditPart).getFigure(), locator); return true; } @@ -246,12 +280,26 @@ public class ExecutionEnvironmentCompositeEditPartCN extends NamedElementEditPar return getContentPane(); } + /** + * @generated + */ + @Override + protected void addBorderItem(IFigure borderItemContainer, IBorderItemEditPart borderItemEditPart) { + if (borderItemEditPart instanceof ExecutionEnvironmentCompositeFloatingLabelEditPartCN) { + IBorderItemLocator locator = new RoundedRectangleLabelPositionLocator(getMainFigure()); + borderItemContainer.add(borderItemEditPart.getFigure(), locator); + } else + { + super.addBorderItem(borderItemContainer, borderItemEditPart); + } + } + /** * @generated */ @Override protected NodeFigure createNodePlate() { - DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(40, 40); + RoundedRectangleNodePlateFigure result = new RoundedRectangleNodePlateFigure(40, 40); return result; } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ExecutionEnvironmentCompositeFloatingLabelEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ExecutionEnvironmentCompositeFloatingLabelEditPart.java new file mode 100644 index 00000000000..73671566797 --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ExecutionEnvironmentCompositeFloatingLabelEditPart.java @@ -0,0 +1,860 @@ +/** + * 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.uml.diagram.composite.edit.parts; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.Label; +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.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.RunnableWithResult; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gef.AccessibleEditPart; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.Request; +import org.eclipse.gef.requests.DirectEditRequest; +import org.eclipse.gef.tools.DirectEditManager; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; +import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; +import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; +import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; +import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; +import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; +import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; +import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; +import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; +import org.eclipse.gmf.runtime.notation.FontStyle; +import org.eclipse.gmf.runtime.notation.NotationPackage; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.text.contentassist.IContentAssistProcessor; +import org.eclipse.jface.viewers.ICellEditorValidator; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.extensionpoints.editors.Activator; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; +import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; +import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.ExternalLabelPrimaryDragRoleEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.PapyrusWrappingLabel; +import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; +import org.eclipse.papyrus.uml.diagram.common.editparts.FloatingLabelEditPart; +import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; +import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; +import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; +import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.accessibility.AccessibleEvent; +import org.eclipse.swt.custom.BusyIndicator; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; +import org.eclipse.uml2.uml.Feature; + +/** + * @generated + */ +public class ExecutionEnvironmentCompositeFloatingLabelEditPart extends FloatingLabelEditPart + implements ITextAwareEditPart, IBorderItemEditPart +{ + + /** + * @generated + */ + public static final int VISUAL_ID = 6087; + + /** + * @generated + */ + private DirectEditManager manager; + + /** + * @generated + */ + private IParser parser; + + /** + * @generated + */ + private List parserElements; + + /** + * @generated + */ + private String defaultText; + + /** + * direct edition mode (default, undefined, registered editor, etc.) + * + * @generated + */ + protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; + + /** + * configuration from a registered edit dialog + * + * @generated + */ + protected IDirectEditorConfiguration configuration; + + + /** + * @generated + */ + static { + registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.ExecutionEnvironmentCompositeFloatingLabelEditPart.VISUAL_ID), new Point(0, 0)); + } + + /** + * @generated + */ + public ExecutionEnvironmentCompositeFloatingLabelEditPart(View view) { + super(view); + } + + /** + * @generated + */ + @Override + protected void createDefaultEditPolicies() { + super.createDefaultEditPolicies(); + installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); + installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ExternalLabelPrimaryDragRoleEditPolicy()); + } + + /** + * @generated + */ + @Override + public IBorderItemLocator getBorderItemLocator() { + IFigure parentFigure = getFigure().getParent(); + if (parentFigure != null && parentFigure.getLayoutManager() != null) { + Object constraint = parentFigure.getLayoutManager().getConstraint(getFigure()); + return (IBorderItemLocator) constraint; + } + return null; + } + + /** + * @generated + */ + @Override + public void refreshBounds() { + int x = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_X())).intValue(); + int y = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_Y())).intValue(); + int width = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Width())).intValue(); + int height = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Height())).intValue(); + getBorderItemLocator().setConstraint(new Rectangle(x, y, width, height)); + } + + + /** + * @generated + */ + protected String getLabelTextHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getText(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getText(); + } else { + return ((Label) figure).getText(); + } + } + + /** + * @generated + */ + protected void setLabelTextHelper(IFigure figure, String text) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setText(text); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setText(text); + } else { + ((Label) figure).setText(text); + } + } + + /** + * @generated + */ + protected Image getLabelIconHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getIcon(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getIcon(); + } else { + return ((Label) figure).getIcon(); + } + } + + /** + * @generated + */ + protected void setLabelIconHelper(IFigure figure, Image icon) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setIcon(icon); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setIcon(icon); + } else { + ((Label) figure).setIcon(icon); + } + } + + /** + * @generated + */ + public void setLabel(IFigure + figure) { + unregisterVisuals(); + setFigure(figure); + defaultText = getLabelTextHelper(figure); + registerVisuals(); + refreshVisuals(); + } + + /** + * @generated + */ + @Override + protected List getModelChildren() { + return Collections.EMPTY_LIST; + } + + /** + * @generated + */ + @Override + public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { + return null; + } + + /** + * @generated + */ + public void setParser(IParser parser) { + this.parser = parser; + } + + /** + * @generated + */ + protected EObject getParserElement() { + return resolveSemanticElement(); + } + + /** + * @generated + */ + protected Image getLabelIcon() { + return null; + } + + /** + * @generated + */ + protected String getLabelText() { + String text = null; + EObject parserElement = getParserElement(); + if (parserElement != null && getParser() != null) { + text = getParser().getPrintString( + new EObjectAdapter(parserElement), + getParserOptions().intValue()); + } + if (text == null || text.length() == 0) { + text = defaultText; + } + return text; + } + + /** + * @generated + */ + @Override + public void setLabelText(String text) { + setLabelTextHelper(getFigure(), text); + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + @Override + public String getEditText() { + if (getParserElement() == null || getParser() == null) { + return ""; //$NON-NLS-1$ + } + return getParser().getEditString( + new EObjectAdapter(getParserElement()), + getParserOptions().intValue()); + } + + /** + * @generated + */ + protected boolean isEditable() { + return getParser() != null; + } + + /** + * @generated + */ + @Override + public ICellEditorValidator getEditTextValidator() { + return new ICellEditorValidator() { + + @Override + public String isValid(final Object value) { + if (value instanceof String) { + final EObject element = getParserElement(); + final IParser parser = getParser(); + try { + IParserEditStatus valid = + (IParserEditStatus) getEditingDomain().runExclusive( + new RunnableWithResult.Impl() { + + @Override + public void run() { + setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); + } + }); + return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); + } catch (InterruptedException ie) { + ie.printStackTrace(); + } + } + + // shouldn't get here + return null; + } + }; + } + + /** + * @generated + */ + @Override + public IContentAssistProcessor getCompletionProcessor() { + if (getParserElement() == null || getParser() == null) { + return null; + } + return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); + } + + /** + * @generated + */ + @Override + public ParserOptions getParserOptions() { + return ParserOptions.NONE; + } + + /** + * @generated + */ + @Override + public IParser getParser() { + if (parser == null) { + parser = UMLParserProvider.getParser(UMLElementTypes.ExecutionEnvironment_2071, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.ExecutionEnvironmentCompositeFloatingLabelEditPart.VISUAL_ID)); + } + return parser; + } + + /** + * @generated + */ + protected DirectEditManager getManager() { + if (manager == null) { + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + } + return manager; + } + + /** + * @generated + */ + protected void setManager(DirectEditManager manager) { + this.manager = manager; + } + + /** + * @generated + */ + protected void performDirectEdit() { + BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { + + @Override + public void run() { + getManager().show(); + } + }); + } + + /** + * @generated + */ + protected void performDirectEdit(Point eventLocation) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); + } + } + + /** + * @generated + */ + private void performDirectEdit(char initialCharacter) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(initialCharacter); + } else { + performDirectEdit(); + } + } + + /** + * @generated + */ + @Override + protected void performDirectEditRequest(Request request) { + + final Request theRequest = request; + + if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { + directEditionMode = getDirectEditionType(); + } + switch (directEditionMode) { + case IDirectEdition.NO_DIRECT_EDITION: + // no direct edition mode => does nothing + return; + case IDirectEdition.EXTENDED_DIRECT_EDITOR: + updateExtendedEditorConfiguration(); + if (configuration == null || configuration.getLanguage() == null) { + // Create default edit manager + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + performDefaultDirectEditorEdit(theRequest); + } else { + configuration.preEditAction(resolveSemanticElement()); + Dialog dialog = null; + if (configuration instanceof ICustomDirectEditorConfiguration) { + setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); + initializeDirectEditManager(theRequest); + return; + } else if (configuration instanceof IPopupEditorConfiguration) { + IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); + helper.showEditor(); + return; + } + else if (configuration instanceof IAdvancedEditorConfiguration) { + dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); + } else if (configuration instanceof IDirectEditorConfiguration) { + dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), + configuration); + } else { + return; + } + final Dialog finalDialog = dialog; + + if (Window.OK == dialog.open()) { + TransactionalEditingDomain domain = getEditingDomain(); + RecordingCommand command = new RecordingCommand(domain, "Edit Label") { + + @Override + protected void doExecute() { + configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); + + } + }; + domain.getCommandStack().execute(command); + } + } + break; + case IDirectEdition.DEFAULT_DIRECT_EDITOR: + initializeDirectEditManager(theRequest); + break; + default: + break; + } + } + + /** + * @generated + */ + protected void initializeDirectEditManager(final Request request) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + @Override + public void run() { + if (isActive() && isEditable()) { + if (request.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } + else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void refreshVisuals() { + super.refreshVisuals(); + refreshLabel(); + refreshFont(); + refreshFontColor(); + refreshUnderline(); + refreshStrikeThrough(); + } + + /** + * @generated + */ + protected void refreshLabel() { + EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); + if (maskLabelPolicy == null) { + maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); + } + if (maskLabelPolicy == null) { + View view = (View) getModel(); + if (view.isVisible()) { + setLabelTextHelper(getFigure(), getLabelText()); + setLabelIconHelper(getFigure(), getLabelIcon()); + } + else { + setLabelTextHelper(getFigure(), ""); //$NON-NLS-1$ + setLabelIconHelper(getFigure(), null); + } + } + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + protected void refreshUnderline() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); + } + if (resolveSemanticElement() instanceof Feature) { + if (((Feature) resolveSemanticElement()).isStatic()) { + ((WrappingLabel) getFigure()).setTextUnderline(true); + } + else { + ((WrappingLabel) getFigure()).setTextUnderline(false); + } + } + } + + /** + * @generated + */ + protected void refreshStrikeThrough() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); + } + } + + /** + * @generated + */ + @Override + protected void refreshFont() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null) { + FontData fontData = new FontData( + style.getFontName(), style.getFontHeight(), + (style.isBold() ? SWT.BOLD : SWT.NORMAL) | + (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); + setFont(fontData); + } + } + + /** + * @generated + */ + @Override + protected void setFontColor(Color color) { + getFigure().setForegroundColor(color); + } + + /** + * @generated + */ + @Override + protected void addSemanticListeners() { + if (getParser() instanceof ISemanticParser) { + EObject element = resolveSemanticElement(); + parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); + for (int i = 0; i < parserElements.size(); i++) { + addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ + } + } else { + super.addSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected void removeSemanticListeners() { + if (parserElements != null) { + for (int i = 0; i < parserElements.size(); i++) { + removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ + } + } else { + super.removeSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected AccessibleEditPart getAccessibleEditPart() { + if (accessibleEP == null) { + accessibleEP = new AccessibleGraphicalEditPart() { + + @Override + public void getName(AccessibleEvent e) { + e.result = getLabelTextHelper(getFigure()); + } + }; + } + return accessibleEP; + } + + /** + * @generated + */ + private View getFontStyleOwnerView() { + return getPrimaryView(); + } + + /** + * Returns the kind of associated editor for direct edition. + * + * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition + * @generated + */ + public int getDirectEditionType() { + if (checkExtendedEditor()) { + initExtendedEditorConfiguration(); + return IDirectEdition.EXTENDED_DIRECT_EDITOR; + } + if (checkDefaultEdition()) { + return IDirectEdition.DEFAULT_DIRECT_EDITOR; + } + + // not a named element. no specific editor => do nothing + return IDirectEdition.NO_DIRECT_EDITION; + } + + /** + * Checks if an extended editor is present. + * + * @return true if an extended editor is present. + * @generated + */ + protected boolean checkExtendedEditor() { + if (resolveSemanticElement() != null) { + return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); + } + return false; + } + + /** + * Checks if a default direct edition is available + * + * @return true if a default direct edition is available + * @generated + */ + protected boolean checkDefaultEdition() { + return (getParser() != null); + } + + /** + * Initializes the extended editor configuration + * + * @generated + */ + protected void initExtendedEditorConfiguration() { + if (configuration == null) { + final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("")) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); + } else { + configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); + } + } + } + + /** + * Updates the preference configuration + * + * @generated + */ + protected void updateExtendedEditorConfiguration() { + String languagePreferred = Activator.getDefault().getPreferenceStore().getString( + IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() + .eClass().getInstanceClassName()); + } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { + configuration = null; + } + } + + /** + * Performs the direct edit usually used by GMF editors. + * + * @param theRequest + * the direct edit request that starts the direct edit system + * @generated + */ + protected void performDefaultDirectEditorEdit(final Request theRequest) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + + @Override + public void run() { + if (isActive() && isEditable()) { + if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) theRequest.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { + DirectEditRequest editRequest = (DirectEditRequest) theRequest; + performDirectEdit(editRequest.getLocation()); + } else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + + /** + * @generated + */ + @Override + protected void handleNotificationEvent(Notification event) { + Object feature = event.getFeature(); + if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { + Integer c = (Integer) event.getNewValue(); + setFontColor(DiagramColorRegistry.getInstance().getColor(c)); + } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { + refreshUnderline(); + } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { + refreshStrikeThrough(); + } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { + refreshFont(); + } else { + if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { + refreshLabel(); + } + if (getParser() instanceof ISemanticParser) { + ISemanticParser modelParser = + (ISemanticParser) getParser(); + if (modelParser.areSemanticElementsAffected(null, event)) { + removeSemanticListeners(); + if (resolveSemanticElement() != null) { + addSemanticListeners(); + } + refreshLabel(); + } + } + } + super.handleNotificationEvent(event); + } + + /** + * @generated + */ + @Override + protected IFigure createFigure() { + IFigure label = createFigurePrim(); + defaultText = getLabelTextHelper(label); + return label; + } + + /** + * @generated + */ + protected IFigure createFigurePrim() { + return new PapyrusWrappingLabel(); + } + +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ExecutionEnvironmentCompositeFloatingLabelEditPartCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ExecutionEnvironmentCompositeFloatingLabelEditPartCN.java new file mode 100644 index 00000000000..f361adf7931 --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ExecutionEnvironmentCompositeFloatingLabelEditPartCN.java @@ -0,0 +1,860 @@ +/** + * 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.uml.diagram.composite.edit.parts; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.Label; +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.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.RunnableWithResult; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gef.AccessibleEditPart; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.Request; +import org.eclipse.gef.requests.DirectEditRequest; +import org.eclipse.gef.tools.DirectEditManager; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; +import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; +import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; +import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; +import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; +import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; +import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; +import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; +import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; +import org.eclipse.gmf.runtime.notation.FontStyle; +import org.eclipse.gmf.runtime.notation.NotationPackage; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.text.contentassist.IContentAssistProcessor; +import org.eclipse.jface.viewers.ICellEditorValidator; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.extensionpoints.editors.Activator; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; +import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; +import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.ExternalLabelPrimaryDragRoleEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.PapyrusWrappingLabel; +import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; +import org.eclipse.papyrus.uml.diagram.common.editparts.FloatingLabelEditPart; +import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; +import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; +import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; +import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.accessibility.AccessibleEvent; +import org.eclipse.swt.custom.BusyIndicator; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; +import org.eclipse.uml2.uml.Feature; + +/** + * @generated + */ +public class ExecutionEnvironmentCompositeFloatingLabelEditPartCN extends FloatingLabelEditPart + implements ITextAwareEditPart, IBorderItemEditPart +{ + + /** + * @generated + */ + public static final int VISUAL_ID = 6065; + + /** + * @generated + */ + private DirectEditManager manager; + + /** + * @generated + */ + private IParser parser; + + /** + * @generated + */ + private List parserElements; + + /** + * @generated + */ + private String defaultText; + + /** + * direct edition mode (default, undefined, registered editor, etc.) + * + * @generated + */ + protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; + + /** + * configuration from a registered edit dialog + * + * @generated + */ + protected IDirectEditorConfiguration configuration; + + + /** + * @generated + */ + static { + registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.ExecutionEnvironmentCompositeFloatingLabelEditPartCN.VISUAL_ID), new Point(0, 0)); + } + + /** + * @generated + */ + public ExecutionEnvironmentCompositeFloatingLabelEditPartCN(View view) { + super(view); + } + + /** + * @generated + */ + @Override + protected void createDefaultEditPolicies() { + super.createDefaultEditPolicies(); + installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); + installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ExternalLabelPrimaryDragRoleEditPolicy()); + } + + /** + * @generated + */ + @Override + public IBorderItemLocator getBorderItemLocator() { + IFigure parentFigure = getFigure().getParent(); + if (parentFigure != null && parentFigure.getLayoutManager() != null) { + Object constraint = parentFigure.getLayoutManager().getConstraint(getFigure()); + return (IBorderItemLocator) constraint; + } + return null; + } + + /** + * @generated + */ + @Override + public void refreshBounds() { + int x = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_X())).intValue(); + int y = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_Y())).intValue(); + int width = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Width())).intValue(); + int height = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Height())).intValue(); + getBorderItemLocator().setConstraint(new Rectangle(x, y, width, height)); + } + + + /** + * @generated + */ + protected String getLabelTextHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getText(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getText(); + } else { + return ((Label) figure).getText(); + } + } + + /** + * @generated + */ + protected void setLabelTextHelper(IFigure figure, String text) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setText(text); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setText(text); + } else { + ((Label) figure).setText(text); + } + } + + /** + * @generated + */ + protected Image getLabelIconHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getIcon(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getIcon(); + } else { + return ((Label) figure).getIcon(); + } + } + + /** + * @generated + */ + protected void setLabelIconHelper(IFigure figure, Image icon) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setIcon(icon); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setIcon(icon); + } else { + ((Label) figure).setIcon(icon); + } + } + + /** + * @generated + */ + public void setLabel(IFigure + figure) { + unregisterVisuals(); + setFigure(figure); + defaultText = getLabelTextHelper(figure); + registerVisuals(); + refreshVisuals(); + } + + /** + * @generated + */ + @Override + protected List getModelChildren() { + return Collections.EMPTY_LIST; + } + + /** + * @generated + */ + @Override + public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { + return null; + } + + /** + * @generated + */ + public void setParser(IParser parser) { + this.parser = parser; + } + + /** + * @generated + */ + protected EObject getParserElement() { + return resolveSemanticElement(); + } + + /** + * @generated + */ + protected Image getLabelIcon() { + return null; + } + + /** + * @generated + */ + protected String getLabelText() { + String text = null; + EObject parserElement = getParserElement(); + if (parserElement != null && getParser() != null) { + text = getParser().getPrintString( + new EObjectAdapter(parserElement), + getParserOptions().intValue()); + } + if (text == null || text.length() == 0) { + text = defaultText; + } + return text; + } + + /** + * @generated + */ + @Override + public void setLabelText(String text) { + setLabelTextHelper(getFigure(), text); + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + @Override + public String getEditText() { + if (getParserElement() == null || getParser() == null) { + return ""; //$NON-NLS-1$ + } + return getParser().getEditString( + new EObjectAdapter(getParserElement()), + getParserOptions().intValue()); + } + + /** + * @generated + */ + protected boolean isEditable() { + return getParser() != null; + } + + /** + * @generated + */ + @Override + public ICellEditorValidator getEditTextValidator() { + return new ICellEditorValidator() { + + @Override + public String isValid(final Object value) { + if (value instanceof String) { + final EObject element = getParserElement(); + final IParser parser = getParser(); + try { + IParserEditStatus valid = + (IParserEditStatus) getEditingDomain().runExclusive( + new RunnableWithResult.Impl() { + + @Override + public void run() { + setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); + } + }); + return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); + } catch (InterruptedException ie) { + ie.printStackTrace(); + } + } + + // shouldn't get here + return null; + } + }; + } + + /** + * @generated + */ + @Override + public IContentAssistProcessor getCompletionProcessor() { + if (getParserElement() == null || getParser() == null) { + return null; + } + return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); + } + + /** + * @generated + */ + @Override + public ParserOptions getParserOptions() { + return ParserOptions.NONE; + } + + /** + * @generated + */ + @Override + public IParser getParser() { + if (parser == null) { + parser = UMLParserProvider.getParser(UMLElementTypes.ExecutionEnvironment_3083, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.ExecutionEnvironmentCompositeFloatingLabelEditPartCN.VISUAL_ID)); + } + return parser; + } + + /** + * @generated + */ + protected DirectEditManager getManager() { + if (manager == null) { + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + } + return manager; + } + + /** + * @generated + */ + protected void setManager(DirectEditManager manager) { + this.manager = manager; + } + + /** + * @generated + */ + protected void performDirectEdit() { + BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { + + @Override + public void run() { + getManager().show(); + } + }); + } + + /** + * @generated + */ + protected void performDirectEdit(Point eventLocation) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); + } + } + + /** + * @generated + */ + private void performDirectEdit(char initialCharacter) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(initialCharacter); + } else { + performDirectEdit(); + } + } + + /** + * @generated + */ + @Override + protected void performDirectEditRequest(Request request) { + + final Request theRequest = request; + + if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { + directEditionMode = getDirectEditionType(); + } + switch (directEditionMode) { + case IDirectEdition.NO_DIRECT_EDITION: + // no direct edition mode => does nothing + return; + case IDirectEdition.EXTENDED_DIRECT_EDITOR: + updateExtendedEditorConfiguration(); + if (configuration == null || configuration.getLanguage() == null) { + // Create default edit manager + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + performDefaultDirectEditorEdit(theRequest); + } else { + configuration.preEditAction(resolveSemanticElement()); + Dialog dialog = null; + if (configuration instanceof ICustomDirectEditorConfiguration) { + setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); + initializeDirectEditManager(theRequest); + return; + } else if (configuration instanceof IPopupEditorConfiguration) { + IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); + helper.showEditor(); + return; + } + else if (configuration instanceof IAdvancedEditorConfiguration) { + dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); + } else if (configuration instanceof IDirectEditorConfiguration) { + dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), + configuration); + } else { + return; + } + final Dialog finalDialog = dialog; + + if (Window.OK == dialog.open()) { + TransactionalEditingDomain domain = getEditingDomain(); + RecordingCommand command = new RecordingCommand(domain, "Edit Label") { + + @Override + protected void doExecute() { + configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); + + } + }; + domain.getCommandStack().execute(command); + } + } + break; + case IDirectEdition.DEFAULT_DIRECT_EDITOR: + initializeDirectEditManager(theRequest); + break; + default: + break; + } + } + + /** + * @generated + */ + protected void initializeDirectEditManager(final Request request) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + @Override + public void run() { + if (isActive() && isEditable()) { + if (request.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } + else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void refreshVisuals() { + super.refreshVisuals(); + refreshLabel(); + refreshFont(); + refreshFontColor(); + refreshUnderline(); + refreshStrikeThrough(); + } + + /** + * @generated + */ + protected void refreshLabel() { + EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); + if (maskLabelPolicy == null) { + maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); + } + if (maskLabelPolicy == null) { + View view = (View) getModel(); + if (view.isVisible()) { + setLabelTextHelper(getFigure(), getLabelText()); + setLabelIconHelper(getFigure(), getLabelIcon()); + } + else { + setLabelTextHelper(getFigure(), ""); //$NON-NLS-1$ + setLabelIconHelper(getFigure(), null); + } + } + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + protected void refreshUnderline() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); + } + if (resolveSemanticElement() instanceof Feature) { + if (((Feature) resolveSemanticElement()).isStatic()) { + ((WrappingLabel) getFigure()).setTextUnderline(true); + } + else { + ((WrappingLabel) getFigure()).setTextUnderline(false); + } + } + } + + /** + * @generated + */ + protected void refreshStrikeThrough() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); + } + } + + /** + * @generated + */ + @Override + protected void refreshFont() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null) { + FontData fontData = new FontData( + style.getFontName(), style.getFontHeight(), + (style.isBold() ? SWT.BOLD : SWT.NORMAL) | + (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); + setFont(fontData); + } + } + + /** + * @generated + */ + @Override + protected void setFontColor(Color color) { + getFigure().setForegroundColor(color); + } + + /** + * @generated + */ + @Override + protected void addSemanticListeners() { + if (getParser() instanceof ISemanticParser) { + EObject element = resolveSemanticElement(); + parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); + for (int i = 0; i < parserElements.size(); i++) { + addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ + } + } else { + super.addSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected void removeSemanticListeners() { + if (parserElements != null) { + for (int i = 0; i < parserElements.size(); i++) { + removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ + } + } else { + super.removeSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected AccessibleEditPart getAccessibleEditPart() { + if (accessibleEP == null) { + accessibleEP = new AccessibleGraphicalEditPart() { + + @Override + public void getName(AccessibleEvent e) { + e.result = getLabelTextHelper(getFigure()); + } + }; + } + return accessibleEP; + } + + /** + * @generated + */ + private View getFontStyleOwnerView() { + return getPrimaryView(); + } + + /** + * Returns the kind of associated editor for direct edition. + * + * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition + * @generated + */ + public int getDirectEditionType() { + if (checkExtendedEditor()) { + initExtendedEditorConfiguration(); + return IDirectEdition.EXTENDED_DIRECT_EDITOR; + } + if (checkDefaultEdition()) { + return IDirectEdition.DEFAULT_DIRECT_EDITOR; + } + + // not a named element. no specific editor => do nothing + return IDirectEdition.NO_DIRECT_EDITION; + } + + /** + * Checks if an extended editor is present. + * + * @return true if an extended editor is present. + * @generated + */ + protected boolean checkExtendedEditor() { + if (resolveSemanticElement() != null) { + return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); + } + return false; + } + + /** + * Checks if a default direct edition is available + * + * @return true if a default direct edition is available + * @generated + */ + protected boolean checkDefaultEdition() { + return (getParser() != null); + } + + /** + * Initializes the extended editor configuration + * + * @generated + */ + protected void initExtendedEditorConfiguration() { + if (configuration == null) { + final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("")) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); + } else { + configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); + } + } + } + + /** + * Updates the preference configuration + * + * @generated + */ + protected void updateExtendedEditorConfiguration() { + String languagePreferred = Activator.getDefault().getPreferenceStore().getString( + IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() + .eClass().getInstanceClassName()); + } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { + configuration = null; + } + } + + /** + * Performs the direct edit usually used by GMF editors. + * + * @param theRequest + * the direct edit request that starts the direct edit system + * @generated + */ + protected void performDefaultDirectEditorEdit(final Request theRequest) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + + @Override + public void run() { + if (isActive() && isEditable()) { + if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) theRequest.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { + DirectEditRequest editRequest = (DirectEditRequest) theRequest; + performDirectEdit(editRequest.getLocation()); + } else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + + /** + * @generated + */ + @Override + protected void handleNotificationEvent(Notification event) { + Object feature = event.getFeature(); + if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { + Integer c = (Integer) event.getNewValue(); + setFontColor(DiagramColorRegistry.getInstance().getColor(c)); + } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { + refreshUnderline(); + } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { + refreshStrikeThrough(); + } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { + refreshFont(); + } else { + if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { + refreshLabel(); + } + if (getParser() instanceof ISemanticParser) { + ISemanticParser modelParser = + (ISemanticParser) getParser(); + if (modelParser.areSemanticElementsAffected(null, event)) { + removeSemanticListeners(); + if (resolveSemanticElement() != null) { + addSemanticListeners(); + } + refreshLabel(); + } + } + } + super.handleNotificationEvent(event); + } + + /** + * @generated + */ + @Override + protected IFigure createFigure() { + IFigure label = createFigurePrim(); + defaultText = getLabelTextHelper(label); + return label; + } + + /** + * @generated + */ + protected IFigure createFigurePrim() { + return new PapyrusWrappingLabel(); + } + +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ExecutionEnvironmentCompositeNameEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ExecutionEnvironmentCompositeNameEditPart.java index 696498f2f6d..8343d1b343b 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ExecutionEnvironmentCompositeNameEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ExecutionEnvironmentCompositeNameEditPart.java @@ -864,7 +864,7 @@ public class ExecutionEnvironmentCompositeNameEditPart extends PapyrusCompartmen * @generated */ protected void addOwnerElementListeners() { - addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); + addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ExecutionEnvironmentCompositeNameEditPartCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ExecutionEnvironmentCompositeNameEditPartCN.java index 9c47f6047c8..82b4d3edf02 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ExecutionEnvironmentCompositeNameEditPartCN.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ExecutionEnvironmentCompositeNameEditPartCN.java @@ -864,7 +864,7 @@ public class ExecutionEnvironmentCompositeNameEditPartCN extends PapyrusCompartm * @generated */ protected void addOwnerElementListeners() { - addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); + addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ExpressionEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ExpressionEditPart.java index c7e485d78b3..60ebb67f6db 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ExpressionEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ExpressionEditPart.java @@ -11,27 +11,40 @@ */ package org.eclipse.papyrus.uml.diagram.composite.edit.parts; +import java.util.Collections; +import java.util.List; + import org.eclipse.draw2d.IFigure; +import org.eclipse.emf.common.notify.Notification; import org.eclipse.gef.EditPart; import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.GraphicalEditPart; 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.handles.MoveHandle; import org.eclipse.gef.requests.CreateRequest; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.BorderItemSelectionEditPolicy; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles; +import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; -import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure; import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure; +import org.eclipse.gmf.runtime.notation.Edge; +import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.gmf.runtime.notation.View; -import org.eclipse.papyrus.infra.gmfdiag.common.editpart.NodeEditPart; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.GetChildLayoutEditPolicy; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.IPapyrusNodeFigure; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.RoundedRectangleNodePlateFigure; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.SelectableBorderedNodeFigure; +import org.eclipse.papyrus.uml.diagram.common.editparts.RoundedCompartmentEditPart; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeNodeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.QualifiedNameDisplayEditPolicy; -import org.eclipse.papyrus.uml.diagram.common.figure.node.NodeNamedElementFigure; +import org.eclipse.papyrus.uml.diagram.common.figure.node.RoundedCompartmentFigure; +import org.eclipse.papyrus.uml.diagram.common.locator.RoundedRectangleLabelPositionLocator; import org.eclipse.papyrus.uml.diagram.composite.edit.policies.ExpressionItemSemanticEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; import org.eclipse.swt.graphics.Color; @@ -39,7 +52,7 @@ import org.eclipse.swt.graphics.Color; /** * @generated */ -public class ExpressionEditPart extends NodeEditPart { +public class ExpressionEditPart extends RoundedCompartmentEditPart { /** * @generated @@ -73,6 +86,7 @@ public class ExpressionEditPart extends NodeEditPart { installEditPolicy(EditPolicy.LAYOUT_ROLE, createLayoutEditPolicy()); installEditPolicy(QualifiedNameDisplayEditPolicy.QUALIFIED_NAME_POLICY, new QualifiedNameDisplayEditPolicy()); installEditPolicy(AppliedStereotypeLabelDisplayEditPolicy.STEREOTYPE_LABEL_POLICY, new AppliedStereotypeNodeLabelDisplayEditPolicy()); + installEditPolicy(EditPolicy.LAYOUT_ROLE, new GetChildLayoutEditPolicy()); // XXX need an SCR to runtime to have another abstract superclass that would let children add reasonable editpolicies // removeEditPolicy(org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles.CONNECTION_HANDLES_ROLE); } @@ -85,6 +99,20 @@ public class ExpressionEditPart extends NodeEditPart { @Override protected EditPolicy createChildEditPolicy(EditPart child) { + View childView = (View) child.getModel(); + switch (UMLVisualIDRegistry.getVisualID(childView)) { + case ExpressionFloatingLabelEditPart.VISUAL_ID: + return new BorderItemSelectionEditPolicy() { + + @Override + protected List createSelectionHandles() { + MoveHandle mh = new MoveHandle((GraphicalEditPart) getHost()); + mh.setBorder(null); + return Collections.singletonList(mh); + } + } + ; + } EditPolicy result = child.getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); if (result == null) { result = new NonResizableEditPolicy(); @@ -105,12 +133,36 @@ public class ExpressionEditPart extends NodeEditPart { return lep; } + /** + * Papyrus codeGen + * + * @generated + **/ + @Override + protected void handleNotificationEvent(Notification event) { + /* + * when a node have external node labels, the methods refreshChildren() remove the EditPart corresponding to the Label from the EditPart + * Registry. After that, we can't reset the visibility to true (using the Show/Hide Label Action)! + */ + if (NotationPackage.eINSTANCE.getView_Visible().equals(event.getFeature())) { + Object notifier = event.getNotifier(); + List modelChildren = ((View) getModel()).getChildren(); + if (!(notifier instanceof Edge)) { + if (modelChildren.contains(event.getNotifier())) { + return; + } + } + } + super.handleNotificationEvent(event); + + } + /** * @generated */ @Override protected IFigure createNodeShape() { - return primaryShape = new NodeNamedElementFigure(); + return primaryShape = new RoundedCompartmentFigure(); } /** @@ -119,8 +171,8 @@ public class ExpressionEditPart extends NodeEditPart { * @generated */ @Override - public NodeNamedElementFigure getPrimaryShape() { - return (NodeNamedElementFigure) primaryShape; + public RoundedCompartmentFigure getPrimaryShape() { + return (RoundedCompartmentFigure) primaryShape; } /** @@ -173,15 +225,32 @@ public class ExpressionEditPart extends NodeEditPart { */ @Override protected IFigure getContentPaneFor(IGraphicalEditPart editPart) { + if (editPart instanceof IBorderItemEditPart) { + return getBorderedFigure().getBorderItemContainer(); + } return getContentPane(); } + /** + * @generated + */ + @Override + protected void addBorderItem(IFigure borderItemContainer, IBorderItemEditPart borderItemEditPart) { + if (borderItemEditPart instanceof ExpressionFloatingLabelEditPart) { + IBorderItemLocator locator = new RoundedRectangleLabelPositionLocator(getMainFigure()); + borderItemContainer.add(borderItemEditPart.getFigure(), locator); + } else + { + super.addBorderItem(borderItemContainer, borderItemEditPart); + } + } + /** * @generated */ @Override protected NodeFigure createNodePlate() { - DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(40, 40); + RoundedRectangleNodePlateFigure result = new RoundedRectangleNodePlateFigure(40, 40); return result; } @@ -194,7 +263,7 @@ public class ExpressionEditPart extends NodeEditPart { * @generated */ @Override - protected NodeFigure createNodeFigure() { + protected NodeFigure createMainFigure() { return new SelectableBorderedNodeFigure(createMainFigureWithSVG()); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ExpressionFloatingLabelEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ExpressionFloatingLabelEditPart.java new file mode 100644 index 00000000000..4a39aa0dafc --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ExpressionFloatingLabelEditPart.java @@ -0,0 +1,860 @@ +/** + * 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.uml.diagram.composite.edit.parts; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.Label; +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.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.RunnableWithResult; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gef.AccessibleEditPart; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.Request; +import org.eclipse.gef.requests.DirectEditRequest; +import org.eclipse.gef.tools.DirectEditManager; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; +import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; +import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; +import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; +import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; +import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; +import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; +import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; +import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; +import org.eclipse.gmf.runtime.notation.FontStyle; +import org.eclipse.gmf.runtime.notation.NotationPackage; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.text.contentassist.IContentAssistProcessor; +import org.eclipse.jface.viewers.ICellEditorValidator; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.extensionpoints.editors.Activator; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; +import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; +import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.ExternalLabelPrimaryDragRoleEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.PapyrusWrappingLabel; +import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; +import org.eclipse.papyrus.uml.diagram.common.editparts.FloatingLabelEditPart; +import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; +import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; +import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; +import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.accessibility.AccessibleEvent; +import org.eclipse.swt.custom.BusyIndicator; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; +import org.eclipse.uml2.uml.Feature; + +/** + * @generated + */ +public class ExpressionFloatingLabelEditPart extends FloatingLabelEditPart + implements ITextAwareEditPart, IBorderItemEditPart +{ + + /** + * @generated + */ + public static final int VISUAL_ID = 6114; + + /** + * @generated + */ + private DirectEditManager manager; + + /** + * @generated + */ + private IParser parser; + + /** + * @generated + */ + private List parserElements; + + /** + * @generated + */ + private String defaultText; + + /** + * direct edition mode (default, undefined, registered editor, etc.) + * + * @generated + */ + protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; + + /** + * configuration from a registered edit dialog + * + * @generated + */ + protected IDirectEditorConfiguration configuration; + + + /** + * @generated + */ + static { + registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.ExpressionFloatingLabelEditPart.VISUAL_ID), new Point(0, 0)); + } + + /** + * @generated + */ + public ExpressionFloatingLabelEditPart(View view) { + super(view); + } + + /** + * @generated + */ + @Override + protected void createDefaultEditPolicies() { + super.createDefaultEditPolicies(); + installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); + installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ExternalLabelPrimaryDragRoleEditPolicy()); + } + + /** + * @generated + */ + @Override + public IBorderItemLocator getBorderItemLocator() { + IFigure parentFigure = getFigure().getParent(); + if (parentFigure != null && parentFigure.getLayoutManager() != null) { + Object constraint = parentFigure.getLayoutManager().getConstraint(getFigure()); + return (IBorderItemLocator) constraint; + } + return null; + } + + /** + * @generated + */ + @Override + public void refreshBounds() { + int x = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_X())).intValue(); + int y = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_Y())).intValue(); + int width = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Width())).intValue(); + int height = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Height())).intValue(); + getBorderItemLocator().setConstraint(new Rectangle(x, y, width, height)); + } + + + /** + * @generated + */ + protected String getLabelTextHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getText(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getText(); + } else { + return ((Label) figure).getText(); + } + } + + /** + * @generated + */ + protected void setLabelTextHelper(IFigure figure, String text) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setText(text); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setText(text); + } else { + ((Label) figure).setText(text); + } + } + + /** + * @generated + */ + protected Image getLabelIconHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getIcon(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getIcon(); + } else { + return ((Label) figure).getIcon(); + } + } + + /** + * @generated + */ + protected void setLabelIconHelper(IFigure figure, Image icon) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setIcon(icon); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setIcon(icon); + } else { + ((Label) figure).setIcon(icon); + } + } + + /** + * @generated + */ + public void setLabel(IFigure + figure) { + unregisterVisuals(); + setFigure(figure); + defaultText = getLabelTextHelper(figure); + registerVisuals(); + refreshVisuals(); + } + + /** + * @generated + */ + @Override + protected List getModelChildren() { + return Collections.EMPTY_LIST; + } + + /** + * @generated + */ + @Override + public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { + return null; + } + + /** + * @generated + */ + public void setParser(IParser parser) { + this.parser = parser; + } + + /** + * @generated + */ + protected EObject getParserElement() { + return resolveSemanticElement(); + } + + /** + * @generated + */ + protected Image getLabelIcon() { + return null; + } + + /** + * @generated + */ + protected String getLabelText() { + String text = null; + EObject parserElement = getParserElement(); + if (parserElement != null && getParser() != null) { + text = getParser().getPrintString( + new EObjectAdapter(parserElement), + getParserOptions().intValue()); + } + if (text == null || text.length() == 0) { + text = defaultText; + } + return text; + } + + /** + * @generated + */ + @Override + public void setLabelText(String text) { + setLabelTextHelper(getFigure(), text); + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + @Override + public String getEditText() { + if (getParserElement() == null || getParser() == null) { + return ""; //$NON-NLS-1$ + } + return getParser().getEditString( + new EObjectAdapter(getParserElement()), + getParserOptions().intValue()); + } + + /** + * @generated + */ + protected boolean isEditable() { + return getParser() != null; + } + + /** + * @generated + */ + @Override + public ICellEditorValidator getEditTextValidator() { + return new ICellEditorValidator() { + + @Override + public String isValid(final Object value) { + if (value instanceof String) { + final EObject element = getParserElement(); + final IParser parser = getParser(); + try { + IParserEditStatus valid = + (IParserEditStatus) getEditingDomain().runExclusive( + new RunnableWithResult.Impl() { + + @Override + public void run() { + setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); + } + }); + return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); + } catch (InterruptedException ie) { + ie.printStackTrace(); + } + } + + // shouldn't get here + return null; + } + }; + } + + /** + * @generated + */ + @Override + public IContentAssistProcessor getCompletionProcessor() { + if (getParserElement() == null || getParser() == null) { + return null; + } + return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); + } + + /** + * @generated + */ + @Override + public ParserOptions getParserOptions() { + return ParserOptions.NONE; + } + + /** + * @generated + */ + @Override + public IParser getParser() { + if (parser == null) { + parser = UMLParserProvider.getParser(UMLElementTypes.Expression_2103, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.ExpressionFloatingLabelEditPart.VISUAL_ID)); + } + return parser; + } + + /** + * @generated + */ + protected DirectEditManager getManager() { + if (manager == null) { + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + } + return manager; + } + + /** + * @generated + */ + protected void setManager(DirectEditManager manager) { + this.manager = manager; + } + + /** + * @generated + */ + protected void performDirectEdit() { + BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { + + @Override + public void run() { + getManager().show(); + } + }); + } + + /** + * @generated + */ + protected void performDirectEdit(Point eventLocation) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); + } + } + + /** + * @generated + */ + private void performDirectEdit(char initialCharacter) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(initialCharacter); + } else { + performDirectEdit(); + } + } + + /** + * @generated + */ + @Override + protected void performDirectEditRequest(Request request) { + + final Request theRequest = request; + + if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { + directEditionMode = getDirectEditionType(); + } + switch (directEditionMode) { + case IDirectEdition.NO_DIRECT_EDITION: + // no direct edition mode => does nothing + return; + case IDirectEdition.EXTENDED_DIRECT_EDITOR: + updateExtendedEditorConfiguration(); + if (configuration == null || configuration.getLanguage() == null) { + // Create default edit manager + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + performDefaultDirectEditorEdit(theRequest); + } else { + configuration.preEditAction(resolveSemanticElement()); + Dialog dialog = null; + if (configuration instanceof ICustomDirectEditorConfiguration) { + setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); + initializeDirectEditManager(theRequest); + return; + } else if (configuration instanceof IPopupEditorConfiguration) { + IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); + helper.showEditor(); + return; + } + else if (configuration instanceof IAdvancedEditorConfiguration) { + dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); + } else if (configuration instanceof IDirectEditorConfiguration) { + dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), + configuration); + } else { + return; + } + final Dialog finalDialog = dialog; + + if (Window.OK == dialog.open()) { + TransactionalEditingDomain domain = getEditingDomain(); + RecordingCommand command = new RecordingCommand(domain, "Edit Label") { + + @Override + protected void doExecute() { + configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); + + } + }; + domain.getCommandStack().execute(command); + } + } + break; + case IDirectEdition.DEFAULT_DIRECT_EDITOR: + initializeDirectEditManager(theRequest); + break; + default: + break; + } + } + + /** + * @generated + */ + protected void initializeDirectEditManager(final Request request) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + @Override + public void run() { + if (isActive() && isEditable()) { + if (request.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } + else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void refreshVisuals() { + super.refreshVisuals(); + refreshLabel(); + refreshFont(); + refreshFontColor(); + refreshUnderline(); + refreshStrikeThrough(); + } + + /** + * @generated + */ + protected void refreshLabel() { + EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); + if (maskLabelPolicy == null) { + maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); + } + if (maskLabelPolicy == null) { + View view = (View) getModel(); + if (view.isVisible()) { + setLabelTextHelper(getFigure(), getLabelText()); + setLabelIconHelper(getFigure(), getLabelIcon()); + } + else { + setLabelTextHelper(getFigure(), ""); //$NON-NLS-1$ + setLabelIconHelper(getFigure(), null); + } + } + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + protected void refreshUnderline() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); + } + if (resolveSemanticElement() instanceof Feature) { + if (((Feature) resolveSemanticElement()).isStatic()) { + ((WrappingLabel) getFigure()).setTextUnderline(true); + } + else { + ((WrappingLabel) getFigure()).setTextUnderline(false); + } + } + } + + /** + * @generated + */ + protected void refreshStrikeThrough() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); + } + } + + /** + * @generated + */ + @Override + protected void refreshFont() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null) { + FontData fontData = new FontData( + style.getFontName(), style.getFontHeight(), + (style.isBold() ? SWT.BOLD : SWT.NORMAL) | + (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); + setFont(fontData); + } + } + + /** + * @generated + */ + @Override + protected void setFontColor(Color color) { + getFigure().setForegroundColor(color); + } + + /** + * @generated + */ + @Override + protected void addSemanticListeners() { + if (getParser() instanceof ISemanticParser) { + EObject element = resolveSemanticElement(); + parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); + for (int i = 0; i < parserElements.size(); i++) { + addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ + } + } else { + super.addSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected void removeSemanticListeners() { + if (parserElements != null) { + for (int i = 0; i < parserElements.size(); i++) { + removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ + } + } else { + super.removeSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected AccessibleEditPart getAccessibleEditPart() { + if (accessibleEP == null) { + accessibleEP = new AccessibleGraphicalEditPart() { + + @Override + public void getName(AccessibleEvent e) { + e.result = getLabelTextHelper(getFigure()); + } + }; + } + return accessibleEP; + } + + /** + * @generated + */ + private View getFontStyleOwnerView() { + return getPrimaryView(); + } + + /** + * Returns the kind of associated editor for direct edition. + * + * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition + * @generated + */ + public int getDirectEditionType() { + if (checkExtendedEditor()) { + initExtendedEditorConfiguration(); + return IDirectEdition.EXTENDED_DIRECT_EDITOR; + } + if (checkDefaultEdition()) { + return IDirectEdition.DEFAULT_DIRECT_EDITOR; + } + + // not a named element. no specific editor => do nothing + return IDirectEdition.NO_DIRECT_EDITION; + } + + /** + * Checks if an extended editor is present. + * + * @return true if an extended editor is present. + * @generated + */ + protected boolean checkExtendedEditor() { + if (resolveSemanticElement() != null) { + return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); + } + return false; + } + + /** + * Checks if a default direct edition is available + * + * @return true if a default direct edition is available + * @generated + */ + protected boolean checkDefaultEdition() { + return (getParser() != null); + } + + /** + * Initializes the extended editor configuration + * + * @generated + */ + protected void initExtendedEditorConfiguration() { + if (configuration == null) { + final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("")) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); + } else { + configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); + } + } + } + + /** + * Updates the preference configuration + * + * @generated + */ + protected void updateExtendedEditorConfiguration() { + String languagePreferred = Activator.getDefault().getPreferenceStore().getString( + IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() + .eClass().getInstanceClassName()); + } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { + configuration = null; + } + } + + /** + * Performs the direct edit usually used by GMF editors. + * + * @param theRequest + * the direct edit request that starts the direct edit system + * @generated + */ + protected void performDefaultDirectEditorEdit(final Request theRequest) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + + @Override + public void run() { + if (isActive() && isEditable()) { + if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) theRequest.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { + DirectEditRequest editRequest = (DirectEditRequest) theRequest; + performDirectEdit(editRequest.getLocation()); + } else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + + /** + * @generated + */ + @Override + protected void handleNotificationEvent(Notification event) { + Object feature = event.getFeature(); + if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { + Integer c = (Integer) event.getNewValue(); + setFontColor(DiagramColorRegistry.getInstance().getColor(c)); + } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { + refreshUnderline(); + } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { + refreshStrikeThrough(); + } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { + refreshFont(); + } else { + if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { + refreshLabel(); + } + if (getParser() instanceof ISemanticParser) { + ISemanticParser modelParser = + (ISemanticParser) getParser(); + if (modelParser.areSemanticElementsAffected(null, event)) { + removeSemanticListeners(); + if (resolveSemanticElement() != null) { + addSemanticListeners(); + } + refreshLabel(); + } + } + } + super.handleNotificationEvent(event); + } + + /** + * @generated + */ + @Override + protected IFigure createFigure() { + IFigure label = createFigurePrim(); + defaultText = getLabelTextHelper(label); + return label; + } + + /** + * @generated + */ + protected IFigure createFigurePrim() { + return new PapyrusWrappingLabel(); + } + +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ExpressionNameEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ExpressionNameEditPart.java index 63d5429ae3e..55a4f5b96cb 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ExpressionNameEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ExpressionNameEditPart.java @@ -864,7 +864,7 @@ public class ExpressionNameEditPart extends PapyrusCompartmentEditPart implement * @generated */ protected void addOwnerElementListeners() { - addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); + addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/FunctionBehaviorCompositeCompartmentEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/FunctionBehaviorCompositeCompartmentEditPart.java index dbb68e077b1..941dd26aa45 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/FunctionBehaviorCompositeCompartmentEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/FunctionBehaviorCompositeCompartmentEditPart.java @@ -26,6 +26,7 @@ import org.eclipse.gmf.runtime.diagram.ui.editpolicies.ResizableCompartmentEditP import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.BorderDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.CustomContainerEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.DuplicatePasteEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.PapyrusCreationEditPolicy; @@ -75,6 +76,7 @@ public class FunctionBehaviorCompositeCompartmentEditPart extends ShapeCompartme installEditPolicy(EditPolicy.GRAPHICAL_NODE_ROLE, new CustomContainerEditPolicy()); installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, new CustomDiagramDragDropEditPolicy()); installEditPolicy(EditPolicyRoles.CREATION_ROLE, new PortInCompartmentCreationEditPolicy()); + installEditPolicy(BorderDisplayEditPolicy.BORDER_DISPLAY_EDITPOLICY, new BorderDisplayEditPolicy()); } /** diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/FunctionBehaviorCompositeCompartmentEditPartCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/FunctionBehaviorCompositeCompartmentEditPartCN.java index 20977f1b6f7..81698c58464 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/FunctionBehaviorCompositeCompartmentEditPartCN.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/FunctionBehaviorCompositeCompartmentEditPartCN.java @@ -26,6 +26,7 @@ import org.eclipse.gmf.runtime.diagram.ui.editpolicies.ResizableCompartmentEditP import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.BorderDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.CustomContainerEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.DuplicatePasteEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.PapyrusCreationEditPolicy; @@ -75,6 +76,7 @@ public class FunctionBehaviorCompositeCompartmentEditPartCN extends ShapeCompart installEditPolicy(EditPolicy.GRAPHICAL_NODE_ROLE, new CustomContainerEditPolicy()); installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, new CustomDiagramDragDropEditPolicy()); installEditPolicy(EditPolicyRoles.CREATION_ROLE, new PortInCompartmentCreationEditPolicy()); + installEditPolicy(BorderDisplayEditPolicy.BORDER_DISPLAY_EDITPOLICY, new BorderDisplayEditPolicy()); } /** diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/FunctionBehaviorCompositeEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/FunctionBehaviorCompositeEditPart.java index 7ca45577d97..d09f575f3bb 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/FunctionBehaviorCompositeEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/FunctionBehaviorCompositeEditPart.java @@ -11,28 +11,37 @@ */ package org.eclipse.papyrus.uml.diagram.composite.edit.parts; +import java.util.Collections; +import java.util.List; + import org.eclipse.draw2d.IFigure; import org.eclipse.draw2d.PositionConstants; import org.eclipse.emf.common.notify.Notification; import org.eclipse.gef.EditPart; import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.GraphicalEditPart; 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.handles.MoveHandle; import org.eclipse.gef.requests.CreateRequest; import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.BorderItemSelectionEditPolicy; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.DragDropEditPolicy; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles; import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; -import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure; import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure; +import org.eclipse.gmf.runtime.notation.Edge; +import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.GetChildLayoutEditPolicy; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.IPapyrusNodeFigure; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.RoundedRectangleNodePlateFigure; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.SelectableBorderedNodeFigure; -import org.eclipse.papyrus.uml.diagram.common.editparts.NamedElementEditPart; +import org.eclipse.papyrus.uml.diagram.common.editparts.RoundedCompartmentEditPart; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AffixedNodeAlignmentEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeNodeLabelDisplayEditPolicy; @@ -41,11 +50,11 @@ import org.eclipse.papyrus.uml.diagram.common.editpolicies.PapyrusCreationEditPo import org.eclipse.papyrus.uml.diagram.common.editpolicies.QualifiedNameDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.ShowHideClassifierContentsEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.ShowHideCompartmentEditPolicy; +import org.eclipse.papyrus.uml.diagram.common.locator.RoundedRectangleLabelPositionLocator; import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.BehaviorLayoutEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.CustomDiagramDragDropEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.RemoveOrphanViewPolicy; import org.eclipse.papyrus.uml.diagram.composite.custom.figures.FunctionBehaviorCompositeFigure; -import org.eclipse.papyrus.uml.diagram.composite.custom.locators.PortPositionLocator; import org.eclipse.papyrus.uml.diagram.composite.edit.policies.FunctionBehaviorCompositeItemSemanticEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; import org.eclipse.swt.graphics.Color; @@ -53,7 +62,7 @@ import org.eclipse.swt.graphics.Color; /** * @generated */ -public class FunctionBehaviorCompositeEditPart extends NamedElementEditPart { +public class FunctionBehaviorCompositeEditPart extends RoundedCompartmentEditPart { /** * @generated @@ -95,6 +104,7 @@ public class FunctionBehaviorCompositeEditPart extends NamedElementEditPart { installEditPolicy(ShowHideCompartmentEditPolicy.SHOW_HIDE_COMPARTMENT_POLICY, new ShowHideCompartmentEditPolicy()); installEditPolicy(AffixedNodeAlignmentEditPolicy.AFFIXED_CHILD_ALIGNMENT_ROLE, new AffixedNodeAlignmentEditPolicy()); installEditPolicy("REMOVE_ORPHAN_VIEW", new RemoveOrphanViewPolicy()); //$NON-NLS-1$ + installEditPolicy(EditPolicy.LAYOUT_ROLE, new GetChildLayoutEditPolicy()); // XXX need an SCR to runtime to have another abstract superclass that would let children add reasonable editpolicies // removeEditPolicy(org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles.CONNECTION_HANDLES_ROLE); } @@ -109,6 +119,17 @@ public class FunctionBehaviorCompositeEditPart extends NamedElementEditPart { protected EditPolicy createChildEditPolicy(EditPart child) { View childView = (View) child.getModel(); switch (UMLVisualIDRegistry.getVisualID(childView)) { + case FunctionBehaviorCompositeFloatingLabelEditPart.VISUAL_ID: + return new BorderItemSelectionEditPolicy() { + + @Override + protected List createSelectionHandles() { + MoveHandle mh = new MoveHandle((GraphicalEditPart) getHost()); + mh.setBorder(null); + return Collections.singletonList(mh); + } + } + ; case PortEditPart.VISUAL_ID: case ParameterEditPart.VISUAL_ID: return new BorderItemResizableEditPolicy(); @@ -140,6 +161,19 @@ public class FunctionBehaviorCompositeEditPart extends NamedElementEditPart { **/ @Override protected void handleNotificationEvent(Notification event) { + /* + * when a node have external node labels, the methods refreshChildren() remove the EditPart corresponding to the Label from the EditPart + * Registry. After that, we can't reset the visibility to true (using the Show/Hide Label Action)! + */ + if (NotationPackage.eINSTANCE.getView_Visible().equals(event.getFeature())) { + Object notifier = event.getNotifier(); + List modelChildren = ((View) getModel()).getChildren(); + if (!(notifier instanceof Edge)) { + if (modelChildren.contains(event.getNotifier())) { + return; + } + } + } super.handleNotificationEvent(event); } @@ -181,9 +215,9 @@ public class FunctionBehaviorCompositeEditPart extends NamedElementEditPart { - //Papyrus Gencode :Affixed Port locator + // Papyrus Gencode :Affixed Port locator if (childEditPart instanceof PortEditPart) { - IBorderItemLocator locator = new PortPositionLocator(getMainFigure(), PositionConstants.NONE); + IBorderItemLocator locator = new org.eclipse.papyrus.uml.diagram.common.locator.PortPositionLocator(getMainFigure(), PositionConstants.NONE); getBorderedFigure().getBorderItemContainer().add(((PortEditPart) childEditPart).getFigure(), locator); return true; } @@ -191,9 +225,9 @@ public class FunctionBehaviorCompositeEditPart extends NamedElementEditPart { - //Papyrus Gencode :Affixed Port locator + // Papyrus Gencode :Affixed Port locator if (childEditPart instanceof ParameterEditPart) { - IBorderItemLocator locator = new PortPositionLocator(getMainFigure(), PositionConstants.NONE); + IBorderItemLocator locator = new org.eclipse.papyrus.uml.diagram.common.locator.PortPositionLocator(getMainFigure(), PositionConstants.NONE); getBorderedFigure().getBorderItemContainer().add(((ParameterEditPart) childEditPart).getFigure(), locator); return true; } @@ -261,12 +295,26 @@ public class FunctionBehaviorCompositeEditPart extends NamedElementEditPart { return getContentPane(); } + /** + * @generated + */ + @Override + protected void addBorderItem(IFigure borderItemContainer, IBorderItemEditPart borderItemEditPart) { + if (borderItemEditPart instanceof FunctionBehaviorCompositeFloatingLabelEditPart) { + IBorderItemLocator locator = new RoundedRectangleLabelPositionLocator(getMainFigure()); + borderItemContainer.add(borderItemEditPart.getFigure(), locator); + } else + { + super.addBorderItem(borderItemContainer, borderItemEditPart); + } + } + /** * @generated */ @Override protected NodeFigure createNodePlate() { - DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(40, 40); + RoundedRectangleNodePlateFigure result = new RoundedRectangleNodePlateFigure(40, 40); return result; } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/FunctionBehaviorCompositeEditPartCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/FunctionBehaviorCompositeEditPartCN.java index 6b3fe5a6bb7..4eb8462e899 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/FunctionBehaviorCompositeEditPartCN.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/FunctionBehaviorCompositeEditPartCN.java @@ -11,28 +11,37 @@ */ package org.eclipse.papyrus.uml.diagram.composite.edit.parts; +import java.util.Collections; +import java.util.List; + import org.eclipse.draw2d.IFigure; import org.eclipse.draw2d.PositionConstants; import org.eclipse.emf.common.notify.Notification; import org.eclipse.gef.EditPart; import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.GraphicalEditPart; 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.handles.MoveHandle; import org.eclipse.gef.requests.CreateRequest; import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.BorderItemSelectionEditPolicy; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.DragDropEditPolicy; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles; import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; -import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure; import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure; +import org.eclipse.gmf.runtime.notation.Edge; +import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.GetChildLayoutEditPolicy; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.IPapyrusNodeFigure; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.RoundedRectangleNodePlateFigure; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.SelectableBorderedNodeFigure; -import org.eclipse.papyrus.uml.diagram.common.editparts.NamedElementEditPart; +import org.eclipse.papyrus.uml.diagram.common.editparts.RoundedCompartmentEditPart; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AffixedNodeAlignmentEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeNodeLabelDisplayEditPolicy; @@ -41,11 +50,11 @@ import org.eclipse.papyrus.uml.diagram.common.editpolicies.PapyrusCreationEditPo import org.eclipse.papyrus.uml.diagram.common.editpolicies.QualifiedNameDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.ShowHideClassifierContentsEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.ShowHideCompartmentEditPolicy; +import org.eclipse.papyrus.uml.diagram.common.locator.RoundedRectangleLabelPositionLocator; import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.BehaviorLayoutEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.CustomDiagramDragDropEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.RemoveOrphanViewPolicy; import org.eclipse.papyrus.uml.diagram.composite.custom.figures.FunctionBehaviorCompositeFigure; -import org.eclipse.papyrus.uml.diagram.composite.custom.locators.PortPositionLocator; import org.eclipse.papyrus.uml.diagram.composite.edit.policies.FunctionBehaviorCompositeItemSemanticEditPolicyCN; import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; import org.eclipse.swt.graphics.Color; @@ -53,7 +62,7 @@ import org.eclipse.swt.graphics.Color; /** * @generated */ -public class FunctionBehaviorCompositeEditPartCN extends NamedElementEditPart { +public class FunctionBehaviorCompositeEditPartCN extends RoundedCompartmentEditPart { /** * @generated @@ -95,6 +104,7 @@ public class FunctionBehaviorCompositeEditPartCN extends NamedElementEditPart { installEditPolicy(ShowHideCompartmentEditPolicy.SHOW_HIDE_COMPARTMENT_POLICY, new ShowHideCompartmentEditPolicy()); installEditPolicy(AffixedNodeAlignmentEditPolicy.AFFIXED_CHILD_ALIGNMENT_ROLE, new AffixedNodeAlignmentEditPolicy()); installEditPolicy("REMOVE_ORPHAN_VIEW", new RemoveOrphanViewPolicy()); //$NON-NLS-1$ + installEditPolicy(EditPolicy.LAYOUT_ROLE, new GetChildLayoutEditPolicy()); // XXX need an SCR to runtime to have another abstract superclass that would let children add reasonable editpolicies // removeEditPolicy(org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles.CONNECTION_HANDLES_ROLE); } @@ -109,6 +119,17 @@ public class FunctionBehaviorCompositeEditPartCN extends NamedElementEditPart { protected EditPolicy createChildEditPolicy(EditPart child) { View childView = (View) child.getModel(); switch (UMLVisualIDRegistry.getVisualID(childView)) { + case FunctionBehaviorCompositeFloatingLabelEditPartCN.VISUAL_ID: + return new BorderItemSelectionEditPolicy() { + + @Override + protected List createSelectionHandles() { + MoveHandle mh = new MoveHandle((GraphicalEditPart) getHost()); + mh.setBorder(null); + return Collections.singletonList(mh); + } + } + ; case PortEditPart.VISUAL_ID: case ParameterEditPart.VISUAL_ID: return new BorderItemResizableEditPolicy(); @@ -140,6 +161,19 @@ public class FunctionBehaviorCompositeEditPartCN extends NamedElementEditPart { **/ @Override protected void handleNotificationEvent(Notification event) { + /* + * when a node have external node labels, the methods refreshChildren() remove the EditPart corresponding to the Label from the EditPart + * Registry. After that, we can't reset the visibility to true (using the Show/Hide Label Action)! + */ + if (NotationPackage.eINSTANCE.getView_Visible().equals(event.getFeature())) { + Object notifier = event.getNotifier(); + List modelChildren = ((View) getModel()).getChildren(); + if (!(notifier instanceof Edge)) { + if (modelChildren.contains(event.getNotifier())) { + return; + } + } + } super.handleNotificationEvent(event); } @@ -181,9 +215,9 @@ public class FunctionBehaviorCompositeEditPartCN extends NamedElementEditPart { - //Papyrus Gencode :Affixed Port locator + // Papyrus Gencode :Affixed Port locator if (childEditPart instanceof PortEditPart) { - IBorderItemLocator locator = new PortPositionLocator(getMainFigure(), PositionConstants.NONE); + IBorderItemLocator locator = new org.eclipse.papyrus.uml.diagram.common.locator.PortPositionLocator(getMainFigure(), PositionConstants.NONE); getBorderedFigure().getBorderItemContainer().add(((PortEditPart) childEditPart).getFigure(), locator); return true; } @@ -191,9 +225,9 @@ public class FunctionBehaviorCompositeEditPartCN extends NamedElementEditPart { - //Papyrus Gencode :Affixed Port locator + // Papyrus Gencode :Affixed Port locator if (childEditPart instanceof ParameterEditPart) { - IBorderItemLocator locator = new PortPositionLocator(getMainFigure(), PositionConstants.NONE); + IBorderItemLocator locator = new org.eclipse.papyrus.uml.diagram.common.locator.PortPositionLocator(getMainFigure(), PositionConstants.NONE); getBorderedFigure().getBorderItemContainer().add(((ParameterEditPart) childEditPart).getFigure(), locator); return true; } @@ -261,12 +295,26 @@ public class FunctionBehaviorCompositeEditPartCN extends NamedElementEditPart { return getContentPane(); } + /** + * @generated + */ + @Override + protected void addBorderItem(IFigure borderItemContainer, IBorderItemEditPart borderItemEditPart) { + if (borderItemEditPart instanceof FunctionBehaviorCompositeFloatingLabelEditPartCN) { + IBorderItemLocator locator = new RoundedRectangleLabelPositionLocator(getMainFigure()); + borderItemContainer.add(borderItemEditPart.getFigure(), locator); + } else + { + super.addBorderItem(borderItemContainer, borderItemEditPart); + } + } + /** * @generated */ @Override protected NodeFigure createNodePlate() { - DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(40, 40); + RoundedRectangleNodePlateFigure result = new RoundedRectangleNodePlateFigure(40, 40); return result; } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/FunctionBehaviorCompositeFloatingLabelEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/FunctionBehaviorCompositeFloatingLabelEditPart.java new file mode 100644 index 00000000000..8b56ad279f1 --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/FunctionBehaviorCompositeFloatingLabelEditPart.java @@ -0,0 +1,860 @@ +/** + * 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.uml.diagram.composite.edit.parts; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.Label; +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.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.RunnableWithResult; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gef.AccessibleEditPart; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.Request; +import org.eclipse.gef.requests.DirectEditRequest; +import org.eclipse.gef.tools.DirectEditManager; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; +import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; +import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; +import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; +import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; +import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; +import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; +import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; +import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; +import org.eclipse.gmf.runtime.notation.FontStyle; +import org.eclipse.gmf.runtime.notation.NotationPackage; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.text.contentassist.IContentAssistProcessor; +import org.eclipse.jface.viewers.ICellEditorValidator; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.extensionpoints.editors.Activator; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; +import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; +import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.ExternalLabelPrimaryDragRoleEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.PapyrusWrappingLabel; +import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; +import org.eclipse.papyrus.uml.diagram.common.editparts.FloatingLabelEditPart; +import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; +import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; +import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; +import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.accessibility.AccessibleEvent; +import org.eclipse.swt.custom.BusyIndicator; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; +import org.eclipse.uml2.uml.Feature; + +/** + * @generated + */ +public class FunctionBehaviorCompositeFloatingLabelEditPart extends FloatingLabelEditPart + implements ITextAwareEditPart, IBorderItemEditPart +{ + + /** + * @generated + */ + public static final int VISUAL_ID = 6083; + + /** + * @generated + */ + private DirectEditManager manager; + + /** + * @generated + */ + private IParser parser; + + /** + * @generated + */ + private List parserElements; + + /** + * @generated + */ + private String defaultText; + + /** + * direct edition mode (default, undefined, registered editor, etc.) + * + * @generated + */ + protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; + + /** + * configuration from a registered edit dialog + * + * @generated + */ + protected IDirectEditorConfiguration configuration; + + + /** + * @generated + */ + static { + registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.FunctionBehaviorCompositeFloatingLabelEditPart.VISUAL_ID), new Point(0, 0)); + } + + /** + * @generated + */ + public FunctionBehaviorCompositeFloatingLabelEditPart(View view) { + super(view); + } + + /** + * @generated + */ + @Override + protected void createDefaultEditPolicies() { + super.createDefaultEditPolicies(); + installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); + installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ExternalLabelPrimaryDragRoleEditPolicy()); + } + + /** + * @generated + */ + @Override + public IBorderItemLocator getBorderItemLocator() { + IFigure parentFigure = getFigure().getParent(); + if (parentFigure != null && parentFigure.getLayoutManager() != null) { + Object constraint = parentFigure.getLayoutManager().getConstraint(getFigure()); + return (IBorderItemLocator) constraint; + } + return null; + } + + /** + * @generated + */ + @Override + public void refreshBounds() { + int x = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_X())).intValue(); + int y = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_Y())).intValue(); + int width = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Width())).intValue(); + int height = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Height())).intValue(); + getBorderItemLocator().setConstraint(new Rectangle(x, y, width, height)); + } + + + /** + * @generated + */ + protected String getLabelTextHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getText(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getText(); + } else { + return ((Label) figure).getText(); + } + } + + /** + * @generated + */ + protected void setLabelTextHelper(IFigure figure, String text) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setText(text); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setText(text); + } else { + ((Label) figure).setText(text); + } + } + + /** + * @generated + */ + protected Image getLabelIconHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getIcon(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getIcon(); + } else { + return ((Label) figure).getIcon(); + } + } + + /** + * @generated + */ + protected void setLabelIconHelper(IFigure figure, Image icon) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setIcon(icon); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setIcon(icon); + } else { + ((Label) figure).setIcon(icon); + } + } + + /** + * @generated + */ + public void setLabel(IFigure + figure) { + unregisterVisuals(); + setFigure(figure); + defaultText = getLabelTextHelper(figure); + registerVisuals(); + refreshVisuals(); + } + + /** + * @generated + */ + @Override + protected List getModelChildren() { + return Collections.EMPTY_LIST; + } + + /** + * @generated + */ + @Override + public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { + return null; + } + + /** + * @generated + */ + public void setParser(IParser parser) { + this.parser = parser; + } + + /** + * @generated + */ + protected EObject getParserElement() { + return resolveSemanticElement(); + } + + /** + * @generated + */ + protected Image getLabelIcon() { + return null; + } + + /** + * @generated + */ + protected String getLabelText() { + String text = null; + EObject parserElement = getParserElement(); + if (parserElement != null && getParser() != null) { + text = getParser().getPrintString( + new EObjectAdapter(parserElement), + getParserOptions().intValue()); + } + if (text == null || text.length() == 0) { + text = defaultText; + } + return text; + } + + /** + * @generated + */ + @Override + public void setLabelText(String text) { + setLabelTextHelper(getFigure(), text); + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + @Override + public String getEditText() { + if (getParserElement() == null || getParser() == null) { + return ""; //$NON-NLS-1$ + } + return getParser().getEditString( + new EObjectAdapter(getParserElement()), + getParserOptions().intValue()); + } + + /** + * @generated + */ + protected boolean isEditable() { + return getParser() != null; + } + + /** + * @generated + */ + @Override + public ICellEditorValidator getEditTextValidator() { + return new ICellEditorValidator() { + + @Override + public String isValid(final Object value) { + if (value instanceof String) { + final EObject element = getParserElement(); + final IParser parser = getParser(); + try { + IParserEditStatus valid = + (IParserEditStatus) getEditingDomain().runExclusive( + new RunnableWithResult.Impl() { + + @Override + public void run() { + setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); + } + }); + return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); + } catch (InterruptedException ie) { + ie.printStackTrace(); + } + } + + // shouldn't get here + return null; + } + }; + } + + /** + * @generated + */ + @Override + public IContentAssistProcessor getCompletionProcessor() { + if (getParserElement() == null || getParser() == null) { + return null; + } + return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); + } + + /** + * @generated + */ + @Override + public ParserOptions getParserOptions() { + return ParserOptions.NONE; + } + + /** + * @generated + */ + @Override + public IParser getParser() { + if (parser == null) { + parser = UMLParserProvider.getParser(UMLElementTypes.FunctionBehavior_2064, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.FunctionBehaviorCompositeFloatingLabelEditPart.VISUAL_ID)); + } + return parser; + } + + /** + * @generated + */ + protected DirectEditManager getManager() { + if (manager == null) { + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + } + return manager; + } + + /** + * @generated + */ + protected void setManager(DirectEditManager manager) { + this.manager = manager; + } + + /** + * @generated + */ + protected void performDirectEdit() { + BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { + + @Override + public void run() { + getManager().show(); + } + }); + } + + /** + * @generated + */ + protected void performDirectEdit(Point eventLocation) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); + } + } + + /** + * @generated + */ + private void performDirectEdit(char initialCharacter) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(initialCharacter); + } else { + performDirectEdit(); + } + } + + /** + * @generated + */ + @Override + protected void performDirectEditRequest(Request request) { + + final Request theRequest = request; + + if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { + directEditionMode = getDirectEditionType(); + } + switch (directEditionMode) { + case IDirectEdition.NO_DIRECT_EDITION: + // no direct edition mode => does nothing + return; + case IDirectEdition.EXTENDED_DIRECT_EDITOR: + updateExtendedEditorConfiguration(); + if (configuration == null || configuration.getLanguage() == null) { + // Create default edit manager + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + performDefaultDirectEditorEdit(theRequest); + } else { + configuration.preEditAction(resolveSemanticElement()); + Dialog dialog = null; + if (configuration instanceof ICustomDirectEditorConfiguration) { + setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); + initializeDirectEditManager(theRequest); + return; + } else if (configuration instanceof IPopupEditorConfiguration) { + IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); + helper.showEditor(); + return; + } + else if (configuration instanceof IAdvancedEditorConfiguration) { + dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); + } else if (configuration instanceof IDirectEditorConfiguration) { + dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), + configuration); + } else { + return; + } + final Dialog finalDialog = dialog; + + if (Window.OK == dialog.open()) { + TransactionalEditingDomain domain = getEditingDomain(); + RecordingCommand command = new RecordingCommand(domain, "Edit Label") { + + @Override + protected void doExecute() { + configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); + + } + }; + domain.getCommandStack().execute(command); + } + } + break; + case IDirectEdition.DEFAULT_DIRECT_EDITOR: + initializeDirectEditManager(theRequest); + break; + default: + break; + } + } + + /** + * @generated + */ + protected void initializeDirectEditManager(final Request request) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + @Override + public void run() { + if (isActive() && isEditable()) { + if (request.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } + else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void refreshVisuals() { + super.refreshVisuals(); + refreshLabel(); + refreshFont(); + refreshFontColor(); + refreshUnderline(); + refreshStrikeThrough(); + } + + /** + * @generated + */ + protected void refreshLabel() { + EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); + if (maskLabelPolicy == null) { + maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); + } + if (maskLabelPolicy == null) { + View view = (View) getModel(); + if (view.isVisible()) { + setLabelTextHelper(getFigure(), getLabelText()); + setLabelIconHelper(getFigure(), getLabelIcon()); + } + else { + setLabelTextHelper(getFigure(), ""); //$NON-NLS-1$ + setLabelIconHelper(getFigure(), null); + } + } + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + protected void refreshUnderline() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); + } + if (resolveSemanticElement() instanceof Feature) { + if (((Feature) resolveSemanticElement()).isStatic()) { + ((WrappingLabel) getFigure()).setTextUnderline(true); + } + else { + ((WrappingLabel) getFigure()).setTextUnderline(false); + } + } + } + + /** + * @generated + */ + protected void refreshStrikeThrough() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); + } + } + + /** + * @generated + */ + @Override + protected void refreshFont() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null) { + FontData fontData = new FontData( + style.getFontName(), style.getFontHeight(), + (style.isBold() ? SWT.BOLD : SWT.NORMAL) | + (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); + setFont(fontData); + } + } + + /** + * @generated + */ + @Override + protected void setFontColor(Color color) { + getFigure().setForegroundColor(color); + } + + /** + * @generated + */ + @Override + protected void addSemanticListeners() { + if (getParser() instanceof ISemanticParser) { + EObject element = resolveSemanticElement(); + parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); + for (int i = 0; i < parserElements.size(); i++) { + addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ + } + } else { + super.addSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected void removeSemanticListeners() { + if (parserElements != null) { + for (int i = 0; i < parserElements.size(); i++) { + removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ + } + } else { + super.removeSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected AccessibleEditPart getAccessibleEditPart() { + if (accessibleEP == null) { + accessibleEP = new AccessibleGraphicalEditPart() { + + @Override + public void getName(AccessibleEvent e) { + e.result = getLabelTextHelper(getFigure()); + } + }; + } + return accessibleEP; + } + + /** + * @generated + */ + private View getFontStyleOwnerView() { + return getPrimaryView(); + } + + /** + * Returns the kind of associated editor for direct edition. + * + * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition + * @generated + */ + public int getDirectEditionType() { + if (checkExtendedEditor()) { + initExtendedEditorConfiguration(); + return IDirectEdition.EXTENDED_DIRECT_EDITOR; + } + if (checkDefaultEdition()) { + return IDirectEdition.DEFAULT_DIRECT_EDITOR; + } + + // not a named element. no specific editor => do nothing + return IDirectEdition.NO_DIRECT_EDITION; + } + + /** + * Checks if an extended editor is present. + * + * @return true if an extended editor is present. + * @generated + */ + protected boolean checkExtendedEditor() { + if (resolveSemanticElement() != null) { + return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); + } + return false; + } + + /** + * Checks if a default direct edition is available + * + * @return true if a default direct edition is available + * @generated + */ + protected boolean checkDefaultEdition() { + return (getParser() != null); + } + + /** + * Initializes the extended editor configuration + * + * @generated + */ + protected void initExtendedEditorConfiguration() { + if (configuration == null) { + final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("")) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); + } else { + configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); + } + } + } + + /** + * Updates the preference configuration + * + * @generated + */ + protected void updateExtendedEditorConfiguration() { + String languagePreferred = Activator.getDefault().getPreferenceStore().getString( + IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() + .eClass().getInstanceClassName()); + } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { + configuration = null; + } + } + + /** + * Performs the direct edit usually used by GMF editors. + * + * @param theRequest + * the direct edit request that starts the direct edit system + * @generated + */ + protected void performDefaultDirectEditorEdit(final Request theRequest) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + + @Override + public void run() { + if (isActive() && isEditable()) { + if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) theRequest.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { + DirectEditRequest editRequest = (DirectEditRequest) theRequest; + performDirectEdit(editRequest.getLocation()); + } else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + + /** + * @generated + */ + @Override + protected void handleNotificationEvent(Notification event) { + Object feature = event.getFeature(); + if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { + Integer c = (Integer) event.getNewValue(); + setFontColor(DiagramColorRegistry.getInstance().getColor(c)); + } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { + refreshUnderline(); + } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { + refreshStrikeThrough(); + } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { + refreshFont(); + } else { + if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { + refreshLabel(); + } + if (getParser() instanceof ISemanticParser) { + ISemanticParser modelParser = + (ISemanticParser) getParser(); + if (modelParser.areSemanticElementsAffected(null, event)) { + removeSemanticListeners(); + if (resolveSemanticElement() != null) { + addSemanticListeners(); + } + refreshLabel(); + } + } + } + super.handleNotificationEvent(event); + } + + /** + * @generated + */ + @Override + protected IFigure createFigure() { + IFigure label = createFigurePrim(); + defaultText = getLabelTextHelper(label); + return label; + } + + /** + * @generated + */ + protected IFigure createFigurePrim() { + return new PapyrusWrappingLabel(); + } + +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/FunctionBehaviorCompositeFloatingLabelEditPartCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/FunctionBehaviorCompositeFloatingLabelEditPartCN.java new file mode 100644 index 00000000000..a899ca5c565 --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/FunctionBehaviorCompositeFloatingLabelEditPartCN.java @@ -0,0 +1,860 @@ +/** + * 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.uml.diagram.composite.edit.parts; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.Label; +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.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.RunnableWithResult; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gef.AccessibleEditPart; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.Request; +import org.eclipse.gef.requests.DirectEditRequest; +import org.eclipse.gef.tools.DirectEditManager; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; +import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; +import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; +import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; +import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; +import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; +import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; +import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; +import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; +import org.eclipse.gmf.runtime.notation.FontStyle; +import org.eclipse.gmf.runtime.notation.NotationPackage; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.text.contentassist.IContentAssistProcessor; +import org.eclipse.jface.viewers.ICellEditorValidator; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.extensionpoints.editors.Activator; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; +import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; +import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.ExternalLabelPrimaryDragRoleEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.PapyrusWrappingLabel; +import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; +import org.eclipse.papyrus.uml.diagram.common.editparts.FloatingLabelEditPart; +import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; +import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; +import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; +import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.accessibility.AccessibleEvent; +import org.eclipse.swt.custom.BusyIndicator; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; +import org.eclipse.uml2.uml.Feature; + +/** + * @generated + */ +public class FunctionBehaviorCompositeFloatingLabelEditPartCN extends FloatingLabelEditPart + implements ITextAwareEditPart, IBorderItemEditPart +{ + + /** + * @generated + */ + public static final int VISUAL_ID = 6061; + + /** + * @generated + */ + private DirectEditManager manager; + + /** + * @generated + */ + private IParser parser; + + /** + * @generated + */ + private List parserElements; + + /** + * @generated + */ + private String defaultText; + + /** + * direct edition mode (default, undefined, registered editor, etc.) + * + * @generated + */ + protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; + + /** + * configuration from a registered edit dialog + * + * @generated + */ + protected IDirectEditorConfiguration configuration; + + + /** + * @generated + */ + static { + registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.FunctionBehaviorCompositeFloatingLabelEditPartCN.VISUAL_ID), new Point(0, 0)); + } + + /** + * @generated + */ + public FunctionBehaviorCompositeFloatingLabelEditPartCN(View view) { + super(view); + } + + /** + * @generated + */ + @Override + protected void createDefaultEditPolicies() { + super.createDefaultEditPolicies(); + installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); + installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ExternalLabelPrimaryDragRoleEditPolicy()); + } + + /** + * @generated + */ + @Override + public IBorderItemLocator getBorderItemLocator() { + IFigure parentFigure = getFigure().getParent(); + if (parentFigure != null && parentFigure.getLayoutManager() != null) { + Object constraint = parentFigure.getLayoutManager().getConstraint(getFigure()); + return (IBorderItemLocator) constraint; + } + return null; + } + + /** + * @generated + */ + @Override + public void refreshBounds() { + int x = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_X())).intValue(); + int y = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_Y())).intValue(); + int width = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Width())).intValue(); + int height = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Height())).intValue(); + getBorderItemLocator().setConstraint(new Rectangle(x, y, width, height)); + } + + + /** + * @generated + */ + protected String getLabelTextHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getText(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getText(); + } else { + return ((Label) figure).getText(); + } + } + + /** + * @generated + */ + protected void setLabelTextHelper(IFigure figure, String text) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setText(text); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setText(text); + } else { + ((Label) figure).setText(text); + } + } + + /** + * @generated + */ + protected Image getLabelIconHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getIcon(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getIcon(); + } else { + return ((Label) figure).getIcon(); + } + } + + /** + * @generated + */ + protected void setLabelIconHelper(IFigure figure, Image icon) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setIcon(icon); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setIcon(icon); + } else { + ((Label) figure).setIcon(icon); + } + } + + /** + * @generated + */ + public void setLabel(IFigure + figure) { + unregisterVisuals(); + setFigure(figure); + defaultText = getLabelTextHelper(figure); + registerVisuals(); + refreshVisuals(); + } + + /** + * @generated + */ + @Override + protected List getModelChildren() { + return Collections.EMPTY_LIST; + } + + /** + * @generated + */ + @Override + public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { + return null; + } + + /** + * @generated + */ + public void setParser(IParser parser) { + this.parser = parser; + } + + /** + * @generated + */ + protected EObject getParserElement() { + return resolveSemanticElement(); + } + + /** + * @generated + */ + protected Image getLabelIcon() { + return null; + } + + /** + * @generated + */ + protected String getLabelText() { + String text = null; + EObject parserElement = getParserElement(); + if (parserElement != null && getParser() != null) { + text = getParser().getPrintString( + new EObjectAdapter(parserElement), + getParserOptions().intValue()); + } + if (text == null || text.length() == 0) { + text = defaultText; + } + return text; + } + + /** + * @generated + */ + @Override + public void setLabelText(String text) { + setLabelTextHelper(getFigure(), text); + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + @Override + public String getEditText() { + if (getParserElement() == null || getParser() == null) { + return ""; //$NON-NLS-1$ + } + return getParser().getEditString( + new EObjectAdapter(getParserElement()), + getParserOptions().intValue()); + } + + /** + * @generated + */ + protected boolean isEditable() { + return getParser() != null; + } + + /** + * @generated + */ + @Override + public ICellEditorValidator getEditTextValidator() { + return new ICellEditorValidator() { + + @Override + public String isValid(final Object value) { + if (value instanceof String) { + final EObject element = getParserElement(); + final IParser parser = getParser(); + try { + IParserEditStatus valid = + (IParserEditStatus) getEditingDomain().runExclusive( + new RunnableWithResult.Impl() { + + @Override + public void run() { + setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); + } + }); + return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); + } catch (InterruptedException ie) { + ie.printStackTrace(); + } + } + + // shouldn't get here + return null; + } + }; + } + + /** + * @generated + */ + @Override + public IContentAssistProcessor getCompletionProcessor() { + if (getParserElement() == null || getParser() == null) { + return null; + } + return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); + } + + /** + * @generated + */ + @Override + public ParserOptions getParserOptions() { + return ParserOptions.NONE; + } + + /** + * @generated + */ + @Override + public IParser getParser() { + if (parser == null) { + parser = UMLParserProvider.getParser(UMLElementTypes.FunctionBehavior_3076, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.FunctionBehaviorCompositeFloatingLabelEditPartCN.VISUAL_ID)); + } + return parser; + } + + /** + * @generated + */ + protected DirectEditManager getManager() { + if (manager == null) { + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + } + return manager; + } + + /** + * @generated + */ + protected void setManager(DirectEditManager manager) { + this.manager = manager; + } + + /** + * @generated + */ + protected void performDirectEdit() { + BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { + + @Override + public void run() { + getManager().show(); + } + }); + } + + /** + * @generated + */ + protected void performDirectEdit(Point eventLocation) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); + } + } + + /** + * @generated + */ + private void performDirectEdit(char initialCharacter) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(initialCharacter); + } else { + performDirectEdit(); + } + } + + /** + * @generated + */ + @Override + protected void performDirectEditRequest(Request request) { + + final Request theRequest = request; + + if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { + directEditionMode = getDirectEditionType(); + } + switch (directEditionMode) { + case IDirectEdition.NO_DIRECT_EDITION: + // no direct edition mode => does nothing + return; + case IDirectEdition.EXTENDED_DIRECT_EDITOR: + updateExtendedEditorConfiguration(); + if (configuration == null || configuration.getLanguage() == null) { + // Create default edit manager + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + performDefaultDirectEditorEdit(theRequest); + } else { + configuration.preEditAction(resolveSemanticElement()); + Dialog dialog = null; + if (configuration instanceof ICustomDirectEditorConfiguration) { + setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); + initializeDirectEditManager(theRequest); + return; + } else if (configuration instanceof IPopupEditorConfiguration) { + IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); + helper.showEditor(); + return; + } + else if (configuration instanceof IAdvancedEditorConfiguration) { + dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); + } else if (configuration instanceof IDirectEditorConfiguration) { + dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), + configuration); + } else { + return; + } + final Dialog finalDialog = dialog; + + if (Window.OK == dialog.open()) { + TransactionalEditingDomain domain = getEditingDomain(); + RecordingCommand command = new RecordingCommand(domain, "Edit Label") { + + @Override + protected void doExecute() { + configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); + + } + }; + domain.getCommandStack().execute(command); + } + } + break; + case IDirectEdition.DEFAULT_DIRECT_EDITOR: + initializeDirectEditManager(theRequest); + break; + default: + break; + } + } + + /** + * @generated + */ + protected void initializeDirectEditManager(final Request request) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + @Override + public void run() { + if (isActive() && isEditable()) { + if (request.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } + else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void refreshVisuals() { + super.refreshVisuals(); + refreshLabel(); + refreshFont(); + refreshFontColor(); + refreshUnderline(); + refreshStrikeThrough(); + } + + /** + * @generated + */ + protected void refreshLabel() { + EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); + if (maskLabelPolicy == null) { + maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); + } + if (maskLabelPolicy == null) { + View view = (View) getModel(); + if (view.isVisible()) { + setLabelTextHelper(getFigure(), getLabelText()); + setLabelIconHelper(getFigure(), getLabelIcon()); + } + else { + setLabelTextHelper(getFigure(), ""); //$NON-NLS-1$ + setLabelIconHelper(getFigure(), null); + } + } + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + protected void refreshUnderline() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); + } + if (resolveSemanticElement() instanceof Feature) { + if (((Feature) resolveSemanticElement()).isStatic()) { + ((WrappingLabel) getFigure()).setTextUnderline(true); + } + else { + ((WrappingLabel) getFigure()).setTextUnderline(false); + } + } + } + + /** + * @generated + */ + protected void refreshStrikeThrough() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); + } + } + + /** + * @generated + */ + @Override + protected void refreshFont() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null) { + FontData fontData = new FontData( + style.getFontName(), style.getFontHeight(), + (style.isBold() ? SWT.BOLD : SWT.NORMAL) | + (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); + setFont(fontData); + } + } + + /** + * @generated + */ + @Override + protected void setFontColor(Color color) { + getFigure().setForegroundColor(color); + } + + /** + * @generated + */ + @Override + protected void addSemanticListeners() { + if (getParser() instanceof ISemanticParser) { + EObject element = resolveSemanticElement(); + parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); + for (int i = 0; i < parserElements.size(); i++) { + addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ + } + } else { + super.addSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected void removeSemanticListeners() { + if (parserElements != null) { + for (int i = 0; i < parserElements.size(); i++) { + removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ + } + } else { + super.removeSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected AccessibleEditPart getAccessibleEditPart() { + if (accessibleEP == null) { + accessibleEP = new AccessibleGraphicalEditPart() { + + @Override + public void getName(AccessibleEvent e) { + e.result = getLabelTextHelper(getFigure()); + } + }; + } + return accessibleEP; + } + + /** + * @generated + */ + private View getFontStyleOwnerView() { + return getPrimaryView(); + } + + /** + * Returns the kind of associated editor for direct edition. + * + * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition + * @generated + */ + public int getDirectEditionType() { + if (checkExtendedEditor()) { + initExtendedEditorConfiguration(); + return IDirectEdition.EXTENDED_DIRECT_EDITOR; + } + if (checkDefaultEdition()) { + return IDirectEdition.DEFAULT_DIRECT_EDITOR; + } + + // not a named element. no specific editor => do nothing + return IDirectEdition.NO_DIRECT_EDITION; + } + + /** + * Checks if an extended editor is present. + * + * @return true if an extended editor is present. + * @generated + */ + protected boolean checkExtendedEditor() { + if (resolveSemanticElement() != null) { + return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); + } + return false; + } + + /** + * Checks if a default direct edition is available + * + * @return true if a default direct edition is available + * @generated + */ + protected boolean checkDefaultEdition() { + return (getParser() != null); + } + + /** + * Initializes the extended editor configuration + * + * @generated + */ + protected void initExtendedEditorConfiguration() { + if (configuration == null) { + final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("")) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); + } else { + configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); + } + } + } + + /** + * Updates the preference configuration + * + * @generated + */ + protected void updateExtendedEditorConfiguration() { + String languagePreferred = Activator.getDefault().getPreferenceStore().getString( + IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() + .eClass().getInstanceClassName()); + } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { + configuration = null; + } + } + + /** + * Performs the direct edit usually used by GMF editors. + * + * @param theRequest + * the direct edit request that starts the direct edit system + * @generated + */ + protected void performDefaultDirectEditorEdit(final Request theRequest) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + + @Override + public void run() { + if (isActive() && isEditable()) { + if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) theRequest.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { + DirectEditRequest editRequest = (DirectEditRequest) theRequest; + performDirectEdit(editRequest.getLocation()); + } else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + + /** + * @generated + */ + @Override + protected void handleNotificationEvent(Notification event) { + Object feature = event.getFeature(); + if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { + Integer c = (Integer) event.getNewValue(); + setFontColor(DiagramColorRegistry.getInstance().getColor(c)); + } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { + refreshUnderline(); + } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { + refreshStrikeThrough(); + } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { + refreshFont(); + } else { + if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { + refreshLabel(); + } + if (getParser() instanceof ISemanticParser) { + ISemanticParser modelParser = + (ISemanticParser) getParser(); + if (modelParser.areSemanticElementsAffected(null, event)) { + removeSemanticListeners(); + if (resolveSemanticElement() != null) { + addSemanticListeners(); + } + refreshLabel(); + } + } + } + super.handleNotificationEvent(event); + } + + /** + * @generated + */ + @Override + protected IFigure createFigure() { + IFigure label = createFigurePrim(); + defaultText = getLabelTextHelper(label); + return label; + } + + /** + * @generated + */ + protected IFigure createFigurePrim() { + return new PapyrusWrappingLabel(); + } + +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/FunctionBehaviorCompositeNameEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/FunctionBehaviorCompositeNameEditPart.java index d18dd3ce735..09d1b43ae54 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/FunctionBehaviorCompositeNameEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/FunctionBehaviorCompositeNameEditPart.java @@ -864,7 +864,7 @@ public class FunctionBehaviorCompositeNameEditPart extends PapyrusCompartmentEdi * @generated */ protected void addOwnerElementListeners() { - addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); + addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/FunctionBehaviorCompositeNameEditPartCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/FunctionBehaviorCompositeNameEditPartCN.java index f895fb833b6..5ed8d5aa12e 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/FunctionBehaviorCompositeNameEditPartCN.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/FunctionBehaviorCompositeNameEditPartCN.java @@ -864,7 +864,7 @@ public class FunctionBehaviorCompositeNameEditPartCN extends PapyrusCompartmentE * @generated */ protected void addOwnerElementListeners() { - addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); + addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/GeneralizationAppliedStereotypeEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/GeneralizationAppliedStereotypeEditPart.java index e268164cb42..0d5c8ca7df1 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/GeneralizationAppliedStereotypeEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/GeneralizationAppliedStereotypeEditPart.java @@ -1,820 +1,815 @@ -/** - * 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.uml.diagram.composite.edit.parts; - -import java.util.Collections; -import java.util.List; - -import org.eclipse.draw2d.ConnectionLocator; -import org.eclipse.draw2d.IFigure; -import org.eclipse.draw2d.Label; -import org.eclipse.draw2d.geometry.Point; -import org.eclipse.emf.common.notify.Notification; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.transaction.RecordingCommand; -import org.eclipse.emf.transaction.RunnableWithResult; -import org.eclipse.emf.transaction.TransactionalEditingDomain; -import org.eclipse.gef.AccessibleEditPart; -import org.eclipse.gef.EditPolicy; -import org.eclipse.gef.Request; -import org.eclipse.gef.requests.DirectEditRequest; -import org.eclipse.gef.tools.DirectEditManager; -import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; -import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; -import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; -import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; -import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; -import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; -import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; -import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; -import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; -import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; -import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; -import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; -import org.eclipse.gmf.runtime.notation.FontStyle; -import org.eclipse.gmf.runtime.notation.NotationPackage; -import org.eclipse.gmf.runtime.notation.View; -import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.jface.text.contentassist.IContentAssistProcessor; -import org.eclipse.jface.viewers.ICellEditorValidator; -import org.eclipse.jface.window.Window; -import org.eclipse.papyrus.extensionpoints.editors.Activator; -import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; -import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; -import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; -import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; -import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; -import org.eclipse.papyrus.infra.gmfdiag.common.editpart.IControlParserForDirectEdit; -import org.eclipse.papyrus.infra.gmfdiag.common.editpart.PapyrusLabelEditPart; -import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; -import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; -import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.PapyrusLinkLabelDragPolicy; -import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; -import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; -import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; -import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; -import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; -import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; -import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; -import org.eclipse.swt.SWT; -import org.eclipse.swt.accessibility.AccessibleEvent; -import org.eclipse.swt.custom.BusyIndicator; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.FontData; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.widgets.Display; -import org.eclipse.ui.PlatformUI; -import org.eclipse.uml2.uml.Feature; - -/** - * @generated - */ -public class GeneralizationAppliedStereotypeEditPart extends PapyrusLabelEditPart implements ITextAwareEditPart, IControlParserForDirectEdit { - - /** - * @generated - */ - public static final int VISUAL_ID = 6024; - - /** - * @generated - */ - private DirectEditManager manager; - - /** - * @generated - */ - private IParser parser; - - /** - * @generated - */ - private List parserElements; - - /** - * @generated - */ - private String defaultText; - - /** - * direct edition mode (default, undefined, registered editor, etc.) - * - * @generated - */ - protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; - - /** - * configuration from a registered edit dialog - * - * @generated - */ - protected IDirectEditorConfiguration configuration; - /** - * @generated - */ - static { - registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.GeneralizationAppliedStereotypeEditPart.VISUAL_ID), new Point(0, 60)); - } - - /** - * @generated - */ - public GeneralizationAppliedStereotypeEditPart(View view) { - super(view); - } - - /** - * @generated - */ - @Override - protected void createDefaultEditPolicies() { - super.createDefaultEditPolicies(); - installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); - installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); - installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new PapyrusLinkLabelDragPolicy()); - } - - /** - * @generated - */ - @Override - public int getKeyPoint() { - return ConnectionLocator.MIDDLE; - } - - /** - * @generated - */ - protected String getLabelTextHelper(IFigure figure) { - if (figure instanceof WrappingLabel) { - return ((WrappingLabel) figure).getText(); - } else if (figure instanceof ILabelFigure) { - return ((ILabelFigure) figure).getText(); - } else { - return ((Label) figure).getText(); - } - } - - /** - * @generated - */ - protected void setLabelTextHelper(IFigure figure, String text) { - if (figure instanceof WrappingLabel) { - ((WrappingLabel) figure).setText(text); - } else if (figure instanceof ILabelFigure) { - ((ILabelFigure) figure).setText(text); - } else { - ((Label) figure).setText(text); - } - } - - /** - * @generated - */ - protected Image getLabelIconHelper(IFigure figure) { - if (figure instanceof WrappingLabel) { - return ((WrappingLabel) figure).getIcon(); - } else if (figure instanceof ILabelFigure) { - return ((ILabelFigure) figure).getIcon(); - } else { - return ((Label) figure).getIcon(); - } - } - - /** - * @generated - */ - protected void setLabelIconHelper(IFigure figure, Image icon) { - if (figure instanceof WrappingLabel) { - ((WrappingLabel) figure).setIcon(icon); - } else if (figure instanceof ILabelFigure) { - ((ILabelFigure) figure).setIcon(icon); - } else { - ((Label) figure).setIcon(icon); - } - } - - /** - * @generated - */ - public void setLabel(IFigure - figure) { - unregisterVisuals(); - setFigure(figure); - defaultText = getLabelTextHelper(figure); - registerVisuals(); - refreshVisuals(); - } - - /** - * @generated - */ - @Override - protected List getModelChildren() { - return Collections.EMPTY_LIST; - } - - /** - * @generated - */ - @Override - public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { - return null; - } - - /** - * @generated - */ - @Override - public void setParser(IParser parser) { - this.parser = parser; - } - - /** - * @generated - */ - protected EObject getParserElement() { - return resolveSemanticElement(); - } - - /** - * @generated - */ - protected Image getLabelIcon() { - return null; - } - - /** - * @generated - */ - protected String getLabelText() { - String text = null; - EObject parserElement = getParserElement(); - if (parserElement != null && getParser() != null) { - text = getParser().getPrintString( - new EObjectAdapter(parserElement), - getParserOptions().intValue()); - } - if (text == null || text.length() == 0) { - text = defaultText; - } - return text; - } - - /** - * @generated - */ - @Override - public void setLabelText(String text) { - setLabelTextHelper(getFigure(), text); - Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); - if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); - } - Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); - if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); - } - } - - /** - * @generated - */ - @Override - public String getEditText() { - if (getParserElement() == null || getParser() == null) { - return ""; //$NON-NLS-1$ - } - return getParser().getEditString( - new EObjectAdapter(getParserElement()), - getParserOptions().intValue()); - } - - /** - * @generated - */ - protected boolean isEditable() { - return false; - } - - /** - * @generated - */ - @Override - public ICellEditorValidator getEditTextValidator() { - return new ICellEditorValidator() { - - @Override - public String isValid(final Object value) { - if (value instanceof String) { - final EObject element = getParserElement(); - final IParser parser = getParser(); - try { - IParserEditStatus valid = - (IParserEditStatus) getEditingDomain().runExclusive( - new RunnableWithResult.Impl() { - - @Override - public void run() { - setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); - } - }); - return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); - } catch (InterruptedException ie) { - ie.printStackTrace(); - } - } - - // shouldn't get here - return null; - } - }; - } - - /** - * @generated - */ - @Override - public IContentAssistProcessor getCompletionProcessor() { - if (getParserElement() == null || getParser() == null) { - return null; - } - return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); - } - - /** - * @generated - */ - @Override - public ParserOptions getParserOptions() { - return ParserOptions.NONE; - } - - /** - * @generated - */ - @Override - public IParser getParser() { - if (parser == null) { - parser = UMLParserProvider.getParser(UMLElementTypes.Generalization_4015, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.GeneralizationAppliedStereotypeEditPart.VISUAL_ID)); - } - return parser; - } - - /** - * @generated - */ - protected DirectEditManager getManager() { - if (manager == null) { - setManager(new MultilineLabelDirectEditManager(this, - MultilineLabelDirectEditManager.getTextCellEditorClass(this), - UMLEditPartFactory.getTextCellEditorLocator(this))); - } - return manager; - } - - /** - * @generated - */ - protected void setManager(DirectEditManager manager) { - this.manager = manager; - } - - /** - * @generated - */ - protected void performDirectEdit() { - BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { - - @Override - public void run() { - getManager().show(); - } - }); - } - - /** - * @generated - */ - protected void performDirectEdit(Point eventLocation) { - if (getManager() instanceof TextDirectEditManager) { - ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); - } - } - - /** - * @generated - */ - private void performDirectEdit(char initialCharacter) { - if (getManager() instanceof TextDirectEditManager) { - ((TextDirectEditManager) getManager()).show(initialCharacter); - } else { - performDirectEdit(); - } - } - - /** - * @generated - */ - @Override - protected void performDirectEditRequest(Request request) { - - final Request theRequest = request; - - if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { - directEditionMode = getDirectEditionType(); - } - switch (directEditionMode) { - case IDirectEdition.NO_DIRECT_EDITION: - // no direct edition mode => does nothing - return; - case IDirectEdition.EXTENDED_DIRECT_EDITOR: - updateExtendedEditorConfiguration(); - if (configuration == null || configuration.getLanguage() == null) { - // Create default edit manager - setManager(new MultilineLabelDirectEditManager(this, - MultilineLabelDirectEditManager.getTextCellEditorClass(this), - UMLEditPartFactory.getTextCellEditorLocator(this))); - performDefaultDirectEditorEdit(theRequest); - } else { - configuration.preEditAction(resolveSemanticElement()); - Dialog dialog = null; - if (configuration instanceof ICustomDirectEditorConfiguration) { - setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); - initializeDirectEditManager(theRequest); - return; - } else if (configuration instanceof IPopupEditorConfiguration) { - IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); - helper.showEditor(); - return; - } - else if (configuration instanceof IAdvancedEditorConfiguration) { - dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); - } else if (configuration instanceof IDirectEditorConfiguration) { - dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), - configuration); - } else { - return; - } - final Dialog finalDialog = dialog; - - if (Window.OK == dialog.open()) { - TransactionalEditingDomain domain = getEditingDomain(); - RecordingCommand command = new RecordingCommand(domain, "Edit Label") { - - @Override - protected void doExecute() { - configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); - - } - }; - domain.getCommandStack().execute(command); - } - } - break; - case IDirectEdition.DEFAULT_DIRECT_EDITOR: - initializeDirectEditManager(theRequest); - break; - default: - break; - } - } - - /** - * @generated - */ - protected void initializeDirectEditManager(final Request request) { - // initialize the direct edit manager - try { - getEditingDomain().runExclusive(new Runnable() { - @Override - public void run() { - if (isActive() && isEditable()) { - if (request.getExtendedData().get( - RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { - Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); - performDirectEdit(initialChar.charValue()); - } - else { - performDirectEdit(); - } - } - } - }); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - - /** - * @generated - */ - @Override - protected void refreshVisuals() { - super.refreshVisuals(); - refreshLabel(); - refreshFont(); - refreshFontColor(); - refreshUnderline(); - refreshStrikeThrough(); - } - - /** - * @generated - */ - protected void refreshLabel() { - EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); - if (maskLabelPolicy == null) { - maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); - } - if (maskLabelPolicy == null) { - View view = (View) getModel(); - if (view.isVisible()) { - setLabelTextHelper(getFigure(), getLabelText()); - setLabelIconHelper(getFigure(), getLabelIcon()); - } - else { - setLabelTextHelper(getFigure(), ""); //$NON-NLS-1$ - setLabelIconHelper(getFigure(), null); - } - } - Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); - if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); - } - Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); - if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); - } - } - - /** - * @generated - */ - protected void refreshUnderline() { - FontStyle style = - (FontStyle) getFontStyleOwnerView().getStyle( - NotationPackage.eINSTANCE.getFontStyle()); - if (style != null && getFigure() instanceof WrappingLabel) { - ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); - } - if (resolveSemanticElement() instanceof Feature) { - if (((Feature) resolveSemanticElement()).isStatic()) { - ((WrappingLabel) getFigure()).setTextUnderline(true); - } - else { - ((WrappingLabel) getFigure()).setTextUnderline(false); - } - } - } - - /** - * @generated - */ - protected void refreshStrikeThrough() { - FontStyle style = - (FontStyle) getFontStyleOwnerView().getStyle( - NotationPackage.eINSTANCE.getFontStyle()); - if (style != null && getFigure() instanceof WrappingLabel) { - ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); - } - } - - /** - * @generated - */ - @Override - protected void refreshFont() { - FontStyle style = - (FontStyle) getFontStyleOwnerView().getStyle( - NotationPackage.eINSTANCE.getFontStyle()); - if (style != null) { - FontData fontData = new FontData( - style.getFontName(), style.getFontHeight(), - (style.isBold() ? SWT.BOLD : SWT.NORMAL) | - (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); - setFont(fontData); - } - } - - /** - * @generated - */ - @Override - protected void setFontColor(Color color) { - getFigure().setForegroundColor(color); - } - - /** - * @generated - */ - @Override - protected void addSemanticListeners() { - if (getParser() instanceof ISemanticParser) { - EObject element = resolveSemanticElement(); - parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); - for (int i = 0; i < parserElements.size(); i++) { - addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ - } - } else { - super.addSemanticListeners(); - } - } - - /** - * @generated - */ - @Override - protected void removeSemanticListeners() { - if (parserElements != null) { - for (int i = 0; i < parserElements.size(); i++) { - removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ - } - } else { - super.removeSemanticListeners(); - } - } - - /** - * @generated - */ - @Override - protected AccessibleEditPart getAccessibleEditPart() { - if (accessibleEP == null) { - accessibleEP = new AccessibleGraphicalEditPart() { - - @Override - public void getName(AccessibleEvent e) { - e.result = getLabelTextHelper(getFigure()); - } - }; - } - return accessibleEP; - } - - /** - * @generated - */ - private View getFontStyleOwnerView() { - return getPrimaryView(); - } - - /** - * Returns the kind of associated editor for direct edition. - * - * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition - * @generated - */ - public int getDirectEditionType() { - // The label is read-only (defined in GMFGen model) - return IDirectEdition.NO_DIRECT_EDITION; - } - - /** - * Checks if an extended editor is present. - * - * @return true if an extended editor is present. - * @generated - */ - protected boolean checkExtendedEditor() { - if (resolveSemanticElement() != null) { - return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); - } - return false; - } - - /** - * Checks if a default direct edition is available - * - * @return true if a default direct edition is available - * @generated - */ - protected boolean checkDefaultEdition() { - return (getParser() != null); - } - - /** - * Initializes the extended editor configuration - * - * @generated - */ - protected void initExtendedEditorConfiguration() { - if (configuration == null) { - final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); - if (languagePreferred != null && !languagePreferred.equals("")) { - configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); - } else { - configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); - } - } - } - - /** - * Updates the preference configuration - * - * @generated - */ - protected void updateExtendedEditorConfiguration() { - String languagePreferred = Activator.getDefault().getPreferenceStore().getString( - IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); - if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { - configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() - .eClass().getInstanceClassName()); - } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { - configuration = null; - } - } - - /** - * Performs the direct edit usually used by GMF editors. - * - * @param theRequest - * the direct edit request that starts the direct edit system - * @generated - */ - protected void performDefaultDirectEditorEdit(final Request theRequest) { - // initialize the direct edit manager - try { - getEditingDomain().runExclusive(new Runnable() { - - @Override - public void run() { - if (isActive() && isEditable()) { - if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { - Character initialChar = (Character) theRequest.getExtendedData().get( - RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); - performDirectEdit(initialChar.charValue()); - } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { - DirectEditRequest editRequest = (DirectEditRequest) theRequest; - performDirectEdit(editRequest.getLocation()); - } else { - performDirectEdit(); - } - } - } - }); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - - /** - * @generated - */ - @Override - protected void handleNotificationEvent(Notification event) { - Object feature = event.getFeature(); - if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { - Integer c = (Integer) event.getNewValue(); - setFontColor(DiagramColorRegistry.getInstance().getColor(c)); - } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { - refreshUnderline(); - } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { - refreshStrikeThrough(); - } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || - NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || - NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || - NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { - refreshFont(); - } else { - if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { - refreshLabel(); - } - if (getParser() instanceof ISemanticParser) { - ISemanticParser modelParser = - (ISemanticParser) getParser(); - if (modelParser.areSemanticElementsAffected(null, event)) { - removeSemanticListeners(); - if (resolveSemanticElement() != null) { - addSemanticListeners(); - } - refreshLabel(); - } - } - } - - super.handleNotificationEvent(event); - } - - /** - * @generated - */ - @Override - protected IFigure createFigure() { - // Parent should assign one using setLabel() method - return 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.uml.diagram.composite.edit.parts; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.draw2d.ConnectionLocator; +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.Label; +import org.eclipse.draw2d.geometry.Point; +import org.eclipse.emf.common.notify.Notification; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.RunnableWithResult; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gef.AccessibleEditPart; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.Request; +import org.eclipse.gef.requests.DirectEditRequest; +import org.eclipse.gef.tools.DirectEditManager; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; +import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; +import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; +import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; +import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; +import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; +import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; +import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; +import org.eclipse.gmf.runtime.notation.FontStyle; +import org.eclipse.gmf.runtime.notation.NotationPackage; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.gmf.tooling.runtime.edit.policies.DefaultLinkLabelDragPolicy; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.text.contentassist.IContentAssistProcessor; +import org.eclipse.jface.viewers.ICellEditorValidator; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.extensionpoints.editors.Activator; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; +import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; +import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; +import org.eclipse.papyrus.infra.gmfdiag.common.editpart.IControlParserForDirectEdit; +import org.eclipse.papyrus.infra.gmfdiag.common.editpart.PapyrusLabelEditPart; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.PapyrusLinkLabelDragPolicy; +import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; +import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; +import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; +import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; +import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.accessibility.AccessibleEvent; +import org.eclipse.swt.custom.BusyIndicator; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; +import org.eclipse.uml2.uml.Feature; + +/** + * @generated + */ +public class GeneralizationAppliedStereotypeEditPart extends PapyrusLabelEditPart implements ITextAwareEditPart, IControlParserForDirectEdit { + + /** + * @generated + */ + public static final int VISUAL_ID = 6024; + + /** + * @generated + */ + private DirectEditManager manager; + + /** + * @generated + */ + private IParser parser; + + /** + * @generated + */ + private List parserElements; + + /** + * @generated + */ + private String defaultText; + + /** + * direct edition mode (default, undefined, registered editor, etc.) + * + * @generated + */ + protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; + + /** + * configuration from a registered edit dialog + * + * @generated + */ + protected IDirectEditorConfiguration configuration; + /** + * @generated + */ + static { + registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.GeneralizationAppliedStereotypeEditPart.VISUAL_ID), new Point(0, 60)); + } + + /** + * @generated + */ + public GeneralizationAppliedStereotypeEditPart(View view) { + super(view); + } + + /** + * @generated + */ + @Override + protected void createDefaultEditPolicies() { + super.createDefaultEditPolicies(); + installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); + installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new DefaultLinkLabelDragPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new PapyrusLinkLabelDragPolicy()); + } + + /** + * @generated + */ + @Override + public int getKeyPoint() { + return ConnectionLocator.MIDDLE; + } + + /** + * @generated + */ + protected String getLabelTextHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getText(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getText(); + } else { + return ((Label) figure).getText(); + } + } + + /** + * @generated + */ + protected void setLabelTextHelper(IFigure figure, String text) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setText(text); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setText(text); + } else { + ((Label) figure).setText(text); + } + } + + /** + * @generated + */ + protected Image getLabelIconHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getIcon(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getIcon(); + } else { + return ((Label) figure).getIcon(); + } + } + + /** + * @generated + */ + protected void setLabelIconHelper(IFigure figure, Image icon) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setIcon(icon); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setIcon(icon); + } else { + ((Label) figure).setIcon(icon); + } + } + + /** + * @generated + */ + public void setLabel(IFigure + figure) { + unregisterVisuals(); + setFigure(figure); + defaultText = getLabelTextHelper(figure); + registerVisuals(); + refreshVisuals(); + } + + /** + * @generated + */ + @Override + protected List getModelChildren() { + return Collections.EMPTY_LIST; + } + + /** + * @generated + */ + @Override + public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { + return null; + } + + /** + * @generated + */ + @Override + public void setParser(IParser parser) { + this.parser = parser; + } + + /** + * @generated + */ + protected EObject getParserElement() { + return resolveSemanticElement(); + } + + /** + * @generated + */ + protected Image getLabelIcon() { + return null; + } + + /** + * @generated + */ + protected String getLabelText() { + String text = null; + EObject parserElement = getParserElement(); + if (parserElement != null && getParser() != null) { + text = getParser().getPrintString( + new EObjectAdapter(parserElement), + getParserOptions().intValue()); + } + if (text == null || text.length() == 0) { + text = defaultText; + } + return text; + } + + /** + * @generated + */ + @Override + public void setLabelText(String text) { + setLabelTextHelper(getFigure(), text); + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + @Override + public String getEditText() { + if (getParserElement() == null || getParser() == null) { + return ""; //$NON-NLS-1$ + } + return getParser().getEditString( + new EObjectAdapter(getParserElement()), + getParserOptions().intValue()); + } + + /** + * @generated + */ + protected boolean isEditable() { + return false; + } + + /** + * @generated + */ + @Override + public ICellEditorValidator getEditTextValidator() { + return new ICellEditorValidator() { + + @Override + public String isValid(final Object value) { + if (value instanceof String) { + final EObject element = getParserElement(); + final IParser parser = getParser(); + try { + IParserEditStatus valid = + (IParserEditStatus) getEditingDomain().runExclusive( + new RunnableWithResult.Impl() { + + @Override + public void run() { + setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); + } + }); + return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); + } catch (InterruptedException ie) { + ie.printStackTrace(); + } + } + + // shouldn't get here + return null; + } + }; + } + + /** + * @generated + */ + @Override + public IContentAssistProcessor getCompletionProcessor() { + if (getParserElement() == null || getParser() == null) { + return null; + } + return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); + } + + /** + * @generated + */ + @Override + public ParserOptions getParserOptions() { + return ParserOptions.NONE; + } + + /** + * @generated + */ + @Override + public IParser getParser() { + if (parser == null) { + parser = UMLParserProvider.getParser(UMLElementTypes.Generalization_4015, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.GeneralizationAppliedStereotypeEditPart.VISUAL_ID)); + } + return parser; + } + + /** + * @generated + */ + protected DirectEditManager getManager() { + if (manager == null) { + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + } + return manager; + } + + /** + * @generated + */ + protected void setManager(DirectEditManager manager) { + this.manager = manager; + } + + /** + * @generated + */ + protected void performDirectEdit() { + BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { + + @Override + public void run() { + getManager().show(); + } + }); + } + + /** + * @generated + */ + protected void performDirectEdit(Point eventLocation) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); + } + } + + /** + * @generated + */ + private void performDirectEdit(char initialCharacter) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(initialCharacter); + } else { + performDirectEdit(); + } + } + + /** + * @generated + */ + @Override + protected void performDirectEditRequest(Request request) { + + final Request theRequest = request; + + if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { + directEditionMode = getDirectEditionType(); + } + switch (directEditionMode) { + case IDirectEdition.NO_DIRECT_EDITION: + // no direct edition mode => does nothing + return; + case IDirectEdition.EXTENDED_DIRECT_EDITOR: + updateExtendedEditorConfiguration(); + if (configuration == null || configuration.getLanguage() == null) { + // Create default edit manager + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + performDefaultDirectEditorEdit(theRequest); + } else { + configuration.preEditAction(resolveSemanticElement()); + Dialog dialog = null; + if (configuration instanceof ICustomDirectEditorConfiguration) { + setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); + initializeDirectEditManager(theRequest); + return; + } else if (configuration instanceof IPopupEditorConfiguration) { + IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); + helper.showEditor(); + return; + } + else if (configuration instanceof IAdvancedEditorConfiguration) { + dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); + } else if (configuration instanceof IDirectEditorConfiguration) { + dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), + configuration); + } else { + return; + } + final Dialog finalDialog = dialog; + + if (Window.OK == dialog.open()) { + TransactionalEditingDomain domain = getEditingDomain(); + RecordingCommand command = new RecordingCommand(domain, "Edit Label") { + + @Override + protected void doExecute() { + configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); + + } + }; + domain.getCommandStack().execute(command); + } + } + break; + case IDirectEdition.DEFAULT_DIRECT_EDITOR: + initializeDirectEditManager(theRequest); + break; + default: + break; + } + } + + /** + * @generated + */ + protected void initializeDirectEditManager(final Request request) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + @Override + public void run() { + if (isActive() && isEditable()) { + if (request.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } + else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void refreshVisuals() { + super.refreshVisuals(); + refreshLabel(); + refreshFont(); + refreshFontColor(); + refreshUnderline(); + refreshStrikeThrough(); + } + + /** + * @generated + */ + protected void refreshLabel() { + EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); + if (maskLabelPolicy == null) { + maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); + } + if (maskLabelPolicy == null) { + setLabelTextHelper(getFigure(), getLabelText()); + setLabelIconHelper(getFigure(), getLabelIcon()); + } + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + protected void refreshUnderline() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); + } + if (resolveSemanticElement() instanceof Feature) { + if (((Feature) resolveSemanticElement()).isStatic()) { + ((WrappingLabel) getFigure()).setTextUnderline(true); + } + else { + ((WrappingLabel) getFigure()).setTextUnderline(false); + } + } + } + + /** + * @generated + */ + protected void refreshStrikeThrough() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); + } + } + + /** + * @generated + */ + @Override + protected void refreshFont() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null) { + FontData fontData = new FontData( + style.getFontName(), style.getFontHeight(), + (style.isBold() ? SWT.BOLD : SWT.NORMAL) | + (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); + setFont(fontData); + } + } + + /** + * @generated + */ + @Override + protected void setFontColor(Color color) { + getFigure().setForegroundColor(color); + } + + /** + * @generated + */ + @Override + protected void addSemanticListeners() { + if (getParser() instanceof ISemanticParser) { + EObject element = resolveSemanticElement(); + parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); + for (int i = 0; i < parserElements.size(); i++) { + addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ + } + } else { + super.addSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected void removeSemanticListeners() { + if (parserElements != null) { + for (int i = 0; i < parserElements.size(); i++) { + removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ + } + } else { + super.removeSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected AccessibleEditPart getAccessibleEditPart() { + if (accessibleEP == null) { + accessibleEP = new AccessibleGraphicalEditPart() { + + @Override + public void getName(AccessibleEvent e) { + e.result = getLabelTextHelper(getFigure()); + } + }; + } + return accessibleEP; + } + + /** + * @generated + */ + private View getFontStyleOwnerView() { + return getPrimaryView(); + } + + /** + * Returns the kind of associated editor for direct edition. + * + * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition + * @generated + */ + public int getDirectEditionType() { + // The label is read-only (defined in GMFGen model) + return IDirectEdition.NO_DIRECT_EDITION; + } + + /** + * Checks if an extended editor is present. + * + * @return true if an extended editor is present. + * @generated + */ + protected boolean checkExtendedEditor() { + if (resolveSemanticElement() != null) { + return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); + } + return false; + } + + /** + * Checks if a default direct edition is available + * + * @return true if a default direct edition is available + * @generated + */ + protected boolean checkDefaultEdition() { + return (getParser() != null); + } + + /** + * Initializes the extended editor configuration + * + * @generated + */ + protected void initExtendedEditorConfiguration() { + if (configuration == null) { + final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("")) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); + } else { + configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); + } + } + } + + /** + * Updates the preference configuration + * + * @generated + */ + protected void updateExtendedEditorConfiguration() { + String languagePreferred = Activator.getDefault().getPreferenceStore().getString( + IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() + .eClass().getInstanceClassName()); + } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { + configuration = null; + } + } + + /** + * Performs the direct edit usually used by GMF editors. + * + * @param theRequest + * the direct edit request that starts the direct edit system + * @generated + */ + protected void performDefaultDirectEditorEdit(final Request theRequest) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + + @Override + public void run() { + if (isActive() && isEditable()) { + if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) theRequest.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { + DirectEditRequest editRequest = (DirectEditRequest) theRequest; + performDirectEdit(editRequest.getLocation()); + } else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void handleNotificationEvent(Notification event) { + Object feature = event.getFeature(); + if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { + Integer c = (Integer) event.getNewValue(); + setFontColor(DiagramColorRegistry.getInstance().getColor(c)); + } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { + refreshUnderline(); + } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { + refreshStrikeThrough(); + } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { + refreshFont(); + } else { + if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { + refreshLabel(); + } + if (getParser() instanceof ISemanticParser) { + ISemanticParser modelParser = + (ISemanticParser) getParser(); + if (modelParser.areSemanticElementsAffected(null, event)) { + removeSemanticListeners(); + if (resolveSemanticElement() != null) { + addSemanticListeners(); + } + refreshLabel(); + } + } + } + + super.handleNotificationEvent(event); + } + + /** + * @generated + */ + @Override + protected IFigure createFigure() { + // Parent should assign one using setLabel() method + return null; + } +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InformationFlowAppliedStereotypeEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InformationFlowAppliedStereotypeEditPart.java index 5448fb48f0d..96339fefc2c 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InformationFlowAppliedStereotypeEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InformationFlowAppliedStereotypeEditPart.java @@ -1,820 +1,815 @@ -/** - * 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.uml.diagram.composite.edit.parts; - -import java.util.Collections; -import java.util.List; - -import org.eclipse.draw2d.ConnectionLocator; -import org.eclipse.draw2d.IFigure; -import org.eclipse.draw2d.Label; -import org.eclipse.draw2d.geometry.Point; -import org.eclipse.emf.common.notify.Notification; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.transaction.RecordingCommand; -import org.eclipse.emf.transaction.RunnableWithResult; -import org.eclipse.emf.transaction.TransactionalEditingDomain; -import org.eclipse.gef.AccessibleEditPart; -import org.eclipse.gef.EditPolicy; -import org.eclipse.gef.Request; -import org.eclipse.gef.requests.DirectEditRequest; -import org.eclipse.gef.tools.DirectEditManager; -import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; -import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; -import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; -import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; -import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; -import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; -import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; -import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; -import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; -import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; -import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; -import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; -import org.eclipse.gmf.runtime.notation.FontStyle; -import org.eclipse.gmf.runtime.notation.NotationPackage; -import org.eclipse.gmf.runtime.notation.View; -import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.jface.text.contentassist.IContentAssistProcessor; -import org.eclipse.jface.viewers.ICellEditorValidator; -import org.eclipse.jface.window.Window; -import org.eclipse.papyrus.extensionpoints.editors.Activator; -import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; -import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; -import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; -import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; -import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; -import org.eclipse.papyrus.infra.gmfdiag.common.editpart.IControlParserForDirectEdit; -import org.eclipse.papyrus.infra.gmfdiag.common.editpart.PapyrusLabelEditPart; -import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; -import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; -import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.PapyrusLinkLabelDragPolicy; -import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; -import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; -import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; -import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; -import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; -import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; -import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; -import org.eclipse.swt.SWT; -import org.eclipse.swt.accessibility.AccessibleEvent; -import org.eclipse.swt.custom.BusyIndicator; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.FontData; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.widgets.Display; -import org.eclipse.ui.PlatformUI; -import org.eclipse.uml2.uml.Feature; - -/** - * @generated - */ -public class InformationFlowAppliedStereotypeEditPart extends PapyrusLabelEditPart implements ITextAwareEditPart, IControlParserForDirectEdit { - - /** - * @generated - */ - public static final int VISUAL_ID = 6032; - - /** - * @generated - */ - private DirectEditManager manager; - - /** - * @generated - */ - private IParser parser; - - /** - * @generated - */ - private List parserElements; - - /** - * @generated - */ - private String defaultText; - - /** - * direct edition mode (default, undefined, registered editor, etc.) - * - * @generated - */ - protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; - - /** - * configuration from a registered edit dialog - * - * @generated - */ - protected IDirectEditorConfiguration configuration; - /** - * @generated - */ - static { - registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.InformationFlowAppliedStereotypeEditPart.VISUAL_ID), new Point(0, 15)); - } - - /** - * @generated - */ - public InformationFlowAppliedStereotypeEditPart(View view) { - super(view); - } - - /** - * @generated - */ - @Override - protected void createDefaultEditPolicies() { - super.createDefaultEditPolicies(); - installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); - installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); - installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new PapyrusLinkLabelDragPolicy()); - } - - /** - * @generated - */ - @Override - public int getKeyPoint() { - return ConnectionLocator.MIDDLE; - } - - /** - * @generated - */ - protected String getLabelTextHelper(IFigure figure) { - if (figure instanceof WrappingLabel) { - return ((WrappingLabel) figure).getText(); - } else if (figure instanceof ILabelFigure) { - return ((ILabelFigure) figure).getText(); - } else { - return ((Label) figure).getText(); - } - } - - /** - * @generated - */ - protected void setLabelTextHelper(IFigure figure, String text) { - if (figure instanceof WrappingLabel) { - ((WrappingLabel) figure).setText(text); - } else if (figure instanceof ILabelFigure) { - ((ILabelFigure) figure).setText(text); - } else { - ((Label) figure).setText(text); - } - } - - /** - * @generated - */ - protected Image getLabelIconHelper(IFigure figure) { - if (figure instanceof WrappingLabel) { - return ((WrappingLabel) figure).getIcon(); - } else if (figure instanceof ILabelFigure) { - return ((ILabelFigure) figure).getIcon(); - } else { - return ((Label) figure).getIcon(); - } - } - - /** - * @generated - */ - protected void setLabelIconHelper(IFigure figure, Image icon) { - if (figure instanceof WrappingLabel) { - ((WrappingLabel) figure).setIcon(icon); - } else if (figure instanceof ILabelFigure) { - ((ILabelFigure) figure).setIcon(icon); - } else { - ((Label) figure).setIcon(icon); - } - } - - /** - * @generated - */ - public void setLabel(IFigure - figure) { - unregisterVisuals(); - setFigure(figure); - defaultText = getLabelTextHelper(figure); - registerVisuals(); - refreshVisuals(); - } - - /** - * @generated - */ - @Override - protected List getModelChildren() { - return Collections.EMPTY_LIST; - } - - /** - * @generated - */ - @Override - public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { - return null; - } - - /** - * @generated - */ - @Override - public void setParser(IParser parser) { - this.parser = parser; - } - - /** - * @generated - */ - protected EObject getParserElement() { - return resolveSemanticElement(); - } - - /** - * @generated - */ - protected Image getLabelIcon() { - return null; - } - - /** - * @generated - */ - protected String getLabelText() { - String text = null; - EObject parserElement = getParserElement(); - if (parserElement != null && getParser() != null) { - text = getParser().getPrintString( - new EObjectAdapter(parserElement), - getParserOptions().intValue()); - } - if (text == null || text.length() == 0) { - text = defaultText; - } - return text; - } - - /** - * @generated - */ - @Override - public void setLabelText(String text) { - setLabelTextHelper(getFigure(), text); - Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); - if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); - } - Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); - if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); - } - } - - /** - * @generated - */ - @Override - public String getEditText() { - if (getParserElement() == null || getParser() == null) { - return ""; //$NON-NLS-1$ - } - return getParser().getEditString( - new EObjectAdapter(getParserElement()), - getParserOptions().intValue()); - } - - /** - * @generated - */ - protected boolean isEditable() { - return false; - } - - /** - * @generated - */ - @Override - public ICellEditorValidator getEditTextValidator() { - return new ICellEditorValidator() { - - @Override - public String isValid(final Object value) { - if (value instanceof String) { - final EObject element = getParserElement(); - final IParser parser = getParser(); - try { - IParserEditStatus valid = - (IParserEditStatus) getEditingDomain().runExclusive( - new RunnableWithResult.Impl() { - - @Override - public void run() { - setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); - } - }); - return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); - } catch (InterruptedException ie) { - ie.printStackTrace(); - } - } - - // shouldn't get here - return null; - } - }; - } - - /** - * @generated - */ - @Override - public IContentAssistProcessor getCompletionProcessor() { - if (getParserElement() == null || getParser() == null) { - return null; - } - return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); - } - - /** - * @generated - */ - @Override - public ParserOptions getParserOptions() { - return ParserOptions.NONE; - } - - /** - * @generated - */ - @Override - public IParser getParser() { - if (parser == null) { - parser = UMLParserProvider.getParser(UMLElementTypes.InformationFlow_4021, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.InformationFlowAppliedStereotypeEditPart.VISUAL_ID)); - } - return parser; - } - - /** - * @generated - */ - protected DirectEditManager getManager() { - if (manager == null) { - setManager(new MultilineLabelDirectEditManager(this, - MultilineLabelDirectEditManager.getTextCellEditorClass(this), - UMLEditPartFactory.getTextCellEditorLocator(this))); - } - return manager; - } - - /** - * @generated - */ - protected void setManager(DirectEditManager manager) { - this.manager = manager; - } - - /** - * @generated - */ - protected void performDirectEdit() { - BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { - - @Override - public void run() { - getManager().show(); - } - }); - } - - /** - * @generated - */ - protected void performDirectEdit(Point eventLocation) { - if (getManager() instanceof TextDirectEditManager) { - ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); - } - } - - /** - * @generated - */ - private void performDirectEdit(char initialCharacter) { - if (getManager() instanceof TextDirectEditManager) { - ((TextDirectEditManager) getManager()).show(initialCharacter); - } else { - performDirectEdit(); - } - } - - /** - * @generated - */ - @Override - protected void performDirectEditRequest(Request request) { - - final Request theRequest = request; - - if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { - directEditionMode = getDirectEditionType(); - } - switch (directEditionMode) { - case IDirectEdition.NO_DIRECT_EDITION: - // no direct edition mode => does nothing - return; - case IDirectEdition.EXTENDED_DIRECT_EDITOR: - updateExtendedEditorConfiguration(); - if (configuration == null || configuration.getLanguage() == null) { - // Create default edit manager - setManager(new MultilineLabelDirectEditManager(this, - MultilineLabelDirectEditManager.getTextCellEditorClass(this), - UMLEditPartFactory.getTextCellEditorLocator(this))); - performDefaultDirectEditorEdit(theRequest); - } else { - configuration.preEditAction(resolveSemanticElement()); - Dialog dialog = null; - if (configuration instanceof ICustomDirectEditorConfiguration) { - setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); - initializeDirectEditManager(theRequest); - return; - } else if (configuration instanceof IPopupEditorConfiguration) { - IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); - helper.showEditor(); - return; - } - else if (configuration instanceof IAdvancedEditorConfiguration) { - dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); - } else if (configuration instanceof IDirectEditorConfiguration) { - dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), - configuration); - } else { - return; - } - final Dialog finalDialog = dialog; - - if (Window.OK == dialog.open()) { - TransactionalEditingDomain domain = getEditingDomain(); - RecordingCommand command = new RecordingCommand(domain, "Edit Label") { - - @Override - protected void doExecute() { - configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); - - } - }; - domain.getCommandStack().execute(command); - } - } - break; - case IDirectEdition.DEFAULT_DIRECT_EDITOR: - initializeDirectEditManager(theRequest); - break; - default: - break; - } - } - - /** - * @generated - */ - protected void initializeDirectEditManager(final Request request) { - // initialize the direct edit manager - try { - getEditingDomain().runExclusive(new Runnable() { - @Override - public void run() { - if (isActive() && isEditable()) { - if (request.getExtendedData().get( - RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { - Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); - performDirectEdit(initialChar.charValue()); - } - else { - performDirectEdit(); - } - } - } - }); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - - /** - * @generated - */ - @Override - protected void refreshVisuals() { - super.refreshVisuals(); - refreshLabel(); - refreshFont(); - refreshFontColor(); - refreshUnderline(); - refreshStrikeThrough(); - } - - /** - * @generated - */ - protected void refreshLabel() { - EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); - if (maskLabelPolicy == null) { - maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); - } - if (maskLabelPolicy == null) { - View view = (View) getModel(); - if (view.isVisible()) { - setLabelTextHelper(getFigure(), getLabelText()); - setLabelIconHelper(getFigure(), getLabelIcon()); - } - else { - setLabelTextHelper(getFigure(), ""); //$NON-NLS-1$ - setLabelIconHelper(getFigure(), null); - } - } - Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); - if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); - } - Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); - if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); - } - } - - /** - * @generated - */ - protected void refreshUnderline() { - FontStyle style = - (FontStyle) getFontStyleOwnerView().getStyle( - NotationPackage.eINSTANCE.getFontStyle()); - if (style != null && getFigure() instanceof WrappingLabel) { - ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); - } - if (resolveSemanticElement() instanceof Feature) { - if (((Feature) resolveSemanticElement()).isStatic()) { - ((WrappingLabel) getFigure()).setTextUnderline(true); - } - else { - ((WrappingLabel) getFigure()).setTextUnderline(false); - } - } - } - - /** - * @generated - */ - protected void refreshStrikeThrough() { - FontStyle style = - (FontStyle) getFontStyleOwnerView().getStyle( - NotationPackage.eINSTANCE.getFontStyle()); - if (style != null && getFigure() instanceof WrappingLabel) { - ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); - } - } - - /** - * @generated - */ - @Override - protected void refreshFont() { - FontStyle style = - (FontStyle) getFontStyleOwnerView().getStyle( - NotationPackage.eINSTANCE.getFontStyle()); - if (style != null) { - FontData fontData = new FontData( - style.getFontName(), style.getFontHeight(), - (style.isBold() ? SWT.BOLD : SWT.NORMAL) | - (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); - setFont(fontData); - } - } - - /** - * @generated - */ - @Override - protected void setFontColor(Color color) { - getFigure().setForegroundColor(color); - } - - /** - * @generated - */ - @Override - protected void addSemanticListeners() { - if (getParser() instanceof ISemanticParser) { - EObject element = resolveSemanticElement(); - parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); - for (int i = 0; i < parserElements.size(); i++) { - addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ - } - } else { - super.addSemanticListeners(); - } - } - - /** - * @generated - */ - @Override - protected void removeSemanticListeners() { - if (parserElements != null) { - for (int i = 0; i < parserElements.size(); i++) { - removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ - } - } else { - super.removeSemanticListeners(); - } - } - - /** - * @generated - */ - @Override - protected AccessibleEditPart getAccessibleEditPart() { - if (accessibleEP == null) { - accessibleEP = new AccessibleGraphicalEditPart() { - - @Override - public void getName(AccessibleEvent e) { - e.result = getLabelTextHelper(getFigure()); - } - }; - } - return accessibleEP; - } - - /** - * @generated - */ - private View getFontStyleOwnerView() { - return getPrimaryView(); - } - - /** - * Returns the kind of associated editor for direct edition. - * - * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition - * @generated - */ - public int getDirectEditionType() { - // The label is read-only (defined in GMFGen model) - return IDirectEdition.NO_DIRECT_EDITION; - } - - /** - * Checks if an extended editor is present. - * - * @return true if an extended editor is present. - * @generated - */ - protected boolean checkExtendedEditor() { - if (resolveSemanticElement() != null) { - return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); - } - return false; - } - - /** - * Checks if a default direct edition is available - * - * @return true if a default direct edition is available - * @generated - */ - protected boolean checkDefaultEdition() { - return (getParser() != null); - } - - /** - * Initializes the extended editor configuration - * - * @generated - */ - protected void initExtendedEditorConfiguration() { - if (configuration == null) { - final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); - if (languagePreferred != null && !languagePreferred.equals("")) { - configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); - } else { - configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); - } - } - } - - /** - * Updates the preference configuration - * - * @generated - */ - protected void updateExtendedEditorConfiguration() { - String languagePreferred = Activator.getDefault().getPreferenceStore().getString( - IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); - if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { - configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() - .eClass().getInstanceClassName()); - } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { - configuration = null; - } - } - - /** - * Performs the direct edit usually used by GMF editors. - * - * @param theRequest - * the direct edit request that starts the direct edit system - * @generated - */ - protected void performDefaultDirectEditorEdit(final Request theRequest) { - // initialize the direct edit manager - try { - getEditingDomain().runExclusive(new Runnable() { - - @Override - public void run() { - if (isActive() && isEditable()) { - if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { - Character initialChar = (Character) theRequest.getExtendedData().get( - RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); - performDirectEdit(initialChar.charValue()); - } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { - DirectEditRequest editRequest = (DirectEditRequest) theRequest; - performDirectEdit(editRequest.getLocation()); - } else { - performDirectEdit(); - } - } - } - }); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - - /** - * @generated - */ - @Override - protected void handleNotificationEvent(Notification event) { - Object feature = event.getFeature(); - if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { - Integer c = (Integer) event.getNewValue(); - setFontColor(DiagramColorRegistry.getInstance().getColor(c)); - } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { - refreshUnderline(); - } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { - refreshStrikeThrough(); - } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || - NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || - NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || - NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { - refreshFont(); - } else { - if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { - refreshLabel(); - } - if (getParser() instanceof ISemanticParser) { - ISemanticParser modelParser = - (ISemanticParser) getParser(); - if (modelParser.areSemanticElementsAffected(null, event)) { - removeSemanticListeners(); - if (resolveSemanticElement() != null) { - addSemanticListeners(); - } - refreshLabel(); - } - } - } - - super.handleNotificationEvent(event); - } - - /** - * @generated - */ - @Override - protected IFigure createFigure() { - // Parent should assign one using setLabel() method - return 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.uml.diagram.composite.edit.parts; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.draw2d.ConnectionLocator; +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.Label; +import org.eclipse.draw2d.geometry.Point; +import org.eclipse.emf.common.notify.Notification; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.RunnableWithResult; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gef.AccessibleEditPart; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.Request; +import org.eclipse.gef.requests.DirectEditRequest; +import org.eclipse.gef.tools.DirectEditManager; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; +import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; +import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; +import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; +import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; +import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; +import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; +import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; +import org.eclipse.gmf.runtime.notation.FontStyle; +import org.eclipse.gmf.runtime.notation.NotationPackage; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.gmf.tooling.runtime.edit.policies.DefaultLinkLabelDragPolicy; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.text.contentassist.IContentAssistProcessor; +import org.eclipse.jface.viewers.ICellEditorValidator; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.extensionpoints.editors.Activator; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; +import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; +import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; +import org.eclipse.papyrus.infra.gmfdiag.common.editpart.IControlParserForDirectEdit; +import org.eclipse.papyrus.infra.gmfdiag.common.editpart.PapyrusLabelEditPart; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.PapyrusLinkLabelDragPolicy; +import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; +import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; +import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; +import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; +import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.accessibility.AccessibleEvent; +import org.eclipse.swt.custom.BusyIndicator; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; +import org.eclipse.uml2.uml.Feature; + +/** + * @generated + */ +public class InformationFlowAppliedStereotypeEditPart extends PapyrusLabelEditPart implements ITextAwareEditPart, IControlParserForDirectEdit { + + /** + * @generated + */ + public static final int VISUAL_ID = 6032; + + /** + * @generated + */ + private DirectEditManager manager; + + /** + * @generated + */ + private IParser parser; + + /** + * @generated + */ + private List parserElements; + + /** + * @generated + */ + private String defaultText; + + /** + * direct edition mode (default, undefined, registered editor, etc.) + * + * @generated + */ + protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; + + /** + * configuration from a registered edit dialog + * + * @generated + */ + protected IDirectEditorConfiguration configuration; + /** + * @generated + */ + static { + registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.InformationFlowAppliedStereotypeEditPart.VISUAL_ID), new Point(0, 15)); + } + + /** + * @generated + */ + public InformationFlowAppliedStereotypeEditPart(View view) { + super(view); + } + + /** + * @generated + */ + @Override + protected void createDefaultEditPolicies() { + super.createDefaultEditPolicies(); + installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); + installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new DefaultLinkLabelDragPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new PapyrusLinkLabelDragPolicy()); + } + + /** + * @generated + */ + @Override + public int getKeyPoint() { + return ConnectionLocator.MIDDLE; + } + + /** + * @generated + */ + protected String getLabelTextHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getText(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getText(); + } else { + return ((Label) figure).getText(); + } + } + + /** + * @generated + */ + protected void setLabelTextHelper(IFigure figure, String text) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setText(text); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setText(text); + } else { + ((Label) figure).setText(text); + } + } + + /** + * @generated + */ + protected Image getLabelIconHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getIcon(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getIcon(); + } else { + return ((Label) figure).getIcon(); + } + } + + /** + * @generated + */ + protected void setLabelIconHelper(IFigure figure, Image icon) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setIcon(icon); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setIcon(icon); + } else { + ((Label) figure).setIcon(icon); + } + } + + /** + * @generated + */ + public void setLabel(IFigure + figure) { + unregisterVisuals(); + setFigure(figure); + defaultText = getLabelTextHelper(figure); + registerVisuals(); + refreshVisuals(); + } + + /** + * @generated + */ + @Override + protected List getModelChildren() { + return Collections.EMPTY_LIST; + } + + /** + * @generated + */ + @Override + public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { + return null; + } + + /** + * @generated + */ + @Override + public void setParser(IParser parser) { + this.parser = parser; + } + + /** + * @generated + */ + protected EObject getParserElement() { + return resolveSemanticElement(); + } + + /** + * @generated + */ + protected Image getLabelIcon() { + return null; + } + + /** + * @generated + */ + protected String getLabelText() { + String text = null; + EObject parserElement = getParserElement(); + if (parserElement != null && getParser() != null) { + text = getParser().getPrintString( + new EObjectAdapter(parserElement), + getParserOptions().intValue()); + } + if (text == null || text.length() == 0) { + text = defaultText; + } + return text; + } + + /** + * @generated + */ + @Override + public void setLabelText(String text) { + setLabelTextHelper(getFigure(), text); + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + @Override + public String getEditText() { + if (getParserElement() == null || getParser() == null) { + return ""; //$NON-NLS-1$ + } + return getParser().getEditString( + new EObjectAdapter(getParserElement()), + getParserOptions().intValue()); + } + + /** + * @generated + */ + protected boolean isEditable() { + return false; + } + + /** + * @generated + */ + @Override + public ICellEditorValidator getEditTextValidator() { + return new ICellEditorValidator() { + + @Override + public String isValid(final Object value) { + if (value instanceof String) { + final EObject element = getParserElement(); + final IParser parser = getParser(); + try { + IParserEditStatus valid = + (IParserEditStatus) getEditingDomain().runExclusive( + new RunnableWithResult.Impl() { + + @Override + public void run() { + setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); + } + }); + return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); + } catch (InterruptedException ie) { + ie.printStackTrace(); + } + } + + // shouldn't get here + return null; + } + }; + } + + /** + * @generated + */ + @Override + public IContentAssistProcessor getCompletionProcessor() { + if (getParserElement() == null || getParser() == null) { + return null; + } + return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); + } + + /** + * @generated + */ + @Override + public ParserOptions getParserOptions() { + return ParserOptions.NONE; + } + + /** + * @generated + */ + @Override + public IParser getParser() { + if (parser == null) { + parser = UMLParserProvider.getParser(UMLElementTypes.InformationFlow_4021, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.InformationFlowAppliedStereotypeEditPart.VISUAL_ID)); + } + return parser; + } + + /** + * @generated + */ + protected DirectEditManager getManager() { + if (manager == null) { + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + } + return manager; + } + + /** + * @generated + */ + protected void setManager(DirectEditManager manager) { + this.manager = manager; + } + + /** + * @generated + */ + protected void performDirectEdit() { + BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { + + @Override + public void run() { + getManager().show(); + } + }); + } + + /** + * @generated + */ + protected void performDirectEdit(Point eventLocation) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); + } + } + + /** + * @generated + */ + private void performDirectEdit(char initialCharacter) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(initialCharacter); + } else { + performDirectEdit(); + } + } + + /** + * @generated + */ + @Override + protected void performDirectEditRequest(Request request) { + + final Request theRequest = request; + + if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { + directEditionMode = getDirectEditionType(); + } + switch (directEditionMode) { + case IDirectEdition.NO_DIRECT_EDITION: + // no direct edition mode => does nothing + return; + case IDirectEdition.EXTENDED_DIRECT_EDITOR: + updateExtendedEditorConfiguration(); + if (configuration == null || configuration.getLanguage() == null) { + // Create default edit manager + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + performDefaultDirectEditorEdit(theRequest); + } else { + configuration.preEditAction(resolveSemanticElement()); + Dialog dialog = null; + if (configuration instanceof ICustomDirectEditorConfiguration) { + setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); + initializeDirectEditManager(theRequest); + return; + } else if (configuration instanceof IPopupEditorConfiguration) { + IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); + helper.showEditor(); + return; + } + else if (configuration instanceof IAdvancedEditorConfiguration) { + dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); + } else if (configuration instanceof IDirectEditorConfiguration) { + dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), + configuration); + } else { + return; + } + final Dialog finalDialog = dialog; + + if (Window.OK == dialog.open()) { + TransactionalEditingDomain domain = getEditingDomain(); + RecordingCommand command = new RecordingCommand(domain, "Edit Label") { + + @Override + protected void doExecute() { + configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); + + } + }; + domain.getCommandStack().execute(command); + } + } + break; + case IDirectEdition.DEFAULT_DIRECT_EDITOR: + initializeDirectEditManager(theRequest); + break; + default: + break; + } + } + + /** + * @generated + */ + protected void initializeDirectEditManager(final Request request) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + @Override + public void run() { + if (isActive() && isEditable()) { + if (request.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } + else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void refreshVisuals() { + super.refreshVisuals(); + refreshLabel(); + refreshFont(); + refreshFontColor(); + refreshUnderline(); + refreshStrikeThrough(); + } + + /** + * @generated + */ + protected void refreshLabel() { + EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); + if (maskLabelPolicy == null) { + maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); + } + if (maskLabelPolicy == null) { + setLabelTextHelper(getFigure(), getLabelText()); + setLabelIconHelper(getFigure(), getLabelIcon()); + } + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + protected void refreshUnderline() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); + } + if (resolveSemanticElement() instanceof Feature) { + if (((Feature) resolveSemanticElement()).isStatic()) { + ((WrappingLabel) getFigure()).setTextUnderline(true); + } + else { + ((WrappingLabel) getFigure()).setTextUnderline(false); + } + } + } + + /** + * @generated + */ + protected void refreshStrikeThrough() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); + } + } + + /** + * @generated + */ + @Override + protected void refreshFont() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null) { + FontData fontData = new FontData( + style.getFontName(), style.getFontHeight(), + (style.isBold() ? SWT.BOLD : SWT.NORMAL) | + (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); + setFont(fontData); + } + } + + /** + * @generated + */ + @Override + protected void setFontColor(Color color) { + getFigure().setForegroundColor(color); + } + + /** + * @generated + */ + @Override + protected void addSemanticListeners() { + if (getParser() instanceof ISemanticParser) { + EObject element = resolveSemanticElement(); + parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); + for (int i = 0; i < parserElements.size(); i++) { + addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ + } + } else { + super.addSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected void removeSemanticListeners() { + if (parserElements != null) { + for (int i = 0; i < parserElements.size(); i++) { + removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ + } + } else { + super.removeSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected AccessibleEditPart getAccessibleEditPart() { + if (accessibleEP == null) { + accessibleEP = new AccessibleGraphicalEditPart() { + + @Override + public void getName(AccessibleEvent e) { + e.result = getLabelTextHelper(getFigure()); + } + }; + } + return accessibleEP; + } + + /** + * @generated + */ + private View getFontStyleOwnerView() { + return getPrimaryView(); + } + + /** + * Returns the kind of associated editor for direct edition. + * + * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition + * @generated + */ + public int getDirectEditionType() { + // The label is read-only (defined in GMFGen model) + return IDirectEdition.NO_DIRECT_EDITION; + } + + /** + * Checks if an extended editor is present. + * + * @return true if an extended editor is present. + * @generated + */ + protected boolean checkExtendedEditor() { + if (resolveSemanticElement() != null) { + return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); + } + return false; + } + + /** + * Checks if a default direct edition is available + * + * @return true if a default direct edition is available + * @generated + */ + protected boolean checkDefaultEdition() { + return (getParser() != null); + } + + /** + * Initializes the extended editor configuration + * + * @generated + */ + protected void initExtendedEditorConfiguration() { + if (configuration == null) { + final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("")) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); + } else { + configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); + } + } + } + + /** + * Updates the preference configuration + * + * @generated + */ + protected void updateExtendedEditorConfiguration() { + String languagePreferred = Activator.getDefault().getPreferenceStore().getString( + IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() + .eClass().getInstanceClassName()); + } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { + configuration = null; + } + } + + /** + * Performs the direct edit usually used by GMF editors. + * + * @param theRequest + * the direct edit request that starts the direct edit system + * @generated + */ + protected void performDefaultDirectEditorEdit(final Request theRequest) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + + @Override + public void run() { + if (isActive() && isEditable()) { + if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) theRequest.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { + DirectEditRequest editRequest = (DirectEditRequest) theRequest; + performDirectEdit(editRequest.getLocation()); + } else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void handleNotificationEvent(Notification event) { + Object feature = event.getFeature(); + if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { + Integer c = (Integer) event.getNewValue(); + setFontColor(DiagramColorRegistry.getInstance().getColor(c)); + } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { + refreshUnderline(); + } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { + refreshStrikeThrough(); + } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { + refreshFont(); + } else { + if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { + refreshLabel(); + } + if (getParser() instanceof ISemanticParser) { + ISemanticParser modelParser = + (ISemanticParser) getParser(); + if (modelParser.areSemanticElementsAffected(null, event)) { + removeSemanticListeners(); + if (resolveSemanticElement() != null) { + addSemanticListeners(); + } + refreshLabel(); + } + } + } + + super.handleNotificationEvent(event); + } + + /** + * @generated + */ + @Override + protected IFigure createFigure() { + // Parent should assign one using setLabel() method + return null; + } +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InformationFlowConveyedLabelEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InformationFlowConveyedLabelEditPart.java index 1114c1cd725..7bbb62176dd 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InformationFlowConveyedLabelEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InformationFlowConveyedLabelEditPart.java @@ -1,832 +1,827 @@ -/** - * 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.uml.diagram.composite.edit.parts; - -import java.util.Collections; -import java.util.List; - -import org.eclipse.draw2d.ConnectionLocator; -import org.eclipse.draw2d.IFigure; -import org.eclipse.draw2d.Label; -import org.eclipse.draw2d.geometry.Point; -import org.eclipse.emf.common.notify.Notification; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.transaction.RecordingCommand; -import org.eclipse.emf.transaction.RunnableWithResult; -import org.eclipse.emf.transaction.TransactionalEditingDomain; -import org.eclipse.gef.AccessibleEditPart; -import org.eclipse.gef.EditPolicy; -import org.eclipse.gef.Request; -import org.eclipse.gef.requests.DirectEditRequest; -import org.eclipse.gef.tools.DirectEditManager; -import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; -import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; -import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; -import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; -import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; -import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; -import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; -import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; -import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; -import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; -import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; -import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; -import org.eclipse.gmf.runtime.notation.FontStyle; -import org.eclipse.gmf.runtime.notation.NotationPackage; -import org.eclipse.gmf.runtime.notation.View; -import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.jface.text.contentassist.IContentAssistProcessor; -import org.eclipse.jface.viewers.ICellEditorValidator; -import org.eclipse.jface.window.Window; -import org.eclipse.papyrus.extensionpoints.editors.Activator; -import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; -import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; -import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; -import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; -import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; -import org.eclipse.papyrus.infra.gmfdiag.common.editpart.IControlParserForDirectEdit; -import org.eclipse.papyrus.infra.gmfdiag.common.editpart.PapyrusLabelEditPart; -import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; -import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; -import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.PapyrusLinkLabelDragPolicy; -import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; -import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; -import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; -import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.AbstractCustomLabelEditPolicy; -import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.InformationFlowCustomLabelEditPolicy; -import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; -import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; -import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; -import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; -import org.eclipse.swt.SWT; -import org.eclipse.swt.accessibility.AccessibleEvent; -import org.eclipse.swt.custom.BusyIndicator; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.FontData; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.widgets.Display; -import org.eclipse.ui.PlatformUI; -import org.eclipse.uml2.uml.Feature; - -/** - * @generated - */ -public class InformationFlowConveyedLabelEditPart extends PapyrusLabelEditPart implements ITextAwareEditPart, IControlParserForDirectEdit { - - /** - * @generated - */ - public static final int VISUAL_ID = 6031; - - /** - * @generated - */ - private DirectEditManager manager; - - /** - * @generated - */ - private IParser parser; - - /** - * @generated - */ - private List parserElements; - - /** - * @generated - */ - private String defaultText; - - /** - * direct edition mode (default, undefined, registered editor, etc.) - * - * @generated - */ - protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; - - /** - * configuration from a registered edit dialog - * - * @generated - */ - protected IDirectEditorConfiguration configuration; - /** - * @generated - */ - static { - registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.InformationFlowConveyedLabelEditPart.VISUAL_ID), new Point(0, 30)); - } - - /** - * @generated - */ - public InformationFlowConveyedLabelEditPart(View view) { - super(view); - } - - /** - * @generated - */ - @Override - protected void createDefaultEditPolicies() { - super.createDefaultEditPolicies(); - installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); - installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); - installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new PapyrusLinkLabelDragPolicy()); - installEditPolicy(AbstractCustomLabelEditPolicy.SPECIFIC_NAME_LABEL_POLICY, new InformationFlowCustomLabelEditPolicy()); - } - - /** - * @generated - */ - @Override - public int getKeyPoint() { - return ConnectionLocator.MIDDLE; - } - - /** - * @generated - */ - protected String getLabelTextHelper(IFigure figure) { - if (figure instanceof WrappingLabel) { - return ((WrappingLabel) figure).getText(); - } else if (figure instanceof ILabelFigure) { - return ((ILabelFigure) figure).getText(); - } else { - return ((Label) figure).getText(); - } - } - - /** - * @generated - */ - protected void setLabelTextHelper(IFigure figure, String text) { - if (figure instanceof WrappingLabel) { - ((WrappingLabel) figure).setText(text); - } else if (figure instanceof ILabelFigure) { - ((ILabelFigure) figure).setText(text); - } else { - ((Label) figure).setText(text); - } - } - - /** - * @generated - */ - protected Image getLabelIconHelper(IFigure figure) { - if (figure instanceof WrappingLabel) { - return ((WrappingLabel) figure).getIcon(); - } else if (figure instanceof ILabelFigure) { - return ((ILabelFigure) figure).getIcon(); - } else { - return ((Label) figure).getIcon(); - } - } - - /** - * @generated - */ - protected void setLabelIconHelper(IFigure figure, Image icon) { - if (figure instanceof WrappingLabel) { - ((WrappingLabel) figure).setIcon(icon); - } else if (figure instanceof ILabelFigure) { - ((ILabelFigure) figure).setIcon(icon); - } else { - ((Label) figure).setIcon(icon); - } - } - - /** - * @generated - */ - public void setLabel(IFigure - figure) { - unregisterVisuals(); - setFigure(figure); - defaultText = getLabelTextHelper(figure); - registerVisuals(); - refreshVisuals(); - } - - /** - * @generated - */ - @Override - protected List getModelChildren() { - return Collections.EMPTY_LIST; - } - - /** - * @generated - */ - @Override - public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { - return null; - } - - /** - * @generated - */ - @Override - public void setParser(IParser parser) { - this.parser = parser; - } - - /** - * @generated - */ - protected EObject getParserElement() { - EObject element = resolveSemanticElement(); - return element != null ? element : (View) getModel(); - } - - /** - * @generated - */ - protected Image getLabelIcon() { - return null; - } - - /** - * @generated - */ - protected String getLabelText() { - String text = null; - EObject parserElement = getParserElement(); - if (parserElement != null && getParser() != null) { - text = getParser().getPrintString( - new EObjectAdapter(parserElement), - getParserOptions().intValue()); - } - if (text == null || text.length() == 0) { - text = defaultText; - } - return text; - } - - /** - * @generated - */ - @Override - public void setLabelText(String text) { - setLabelTextHelper(getFigure(), text); - Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); - if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); - } - Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); - if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); - } - } - - /** - * @generated - */ - @Override - public String getEditText() { - if (getParserElement() == null || getParser() == null) { - return ""; //$NON-NLS-1$ - } - return getParser().getEditString( - new EObjectAdapter(getParserElement()), - getParserOptions().intValue()); - } - - /** - * @generated - */ - protected boolean isEditable() { - return getParser() != null; - } - - /** - * @generated - */ - @Override - public ICellEditorValidator getEditTextValidator() { - return new ICellEditorValidator() { - - @Override - public String isValid(final Object value) { - if (value instanceof String) { - final EObject element = getParserElement(); - final IParser parser = getParser(); - try { - IParserEditStatus valid = - (IParserEditStatus) getEditingDomain().runExclusive( - new RunnableWithResult.Impl() { - - @Override - public void run() { - setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); - } - }); - return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); - } catch (InterruptedException ie) { - ie.printStackTrace(); - } - } - - // shouldn't get here - return null; - } - }; - } - - /** - * @generated - */ - @Override - public IContentAssistProcessor getCompletionProcessor() { - if (getParserElement() == null || getParser() == null) { - return null; - } - return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); - } - - /** - * @generated - */ - @Override - public ParserOptions getParserOptions() { - return ParserOptions.NONE; - } - - /** - * @generated - */ - @Override - public IParser getParser() { - if (parser == null) { - parser = UMLParserProvider.getParser(UMLElementTypes.InformationFlow_4021, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.InformationFlowConveyedLabelEditPart.VISUAL_ID)); - } - return parser; - } - - /** - * @generated - */ - protected DirectEditManager getManager() { - if (manager == null) { - setManager(new MultilineLabelDirectEditManager(this, - MultilineLabelDirectEditManager.getTextCellEditorClass(this), - UMLEditPartFactory.getTextCellEditorLocator(this))); - } - return manager; - } - - /** - * @generated - */ - protected void setManager(DirectEditManager manager) { - this.manager = manager; - } - - /** - * @generated - */ - protected void performDirectEdit() { - BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { - - @Override - public void run() { - getManager().show(); - } - }); - } - - /** - * @generated - */ - protected void performDirectEdit(Point eventLocation) { - if (getManager() instanceof TextDirectEditManager) { - ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); - } - } - - /** - * @generated - */ - private void performDirectEdit(char initialCharacter) { - if (getManager() instanceof TextDirectEditManager) { - ((TextDirectEditManager) getManager()).show(initialCharacter); - } else { - performDirectEdit(); - } - } - - /** - * @generated - */ - @Override - protected void performDirectEditRequest(Request request) { - - final Request theRequest = request; - - if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { - directEditionMode = getDirectEditionType(); - } - switch (directEditionMode) { - case IDirectEdition.NO_DIRECT_EDITION: - // no direct edition mode => does nothing - return; - case IDirectEdition.EXTENDED_DIRECT_EDITOR: - updateExtendedEditorConfiguration(); - if (configuration == null || configuration.getLanguage() == null) { - // Create default edit manager - setManager(new MultilineLabelDirectEditManager(this, - MultilineLabelDirectEditManager.getTextCellEditorClass(this), - UMLEditPartFactory.getTextCellEditorLocator(this))); - performDefaultDirectEditorEdit(theRequest); - } else { - configuration.preEditAction(resolveSemanticElement()); - Dialog dialog = null; - if (configuration instanceof ICustomDirectEditorConfiguration) { - setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); - initializeDirectEditManager(theRequest); - return; - } else if (configuration instanceof IPopupEditorConfiguration) { - IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); - helper.showEditor(); - return; - } - else if (configuration instanceof IAdvancedEditorConfiguration) { - dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); - } else if (configuration instanceof IDirectEditorConfiguration) { - dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), - configuration); - } else { - return; - } - final Dialog finalDialog = dialog; - - if (Window.OK == dialog.open()) { - TransactionalEditingDomain domain = getEditingDomain(); - RecordingCommand command = new RecordingCommand(domain, "Edit Label") { - - @Override - protected void doExecute() { - configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); - - } - }; - domain.getCommandStack().execute(command); - } - } - break; - case IDirectEdition.DEFAULT_DIRECT_EDITOR: - initializeDirectEditManager(theRequest); - break; - default: - break; - } - } - - /** - * @generated - */ - protected void initializeDirectEditManager(final Request request) { - // initialize the direct edit manager - try { - getEditingDomain().runExclusive(new Runnable() { - @Override - public void run() { - if (isActive() && isEditable()) { - if (request.getExtendedData().get( - RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { - Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); - performDirectEdit(initialChar.charValue()); - } - else { - performDirectEdit(); - } - } - } - }); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - - /** - * @generated - */ - @Override - protected void refreshVisuals() { - super.refreshVisuals(); - refreshLabel(); - refreshFont(); - refreshFontColor(); - refreshUnderline(); - refreshStrikeThrough(); - } - - /** - * @generated - */ - protected void refreshLabel() { - EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); - if (maskLabelPolicy == null) { - maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); - } - if (maskLabelPolicy == null) { - View view = (View) getModel(); - if (view.isVisible()) { - setLabelTextHelper(getFigure(), getLabelText()); - setLabelIconHelper(getFigure(), getLabelIcon()); - } - else { - setLabelTextHelper(getFigure(), ""); //$NON-NLS-1$ - setLabelIconHelper(getFigure(), null); - } - } - Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); - if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); - } - Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); - if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); - } - } - - /** - * @generated - */ - protected void refreshUnderline() { - FontStyle style = - (FontStyle) getFontStyleOwnerView().getStyle( - NotationPackage.eINSTANCE.getFontStyle()); - if (style != null && getFigure() instanceof WrappingLabel) { - ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); - } - if (resolveSemanticElement() instanceof Feature) { - if (((Feature) resolveSemanticElement()).isStatic()) { - ((WrappingLabel) getFigure()).setTextUnderline(true); - } - else { - ((WrappingLabel) getFigure()).setTextUnderline(false); - } - } - } - - /** - * @generated - */ - protected void refreshStrikeThrough() { - FontStyle style = - (FontStyle) getFontStyleOwnerView().getStyle( - NotationPackage.eINSTANCE.getFontStyle()); - if (style != null && getFigure() instanceof WrappingLabel) { - ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); - } - } - - /** - * @generated - */ - @Override - protected void refreshFont() { - FontStyle style = - (FontStyle) getFontStyleOwnerView().getStyle( - NotationPackage.eINSTANCE.getFontStyle()); - if (style != null) { - FontData fontData = new FontData( - style.getFontName(), style.getFontHeight(), - (style.isBold() ? SWT.BOLD : SWT.NORMAL) | - (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); - setFont(fontData); - } - } - - /** - * @generated - */ - @Override - protected void setFontColor(Color color) { - getFigure().setForegroundColor(color); - } - - /** - * @generated - */ - @Override - protected void addSemanticListeners() { - if (getParser() instanceof ISemanticParser) { - EObject element = resolveSemanticElement(); - parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); - for (int i = 0; i < parserElements.size(); i++) { - addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ - } - } else { - super.addSemanticListeners(); - } - } - - /** - * @generated - */ - @Override - protected void removeSemanticListeners() { - if (parserElements != null) { - for (int i = 0; i < parserElements.size(); i++) { - removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ - } - } else { - super.removeSemanticListeners(); - } - } - - /** - * @generated - */ - @Override - protected AccessibleEditPart getAccessibleEditPart() { - if (accessibleEP == null) { - accessibleEP = new AccessibleGraphicalEditPart() { - - @Override - public void getName(AccessibleEvent e) { - e.result = getLabelTextHelper(getFigure()); - } - }; - } - return accessibleEP; - } - - /** - * @generated - */ - private View getFontStyleOwnerView() { - return getPrimaryView(); - } - - /** - * Returns the kind of associated editor for direct edition. - * - * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition - * @generated - */ - public int getDirectEditionType() { - if (checkExtendedEditor()) { - initExtendedEditorConfiguration(); - return IDirectEdition.EXTENDED_DIRECT_EDITOR; - } - if (checkDefaultEdition()) { - return IDirectEdition.DEFAULT_DIRECT_EDITOR; - } - - // not a named element. no specific editor => do nothing - return IDirectEdition.NO_DIRECT_EDITION; - } - - /** - * Checks if an extended editor is present. - * - * @return true if an extended editor is present. - * @generated - */ - protected boolean checkExtendedEditor() { - if (resolveSemanticElement() != null) { - return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); - } - return false; - } - - /** - * Checks if a default direct edition is available - * - * @return true if a default direct edition is available - * @generated - */ - protected boolean checkDefaultEdition() { - return (getParser() != null); - } - - /** - * Initializes the extended editor configuration - * - * @generated - */ - protected void initExtendedEditorConfiguration() { - if (configuration == null) { - final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); - if (languagePreferred != null && !languagePreferred.equals("")) { - configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); - } else { - configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); - } - } - } - - /** - * Updates the preference configuration - * - * @generated - */ - protected void updateExtendedEditorConfiguration() { - String languagePreferred = Activator.getDefault().getPreferenceStore().getString( - IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); - if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { - configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() - .eClass().getInstanceClassName()); - } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { - configuration = null; - } - } - - /** - * Performs the direct edit usually used by GMF editors. - * - * @param theRequest - * the direct edit request that starts the direct edit system - * @generated - */ - protected void performDefaultDirectEditorEdit(final Request theRequest) { - // initialize the direct edit manager - try { - getEditingDomain().runExclusive(new Runnable() { - - @Override - public void run() { - if (isActive() && isEditable()) { - if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { - Character initialChar = (Character) theRequest.getExtendedData().get( - RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); - performDirectEdit(initialChar.charValue()); - } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { - DirectEditRequest editRequest = (DirectEditRequest) theRequest; - performDirectEdit(editRequest.getLocation()); - } else { - performDirectEdit(); - } - } - } - }); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - - /** - * @generated - */ - @Override - protected void handleNotificationEvent(Notification event) { - Object feature = event.getFeature(); - if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { - Integer c = (Integer) event.getNewValue(); - setFontColor(DiagramColorRegistry.getInstance().getColor(c)); - } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { - refreshUnderline(); - } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { - refreshStrikeThrough(); - } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || - NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || - NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || - NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { - refreshFont(); - } else { - if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { - refreshLabel(); - } - if (getParser() instanceof ISemanticParser) { - ISemanticParser modelParser = - (ISemanticParser) getParser(); - if (modelParser.areSemanticElementsAffected(null, event)) { - removeSemanticListeners(); - if (resolveSemanticElement() != null) { - addSemanticListeners(); - } - refreshLabel(); - } - } - } - - super.handleNotificationEvent(event); - } - - /** - * @generated - */ - @Override - protected IFigure createFigure() { - // Parent should assign one using setLabel() method - return 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.uml.diagram.composite.edit.parts; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.draw2d.ConnectionLocator; +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.Label; +import org.eclipse.draw2d.geometry.Point; +import org.eclipse.emf.common.notify.Notification; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.RunnableWithResult; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gef.AccessibleEditPart; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.Request; +import org.eclipse.gef.requests.DirectEditRequest; +import org.eclipse.gef.tools.DirectEditManager; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; +import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; +import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; +import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; +import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; +import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; +import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; +import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; +import org.eclipse.gmf.runtime.notation.FontStyle; +import org.eclipse.gmf.runtime.notation.NotationPackage; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.gmf.tooling.runtime.edit.policies.DefaultLinkLabelDragPolicy; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.text.contentassist.IContentAssistProcessor; +import org.eclipse.jface.viewers.ICellEditorValidator; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.extensionpoints.editors.Activator; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; +import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; +import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; +import org.eclipse.papyrus.infra.gmfdiag.common.editpart.IControlParserForDirectEdit; +import org.eclipse.papyrus.infra.gmfdiag.common.editpart.PapyrusLabelEditPart; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.PapyrusLinkLabelDragPolicy; +import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; +import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; +import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; +import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.AbstractCustomLabelEditPolicy; +import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.InformationFlowCustomLabelEditPolicy; +import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; +import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.accessibility.AccessibleEvent; +import org.eclipse.swt.custom.BusyIndicator; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; +import org.eclipse.uml2.uml.Feature; + +/** + * @generated + */ +public class InformationFlowConveyedLabelEditPart extends PapyrusLabelEditPart implements ITextAwareEditPart, IControlParserForDirectEdit { + + /** + * @generated + */ + public static final int VISUAL_ID = 6031; + + /** + * @generated + */ + private DirectEditManager manager; + + /** + * @generated + */ + private IParser parser; + + /** + * @generated + */ + private List parserElements; + + /** + * @generated + */ + private String defaultText; + + /** + * direct edition mode (default, undefined, registered editor, etc.) + * + * @generated + */ + protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; + + /** + * configuration from a registered edit dialog + * + * @generated + */ + protected IDirectEditorConfiguration configuration; + /** + * @generated + */ + static { + registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.InformationFlowConveyedLabelEditPart.VISUAL_ID), new Point(0, 30)); + } + + /** + * @generated + */ + public InformationFlowConveyedLabelEditPart(View view) { + super(view); + } + + /** + * @generated + */ + @Override + protected void createDefaultEditPolicies() { + super.createDefaultEditPolicies(); + installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); + installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new DefaultLinkLabelDragPolicy()); + installEditPolicy(AbstractCustomLabelEditPolicy.SPECIFIC_NAME_LABEL_POLICY, new InformationFlowCustomLabelEditPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new PapyrusLinkLabelDragPolicy()); + } + + /** + * @generated + */ + @Override + public int getKeyPoint() { + return ConnectionLocator.MIDDLE; + } + + /** + * @generated + */ + protected String getLabelTextHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getText(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getText(); + } else { + return ((Label) figure).getText(); + } + } + + /** + * @generated + */ + protected void setLabelTextHelper(IFigure figure, String text) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setText(text); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setText(text); + } else { + ((Label) figure).setText(text); + } + } + + /** + * @generated + */ + protected Image getLabelIconHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getIcon(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getIcon(); + } else { + return ((Label) figure).getIcon(); + } + } + + /** + * @generated + */ + protected void setLabelIconHelper(IFigure figure, Image icon) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setIcon(icon); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setIcon(icon); + } else { + ((Label) figure).setIcon(icon); + } + } + + /** + * @generated + */ + public void setLabel(IFigure + figure) { + unregisterVisuals(); + setFigure(figure); + defaultText = getLabelTextHelper(figure); + registerVisuals(); + refreshVisuals(); + } + + /** + * @generated + */ + @Override + protected List getModelChildren() { + return Collections.EMPTY_LIST; + } + + /** + * @generated + */ + @Override + public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { + return null; + } + + /** + * @generated + */ + @Override + public void setParser(IParser parser) { + this.parser = parser; + } + + /** + * @generated + */ + protected EObject getParserElement() { + EObject element = resolveSemanticElement(); + return element != null ? element : (View) getModel(); + } + + /** + * @generated + */ + protected Image getLabelIcon() { + return null; + } + + /** + * @generated + */ + protected String getLabelText() { + String text = null; + EObject parserElement = getParserElement(); + if (parserElement != null && getParser() != null) { + text = getParser().getPrintString( + new EObjectAdapter(parserElement), + getParserOptions().intValue()); + } + if (text == null || text.length() == 0) { + text = defaultText; + } + return text; + } + + /** + * @generated + */ + @Override + public void setLabelText(String text) { + setLabelTextHelper(getFigure(), text); + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + @Override + public String getEditText() { + if (getParserElement() == null || getParser() == null) { + return ""; //$NON-NLS-1$ + } + return getParser().getEditString( + new EObjectAdapter(getParserElement()), + getParserOptions().intValue()); + } + + /** + * @generated + */ + protected boolean isEditable() { + return getParser() != null; + } + + /** + * @generated + */ + @Override + public ICellEditorValidator getEditTextValidator() { + return new ICellEditorValidator() { + + @Override + public String isValid(final Object value) { + if (value instanceof String) { + final EObject element = getParserElement(); + final IParser parser = getParser(); + try { + IParserEditStatus valid = + (IParserEditStatus) getEditingDomain().runExclusive( + new RunnableWithResult.Impl() { + + @Override + public void run() { + setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); + } + }); + return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); + } catch (InterruptedException ie) { + ie.printStackTrace(); + } + } + + // shouldn't get here + return null; + } + }; + } + + /** + * @generated + */ + @Override + public IContentAssistProcessor getCompletionProcessor() { + if (getParserElement() == null || getParser() == null) { + return null; + } + return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); + } + + /** + * @generated + */ + @Override + public ParserOptions getParserOptions() { + return ParserOptions.NONE; + } + + /** + * @generated + */ + @Override + public IParser getParser() { + if (parser == null) { + parser = UMLParserProvider.getParser(UMLElementTypes.InformationFlow_4021, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.InformationFlowConveyedLabelEditPart.VISUAL_ID)); + } + return parser; + } + + /** + * @generated + */ + protected DirectEditManager getManager() { + if (manager == null) { + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + } + return manager; + } + + /** + * @generated + */ + protected void setManager(DirectEditManager manager) { + this.manager = manager; + } + + /** + * @generated + */ + protected void performDirectEdit() { + BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { + + @Override + public void run() { + getManager().show(); + } + }); + } + + /** + * @generated + */ + protected void performDirectEdit(Point eventLocation) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); + } + } + + /** + * @generated + */ + private void performDirectEdit(char initialCharacter) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(initialCharacter); + } else { + performDirectEdit(); + } + } + + /** + * @generated + */ + @Override + protected void performDirectEditRequest(Request request) { + + final Request theRequest = request; + + if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { + directEditionMode = getDirectEditionType(); + } + switch (directEditionMode) { + case IDirectEdition.NO_DIRECT_EDITION: + // no direct edition mode => does nothing + return; + case IDirectEdition.EXTENDED_DIRECT_EDITOR: + updateExtendedEditorConfiguration(); + if (configuration == null || configuration.getLanguage() == null) { + // Create default edit manager + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + performDefaultDirectEditorEdit(theRequest); + } else { + configuration.preEditAction(resolveSemanticElement()); + Dialog dialog = null; + if (configuration instanceof ICustomDirectEditorConfiguration) { + setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); + initializeDirectEditManager(theRequest); + return; + } else if (configuration instanceof IPopupEditorConfiguration) { + IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); + helper.showEditor(); + return; + } + else if (configuration instanceof IAdvancedEditorConfiguration) { + dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); + } else if (configuration instanceof IDirectEditorConfiguration) { + dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), + configuration); + } else { + return; + } + final Dialog finalDialog = dialog; + + if (Window.OK == dialog.open()) { + TransactionalEditingDomain domain = getEditingDomain(); + RecordingCommand command = new RecordingCommand(domain, "Edit Label") { + + @Override + protected void doExecute() { + configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); + + } + }; + domain.getCommandStack().execute(command); + } + } + break; + case IDirectEdition.DEFAULT_DIRECT_EDITOR: + initializeDirectEditManager(theRequest); + break; + default: + break; + } + } + + /** + * @generated + */ + protected void initializeDirectEditManager(final Request request) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + @Override + public void run() { + if (isActive() && isEditable()) { + if (request.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } + else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void refreshVisuals() { + super.refreshVisuals(); + refreshLabel(); + refreshFont(); + refreshFontColor(); + refreshUnderline(); + refreshStrikeThrough(); + } + + /** + * @generated + */ + protected void refreshLabel() { + EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); + if (maskLabelPolicy == null) { + maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); + } + if (maskLabelPolicy == null) { + setLabelTextHelper(getFigure(), getLabelText()); + setLabelIconHelper(getFigure(), getLabelIcon()); + } + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + protected void refreshUnderline() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); + } + if (resolveSemanticElement() instanceof Feature) { + if (((Feature) resolveSemanticElement()).isStatic()) { + ((WrappingLabel) getFigure()).setTextUnderline(true); + } + else { + ((WrappingLabel) getFigure()).setTextUnderline(false); + } + } + } + + /** + * @generated + */ + protected void refreshStrikeThrough() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); + } + } + + /** + * @generated + */ + @Override + protected void refreshFont() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null) { + FontData fontData = new FontData( + style.getFontName(), style.getFontHeight(), + (style.isBold() ? SWT.BOLD : SWT.NORMAL) | + (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); + setFont(fontData); + } + } + + /** + * @generated + */ + @Override + protected void setFontColor(Color color) { + getFigure().setForegroundColor(color); + } + + /** + * @generated + */ + @Override + protected void addSemanticListeners() { + if (getParser() instanceof ISemanticParser) { + EObject element = resolveSemanticElement(); + parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); + for (int i = 0; i < parserElements.size(); i++) { + addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ + } + } else { + super.addSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected void removeSemanticListeners() { + if (parserElements != null) { + for (int i = 0; i < parserElements.size(); i++) { + removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ + } + } else { + super.removeSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected AccessibleEditPart getAccessibleEditPart() { + if (accessibleEP == null) { + accessibleEP = new AccessibleGraphicalEditPart() { + + @Override + public void getName(AccessibleEvent e) { + e.result = getLabelTextHelper(getFigure()); + } + }; + } + return accessibleEP; + } + + /** + * @generated + */ + private View getFontStyleOwnerView() { + return getPrimaryView(); + } + + /** + * Returns the kind of associated editor for direct edition. + * + * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition + * @generated + */ + public int getDirectEditionType() { + if (checkExtendedEditor()) { + initExtendedEditorConfiguration(); + return IDirectEdition.EXTENDED_DIRECT_EDITOR; + } + if (checkDefaultEdition()) { + return IDirectEdition.DEFAULT_DIRECT_EDITOR; + } + + // not a named element. no specific editor => do nothing + return IDirectEdition.NO_DIRECT_EDITION; + } + + /** + * Checks if an extended editor is present. + * + * @return true if an extended editor is present. + * @generated + */ + protected boolean checkExtendedEditor() { + if (resolveSemanticElement() != null) { + return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); + } + return false; + } + + /** + * Checks if a default direct edition is available + * + * @return true if a default direct edition is available + * @generated + */ + protected boolean checkDefaultEdition() { + return (getParser() != null); + } + + /** + * Initializes the extended editor configuration + * + * @generated + */ + protected void initExtendedEditorConfiguration() { + if (configuration == null) { + final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("")) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); + } else { + configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); + } + } + } + + /** + * Updates the preference configuration + * + * @generated + */ + protected void updateExtendedEditorConfiguration() { + String languagePreferred = Activator.getDefault().getPreferenceStore().getString( + IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() + .eClass().getInstanceClassName()); + } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { + configuration = null; + } + } + + /** + * Performs the direct edit usually used by GMF editors. + * + * @param theRequest + * the direct edit request that starts the direct edit system + * @generated + */ + protected void performDefaultDirectEditorEdit(final Request theRequest) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + + @Override + public void run() { + if (isActive() && isEditable()) { + if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) theRequest.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { + DirectEditRequest editRequest = (DirectEditRequest) theRequest; + performDirectEdit(editRequest.getLocation()); + } else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void handleNotificationEvent(Notification event) { + Object feature = event.getFeature(); + if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { + Integer c = (Integer) event.getNewValue(); + setFontColor(DiagramColorRegistry.getInstance().getColor(c)); + } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { + refreshUnderline(); + } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { + refreshStrikeThrough(); + } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { + refreshFont(); + } else { + if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { + refreshLabel(); + } + if (getParser() instanceof ISemanticParser) { + ISemanticParser modelParser = + (ISemanticParser) getParser(); + if (modelParser.areSemanticElementsAffected(null, event)) { + removeSemanticListeners(); + if (resolveSemanticElement() != null) { + addSemanticListeners(); + } + refreshLabel(); + } + } + } + + super.handleNotificationEvent(event); + } + + /** + * @generated + */ + @Override + protected IFigure createFigure() { + // Parent should assign one using setLabel() method + return null; + } +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InformationItemEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InformationItemEditPart.java index 86d7a57ecdf..de5d86e5ca6 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InformationItemEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InformationItemEditPart.java @@ -11,27 +11,39 @@ */ package org.eclipse.papyrus.uml.diagram.composite.edit.parts; +import java.util.Collections; +import java.util.List; + import org.eclipse.draw2d.IFigure; import org.eclipse.emf.common.notify.Notification; import org.eclipse.gef.EditPart; import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.GraphicalEditPart; 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.handles.MoveHandle; import org.eclipse.gef.requests.CreateRequest; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.BorderItemSelectionEditPolicy; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles; +import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; -import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure; import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure; +import org.eclipse.gmf.runtime.notation.Edge; +import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.GetChildLayoutEditPolicy; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.IPapyrusNodeFigure; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.RoundedRectangleNodePlateFigure; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.SelectableBorderedNodeFigure; -import org.eclipse.papyrus.uml.diagram.common.editparts.NamedElementEditPart; +import org.eclipse.papyrus.uml.diagram.common.editparts.RoundedCompartmentEditPart; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeNodeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.QualifiedNameDisplayEditPolicy; +import org.eclipse.papyrus.uml.diagram.common.locator.RoundedRectangleLabelPositionLocator; import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.CustomDiagramDragDropEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.custom.figures.InformationItemFigure; import org.eclipse.papyrus.uml.diagram.composite.edit.policies.InformationItemItemSemanticEditPolicy; @@ -41,7 +53,7 @@ import org.eclipse.swt.graphics.Color; /** * @generated */ -public class InformationItemEditPart extends NamedElementEditPart { +public class InformationItemEditPart extends RoundedCompartmentEditPart { /** * @generated @@ -76,6 +88,7 @@ public class InformationItemEditPart extends NamedElementEditPart { installEditPolicy(QualifiedNameDisplayEditPolicy.QUALIFIED_NAME_POLICY, new QualifiedNameDisplayEditPolicy()); installEditPolicy(AppliedStereotypeLabelDisplayEditPolicy.STEREOTYPE_LABEL_POLICY, new AppliedStereotypeNodeLabelDisplayEditPolicy()); installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, new CustomDiagramDragDropEditPolicy()); + installEditPolicy(EditPolicy.LAYOUT_ROLE, new GetChildLayoutEditPolicy()); // XXX need an SCR to runtime to have another abstract superclass that would let children add reasonable editpolicies // removeEditPolicy(org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles.CONNECTION_HANDLES_ROLE); } @@ -88,6 +101,20 @@ public class InformationItemEditPart extends NamedElementEditPart { @Override protected EditPolicy createChildEditPolicy(EditPart child) { + View childView = (View) child.getModel(); + switch (UMLVisualIDRegistry.getVisualID(childView)) { + case InformationItemFloatingLabelEditPart.VISUAL_ID: + return new BorderItemSelectionEditPolicy() { + + @Override + protected List createSelectionHandles() { + MoveHandle mh = new MoveHandle((GraphicalEditPart) getHost()); + mh.setBorder(null); + return Collections.singletonList(mh); + } + } + ; + } EditPolicy result = child.getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); if (result == null) { result = new NonResizableEditPolicy(); @@ -115,6 +142,19 @@ public class InformationItemEditPart extends NamedElementEditPart { **/ @Override protected void handleNotificationEvent(Notification event) { + /* + * when a node have external node labels, the methods refreshChildren() remove the EditPart corresponding to the Label from the EditPart + * Registry. After that, we can't reset the visibility to true (using the Show/Hide Label Action)! + */ + if (NotationPackage.eINSTANCE.getView_Visible().equals(event.getFeature())) { + Object notifier = event.getNotifier(); + List modelChildren = ((View) getModel()).getChildren(); + if (!(notifier instanceof Edge)) { + if (modelChildren.contains(event.getNotifier())) { + return; + } + } + } super.handleNotificationEvent(event); } @@ -187,15 +227,32 @@ public class InformationItemEditPart extends NamedElementEditPart { */ @Override protected IFigure getContentPaneFor(IGraphicalEditPart editPart) { + if (editPart instanceof IBorderItemEditPart) { + return getBorderedFigure().getBorderItemContainer(); + } return getContentPane(); } + /** + * @generated + */ + @Override + protected void addBorderItem(IFigure borderItemContainer, IBorderItemEditPart borderItemEditPart) { + if (borderItemEditPart instanceof InformationItemFloatingLabelEditPart) { + IBorderItemLocator locator = new RoundedRectangleLabelPositionLocator(getMainFigure()); + borderItemContainer.add(borderItemEditPart.getFigure(), locator); + } else + { + super.addBorderItem(borderItemContainer, borderItemEditPart); + } + } + /** * @generated */ @Override protected NodeFigure createNodePlate() { - DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(80, 40); + RoundedRectangleNodePlateFigure result = new RoundedRectangleNodePlateFigure(80, 40); return result; } @@ -208,7 +265,7 @@ public class InformationItemEditPart extends NamedElementEditPart { * @generated */ @Override - protected NodeFigure createNodeFigure() { + protected NodeFigure createMainFigure() { return new SelectableBorderedNodeFigure(createMainFigureWithSVG()); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InformationItemEditPartCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InformationItemEditPartCN.java index cc8d167b5cf..abda0ea7bc7 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InformationItemEditPartCN.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InformationItemEditPartCN.java @@ -11,27 +11,39 @@ */ package org.eclipse.papyrus.uml.diagram.composite.edit.parts; +import java.util.Collections; +import java.util.List; + import org.eclipse.draw2d.IFigure; import org.eclipse.emf.common.notify.Notification; import org.eclipse.gef.EditPart; import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.GraphicalEditPart; 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.handles.MoveHandle; import org.eclipse.gef.requests.CreateRequest; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.BorderItemSelectionEditPolicy; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles; +import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; -import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure; import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure; +import org.eclipse.gmf.runtime.notation.Edge; +import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.GetChildLayoutEditPolicy; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.IPapyrusNodeFigure; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.RoundedRectangleNodePlateFigure; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.SelectableBorderedNodeFigure; -import org.eclipse.papyrus.uml.diagram.common.editparts.NamedElementEditPart; +import org.eclipse.papyrus.uml.diagram.common.editparts.RoundedCompartmentEditPart; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeNodeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.QualifiedNameDisplayEditPolicy; +import org.eclipse.papyrus.uml.diagram.common.locator.RoundedRectangleLabelPositionLocator; import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.CustomDiagramDragDropEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.custom.figures.InformationItemFigure; import org.eclipse.papyrus.uml.diagram.composite.edit.policies.InformationItemItemSemanticEditPolicyCN; @@ -41,7 +53,7 @@ import org.eclipse.swt.graphics.Color; /** * @generated */ -public class InformationItemEditPartCN extends NamedElementEditPart { +public class InformationItemEditPartCN extends RoundedCompartmentEditPart { /** * @generated @@ -76,6 +88,7 @@ public class InformationItemEditPartCN extends NamedElementEditPart { installEditPolicy(QualifiedNameDisplayEditPolicy.QUALIFIED_NAME_POLICY, new QualifiedNameDisplayEditPolicy()); installEditPolicy(AppliedStereotypeLabelDisplayEditPolicy.STEREOTYPE_LABEL_POLICY, new AppliedStereotypeNodeLabelDisplayEditPolicy()); installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, new CustomDiagramDragDropEditPolicy()); + installEditPolicy(EditPolicy.LAYOUT_ROLE, new GetChildLayoutEditPolicy()); // XXX need an SCR to runtime to have another abstract superclass that would let children add reasonable editpolicies // removeEditPolicy(org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles.CONNECTION_HANDLES_ROLE); } @@ -88,6 +101,20 @@ public class InformationItemEditPartCN extends NamedElementEditPart { @Override protected EditPolicy createChildEditPolicy(EditPart child) { + View childView = (View) child.getModel(); + switch (UMLVisualIDRegistry.getVisualID(childView)) { + case InformationItemFloatingLabelEditPartCN.VISUAL_ID: + return new BorderItemSelectionEditPolicy() { + + @Override + protected List createSelectionHandles() { + MoveHandle mh = new MoveHandle((GraphicalEditPart) getHost()); + mh.setBorder(null); + return Collections.singletonList(mh); + } + } + ; + } EditPolicy result = child.getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); if (result == null) { result = new NonResizableEditPolicy(); @@ -115,6 +142,19 @@ public class InformationItemEditPartCN extends NamedElementEditPart { **/ @Override protected void handleNotificationEvent(Notification event) { + /* + * when a node have external node labels, the methods refreshChildren() remove the EditPart corresponding to the Label from the EditPart + * Registry. After that, we can't reset the visibility to true (using the Show/Hide Label Action)! + */ + if (NotationPackage.eINSTANCE.getView_Visible().equals(event.getFeature())) { + Object notifier = event.getNotifier(); + List modelChildren = ((View) getModel()).getChildren(); + if (!(notifier instanceof Edge)) { + if (modelChildren.contains(event.getNotifier())) { + return; + } + } + } super.handleNotificationEvent(event); } @@ -187,15 +227,32 @@ public class InformationItemEditPartCN extends NamedElementEditPart { */ @Override protected IFigure getContentPaneFor(IGraphicalEditPart editPart) { + if (editPart instanceof IBorderItemEditPart) { + return getBorderedFigure().getBorderItemContainer(); + } return getContentPane(); } + /** + * @generated + */ + @Override + protected void addBorderItem(IFigure borderItemContainer, IBorderItemEditPart borderItemEditPart) { + if (borderItemEditPart instanceof InformationItemFloatingLabelEditPartCN) { + IBorderItemLocator locator = new RoundedRectangleLabelPositionLocator(getMainFigure()); + borderItemContainer.add(borderItemEditPart.getFigure(), locator); + } else + { + super.addBorderItem(borderItemContainer, borderItemEditPart); + } + } + /** * @generated */ @Override protected NodeFigure createNodePlate() { - DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(80, 40); + RoundedRectangleNodePlateFigure result = new RoundedRectangleNodePlateFigure(80, 40); return result; } @@ -208,7 +265,7 @@ public class InformationItemEditPartCN extends NamedElementEditPart { * @generated */ @Override - protected NodeFigure createNodeFigure() { + protected NodeFigure createMainFigure() { return new SelectableBorderedNodeFigure(createMainFigureWithSVG()); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InformationItemFloatingLabelEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InformationItemFloatingLabelEditPart.java new file mode 100644 index 00000000000..c212912a368 --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InformationItemFloatingLabelEditPart.java @@ -0,0 +1,860 @@ +/** + * 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.uml.diagram.composite.edit.parts; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.Label; +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.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.RunnableWithResult; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gef.AccessibleEditPart; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.Request; +import org.eclipse.gef.requests.DirectEditRequest; +import org.eclipse.gef.tools.DirectEditManager; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; +import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; +import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; +import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; +import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; +import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; +import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; +import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; +import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; +import org.eclipse.gmf.runtime.notation.FontStyle; +import org.eclipse.gmf.runtime.notation.NotationPackage; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.text.contentassist.IContentAssistProcessor; +import org.eclipse.jface.viewers.ICellEditorValidator; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.extensionpoints.editors.Activator; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; +import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; +import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.ExternalLabelPrimaryDragRoleEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.PapyrusWrappingLabel; +import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; +import org.eclipse.papyrus.uml.diagram.common.editparts.FloatingLabelEditPart; +import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; +import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; +import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; +import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.accessibility.AccessibleEvent; +import org.eclipse.swt.custom.BusyIndicator; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; +import org.eclipse.uml2.uml.Feature; + +/** + * @generated + */ +public class InformationItemFloatingLabelEditPart extends FloatingLabelEditPart + implements ITextAwareEditPart, IBorderItemEditPart +{ + + /** + * @generated + */ + public static final int VISUAL_ID = 6098; + + /** + * @generated + */ + private DirectEditManager manager; + + /** + * @generated + */ + private IParser parser; + + /** + * @generated + */ + private List parserElements; + + /** + * @generated + */ + private String defaultText; + + /** + * direct edition mode (default, undefined, registered editor, etc.) + * + * @generated + */ + protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; + + /** + * configuration from a registered edit dialog + * + * @generated + */ + protected IDirectEditorConfiguration configuration; + + + /** + * @generated + */ + static { + registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.InformationItemFloatingLabelEditPart.VISUAL_ID), new Point(0, 0)); + } + + /** + * @generated + */ + public InformationItemFloatingLabelEditPart(View view) { + super(view); + } + + /** + * @generated + */ + @Override + protected void createDefaultEditPolicies() { + super.createDefaultEditPolicies(); + installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); + installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ExternalLabelPrimaryDragRoleEditPolicy()); + } + + /** + * @generated + */ + @Override + public IBorderItemLocator getBorderItemLocator() { + IFigure parentFigure = getFigure().getParent(); + if (parentFigure != null && parentFigure.getLayoutManager() != null) { + Object constraint = parentFigure.getLayoutManager().getConstraint(getFigure()); + return (IBorderItemLocator) constraint; + } + return null; + } + + /** + * @generated + */ + @Override + public void refreshBounds() { + int x = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_X())).intValue(); + int y = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_Y())).intValue(); + int width = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Width())).intValue(); + int height = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Height())).intValue(); + getBorderItemLocator().setConstraint(new Rectangle(x, y, width, height)); + } + + + /** + * @generated + */ + protected String getLabelTextHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getText(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getText(); + } else { + return ((Label) figure).getText(); + } + } + + /** + * @generated + */ + protected void setLabelTextHelper(IFigure figure, String text) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setText(text); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setText(text); + } else { + ((Label) figure).setText(text); + } + } + + /** + * @generated + */ + protected Image getLabelIconHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getIcon(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getIcon(); + } else { + return ((Label) figure).getIcon(); + } + } + + /** + * @generated + */ + protected void setLabelIconHelper(IFigure figure, Image icon) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setIcon(icon); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setIcon(icon); + } else { + ((Label) figure).setIcon(icon); + } + } + + /** + * @generated + */ + public void setLabel(IFigure + figure) { + unregisterVisuals(); + setFigure(figure); + defaultText = getLabelTextHelper(figure); + registerVisuals(); + refreshVisuals(); + } + + /** + * @generated + */ + @Override + protected List getModelChildren() { + return Collections.EMPTY_LIST; + } + + /** + * @generated + */ + @Override + public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { + return null; + } + + /** + * @generated + */ + public void setParser(IParser parser) { + this.parser = parser; + } + + /** + * @generated + */ + protected EObject getParserElement() { + return resolveSemanticElement(); + } + + /** + * @generated + */ + protected Image getLabelIcon() { + return null; + } + + /** + * @generated + */ + protected String getLabelText() { + String text = null; + EObject parserElement = getParserElement(); + if (parserElement != null && getParser() != null) { + text = getParser().getPrintString( + new EObjectAdapter(parserElement), + getParserOptions().intValue()); + } + if (text == null || text.length() == 0) { + text = defaultText; + } + return text; + } + + /** + * @generated + */ + @Override + public void setLabelText(String text) { + setLabelTextHelper(getFigure(), text); + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + @Override + public String getEditText() { + if (getParserElement() == null || getParser() == null) { + return ""; //$NON-NLS-1$ + } + return getParser().getEditString( + new EObjectAdapter(getParserElement()), + getParserOptions().intValue()); + } + + /** + * @generated + */ + protected boolean isEditable() { + return getParser() != null; + } + + /** + * @generated + */ + @Override + public ICellEditorValidator getEditTextValidator() { + return new ICellEditorValidator() { + + @Override + public String isValid(final Object value) { + if (value instanceof String) { + final EObject element = getParserElement(); + final IParser parser = getParser(); + try { + IParserEditStatus valid = + (IParserEditStatus) getEditingDomain().runExclusive( + new RunnableWithResult.Impl() { + + @Override + public void run() { + setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); + } + }); + return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); + } catch (InterruptedException ie) { + ie.printStackTrace(); + } + } + + // shouldn't get here + return null; + } + }; + } + + /** + * @generated + */ + @Override + public IContentAssistProcessor getCompletionProcessor() { + if (getParserElement() == null || getParser() == null) { + return null; + } + return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); + } + + /** + * @generated + */ + @Override + public ParserOptions getParserOptions() { + return ParserOptions.NONE; + } + + /** + * @generated + */ + @Override + public IParser getParser() { + if (parser == null) { + parser = UMLParserProvider.getParser(UMLElementTypes.InformationItem_2080, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.InformationItemFloatingLabelEditPart.VISUAL_ID)); + } + return parser; + } + + /** + * @generated + */ + protected DirectEditManager getManager() { + if (manager == null) { + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + } + return manager; + } + + /** + * @generated + */ + protected void setManager(DirectEditManager manager) { + this.manager = manager; + } + + /** + * @generated + */ + protected void performDirectEdit() { + BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { + + @Override + public void run() { + getManager().show(); + } + }); + } + + /** + * @generated + */ + protected void performDirectEdit(Point eventLocation) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); + } + } + + /** + * @generated + */ + private void performDirectEdit(char initialCharacter) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(initialCharacter); + } else { + performDirectEdit(); + } + } + + /** + * @generated + */ + @Override + protected void performDirectEditRequest(Request request) { + + final Request theRequest = request; + + if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { + directEditionMode = getDirectEditionType(); + } + switch (directEditionMode) { + case IDirectEdition.NO_DIRECT_EDITION: + // no direct edition mode => does nothing + return; + case IDirectEdition.EXTENDED_DIRECT_EDITOR: + updateExtendedEditorConfiguration(); + if (configuration == null || configuration.getLanguage() == null) { + // Create default edit manager + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + performDefaultDirectEditorEdit(theRequest); + } else { + configuration.preEditAction(resolveSemanticElement()); + Dialog dialog = null; + if (configuration instanceof ICustomDirectEditorConfiguration) { + setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); + initializeDirectEditManager(theRequest); + return; + } else if (configuration instanceof IPopupEditorConfiguration) { + IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); + helper.showEditor(); + return; + } + else if (configuration instanceof IAdvancedEditorConfiguration) { + dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); + } else if (configuration instanceof IDirectEditorConfiguration) { + dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), + configuration); + } else { + return; + } + final Dialog finalDialog = dialog; + + if (Window.OK == dialog.open()) { + TransactionalEditingDomain domain = getEditingDomain(); + RecordingCommand command = new RecordingCommand(domain, "Edit Label") { + + @Override + protected void doExecute() { + configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); + + } + }; + domain.getCommandStack().execute(command); + } + } + break; + case IDirectEdition.DEFAULT_DIRECT_EDITOR: + initializeDirectEditManager(theRequest); + break; + default: + break; + } + } + + /** + * @generated + */ + protected void initializeDirectEditManager(final Request request) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + @Override + public void run() { + if (isActive() && isEditable()) { + if (request.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } + else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void refreshVisuals() { + super.refreshVisuals(); + refreshLabel(); + refreshFont(); + refreshFontColor(); + refreshUnderline(); + refreshStrikeThrough(); + } + + /** + * @generated + */ + protected void refreshLabel() { + EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); + if (maskLabelPolicy == null) { + maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); + } + if (maskLabelPolicy == null) { + View view = (View) getModel(); + if (view.isVisible()) { + setLabelTextHelper(getFigure(), getLabelText()); + setLabelIconHelper(getFigure(), getLabelIcon()); + } + else { + setLabelTextHelper(getFigure(), ""); //$NON-NLS-1$ + setLabelIconHelper(getFigure(), null); + } + } + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + protected void refreshUnderline() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); + } + if (resolveSemanticElement() instanceof Feature) { + if (((Feature) resolveSemanticElement()).isStatic()) { + ((WrappingLabel) getFigure()).setTextUnderline(true); + } + else { + ((WrappingLabel) getFigure()).setTextUnderline(false); + } + } + } + + /** + * @generated + */ + protected void refreshStrikeThrough() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); + } + } + + /** + * @generated + */ + @Override + protected void refreshFont() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null) { + FontData fontData = new FontData( + style.getFontName(), style.getFontHeight(), + (style.isBold() ? SWT.BOLD : SWT.NORMAL) | + (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); + setFont(fontData); + } + } + + /** + * @generated + */ + @Override + protected void setFontColor(Color color) { + getFigure().setForegroundColor(color); + } + + /** + * @generated + */ + @Override + protected void addSemanticListeners() { + if (getParser() instanceof ISemanticParser) { + EObject element = resolveSemanticElement(); + parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); + for (int i = 0; i < parserElements.size(); i++) { + addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ + } + } else { + super.addSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected void removeSemanticListeners() { + if (parserElements != null) { + for (int i = 0; i < parserElements.size(); i++) { + removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ + } + } else { + super.removeSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected AccessibleEditPart getAccessibleEditPart() { + if (accessibleEP == null) { + accessibleEP = new AccessibleGraphicalEditPart() { + + @Override + public void getName(AccessibleEvent e) { + e.result = getLabelTextHelper(getFigure()); + } + }; + } + return accessibleEP; + } + + /** + * @generated + */ + private View getFontStyleOwnerView() { + return getPrimaryView(); + } + + /** + * Returns the kind of associated editor for direct edition. + * + * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition + * @generated + */ + public int getDirectEditionType() { + if (checkExtendedEditor()) { + initExtendedEditorConfiguration(); + return IDirectEdition.EXTENDED_DIRECT_EDITOR; + } + if (checkDefaultEdition()) { + return IDirectEdition.DEFAULT_DIRECT_EDITOR; + } + + // not a named element. no specific editor => do nothing + return IDirectEdition.NO_DIRECT_EDITION; + } + + /** + * Checks if an extended editor is present. + * + * @return true if an extended editor is present. + * @generated + */ + protected boolean checkExtendedEditor() { + if (resolveSemanticElement() != null) { + return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); + } + return false; + } + + /** + * Checks if a default direct edition is available + * + * @return true if a default direct edition is available + * @generated + */ + protected boolean checkDefaultEdition() { + return (getParser() != null); + } + + /** + * Initializes the extended editor configuration + * + * @generated + */ + protected void initExtendedEditorConfiguration() { + if (configuration == null) { + final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("")) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); + } else { + configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); + } + } + } + + /** + * Updates the preference configuration + * + * @generated + */ + protected void updateExtendedEditorConfiguration() { + String languagePreferred = Activator.getDefault().getPreferenceStore().getString( + IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() + .eClass().getInstanceClassName()); + } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { + configuration = null; + } + } + + /** + * Performs the direct edit usually used by GMF editors. + * + * @param theRequest + * the direct edit request that starts the direct edit system + * @generated + */ + protected void performDefaultDirectEditorEdit(final Request theRequest) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + + @Override + public void run() { + if (isActive() && isEditable()) { + if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) theRequest.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { + DirectEditRequest editRequest = (DirectEditRequest) theRequest; + performDirectEdit(editRequest.getLocation()); + } else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + + /** + * @generated + */ + @Override + protected void handleNotificationEvent(Notification event) { + Object feature = event.getFeature(); + if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { + Integer c = (Integer) event.getNewValue(); + setFontColor(DiagramColorRegistry.getInstance().getColor(c)); + } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { + refreshUnderline(); + } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { + refreshStrikeThrough(); + } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { + refreshFont(); + } else { + if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { + refreshLabel(); + } + if (getParser() instanceof ISemanticParser) { + ISemanticParser modelParser = + (ISemanticParser) getParser(); + if (modelParser.areSemanticElementsAffected(null, event)) { + removeSemanticListeners(); + if (resolveSemanticElement() != null) { + addSemanticListeners(); + } + refreshLabel(); + } + } + } + super.handleNotificationEvent(event); + } + + /** + * @generated + */ + @Override + protected IFigure createFigure() { + IFigure label = createFigurePrim(); + defaultText = getLabelTextHelper(label); + return label; + } + + /** + * @generated + */ + protected IFigure createFigurePrim() { + return new PapyrusWrappingLabel(); + } + +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InformationItemFloatingLabelEditPartCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InformationItemFloatingLabelEditPartCN.java new file mode 100644 index 00000000000..a5b8dc28ff5 --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InformationItemFloatingLabelEditPartCN.java @@ -0,0 +1,860 @@ +/** + * 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.uml.diagram.composite.edit.parts; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.Label; +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.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.RunnableWithResult; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gef.AccessibleEditPart; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.Request; +import org.eclipse.gef.requests.DirectEditRequest; +import org.eclipse.gef.tools.DirectEditManager; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; +import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; +import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; +import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; +import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; +import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; +import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; +import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; +import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; +import org.eclipse.gmf.runtime.notation.FontStyle; +import org.eclipse.gmf.runtime.notation.NotationPackage; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.text.contentassist.IContentAssistProcessor; +import org.eclipse.jface.viewers.ICellEditorValidator; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.extensionpoints.editors.Activator; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; +import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; +import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.ExternalLabelPrimaryDragRoleEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.PapyrusWrappingLabel; +import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; +import org.eclipse.papyrus.uml.diagram.common.editparts.FloatingLabelEditPart; +import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; +import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; +import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; +import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.accessibility.AccessibleEvent; +import org.eclipse.swt.custom.BusyIndicator; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; +import org.eclipse.uml2.uml.Feature; + +/** + * @generated + */ +public class InformationItemFloatingLabelEditPartCN extends FloatingLabelEditPart + implements ITextAwareEditPart, IBorderItemEditPart +{ + + /** + * @generated + */ + public static final int VISUAL_ID = 6076; + + /** + * @generated + */ + private DirectEditManager manager; + + /** + * @generated + */ + private IParser parser; + + /** + * @generated + */ + private List parserElements; + + /** + * @generated + */ + private String defaultText; + + /** + * direct edition mode (default, undefined, registered editor, etc.) + * + * @generated + */ + protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; + + /** + * configuration from a registered edit dialog + * + * @generated + */ + protected IDirectEditorConfiguration configuration; + + + /** + * @generated + */ + static { + registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.InformationItemFloatingLabelEditPartCN.VISUAL_ID), new Point(0, 0)); + } + + /** + * @generated + */ + public InformationItemFloatingLabelEditPartCN(View view) { + super(view); + } + + /** + * @generated + */ + @Override + protected void createDefaultEditPolicies() { + super.createDefaultEditPolicies(); + installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); + installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ExternalLabelPrimaryDragRoleEditPolicy()); + } + + /** + * @generated + */ + @Override + public IBorderItemLocator getBorderItemLocator() { + IFigure parentFigure = getFigure().getParent(); + if (parentFigure != null && parentFigure.getLayoutManager() != null) { + Object constraint = parentFigure.getLayoutManager().getConstraint(getFigure()); + return (IBorderItemLocator) constraint; + } + return null; + } + + /** + * @generated + */ + @Override + public void refreshBounds() { + int x = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_X())).intValue(); + int y = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_Y())).intValue(); + int width = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Width())).intValue(); + int height = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Height())).intValue(); + getBorderItemLocator().setConstraint(new Rectangle(x, y, width, height)); + } + + + /** + * @generated + */ + protected String getLabelTextHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getText(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getText(); + } else { + return ((Label) figure).getText(); + } + } + + /** + * @generated + */ + protected void setLabelTextHelper(IFigure figure, String text) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setText(text); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setText(text); + } else { + ((Label) figure).setText(text); + } + } + + /** + * @generated + */ + protected Image getLabelIconHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getIcon(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getIcon(); + } else { + return ((Label) figure).getIcon(); + } + } + + /** + * @generated + */ + protected void setLabelIconHelper(IFigure figure, Image icon) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setIcon(icon); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setIcon(icon); + } else { + ((Label) figure).setIcon(icon); + } + } + + /** + * @generated + */ + public void setLabel(IFigure + figure) { + unregisterVisuals(); + setFigure(figure); + defaultText = getLabelTextHelper(figure); + registerVisuals(); + refreshVisuals(); + } + + /** + * @generated + */ + @Override + protected List getModelChildren() { + return Collections.EMPTY_LIST; + } + + /** + * @generated + */ + @Override + public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { + return null; + } + + /** + * @generated + */ + public void setParser(IParser parser) { + this.parser = parser; + } + + /** + * @generated + */ + protected EObject getParserElement() { + return resolveSemanticElement(); + } + + /** + * @generated + */ + protected Image getLabelIcon() { + return null; + } + + /** + * @generated + */ + protected String getLabelText() { + String text = null; + EObject parserElement = getParserElement(); + if (parserElement != null && getParser() != null) { + text = getParser().getPrintString( + new EObjectAdapter(parserElement), + getParserOptions().intValue()); + } + if (text == null || text.length() == 0) { + text = defaultText; + } + return text; + } + + /** + * @generated + */ + @Override + public void setLabelText(String text) { + setLabelTextHelper(getFigure(), text); + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + @Override + public String getEditText() { + if (getParserElement() == null || getParser() == null) { + return ""; //$NON-NLS-1$ + } + return getParser().getEditString( + new EObjectAdapter(getParserElement()), + getParserOptions().intValue()); + } + + /** + * @generated + */ + protected boolean isEditable() { + return getParser() != null; + } + + /** + * @generated + */ + @Override + public ICellEditorValidator getEditTextValidator() { + return new ICellEditorValidator() { + + @Override + public String isValid(final Object value) { + if (value instanceof String) { + final EObject element = getParserElement(); + final IParser parser = getParser(); + try { + IParserEditStatus valid = + (IParserEditStatus) getEditingDomain().runExclusive( + new RunnableWithResult.Impl() { + + @Override + public void run() { + setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); + } + }); + return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); + } catch (InterruptedException ie) { + ie.printStackTrace(); + } + } + + // shouldn't get here + return null; + } + }; + } + + /** + * @generated + */ + @Override + public IContentAssistProcessor getCompletionProcessor() { + if (getParserElement() == null || getParser() == null) { + return null; + } + return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); + } + + /** + * @generated + */ + @Override + public ParserOptions getParserOptions() { + return ParserOptions.NONE; + } + + /** + * @generated + */ + @Override + public IParser getParser() { + if (parser == null) { + parser = UMLParserProvider.getParser(UMLElementTypes.InformationItem_3094, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.InformationItemFloatingLabelEditPartCN.VISUAL_ID)); + } + return parser; + } + + /** + * @generated + */ + protected DirectEditManager getManager() { + if (manager == null) { + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + } + return manager; + } + + /** + * @generated + */ + protected void setManager(DirectEditManager manager) { + this.manager = manager; + } + + /** + * @generated + */ + protected void performDirectEdit() { + BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { + + @Override + public void run() { + getManager().show(); + } + }); + } + + /** + * @generated + */ + protected void performDirectEdit(Point eventLocation) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); + } + } + + /** + * @generated + */ + private void performDirectEdit(char initialCharacter) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(initialCharacter); + } else { + performDirectEdit(); + } + } + + /** + * @generated + */ + @Override + protected void performDirectEditRequest(Request request) { + + final Request theRequest = request; + + if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { + directEditionMode = getDirectEditionType(); + } + switch (directEditionMode) { + case IDirectEdition.NO_DIRECT_EDITION: + // no direct edition mode => does nothing + return; + case IDirectEdition.EXTENDED_DIRECT_EDITOR: + updateExtendedEditorConfiguration(); + if (configuration == null || configuration.getLanguage() == null) { + // Create default edit manager + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + performDefaultDirectEditorEdit(theRequest); + } else { + configuration.preEditAction(resolveSemanticElement()); + Dialog dialog = null; + if (configuration instanceof ICustomDirectEditorConfiguration) { + setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); + initializeDirectEditManager(theRequest); + return; + } else if (configuration instanceof IPopupEditorConfiguration) { + IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); + helper.showEditor(); + return; + } + else if (configuration instanceof IAdvancedEditorConfiguration) { + dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); + } else if (configuration instanceof IDirectEditorConfiguration) { + dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), + configuration); + } else { + return; + } + final Dialog finalDialog = dialog; + + if (Window.OK == dialog.open()) { + TransactionalEditingDomain domain = getEditingDomain(); + RecordingCommand command = new RecordingCommand(domain, "Edit Label") { + + @Override + protected void doExecute() { + configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); + + } + }; + domain.getCommandStack().execute(command); + } + } + break; + case IDirectEdition.DEFAULT_DIRECT_EDITOR: + initializeDirectEditManager(theRequest); + break; + default: + break; + } + } + + /** + * @generated + */ + protected void initializeDirectEditManager(final Request request) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + @Override + public void run() { + if (isActive() && isEditable()) { + if (request.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } + else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void refreshVisuals() { + super.refreshVisuals(); + refreshLabel(); + refreshFont(); + refreshFontColor(); + refreshUnderline(); + refreshStrikeThrough(); + } + + /** + * @generated + */ + protected void refreshLabel() { + EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); + if (maskLabelPolicy == null) { + maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); + } + if (maskLabelPolicy == null) { + View view = (View) getModel(); + if (view.isVisible()) { + setLabelTextHelper(getFigure(), getLabelText()); + setLabelIconHelper(getFigure(), getLabelIcon()); + } + else { + setLabelTextHelper(getFigure(), ""); //$NON-NLS-1$ + setLabelIconHelper(getFigure(), null); + } + } + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + protected void refreshUnderline() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); + } + if (resolveSemanticElement() instanceof Feature) { + if (((Feature) resolveSemanticElement()).isStatic()) { + ((WrappingLabel) getFigure()).setTextUnderline(true); + } + else { + ((WrappingLabel) getFigure()).setTextUnderline(false); + } + } + } + + /** + * @generated + */ + protected void refreshStrikeThrough() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); + } + } + + /** + * @generated + */ + @Override + protected void refreshFont() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null) { + FontData fontData = new FontData( + style.getFontName(), style.getFontHeight(), + (style.isBold() ? SWT.BOLD : SWT.NORMAL) | + (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); + setFont(fontData); + } + } + + /** + * @generated + */ + @Override + protected void setFontColor(Color color) { + getFigure().setForegroundColor(color); + } + + /** + * @generated + */ + @Override + protected void addSemanticListeners() { + if (getParser() instanceof ISemanticParser) { + EObject element = resolveSemanticElement(); + parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); + for (int i = 0; i < parserElements.size(); i++) { + addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ + } + } else { + super.addSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected void removeSemanticListeners() { + if (parserElements != null) { + for (int i = 0; i < parserElements.size(); i++) { + removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ + } + } else { + super.removeSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected AccessibleEditPart getAccessibleEditPart() { + if (accessibleEP == null) { + accessibleEP = new AccessibleGraphicalEditPart() { + + @Override + public void getName(AccessibleEvent e) { + e.result = getLabelTextHelper(getFigure()); + } + }; + } + return accessibleEP; + } + + /** + * @generated + */ + private View getFontStyleOwnerView() { + return getPrimaryView(); + } + + /** + * Returns the kind of associated editor for direct edition. + * + * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition + * @generated + */ + public int getDirectEditionType() { + if (checkExtendedEditor()) { + initExtendedEditorConfiguration(); + return IDirectEdition.EXTENDED_DIRECT_EDITOR; + } + if (checkDefaultEdition()) { + return IDirectEdition.DEFAULT_DIRECT_EDITOR; + } + + // not a named element. no specific editor => do nothing + return IDirectEdition.NO_DIRECT_EDITION; + } + + /** + * Checks if an extended editor is present. + * + * @return true if an extended editor is present. + * @generated + */ + protected boolean checkExtendedEditor() { + if (resolveSemanticElement() != null) { + return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); + } + return false; + } + + /** + * Checks if a default direct edition is available + * + * @return true if a default direct edition is available + * @generated + */ + protected boolean checkDefaultEdition() { + return (getParser() != null); + } + + /** + * Initializes the extended editor configuration + * + * @generated + */ + protected void initExtendedEditorConfiguration() { + if (configuration == null) { + final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("")) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); + } else { + configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); + } + } + } + + /** + * Updates the preference configuration + * + * @generated + */ + protected void updateExtendedEditorConfiguration() { + String languagePreferred = Activator.getDefault().getPreferenceStore().getString( + IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() + .eClass().getInstanceClassName()); + } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { + configuration = null; + } + } + + /** + * Performs the direct edit usually used by GMF editors. + * + * @param theRequest + * the direct edit request that starts the direct edit system + * @generated + */ + protected void performDefaultDirectEditorEdit(final Request theRequest) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + + @Override + public void run() { + if (isActive() && isEditable()) { + if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) theRequest.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { + DirectEditRequest editRequest = (DirectEditRequest) theRequest; + performDirectEdit(editRequest.getLocation()); + } else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + + /** + * @generated + */ + @Override + protected void handleNotificationEvent(Notification event) { + Object feature = event.getFeature(); + if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { + Integer c = (Integer) event.getNewValue(); + setFontColor(DiagramColorRegistry.getInstance().getColor(c)); + } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { + refreshUnderline(); + } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { + refreshStrikeThrough(); + } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { + refreshFont(); + } else { + if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { + refreshLabel(); + } + if (getParser() instanceof ISemanticParser) { + ISemanticParser modelParser = + (ISemanticParser) getParser(); + if (modelParser.areSemanticElementsAffected(null, event)) { + removeSemanticListeners(); + if (resolveSemanticElement() != null) { + addSemanticListeners(); + } + refreshLabel(); + } + } + } + super.handleNotificationEvent(event); + } + + /** + * @generated + */ + @Override + protected IFigure createFigure() { + IFigure label = createFigurePrim(); + defaultText = getLabelTextHelper(label); + return label; + } + + /** + * @generated + */ + protected IFigure createFigurePrim() { + return new PapyrusWrappingLabel(); + } + +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InformationItemNameEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InformationItemNameEditPart.java index 4b49f2b5ca7..463023540cc 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InformationItemNameEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InformationItemNameEditPart.java @@ -864,7 +864,7 @@ public class InformationItemNameEditPart extends PapyrusCompartmentEditPart impl * @generated */ protected void addOwnerElementListeners() { - addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); + addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InformationItemNameEditPartCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InformationItemNameEditPartCN.java index cf23990182e..4fd5532d2ae 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InformationItemNameEditPartCN.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InformationItemNameEditPartCN.java @@ -864,7 +864,7 @@ public class InformationItemNameEditPartCN extends PapyrusCompartmentEditPart im * @generated */ protected void addOwnerElementListeners() { - addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); + addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InstanceValueEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InstanceValueEditPart.java index 501c85997b2..0bd1843e65b 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InstanceValueEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InstanceValueEditPart.java @@ -11,27 +11,40 @@ */ package org.eclipse.papyrus.uml.diagram.composite.edit.parts; +import java.util.Collections; +import java.util.List; + import org.eclipse.draw2d.IFigure; +import org.eclipse.emf.common.notify.Notification; import org.eclipse.gef.EditPart; import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.GraphicalEditPart; 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.handles.MoveHandle; import org.eclipse.gef.requests.CreateRequest; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.BorderItemSelectionEditPolicy; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles; +import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; -import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure; import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure; +import org.eclipse.gmf.runtime.notation.Edge; +import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.gmf.runtime.notation.View; -import org.eclipse.papyrus.infra.gmfdiag.common.editpart.NodeEditPart; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.GetChildLayoutEditPolicy; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.IPapyrusNodeFigure; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.RoundedRectangleNodePlateFigure; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.SelectableBorderedNodeFigure; +import org.eclipse.papyrus.uml.diagram.common.editparts.RoundedCompartmentEditPart; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeNodeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.QualifiedNameDisplayEditPolicy; -import org.eclipse.papyrus.uml.diagram.common.figure.node.NodeNamedElementFigure; +import org.eclipse.papyrus.uml.diagram.common.figure.node.RoundedCompartmentFigure; +import org.eclipse.papyrus.uml.diagram.common.locator.RoundedRectangleLabelPositionLocator; import org.eclipse.papyrus.uml.diagram.composite.edit.policies.InstanceValueItemSemanticEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; import org.eclipse.swt.graphics.Color; @@ -39,7 +52,7 @@ import org.eclipse.swt.graphics.Color; /** * @generated */ -public class InstanceValueEditPart extends NodeEditPart { +public class InstanceValueEditPart extends RoundedCompartmentEditPart { /** * @generated @@ -73,6 +86,7 @@ public class InstanceValueEditPart extends NodeEditPart { installEditPolicy(EditPolicy.LAYOUT_ROLE, createLayoutEditPolicy()); installEditPolicy(QualifiedNameDisplayEditPolicy.QUALIFIED_NAME_POLICY, new QualifiedNameDisplayEditPolicy()); installEditPolicy(AppliedStereotypeLabelDisplayEditPolicy.STEREOTYPE_LABEL_POLICY, new AppliedStereotypeNodeLabelDisplayEditPolicy()); + installEditPolicy(EditPolicy.LAYOUT_ROLE, new GetChildLayoutEditPolicy()); // XXX need an SCR to runtime to have another abstract superclass that would let children add reasonable editpolicies // removeEditPolicy(org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles.CONNECTION_HANDLES_ROLE); } @@ -85,6 +99,20 @@ public class InstanceValueEditPart extends NodeEditPart { @Override protected EditPolicy createChildEditPolicy(EditPart child) { + View childView = (View) child.getModel(); + switch (UMLVisualIDRegistry.getVisualID(childView)) { + case InstanceValueFloatingLabelEditPart.VISUAL_ID: + return new BorderItemSelectionEditPolicy() { + + @Override + protected List createSelectionHandles() { + MoveHandle mh = new MoveHandle((GraphicalEditPart) getHost()); + mh.setBorder(null); + return Collections.singletonList(mh); + } + } + ; + } EditPolicy result = child.getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); if (result == null) { result = new NonResizableEditPolicy(); @@ -105,12 +133,36 @@ public class InstanceValueEditPart extends NodeEditPart { return lep; } + /** + * Papyrus codeGen + * + * @generated + **/ + @Override + protected void handleNotificationEvent(Notification event) { + /* + * when a node have external node labels, the methods refreshChildren() remove the EditPart corresponding to the Label from the EditPart + * Registry. After that, we can't reset the visibility to true (using the Show/Hide Label Action)! + */ + if (NotationPackage.eINSTANCE.getView_Visible().equals(event.getFeature())) { + Object notifier = event.getNotifier(); + List modelChildren = ((View) getModel()).getChildren(); + if (!(notifier instanceof Edge)) { + if (modelChildren.contains(event.getNotifier())) { + return; + } + } + } + super.handleNotificationEvent(event); + + } + /** * @generated */ @Override protected IFigure createNodeShape() { - return primaryShape = new NodeNamedElementFigure(); + return primaryShape = new RoundedCompartmentFigure(); } /** @@ -119,8 +171,8 @@ public class InstanceValueEditPart extends NodeEditPart { * @generated */ @Override - public NodeNamedElementFigure getPrimaryShape() { - return (NodeNamedElementFigure) primaryShape; + public RoundedCompartmentFigure getPrimaryShape() { + return (RoundedCompartmentFigure) primaryShape; } /** @@ -173,15 +225,32 @@ public class InstanceValueEditPart extends NodeEditPart { */ @Override protected IFigure getContentPaneFor(IGraphicalEditPart editPart) { + if (editPart instanceof IBorderItemEditPart) { + return getBorderedFigure().getBorderItemContainer(); + } return getContentPane(); } + /** + * @generated + */ + @Override + protected void addBorderItem(IFigure borderItemContainer, IBorderItemEditPart borderItemEditPart) { + if (borderItemEditPart instanceof InstanceValueFloatingLabelEditPart) { + IBorderItemLocator locator = new RoundedRectangleLabelPositionLocator(getMainFigure()); + borderItemContainer.add(borderItemEditPart.getFigure(), locator); + } else + { + super.addBorderItem(borderItemContainer, borderItemEditPart); + } + } + /** * @generated */ @Override protected NodeFigure createNodePlate() { - DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(40, 40); + RoundedRectangleNodePlateFigure result = new RoundedRectangleNodePlateFigure(40, 40); return result; } @@ -194,7 +263,7 @@ public class InstanceValueEditPart extends NodeEditPart { * @generated */ @Override - protected NodeFigure createNodeFigure() { + protected NodeFigure createMainFigure() { return new SelectableBorderedNodeFigure(createMainFigureWithSVG()); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InstanceValueFloatingLabelEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InstanceValueFloatingLabelEditPart.java new file mode 100644 index 00000000000..ec4ad5568a8 --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InstanceValueFloatingLabelEditPart.java @@ -0,0 +1,860 @@ +/** + * 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.uml.diagram.composite.edit.parts; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.Label; +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.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.RunnableWithResult; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gef.AccessibleEditPart; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.Request; +import org.eclipse.gef.requests.DirectEditRequest; +import org.eclipse.gef.tools.DirectEditManager; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; +import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; +import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; +import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; +import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; +import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; +import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; +import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; +import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; +import org.eclipse.gmf.runtime.notation.FontStyle; +import org.eclipse.gmf.runtime.notation.NotationPackage; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.text.contentassist.IContentAssistProcessor; +import org.eclipse.jface.viewers.ICellEditorValidator; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.extensionpoints.editors.Activator; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; +import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; +import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.ExternalLabelPrimaryDragRoleEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.PapyrusWrappingLabel; +import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; +import org.eclipse.papyrus.uml.diagram.common.editparts.FloatingLabelEditPart; +import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; +import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; +import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; +import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.accessibility.AccessibleEvent; +import org.eclipse.swt.custom.BusyIndicator; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; +import org.eclipse.uml2.uml.Feature; + +/** + * @generated + */ +public class InstanceValueFloatingLabelEditPart extends FloatingLabelEditPart + implements ITextAwareEditPart, IBorderItemEditPart +{ + + /** + * @generated + */ + public static final int VISUAL_ID = 6119; + + /** + * @generated + */ + private DirectEditManager manager; + + /** + * @generated + */ + private IParser parser; + + /** + * @generated + */ + private List parserElements; + + /** + * @generated + */ + private String defaultText; + + /** + * direct edition mode (default, undefined, registered editor, etc.) + * + * @generated + */ + protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; + + /** + * configuration from a registered edit dialog + * + * @generated + */ + protected IDirectEditorConfiguration configuration; + + + /** + * @generated + */ + static { + registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.InstanceValueFloatingLabelEditPart.VISUAL_ID), new Point(0, 0)); + } + + /** + * @generated + */ + public InstanceValueFloatingLabelEditPart(View view) { + super(view); + } + + /** + * @generated + */ + @Override + protected void createDefaultEditPolicies() { + super.createDefaultEditPolicies(); + installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); + installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ExternalLabelPrimaryDragRoleEditPolicy()); + } + + /** + * @generated + */ + @Override + public IBorderItemLocator getBorderItemLocator() { + IFigure parentFigure = getFigure().getParent(); + if (parentFigure != null && parentFigure.getLayoutManager() != null) { + Object constraint = parentFigure.getLayoutManager().getConstraint(getFigure()); + return (IBorderItemLocator) constraint; + } + return null; + } + + /** + * @generated + */ + @Override + public void refreshBounds() { + int x = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_X())).intValue(); + int y = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_Y())).intValue(); + int width = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Width())).intValue(); + int height = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Height())).intValue(); + getBorderItemLocator().setConstraint(new Rectangle(x, y, width, height)); + } + + + /** + * @generated + */ + protected String getLabelTextHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getText(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getText(); + } else { + return ((Label) figure).getText(); + } + } + + /** + * @generated + */ + protected void setLabelTextHelper(IFigure figure, String text) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setText(text); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setText(text); + } else { + ((Label) figure).setText(text); + } + } + + /** + * @generated + */ + protected Image getLabelIconHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getIcon(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getIcon(); + } else { + return ((Label) figure).getIcon(); + } + } + + /** + * @generated + */ + protected void setLabelIconHelper(IFigure figure, Image icon) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setIcon(icon); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setIcon(icon); + } else { + ((Label) figure).setIcon(icon); + } + } + + /** + * @generated + */ + public void setLabel(IFigure + figure) { + unregisterVisuals(); + setFigure(figure); + defaultText = getLabelTextHelper(figure); + registerVisuals(); + refreshVisuals(); + } + + /** + * @generated + */ + @Override + protected List getModelChildren() { + return Collections.EMPTY_LIST; + } + + /** + * @generated + */ + @Override + public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { + return null; + } + + /** + * @generated + */ + public void setParser(IParser parser) { + this.parser = parser; + } + + /** + * @generated + */ + protected EObject getParserElement() { + return resolveSemanticElement(); + } + + /** + * @generated + */ + protected Image getLabelIcon() { + return null; + } + + /** + * @generated + */ + protected String getLabelText() { + String text = null; + EObject parserElement = getParserElement(); + if (parserElement != null && getParser() != null) { + text = getParser().getPrintString( + new EObjectAdapter(parserElement), + getParserOptions().intValue()); + } + if (text == null || text.length() == 0) { + text = defaultText; + } + return text; + } + + /** + * @generated + */ + @Override + public void setLabelText(String text) { + setLabelTextHelper(getFigure(), text); + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + @Override + public String getEditText() { + if (getParserElement() == null || getParser() == null) { + return ""; //$NON-NLS-1$ + } + return getParser().getEditString( + new EObjectAdapter(getParserElement()), + getParserOptions().intValue()); + } + + /** + * @generated + */ + protected boolean isEditable() { + return getParser() != null; + } + + /** + * @generated + */ + @Override + public ICellEditorValidator getEditTextValidator() { + return new ICellEditorValidator() { + + @Override + public String isValid(final Object value) { + if (value instanceof String) { + final EObject element = getParserElement(); + final IParser parser = getParser(); + try { + IParserEditStatus valid = + (IParserEditStatus) getEditingDomain().runExclusive( + new RunnableWithResult.Impl() { + + @Override + public void run() { + setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); + } + }); + return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); + } catch (InterruptedException ie) { + ie.printStackTrace(); + } + } + + // shouldn't get here + return null; + } + }; + } + + /** + * @generated + */ + @Override + public IContentAssistProcessor getCompletionProcessor() { + if (getParserElement() == null || getParser() == null) { + return null; + } + return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); + } + + /** + * @generated + */ + @Override + public ParserOptions getParserOptions() { + return ParserOptions.NONE; + } + + /** + * @generated + */ + @Override + public IParser getParser() { + if (parser == null) { + parser = UMLParserProvider.getParser(UMLElementTypes.InstanceValue_2108, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.InstanceValueFloatingLabelEditPart.VISUAL_ID)); + } + return parser; + } + + /** + * @generated + */ + protected DirectEditManager getManager() { + if (manager == null) { + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + } + return manager; + } + + /** + * @generated + */ + protected void setManager(DirectEditManager manager) { + this.manager = manager; + } + + /** + * @generated + */ + protected void performDirectEdit() { + BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { + + @Override + public void run() { + getManager().show(); + } + }); + } + + /** + * @generated + */ + protected void performDirectEdit(Point eventLocation) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); + } + } + + /** + * @generated + */ + private void performDirectEdit(char initialCharacter) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(initialCharacter); + } else { + performDirectEdit(); + } + } + + /** + * @generated + */ + @Override + protected void performDirectEditRequest(Request request) { + + final Request theRequest = request; + + if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { + directEditionMode = getDirectEditionType(); + } + switch (directEditionMode) { + case IDirectEdition.NO_DIRECT_EDITION: + // no direct edition mode => does nothing + return; + case IDirectEdition.EXTENDED_DIRECT_EDITOR: + updateExtendedEditorConfiguration(); + if (configuration == null || configuration.getLanguage() == null) { + // Create default edit manager + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + performDefaultDirectEditorEdit(theRequest); + } else { + configuration.preEditAction(resolveSemanticElement()); + Dialog dialog = null; + if (configuration instanceof ICustomDirectEditorConfiguration) { + setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); + initializeDirectEditManager(theRequest); + return; + } else if (configuration instanceof IPopupEditorConfiguration) { + IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); + helper.showEditor(); + return; + } + else if (configuration instanceof IAdvancedEditorConfiguration) { + dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); + } else if (configuration instanceof IDirectEditorConfiguration) { + dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), + configuration); + } else { + return; + } + final Dialog finalDialog = dialog; + + if (Window.OK == dialog.open()) { + TransactionalEditingDomain domain = getEditingDomain(); + RecordingCommand command = new RecordingCommand(domain, "Edit Label") { + + @Override + protected void doExecute() { + configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); + + } + }; + domain.getCommandStack().execute(command); + } + } + break; + case IDirectEdition.DEFAULT_DIRECT_EDITOR: + initializeDirectEditManager(theRequest); + break; + default: + break; + } + } + + /** + * @generated + */ + protected void initializeDirectEditManager(final Request request) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + @Override + public void run() { + if (isActive() && isEditable()) { + if (request.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } + else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void refreshVisuals() { + super.refreshVisuals(); + refreshLabel(); + refreshFont(); + refreshFontColor(); + refreshUnderline(); + refreshStrikeThrough(); + } + + /** + * @generated + */ + protected void refreshLabel() { + EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); + if (maskLabelPolicy == null) { + maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); + } + if (maskLabelPolicy == null) { + View view = (View) getModel(); + if (view.isVisible()) { + setLabelTextHelper(getFigure(), getLabelText()); + setLabelIconHelper(getFigure(), getLabelIcon()); + } + else { + setLabelTextHelper(getFigure(), ""); //$NON-NLS-1$ + setLabelIconHelper(getFigure(), null); + } + } + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + protected void refreshUnderline() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); + } + if (resolveSemanticElement() instanceof Feature) { + if (((Feature) resolveSemanticElement()).isStatic()) { + ((WrappingLabel) getFigure()).setTextUnderline(true); + } + else { + ((WrappingLabel) getFigure()).setTextUnderline(false); + } + } + } + + /** + * @generated + */ + protected void refreshStrikeThrough() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); + } + } + + /** + * @generated + */ + @Override + protected void refreshFont() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null) { + FontData fontData = new FontData( + style.getFontName(), style.getFontHeight(), + (style.isBold() ? SWT.BOLD : SWT.NORMAL) | + (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); + setFont(fontData); + } + } + + /** + * @generated + */ + @Override + protected void setFontColor(Color color) { + getFigure().setForegroundColor(color); + } + + /** + * @generated + */ + @Override + protected void addSemanticListeners() { + if (getParser() instanceof ISemanticParser) { + EObject element = resolveSemanticElement(); + parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); + for (int i = 0; i < parserElements.size(); i++) { + addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ + } + } else { + super.addSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected void removeSemanticListeners() { + if (parserElements != null) { + for (int i = 0; i < parserElements.size(); i++) { + removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ + } + } else { + super.removeSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected AccessibleEditPart getAccessibleEditPart() { + if (accessibleEP == null) { + accessibleEP = new AccessibleGraphicalEditPart() { + + @Override + public void getName(AccessibleEvent e) { + e.result = getLabelTextHelper(getFigure()); + } + }; + } + return accessibleEP; + } + + /** + * @generated + */ + private View getFontStyleOwnerView() { + return getPrimaryView(); + } + + /** + * Returns the kind of associated editor for direct edition. + * + * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition + * @generated + */ + public int getDirectEditionType() { + if (checkExtendedEditor()) { + initExtendedEditorConfiguration(); + return IDirectEdition.EXTENDED_DIRECT_EDITOR; + } + if (checkDefaultEdition()) { + return IDirectEdition.DEFAULT_DIRECT_EDITOR; + } + + // not a named element. no specific editor => do nothing + return IDirectEdition.NO_DIRECT_EDITION; + } + + /** + * Checks if an extended editor is present. + * + * @return true if an extended editor is present. + * @generated + */ + protected boolean checkExtendedEditor() { + if (resolveSemanticElement() != null) { + return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); + } + return false; + } + + /** + * Checks if a default direct edition is available + * + * @return true if a default direct edition is available + * @generated + */ + protected boolean checkDefaultEdition() { + return (getParser() != null); + } + + /** + * Initializes the extended editor configuration + * + * @generated + */ + protected void initExtendedEditorConfiguration() { + if (configuration == null) { + final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("")) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); + } else { + configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); + } + } + } + + /** + * Updates the preference configuration + * + * @generated + */ + protected void updateExtendedEditorConfiguration() { + String languagePreferred = Activator.getDefault().getPreferenceStore().getString( + IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() + .eClass().getInstanceClassName()); + } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { + configuration = null; + } + } + + /** + * Performs the direct edit usually used by GMF editors. + * + * @param theRequest + * the direct edit request that starts the direct edit system + * @generated + */ + protected void performDefaultDirectEditorEdit(final Request theRequest) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + + @Override + public void run() { + if (isActive() && isEditable()) { + if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) theRequest.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { + DirectEditRequest editRequest = (DirectEditRequest) theRequest; + performDirectEdit(editRequest.getLocation()); + } else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + + /** + * @generated + */ + @Override + protected void handleNotificationEvent(Notification event) { + Object feature = event.getFeature(); + if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { + Integer c = (Integer) event.getNewValue(); + setFontColor(DiagramColorRegistry.getInstance().getColor(c)); + } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { + refreshUnderline(); + } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { + refreshStrikeThrough(); + } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { + refreshFont(); + } else { + if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { + refreshLabel(); + } + if (getParser() instanceof ISemanticParser) { + ISemanticParser modelParser = + (ISemanticParser) getParser(); + if (modelParser.areSemanticElementsAffected(null, event)) { + removeSemanticListeners(); + if (resolveSemanticElement() != null) { + addSemanticListeners(); + } + refreshLabel(); + } + } + } + super.handleNotificationEvent(event); + } + + /** + * @generated + */ + @Override + protected IFigure createFigure() { + IFigure label = createFigurePrim(); + defaultText = getLabelTextHelper(label); + return label; + } + + /** + * @generated + */ + protected IFigure createFigurePrim() { + return new PapyrusWrappingLabel(); + } + +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InstanceValueNameEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InstanceValueNameEditPart.java index c8d6d5574b6..9f514d1784d 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InstanceValueNameEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InstanceValueNameEditPart.java @@ -864,7 +864,7 @@ public class InstanceValueNameEditPart extends PapyrusCompartmentEditPart implem * @generated */ protected void addOwnerElementListeners() { - addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); + addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InteractionCompositeCompartmentEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InteractionCompositeCompartmentEditPart.java index 8fd036c7c0c..36535ec8017 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InteractionCompositeCompartmentEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InteractionCompositeCompartmentEditPart.java @@ -26,6 +26,7 @@ import org.eclipse.gmf.runtime.diagram.ui.editpolicies.ResizableCompartmentEditP import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.BorderDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.CustomContainerEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.DuplicatePasteEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.PapyrusCreationEditPolicy; @@ -75,6 +76,7 @@ public class InteractionCompositeCompartmentEditPart extends ShapeCompartmentEdi installEditPolicy(EditPolicy.GRAPHICAL_NODE_ROLE, new CustomContainerEditPolicy()); installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, new CustomDiagramDragDropEditPolicy()); installEditPolicy(EditPolicyRoles.CREATION_ROLE, new PortInCompartmentCreationEditPolicy()); + installEditPolicy(BorderDisplayEditPolicy.BORDER_DISPLAY_EDITPOLICY, new BorderDisplayEditPolicy()); } /** diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InteractionCompositeCompartmentEditPartCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InteractionCompositeCompartmentEditPartCN.java index cbcc84137b8..ac504f11f29 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InteractionCompositeCompartmentEditPartCN.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InteractionCompositeCompartmentEditPartCN.java @@ -26,6 +26,7 @@ import org.eclipse.gmf.runtime.diagram.ui.editpolicies.ResizableCompartmentEditP import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.BorderDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.CustomContainerEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.DuplicatePasteEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.PapyrusCreationEditPolicy; @@ -75,6 +76,7 @@ public class InteractionCompositeCompartmentEditPartCN extends ShapeCompartmentE installEditPolicy(EditPolicy.GRAPHICAL_NODE_ROLE, new CustomContainerEditPolicy()); installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, new CustomDiagramDragDropEditPolicy()); installEditPolicy(EditPolicyRoles.CREATION_ROLE, new PortInCompartmentCreationEditPolicy()); + installEditPolicy(BorderDisplayEditPolicy.BORDER_DISPLAY_EDITPOLICY, new BorderDisplayEditPolicy()); } /** diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InteractionCompositeEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InteractionCompositeEditPart.java index ca67f70a70f..77c0814b083 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InteractionCompositeEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InteractionCompositeEditPart.java @@ -11,28 +11,37 @@ */ package org.eclipse.papyrus.uml.diagram.composite.edit.parts; +import java.util.Collections; +import java.util.List; + import org.eclipse.draw2d.IFigure; import org.eclipse.draw2d.PositionConstants; import org.eclipse.emf.common.notify.Notification; import org.eclipse.gef.EditPart; import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.GraphicalEditPart; 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.handles.MoveHandle; import org.eclipse.gef.requests.CreateRequest; import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.BorderItemSelectionEditPolicy; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.DragDropEditPolicy; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles; import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; -import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure; import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure; +import org.eclipse.gmf.runtime.notation.Edge; +import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.GetChildLayoutEditPolicy; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.IPapyrusNodeFigure; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.RoundedRectangleNodePlateFigure; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.SelectableBorderedNodeFigure; -import org.eclipse.papyrus.uml.diagram.common.editparts.NamedElementEditPart; +import org.eclipse.papyrus.uml.diagram.common.editparts.RoundedCompartmentEditPart; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AffixedNodeAlignmentEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeNodeLabelDisplayEditPolicy; @@ -41,11 +50,11 @@ import org.eclipse.papyrus.uml.diagram.common.editpolicies.PapyrusCreationEditPo import org.eclipse.papyrus.uml.diagram.common.editpolicies.QualifiedNameDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.ShowHideClassifierContentsEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.ShowHideCompartmentEditPolicy; +import org.eclipse.papyrus.uml.diagram.common.locator.RoundedRectangleLabelPositionLocator; import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.BehaviorLayoutEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.CustomDiagramDragDropEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.RemoveOrphanViewPolicy; import org.eclipse.papyrus.uml.diagram.composite.custom.figures.InteractionCompositeFigure; -import org.eclipse.papyrus.uml.diagram.composite.custom.locators.PortPositionLocator; import org.eclipse.papyrus.uml.diagram.composite.edit.policies.InteractionCompositeItemSemanticEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; import org.eclipse.swt.graphics.Color; @@ -53,7 +62,7 @@ import org.eclipse.swt.graphics.Color; /** * @generated */ -public class InteractionCompositeEditPart extends NamedElementEditPart { +public class InteractionCompositeEditPart extends RoundedCompartmentEditPart { /** * @generated @@ -95,6 +104,7 @@ public class InteractionCompositeEditPart extends NamedElementEditPart { installEditPolicy(ShowHideCompartmentEditPolicy.SHOW_HIDE_COMPARTMENT_POLICY, new ShowHideCompartmentEditPolicy()); installEditPolicy(AffixedNodeAlignmentEditPolicy.AFFIXED_CHILD_ALIGNMENT_ROLE, new AffixedNodeAlignmentEditPolicy()); installEditPolicy("REMOVE_ORPHAN_VIEW", new RemoveOrphanViewPolicy()); //$NON-NLS-1$ + installEditPolicy(EditPolicy.LAYOUT_ROLE, new GetChildLayoutEditPolicy()); // XXX need an SCR to runtime to have another abstract superclass that would let children add reasonable editpolicies // removeEditPolicy(org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles.CONNECTION_HANDLES_ROLE); } @@ -109,6 +119,17 @@ public class InteractionCompositeEditPart extends NamedElementEditPart { protected EditPolicy createChildEditPolicy(EditPart child) { View childView = (View) child.getModel(); switch (UMLVisualIDRegistry.getVisualID(childView)) { + case InteractionCompositeFloatingLabelEditPart.VISUAL_ID: + return new BorderItemSelectionEditPolicy() { + + @Override + protected List createSelectionHandles() { + MoveHandle mh = new MoveHandle((GraphicalEditPart) getHost()); + mh.setBorder(null); + return Collections.singletonList(mh); + } + } + ; case PortEditPart.VISUAL_ID: case ParameterEditPart.VISUAL_ID: return new BorderItemResizableEditPolicy(); @@ -140,6 +161,19 @@ public class InteractionCompositeEditPart extends NamedElementEditPart { **/ @Override protected void handleNotificationEvent(Notification event) { + /* + * when a node have external node labels, the methods refreshChildren() remove the EditPart corresponding to the Label from the EditPart + * Registry. After that, we can't reset the visibility to true (using the Show/Hide Label Action)! + */ + if (NotationPackage.eINSTANCE.getView_Visible().equals(event.getFeature())) { + Object notifier = event.getNotifier(); + List modelChildren = ((View) getModel()).getChildren(); + if (!(notifier instanceof Edge)) { + if (modelChildren.contains(event.getNotifier())) { + return; + } + } + } super.handleNotificationEvent(event); } @@ -181,9 +215,9 @@ public class InteractionCompositeEditPart extends NamedElementEditPart { - //Papyrus Gencode :Affixed Port locator + // Papyrus Gencode :Affixed Port locator if (childEditPart instanceof PortEditPart) { - IBorderItemLocator locator = new PortPositionLocator(getMainFigure(), PositionConstants.NONE); + IBorderItemLocator locator = new org.eclipse.papyrus.uml.diagram.common.locator.PortPositionLocator(getMainFigure(), PositionConstants.NONE); getBorderedFigure().getBorderItemContainer().add(((PortEditPart) childEditPart).getFigure(), locator); return true; } @@ -191,9 +225,9 @@ public class InteractionCompositeEditPart extends NamedElementEditPart { - //Papyrus Gencode :Affixed Port locator + // Papyrus Gencode :Affixed Port locator if (childEditPart instanceof ParameterEditPart) { - IBorderItemLocator locator = new PortPositionLocator(getMainFigure(), PositionConstants.NONE); + IBorderItemLocator locator = new org.eclipse.papyrus.uml.diagram.common.locator.PortPositionLocator(getMainFigure(), PositionConstants.NONE); getBorderedFigure().getBorderItemContainer().add(((ParameterEditPart) childEditPart).getFigure(), locator); return true; } @@ -261,12 +295,26 @@ public class InteractionCompositeEditPart extends NamedElementEditPart { return getContentPane(); } + /** + * @generated + */ + @Override + protected void addBorderItem(IFigure borderItemContainer, IBorderItemEditPart borderItemEditPart) { + if (borderItemEditPart instanceof InteractionCompositeFloatingLabelEditPart) { + IBorderItemLocator locator = new RoundedRectangleLabelPositionLocator(getMainFigure()); + borderItemContainer.add(borderItemEditPart.getFigure(), locator); + } else + { + super.addBorderItem(borderItemContainer, borderItemEditPart); + } + } + /** * @generated */ @Override protected NodeFigure createNodePlate() { - DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(40, 40); + RoundedRectangleNodePlateFigure result = new RoundedRectangleNodePlateFigure(40, 40); return result; } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InteractionCompositeEditPartCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InteractionCompositeEditPartCN.java index 55baaf15192..c4c1e923302 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InteractionCompositeEditPartCN.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InteractionCompositeEditPartCN.java @@ -11,28 +11,37 @@ */ package org.eclipse.papyrus.uml.diagram.composite.edit.parts; +import java.util.Collections; +import java.util.List; + import org.eclipse.draw2d.IFigure; import org.eclipse.draw2d.PositionConstants; import org.eclipse.emf.common.notify.Notification; import org.eclipse.gef.EditPart; import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.GraphicalEditPart; 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.handles.MoveHandle; import org.eclipse.gef.requests.CreateRequest; import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.BorderItemSelectionEditPolicy; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.DragDropEditPolicy; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles; import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; -import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure; import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure; +import org.eclipse.gmf.runtime.notation.Edge; +import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.GetChildLayoutEditPolicy; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.IPapyrusNodeFigure; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.RoundedRectangleNodePlateFigure; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.SelectableBorderedNodeFigure; -import org.eclipse.papyrus.uml.diagram.common.editparts.NamedElementEditPart; +import org.eclipse.papyrus.uml.diagram.common.editparts.RoundedCompartmentEditPart; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AffixedNodeAlignmentEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeNodeLabelDisplayEditPolicy; @@ -41,11 +50,11 @@ import org.eclipse.papyrus.uml.diagram.common.editpolicies.PapyrusCreationEditPo import org.eclipse.papyrus.uml.diagram.common.editpolicies.QualifiedNameDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.ShowHideClassifierContentsEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.ShowHideCompartmentEditPolicy; +import org.eclipse.papyrus.uml.diagram.common.locator.RoundedRectangleLabelPositionLocator; import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.BehaviorLayoutEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.CustomDiagramDragDropEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.RemoveOrphanViewPolicy; import org.eclipse.papyrus.uml.diagram.composite.custom.figures.InteractionCompositeFigure; -import org.eclipse.papyrus.uml.diagram.composite.custom.locators.PortPositionLocator; import org.eclipse.papyrus.uml.diagram.composite.edit.policies.InteractionCompositeItemSemanticEditPolicyCN; import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; import org.eclipse.swt.graphics.Color; @@ -53,7 +62,7 @@ import org.eclipse.swt.graphics.Color; /** * @generated */ -public class InteractionCompositeEditPartCN extends NamedElementEditPart { +public class InteractionCompositeEditPartCN extends RoundedCompartmentEditPart { /** * @generated @@ -95,6 +104,7 @@ public class InteractionCompositeEditPartCN extends NamedElementEditPart { installEditPolicy(ShowHideCompartmentEditPolicy.SHOW_HIDE_COMPARTMENT_POLICY, new ShowHideCompartmentEditPolicy()); installEditPolicy(AffixedNodeAlignmentEditPolicy.AFFIXED_CHILD_ALIGNMENT_ROLE, new AffixedNodeAlignmentEditPolicy()); installEditPolicy("REMOVE_ORPHAN_VIEW", new RemoveOrphanViewPolicy()); //$NON-NLS-1$ + installEditPolicy(EditPolicy.LAYOUT_ROLE, new GetChildLayoutEditPolicy()); // XXX need an SCR to runtime to have another abstract superclass that would let children add reasonable editpolicies // removeEditPolicy(org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles.CONNECTION_HANDLES_ROLE); } @@ -109,6 +119,17 @@ public class InteractionCompositeEditPartCN extends NamedElementEditPart { protected EditPolicy createChildEditPolicy(EditPart child) { View childView = (View) child.getModel(); switch (UMLVisualIDRegistry.getVisualID(childView)) { + case InteractionCompositeFloatingLabelEditPartCN.VISUAL_ID: + return new BorderItemSelectionEditPolicy() { + + @Override + protected List createSelectionHandles() { + MoveHandle mh = new MoveHandle((GraphicalEditPart) getHost()); + mh.setBorder(null); + return Collections.singletonList(mh); + } + } + ; case PortEditPart.VISUAL_ID: case ParameterEditPart.VISUAL_ID: return new BorderItemResizableEditPolicy(); @@ -140,6 +161,19 @@ public class InteractionCompositeEditPartCN extends NamedElementEditPart { **/ @Override protected void handleNotificationEvent(Notification event) { + /* + * when a node have external node labels, the methods refreshChildren() remove the EditPart corresponding to the Label from the EditPart + * Registry. After that, we can't reset the visibility to true (using the Show/Hide Label Action)! + */ + if (NotationPackage.eINSTANCE.getView_Visible().equals(event.getFeature())) { + Object notifier = event.getNotifier(); + List modelChildren = ((View) getModel()).getChildren(); + if (!(notifier instanceof Edge)) { + if (modelChildren.contains(event.getNotifier())) { + return; + } + } + } super.handleNotificationEvent(event); } @@ -181,9 +215,9 @@ public class InteractionCompositeEditPartCN extends NamedElementEditPart { - //Papyrus Gencode :Affixed Port locator + // Papyrus Gencode :Affixed Port locator if (childEditPart instanceof PortEditPart) { - IBorderItemLocator locator = new PortPositionLocator(getMainFigure(), PositionConstants.NONE); + IBorderItemLocator locator = new org.eclipse.papyrus.uml.diagram.common.locator.PortPositionLocator(getMainFigure(), PositionConstants.NONE); getBorderedFigure().getBorderItemContainer().add(((PortEditPart) childEditPart).getFigure(), locator); return true; } @@ -191,9 +225,9 @@ public class InteractionCompositeEditPartCN extends NamedElementEditPart { - //Papyrus Gencode :Affixed Port locator + // Papyrus Gencode :Affixed Port locator if (childEditPart instanceof ParameterEditPart) { - IBorderItemLocator locator = new PortPositionLocator(getMainFigure(), PositionConstants.NONE); + IBorderItemLocator locator = new org.eclipse.papyrus.uml.diagram.common.locator.PortPositionLocator(getMainFigure(), PositionConstants.NONE); getBorderedFigure().getBorderItemContainer().add(((ParameterEditPart) childEditPart).getFigure(), locator); return true; } @@ -261,12 +295,26 @@ public class InteractionCompositeEditPartCN extends NamedElementEditPart { return getContentPane(); } + /** + * @generated + */ + @Override + protected void addBorderItem(IFigure borderItemContainer, IBorderItemEditPart borderItemEditPart) { + if (borderItemEditPart instanceof InteractionCompositeFloatingLabelEditPartCN) { + IBorderItemLocator locator = new RoundedRectangleLabelPositionLocator(getMainFigure()); + borderItemContainer.add(borderItemEditPart.getFigure(), locator); + } else + { + super.addBorderItem(borderItemContainer, borderItemEditPart); + } + } + /** * @generated */ @Override protected NodeFigure createNodePlate() { - DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(40, 40); + RoundedRectangleNodePlateFigure result = new RoundedRectangleNodePlateFigure(40, 40); return result; } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InteractionCompositeFloatingLabelEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InteractionCompositeFloatingLabelEditPart.java new file mode 100644 index 00000000000..862b4ded18b --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InteractionCompositeFloatingLabelEditPart.java @@ -0,0 +1,860 @@ +/** + * 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.uml.diagram.composite.edit.parts; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.Label; +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.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.RunnableWithResult; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gef.AccessibleEditPart; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.Request; +import org.eclipse.gef.requests.DirectEditRequest; +import org.eclipse.gef.tools.DirectEditManager; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; +import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; +import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; +import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; +import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; +import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; +import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; +import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; +import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; +import org.eclipse.gmf.runtime.notation.FontStyle; +import org.eclipse.gmf.runtime.notation.NotationPackage; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.text.contentassist.IContentAssistProcessor; +import org.eclipse.jface.viewers.ICellEditorValidator; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.extensionpoints.editors.Activator; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; +import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; +import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.ExternalLabelPrimaryDragRoleEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.PapyrusWrappingLabel; +import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; +import org.eclipse.papyrus.uml.diagram.common.editparts.FloatingLabelEditPart; +import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; +import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; +import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; +import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.accessibility.AccessibleEvent; +import org.eclipse.swt.custom.BusyIndicator; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; +import org.eclipse.uml2.uml.Feature; + +/** + * @generated + */ +public class InteractionCompositeFloatingLabelEditPart extends FloatingLabelEditPart + implements ITextAwareEditPart, IBorderItemEditPart +{ + + /** + * @generated + */ + public static final int VISUAL_ID = 6080; + + /** + * @generated + */ + private DirectEditManager manager; + + /** + * @generated + */ + private IParser parser; + + /** + * @generated + */ + private List parserElements; + + /** + * @generated + */ + private String defaultText; + + /** + * direct edition mode (default, undefined, registered editor, etc.) + * + * @generated + */ + protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; + + /** + * configuration from a registered edit dialog + * + * @generated + */ + protected IDirectEditorConfiguration configuration; + + + /** + * @generated + */ + static { + registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.InteractionCompositeFloatingLabelEditPart.VISUAL_ID), new Point(0, 0)); + } + + /** + * @generated + */ + public InteractionCompositeFloatingLabelEditPart(View view) { + super(view); + } + + /** + * @generated + */ + @Override + protected void createDefaultEditPolicies() { + super.createDefaultEditPolicies(); + installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); + installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ExternalLabelPrimaryDragRoleEditPolicy()); + } + + /** + * @generated + */ + @Override + public IBorderItemLocator getBorderItemLocator() { + IFigure parentFigure = getFigure().getParent(); + if (parentFigure != null && parentFigure.getLayoutManager() != null) { + Object constraint = parentFigure.getLayoutManager().getConstraint(getFigure()); + return (IBorderItemLocator) constraint; + } + return null; + } + + /** + * @generated + */ + @Override + public void refreshBounds() { + int x = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_X())).intValue(); + int y = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_Y())).intValue(); + int width = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Width())).intValue(); + int height = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Height())).intValue(); + getBorderItemLocator().setConstraint(new Rectangle(x, y, width, height)); + } + + + /** + * @generated + */ + protected String getLabelTextHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getText(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getText(); + } else { + return ((Label) figure).getText(); + } + } + + /** + * @generated + */ + protected void setLabelTextHelper(IFigure figure, String text) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setText(text); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setText(text); + } else { + ((Label) figure).setText(text); + } + } + + /** + * @generated + */ + protected Image getLabelIconHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getIcon(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getIcon(); + } else { + return ((Label) figure).getIcon(); + } + } + + /** + * @generated + */ + protected void setLabelIconHelper(IFigure figure, Image icon) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setIcon(icon); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setIcon(icon); + } else { + ((Label) figure).setIcon(icon); + } + } + + /** + * @generated + */ + public void setLabel(IFigure + figure) { + unregisterVisuals(); + setFigure(figure); + defaultText = getLabelTextHelper(figure); + registerVisuals(); + refreshVisuals(); + } + + /** + * @generated + */ + @Override + protected List getModelChildren() { + return Collections.EMPTY_LIST; + } + + /** + * @generated + */ + @Override + public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { + return null; + } + + /** + * @generated + */ + public void setParser(IParser parser) { + this.parser = parser; + } + + /** + * @generated + */ + protected EObject getParserElement() { + return resolveSemanticElement(); + } + + /** + * @generated + */ + protected Image getLabelIcon() { + return null; + } + + /** + * @generated + */ + protected String getLabelText() { + String text = null; + EObject parserElement = getParserElement(); + if (parserElement != null && getParser() != null) { + text = getParser().getPrintString( + new EObjectAdapter(parserElement), + getParserOptions().intValue()); + } + if (text == null || text.length() == 0) { + text = defaultText; + } + return text; + } + + /** + * @generated + */ + @Override + public void setLabelText(String text) { + setLabelTextHelper(getFigure(), text); + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + @Override + public String getEditText() { + if (getParserElement() == null || getParser() == null) { + return ""; //$NON-NLS-1$ + } + return getParser().getEditString( + new EObjectAdapter(getParserElement()), + getParserOptions().intValue()); + } + + /** + * @generated + */ + protected boolean isEditable() { + return getParser() != null; + } + + /** + * @generated + */ + @Override + public ICellEditorValidator getEditTextValidator() { + return new ICellEditorValidator() { + + @Override + public String isValid(final Object value) { + if (value instanceof String) { + final EObject element = getParserElement(); + final IParser parser = getParser(); + try { + IParserEditStatus valid = + (IParserEditStatus) getEditingDomain().runExclusive( + new RunnableWithResult.Impl() { + + @Override + public void run() { + setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); + } + }); + return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); + } catch (InterruptedException ie) { + ie.printStackTrace(); + } + } + + // shouldn't get here + return null; + } + }; + } + + /** + * @generated + */ + @Override + public IContentAssistProcessor getCompletionProcessor() { + if (getParserElement() == null || getParser() == null) { + return null; + } + return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); + } + + /** + * @generated + */ + @Override + public ParserOptions getParserOptions() { + return ParserOptions.NONE; + } + + /** + * @generated + */ + @Override + public IParser getParser() { + if (parser == null) { + parser = UMLParserProvider.getParser(UMLElementTypes.Interaction_2061, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.InteractionCompositeFloatingLabelEditPart.VISUAL_ID)); + } + return parser; + } + + /** + * @generated + */ + protected DirectEditManager getManager() { + if (manager == null) { + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + } + return manager; + } + + /** + * @generated + */ + protected void setManager(DirectEditManager manager) { + this.manager = manager; + } + + /** + * @generated + */ + protected void performDirectEdit() { + BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { + + @Override + public void run() { + getManager().show(); + } + }); + } + + /** + * @generated + */ + protected void performDirectEdit(Point eventLocation) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); + } + } + + /** + * @generated + */ + private void performDirectEdit(char initialCharacter) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(initialCharacter); + } else { + performDirectEdit(); + } + } + + /** + * @generated + */ + @Override + protected void performDirectEditRequest(Request request) { + + final Request theRequest = request; + + if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { + directEditionMode = getDirectEditionType(); + } + switch (directEditionMode) { + case IDirectEdition.NO_DIRECT_EDITION: + // no direct edition mode => does nothing + return; + case IDirectEdition.EXTENDED_DIRECT_EDITOR: + updateExtendedEditorConfiguration(); + if (configuration == null || configuration.getLanguage() == null) { + // Create default edit manager + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + performDefaultDirectEditorEdit(theRequest); + } else { + configuration.preEditAction(resolveSemanticElement()); + Dialog dialog = null; + if (configuration instanceof ICustomDirectEditorConfiguration) { + setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); + initializeDirectEditManager(theRequest); + return; + } else if (configuration instanceof IPopupEditorConfiguration) { + IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); + helper.showEditor(); + return; + } + else if (configuration instanceof IAdvancedEditorConfiguration) { + dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); + } else if (configuration instanceof IDirectEditorConfiguration) { + dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), + configuration); + } else { + return; + } + final Dialog finalDialog = dialog; + + if (Window.OK == dialog.open()) { + TransactionalEditingDomain domain = getEditingDomain(); + RecordingCommand command = new RecordingCommand(domain, "Edit Label") { + + @Override + protected void doExecute() { + configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); + + } + }; + domain.getCommandStack().execute(command); + } + } + break; + case IDirectEdition.DEFAULT_DIRECT_EDITOR: + initializeDirectEditManager(theRequest); + break; + default: + break; + } + } + + /** + * @generated + */ + protected void initializeDirectEditManager(final Request request) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + @Override + public void run() { + if (isActive() && isEditable()) { + if (request.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } + else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void refreshVisuals() { + super.refreshVisuals(); + refreshLabel(); + refreshFont(); + refreshFontColor(); + refreshUnderline(); + refreshStrikeThrough(); + } + + /** + * @generated + */ + protected void refreshLabel() { + EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); + if (maskLabelPolicy == null) { + maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); + } + if (maskLabelPolicy == null) { + View view = (View) getModel(); + if (view.isVisible()) { + setLabelTextHelper(getFigure(), getLabelText()); + setLabelIconHelper(getFigure(), getLabelIcon()); + } + else { + setLabelTextHelper(getFigure(), ""); //$NON-NLS-1$ + setLabelIconHelper(getFigure(), null); + } + } + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + protected void refreshUnderline() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); + } + if (resolveSemanticElement() instanceof Feature) { + if (((Feature) resolveSemanticElement()).isStatic()) { + ((WrappingLabel) getFigure()).setTextUnderline(true); + } + else { + ((WrappingLabel) getFigure()).setTextUnderline(false); + } + } + } + + /** + * @generated + */ + protected void refreshStrikeThrough() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); + } + } + + /** + * @generated + */ + @Override + protected void refreshFont() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null) { + FontData fontData = new FontData( + style.getFontName(), style.getFontHeight(), + (style.isBold() ? SWT.BOLD : SWT.NORMAL) | + (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); + setFont(fontData); + } + } + + /** + * @generated + */ + @Override + protected void setFontColor(Color color) { + getFigure().setForegroundColor(color); + } + + /** + * @generated + */ + @Override + protected void addSemanticListeners() { + if (getParser() instanceof ISemanticParser) { + EObject element = resolveSemanticElement(); + parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); + for (int i = 0; i < parserElements.size(); i++) { + addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ + } + } else { + super.addSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected void removeSemanticListeners() { + if (parserElements != null) { + for (int i = 0; i < parserElements.size(); i++) { + removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ + } + } else { + super.removeSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected AccessibleEditPart getAccessibleEditPart() { + if (accessibleEP == null) { + accessibleEP = new AccessibleGraphicalEditPart() { + + @Override + public void getName(AccessibleEvent e) { + e.result = getLabelTextHelper(getFigure()); + } + }; + } + return accessibleEP; + } + + /** + * @generated + */ + private View getFontStyleOwnerView() { + return getPrimaryView(); + } + + /** + * Returns the kind of associated editor for direct edition. + * + * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition + * @generated + */ + public int getDirectEditionType() { + if (checkExtendedEditor()) { + initExtendedEditorConfiguration(); + return IDirectEdition.EXTENDED_DIRECT_EDITOR; + } + if (checkDefaultEdition()) { + return IDirectEdition.DEFAULT_DIRECT_EDITOR; + } + + // not a named element. no specific editor => do nothing + return IDirectEdition.NO_DIRECT_EDITION; + } + + /** + * Checks if an extended editor is present. + * + * @return true if an extended editor is present. + * @generated + */ + protected boolean checkExtendedEditor() { + if (resolveSemanticElement() != null) { + return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); + } + return false; + } + + /** + * Checks if a default direct edition is available + * + * @return true if a default direct edition is available + * @generated + */ + protected boolean checkDefaultEdition() { + return (getParser() != null); + } + + /** + * Initializes the extended editor configuration + * + * @generated + */ + protected void initExtendedEditorConfiguration() { + if (configuration == null) { + final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("")) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); + } else { + configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); + } + } + } + + /** + * Updates the preference configuration + * + * @generated + */ + protected void updateExtendedEditorConfiguration() { + String languagePreferred = Activator.getDefault().getPreferenceStore().getString( + IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() + .eClass().getInstanceClassName()); + } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { + configuration = null; + } + } + + /** + * Performs the direct edit usually used by GMF editors. + * + * @param theRequest + * the direct edit request that starts the direct edit system + * @generated + */ + protected void performDefaultDirectEditorEdit(final Request theRequest) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + + @Override + public void run() { + if (isActive() && isEditable()) { + if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) theRequest.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { + DirectEditRequest editRequest = (DirectEditRequest) theRequest; + performDirectEdit(editRequest.getLocation()); + } else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + + /** + * @generated + */ + @Override + protected void handleNotificationEvent(Notification event) { + Object feature = event.getFeature(); + if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { + Integer c = (Integer) event.getNewValue(); + setFontColor(DiagramColorRegistry.getInstance().getColor(c)); + } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { + refreshUnderline(); + } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { + refreshStrikeThrough(); + } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { + refreshFont(); + } else { + if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { + refreshLabel(); + } + if (getParser() instanceof ISemanticParser) { + ISemanticParser modelParser = + (ISemanticParser) getParser(); + if (modelParser.areSemanticElementsAffected(null, event)) { + removeSemanticListeners(); + if (resolveSemanticElement() != null) { + addSemanticListeners(); + } + refreshLabel(); + } + } + } + super.handleNotificationEvent(event); + } + + /** + * @generated + */ + @Override + protected IFigure createFigure() { + IFigure label = createFigurePrim(); + defaultText = getLabelTextHelper(label); + return label; + } + + /** + * @generated + */ + protected IFigure createFigurePrim() { + return new PapyrusWrappingLabel(); + } + +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InteractionCompositeFloatingLabelEditPartCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InteractionCompositeFloatingLabelEditPartCN.java new file mode 100644 index 00000000000..53dacc1e6b6 --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InteractionCompositeFloatingLabelEditPartCN.java @@ -0,0 +1,860 @@ +/** + * 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.uml.diagram.composite.edit.parts; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.Label; +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.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.RunnableWithResult; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gef.AccessibleEditPart; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.Request; +import org.eclipse.gef.requests.DirectEditRequest; +import org.eclipse.gef.tools.DirectEditManager; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; +import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; +import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; +import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; +import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; +import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; +import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; +import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; +import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; +import org.eclipse.gmf.runtime.notation.FontStyle; +import org.eclipse.gmf.runtime.notation.NotationPackage; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.text.contentassist.IContentAssistProcessor; +import org.eclipse.jface.viewers.ICellEditorValidator; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.extensionpoints.editors.Activator; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; +import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; +import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.ExternalLabelPrimaryDragRoleEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.PapyrusWrappingLabel; +import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; +import org.eclipse.papyrus.uml.diagram.common.editparts.FloatingLabelEditPart; +import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; +import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; +import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; +import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.accessibility.AccessibleEvent; +import org.eclipse.swt.custom.BusyIndicator; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; +import org.eclipse.uml2.uml.Feature; + +/** + * @generated + */ +public class InteractionCompositeFloatingLabelEditPartCN extends FloatingLabelEditPart + implements ITextAwareEditPart, IBorderItemEditPart +{ + + /** + * @generated + */ + public static final int VISUAL_ID = 6058; + + /** + * @generated + */ + private DirectEditManager manager; + + /** + * @generated + */ + private IParser parser; + + /** + * @generated + */ + private List parserElements; + + /** + * @generated + */ + private String defaultText; + + /** + * direct edition mode (default, undefined, registered editor, etc.) + * + * @generated + */ + protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; + + /** + * configuration from a registered edit dialog + * + * @generated + */ + protected IDirectEditorConfiguration configuration; + + + /** + * @generated + */ + static { + registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.InteractionCompositeFloatingLabelEditPartCN.VISUAL_ID), new Point(0, 0)); + } + + /** + * @generated + */ + public InteractionCompositeFloatingLabelEditPartCN(View view) { + super(view); + } + + /** + * @generated + */ + @Override + protected void createDefaultEditPolicies() { + super.createDefaultEditPolicies(); + installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); + installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ExternalLabelPrimaryDragRoleEditPolicy()); + } + + /** + * @generated + */ + @Override + public IBorderItemLocator getBorderItemLocator() { + IFigure parentFigure = getFigure().getParent(); + if (parentFigure != null && parentFigure.getLayoutManager() != null) { + Object constraint = parentFigure.getLayoutManager().getConstraint(getFigure()); + return (IBorderItemLocator) constraint; + } + return null; + } + + /** + * @generated + */ + @Override + public void refreshBounds() { + int x = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_X())).intValue(); + int y = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_Y())).intValue(); + int width = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Width())).intValue(); + int height = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Height())).intValue(); + getBorderItemLocator().setConstraint(new Rectangle(x, y, width, height)); + } + + + /** + * @generated + */ + protected String getLabelTextHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getText(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getText(); + } else { + return ((Label) figure).getText(); + } + } + + /** + * @generated + */ + protected void setLabelTextHelper(IFigure figure, String text) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setText(text); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setText(text); + } else { + ((Label) figure).setText(text); + } + } + + /** + * @generated + */ + protected Image getLabelIconHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getIcon(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getIcon(); + } else { + return ((Label) figure).getIcon(); + } + } + + /** + * @generated + */ + protected void setLabelIconHelper(IFigure figure, Image icon) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setIcon(icon); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setIcon(icon); + } else { + ((Label) figure).setIcon(icon); + } + } + + /** + * @generated + */ + public void setLabel(IFigure + figure) { + unregisterVisuals(); + setFigure(figure); + defaultText = getLabelTextHelper(figure); + registerVisuals(); + refreshVisuals(); + } + + /** + * @generated + */ + @Override + protected List getModelChildren() { + return Collections.EMPTY_LIST; + } + + /** + * @generated + */ + @Override + public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { + return null; + } + + /** + * @generated + */ + public void setParser(IParser parser) { + this.parser = parser; + } + + /** + * @generated + */ + protected EObject getParserElement() { + return resolveSemanticElement(); + } + + /** + * @generated + */ + protected Image getLabelIcon() { + return null; + } + + /** + * @generated + */ + protected String getLabelText() { + String text = null; + EObject parserElement = getParserElement(); + if (parserElement != null && getParser() != null) { + text = getParser().getPrintString( + new EObjectAdapter(parserElement), + getParserOptions().intValue()); + } + if (text == null || text.length() == 0) { + text = defaultText; + } + return text; + } + + /** + * @generated + */ + @Override + public void setLabelText(String text) { + setLabelTextHelper(getFigure(), text); + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + @Override + public String getEditText() { + if (getParserElement() == null || getParser() == null) { + return ""; //$NON-NLS-1$ + } + return getParser().getEditString( + new EObjectAdapter(getParserElement()), + getParserOptions().intValue()); + } + + /** + * @generated + */ + protected boolean isEditable() { + return getParser() != null; + } + + /** + * @generated + */ + @Override + public ICellEditorValidator getEditTextValidator() { + return new ICellEditorValidator() { + + @Override + public String isValid(final Object value) { + if (value instanceof String) { + final EObject element = getParserElement(); + final IParser parser = getParser(); + try { + IParserEditStatus valid = + (IParserEditStatus) getEditingDomain().runExclusive( + new RunnableWithResult.Impl() { + + @Override + public void run() { + setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); + } + }); + return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); + } catch (InterruptedException ie) { + ie.printStackTrace(); + } + } + + // shouldn't get here + return null; + } + }; + } + + /** + * @generated + */ + @Override + public IContentAssistProcessor getCompletionProcessor() { + if (getParserElement() == null || getParser() == null) { + return null; + } + return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); + } + + /** + * @generated + */ + @Override + public ParserOptions getParserOptions() { + return ParserOptions.NONE; + } + + /** + * @generated + */ + @Override + public IParser getParser() { + if (parser == null) { + parser = UMLParserProvider.getParser(UMLElementTypes.Interaction_3073, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.InteractionCompositeFloatingLabelEditPartCN.VISUAL_ID)); + } + return parser; + } + + /** + * @generated + */ + protected DirectEditManager getManager() { + if (manager == null) { + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + } + return manager; + } + + /** + * @generated + */ + protected void setManager(DirectEditManager manager) { + this.manager = manager; + } + + /** + * @generated + */ + protected void performDirectEdit() { + BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { + + @Override + public void run() { + getManager().show(); + } + }); + } + + /** + * @generated + */ + protected void performDirectEdit(Point eventLocation) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); + } + } + + /** + * @generated + */ + private void performDirectEdit(char initialCharacter) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(initialCharacter); + } else { + performDirectEdit(); + } + } + + /** + * @generated + */ + @Override + protected void performDirectEditRequest(Request request) { + + final Request theRequest = request; + + if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { + directEditionMode = getDirectEditionType(); + } + switch (directEditionMode) { + case IDirectEdition.NO_DIRECT_EDITION: + // no direct edition mode => does nothing + return; + case IDirectEdition.EXTENDED_DIRECT_EDITOR: + updateExtendedEditorConfiguration(); + if (configuration == null || configuration.getLanguage() == null) { + // Create default edit manager + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + performDefaultDirectEditorEdit(theRequest); + } else { + configuration.preEditAction(resolveSemanticElement()); + Dialog dialog = null; + if (configuration instanceof ICustomDirectEditorConfiguration) { + setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); + initializeDirectEditManager(theRequest); + return; + } else if (configuration instanceof IPopupEditorConfiguration) { + IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); + helper.showEditor(); + return; + } + else if (configuration instanceof IAdvancedEditorConfiguration) { + dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); + } else if (configuration instanceof IDirectEditorConfiguration) { + dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), + configuration); + } else { + return; + } + final Dialog finalDialog = dialog; + + if (Window.OK == dialog.open()) { + TransactionalEditingDomain domain = getEditingDomain(); + RecordingCommand command = new RecordingCommand(domain, "Edit Label") { + + @Override + protected void doExecute() { + configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); + + } + }; + domain.getCommandStack().execute(command); + } + } + break; + case IDirectEdition.DEFAULT_DIRECT_EDITOR: + initializeDirectEditManager(theRequest); + break; + default: + break; + } + } + + /** + * @generated + */ + protected void initializeDirectEditManager(final Request request) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + @Override + public void run() { + if (isActive() && isEditable()) { + if (request.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } + else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void refreshVisuals() { + super.refreshVisuals(); + refreshLabel(); + refreshFont(); + refreshFontColor(); + refreshUnderline(); + refreshStrikeThrough(); + } + + /** + * @generated + */ + protected void refreshLabel() { + EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); + if (maskLabelPolicy == null) { + maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); + } + if (maskLabelPolicy == null) { + View view = (View) getModel(); + if (view.isVisible()) { + setLabelTextHelper(getFigure(), getLabelText()); + setLabelIconHelper(getFigure(), getLabelIcon()); + } + else { + setLabelTextHelper(getFigure(), ""); //$NON-NLS-1$ + setLabelIconHelper(getFigure(), null); + } + } + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + protected void refreshUnderline() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); + } + if (resolveSemanticElement() instanceof Feature) { + if (((Feature) resolveSemanticElement()).isStatic()) { + ((WrappingLabel) getFigure()).setTextUnderline(true); + } + else { + ((WrappingLabel) getFigure()).setTextUnderline(false); + } + } + } + + /** + * @generated + */ + protected void refreshStrikeThrough() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); + } + } + + /** + * @generated + */ + @Override + protected void refreshFont() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null) { + FontData fontData = new FontData( + style.getFontName(), style.getFontHeight(), + (style.isBold() ? SWT.BOLD : SWT.NORMAL) | + (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); + setFont(fontData); + } + } + + /** + * @generated + */ + @Override + protected void setFontColor(Color color) { + getFigure().setForegroundColor(color); + } + + /** + * @generated + */ + @Override + protected void addSemanticListeners() { + if (getParser() instanceof ISemanticParser) { + EObject element = resolveSemanticElement(); + parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); + for (int i = 0; i < parserElements.size(); i++) { + addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ + } + } else { + super.addSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected void removeSemanticListeners() { + if (parserElements != null) { + for (int i = 0; i < parserElements.size(); i++) { + removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ + } + } else { + super.removeSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected AccessibleEditPart getAccessibleEditPart() { + if (accessibleEP == null) { + accessibleEP = new AccessibleGraphicalEditPart() { + + @Override + public void getName(AccessibleEvent e) { + e.result = getLabelTextHelper(getFigure()); + } + }; + } + return accessibleEP; + } + + /** + * @generated + */ + private View getFontStyleOwnerView() { + return getPrimaryView(); + } + + /** + * Returns the kind of associated editor for direct edition. + * + * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition + * @generated + */ + public int getDirectEditionType() { + if (checkExtendedEditor()) { + initExtendedEditorConfiguration(); + return IDirectEdition.EXTENDED_DIRECT_EDITOR; + } + if (checkDefaultEdition()) { + return IDirectEdition.DEFAULT_DIRECT_EDITOR; + } + + // not a named element. no specific editor => do nothing + return IDirectEdition.NO_DIRECT_EDITION; + } + + /** + * Checks if an extended editor is present. + * + * @return true if an extended editor is present. + * @generated + */ + protected boolean checkExtendedEditor() { + if (resolveSemanticElement() != null) { + return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); + } + return false; + } + + /** + * Checks if a default direct edition is available + * + * @return true if a default direct edition is available + * @generated + */ + protected boolean checkDefaultEdition() { + return (getParser() != null); + } + + /** + * Initializes the extended editor configuration + * + * @generated + */ + protected void initExtendedEditorConfiguration() { + if (configuration == null) { + final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("")) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); + } else { + configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); + } + } + } + + /** + * Updates the preference configuration + * + * @generated + */ + protected void updateExtendedEditorConfiguration() { + String languagePreferred = Activator.getDefault().getPreferenceStore().getString( + IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() + .eClass().getInstanceClassName()); + } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { + configuration = null; + } + } + + /** + * Performs the direct edit usually used by GMF editors. + * + * @param theRequest + * the direct edit request that starts the direct edit system + * @generated + */ + protected void performDefaultDirectEditorEdit(final Request theRequest) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + + @Override + public void run() { + if (isActive() && isEditable()) { + if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) theRequest.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { + DirectEditRequest editRequest = (DirectEditRequest) theRequest; + performDirectEdit(editRequest.getLocation()); + } else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + + /** + * @generated + */ + @Override + protected void handleNotificationEvent(Notification event) { + Object feature = event.getFeature(); + if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { + Integer c = (Integer) event.getNewValue(); + setFontColor(DiagramColorRegistry.getInstance().getColor(c)); + } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { + refreshUnderline(); + } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { + refreshStrikeThrough(); + } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { + refreshFont(); + } else { + if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { + refreshLabel(); + } + if (getParser() instanceof ISemanticParser) { + ISemanticParser modelParser = + (ISemanticParser) getParser(); + if (modelParser.areSemanticElementsAffected(null, event)) { + removeSemanticListeners(); + if (resolveSemanticElement() != null) { + addSemanticListeners(); + } + refreshLabel(); + } + } + } + super.handleNotificationEvent(event); + } + + /** + * @generated + */ + @Override + protected IFigure createFigure() { + IFigure label = createFigurePrim(); + defaultText = getLabelTextHelper(label); + return label; + } + + /** + * @generated + */ + protected IFigure createFigurePrim() { + return new PapyrusWrappingLabel(); + } + +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InteractionCompositeNameEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InteractionCompositeNameEditPart.java index 57e11cf3d52..a163b13a107 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InteractionCompositeNameEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InteractionCompositeNameEditPart.java @@ -864,7 +864,7 @@ public class InteractionCompositeNameEditPart extends PapyrusCompartmentEditPart * @generated */ protected void addOwnerElementListeners() { - addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); + addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InteractionCompositeNameEditPartCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InteractionCompositeNameEditPartCN.java index 4f8fd03dbf1..6c77a4029b0 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InteractionCompositeNameEditPartCN.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InteractionCompositeNameEditPartCN.java @@ -864,7 +864,7 @@ public class InteractionCompositeNameEditPartCN extends PapyrusCompartmentEditPa * @generated */ protected void addOwnerElementListeners() { - addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); + addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InteractionConstraintEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InteractionConstraintEditPart.java index 80a57c549aa..5c6ba3b0df0 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InteractionConstraintEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InteractionConstraintEditPart.java @@ -23,10 +23,10 @@ import org.eclipse.gef.requests.CreateRequest; import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles; import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; -import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure; import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure; import org.eclipse.gmf.runtime.notation.View; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.IPapyrusNodeFigure; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.RoundedRectangleNodePlateFigure; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.SelectableBorderedNodeFigure; import org.eclipse.papyrus.uml.diagram.common.editparts.AbstractConstraintEditPart; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeLabelDisplayEditPolicy; @@ -198,7 +198,7 @@ public class InteractionConstraintEditPart extends AbstractConstraintEditPart { */ @Override protected NodeFigure createNodePlate() { - DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(40, 40); + RoundedRectangleNodePlateFigure result = new RoundedRectangleNodePlateFigure(40, 40); return result; } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InteractionConstraintEditPartCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InteractionConstraintEditPartCN.java index d2f79cbf6b8..5ce2b772787 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InteractionConstraintEditPartCN.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InteractionConstraintEditPartCN.java @@ -23,10 +23,10 @@ import org.eclipse.gef.requests.CreateRequest; import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles; import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; -import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure; import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure; import org.eclipse.gmf.runtime.notation.View; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.IPapyrusNodeFigure; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.RoundedRectangleNodePlateFigure; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.SelectableBorderedNodeFigure; import org.eclipse.papyrus.uml.diagram.common.editparts.AbstractConstraintEditPart; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeLabelDisplayEditPolicy; @@ -198,7 +198,7 @@ public class InteractionConstraintEditPartCN extends AbstractConstraintEditPart */ @Override protected NodeFigure createNodePlate() { - DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(40, 40); + RoundedRectangleNodePlateFigure result = new RoundedRectangleNodePlateFigure(40, 40); return result; } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InteractionConstraintNameEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InteractionConstraintNameEditPart.java index b64c9e5e665..360efa6f965 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InteractionConstraintNameEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InteractionConstraintNameEditPart.java @@ -864,7 +864,7 @@ public class InteractionConstraintNameEditPart extends PapyrusCompartmentEditPar * @generated */ protected void addOwnerElementListeners() { - addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); + addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InteractionConstraintNameEditPartCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InteractionConstraintNameEditPartCN.java index 22fd5a4a375..63c057247fd 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InteractionConstraintNameEditPartCN.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InteractionConstraintNameEditPartCN.java @@ -864,7 +864,7 @@ public class InteractionConstraintNameEditPartCN extends PapyrusCompartmentEditP * @generated */ protected void addOwnerElementListeners() { - addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); + addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InteractionConstraintSpecificationEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InteractionConstraintSpecificationEditPart.java index df7439e1859..8012ffbc3ce 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InteractionConstraintSpecificationEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InteractionConstraintSpecificationEditPart.java @@ -847,7 +847,7 @@ public class InteractionConstraintSpecificationEditPart extends PapyrusCompartme * @generated */ protected void addOwnerElementListeners() { - addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); + addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InteractionConstraintSpecificationEditPartCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InteractionConstraintSpecificationEditPartCN.java index acc88b0ead5..88c32582ab1 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InteractionConstraintSpecificationEditPartCN.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InteractionConstraintSpecificationEditPartCN.java @@ -847,7 +847,7 @@ public class InteractionConstraintSpecificationEditPartCN extends PapyrusCompart * @generated */ protected void addOwnerElementListeners() { - addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); + addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InterfaceEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InterfaceEditPart.java index 1d66ba231f8..37df6a9ae34 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InterfaceEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InterfaceEditPart.java @@ -11,29 +11,41 @@ */ package org.eclipse.papyrus.uml.diagram.composite.edit.parts; +import java.util.Collections; +import java.util.List; + import org.eclipse.draw2d.IFigure; import org.eclipse.emf.common.notify.Notification; import org.eclipse.gef.EditPart; import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.GraphicalEditPart; 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.handles.MoveHandle; import org.eclipse.gef.requests.CreateRequest; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.BorderItemSelectionEditPolicy; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles; +import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; -import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure; import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure; +import org.eclipse.gmf.runtime.notation.Edge; +import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.GetChildLayoutEditPolicy; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.IPapyrusNodeFigure; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.RoundedRectangleNodePlateFigure; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.SelectableBorderedNodeFigure; -import org.eclipse.papyrus.uml.diagram.common.editparts.NamedElementEditPart; +import org.eclipse.papyrus.uml.diagram.common.editparts.RoundedCompartmentEditPart; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeNodeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.QualifiedNameDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.ShowHideClassifierContentsEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.ShowHideCompartmentEditPolicy; +import org.eclipse.papyrus.uml.diagram.common.locator.RoundedRectangleLabelPositionLocator; import org.eclipse.papyrus.uml.diagram.composite.custom.figures.InterfaceCompositeFigure; import org.eclipse.papyrus.uml.diagram.composite.edit.policies.InterfaceItemSemanticEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; @@ -42,7 +54,7 @@ import org.eclipse.swt.graphics.Color; /** * @generated */ -public class InterfaceEditPart extends NamedElementEditPart { +public class InterfaceEditPart extends RoundedCompartmentEditPart { /** * @generated @@ -78,6 +90,7 @@ public class InterfaceEditPart extends NamedElementEditPart { installEditPolicy(AppliedStereotypeLabelDisplayEditPolicy.STEREOTYPE_LABEL_POLICY, new AppliedStereotypeNodeLabelDisplayEditPolicy()); installEditPolicy(ShowHideClassifierContentsEditPolicy.SHOW_HIDE_CLASSIFIER_CONTENTS_POLICY, new ShowHideClassifierContentsEditPolicy()); installEditPolicy(ShowHideCompartmentEditPolicy.SHOW_HIDE_COMPARTMENT_POLICY, new ShowHideCompartmentEditPolicy()); + installEditPolicy(EditPolicy.LAYOUT_ROLE, new GetChildLayoutEditPolicy()); // XXX need an SCR to runtime to have another abstract superclass that would let children add reasonable editpolicies // removeEditPolicy(org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles.CONNECTION_HANDLES_ROLE); } @@ -90,6 +103,20 @@ public class InterfaceEditPart extends NamedElementEditPart { @Override protected EditPolicy createChildEditPolicy(EditPart child) { + View childView = (View) child.getModel(); + switch (UMLVisualIDRegistry.getVisualID(childView)) { + case InterfaceFloatingLabelEditPart.VISUAL_ID: + return new BorderItemSelectionEditPolicy() { + + @Override + protected List createSelectionHandles() { + MoveHandle mh = new MoveHandle((GraphicalEditPart) getHost()); + mh.setBorder(null); + return Collections.singletonList(mh); + } + } + ; + } EditPolicy result = child.getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); if (result == null) { result = new NonResizableEditPolicy(); @@ -117,6 +144,19 @@ public class InterfaceEditPart extends NamedElementEditPart { **/ @Override protected void handleNotificationEvent(Notification event) { + /* + * when a node have external node labels, the methods refreshChildren() remove the EditPart corresponding to the Label from the EditPart + * Registry. After that, we can't reset the visibility to true (using the Show/Hide Label Action)! + */ + if (NotationPackage.eINSTANCE.getView_Visible().equals(event.getFeature())) { + Object notifier = event.getNotifier(); + List modelChildren = ((View) getModel()).getChildren(); + if (!(notifier instanceof Edge)) { + if (modelChildren.contains(event.getNotifier())) { + return; + } + } + } super.handleNotificationEvent(event); } @@ -189,15 +229,32 @@ public class InterfaceEditPart extends NamedElementEditPart { */ @Override protected IFigure getContentPaneFor(IGraphicalEditPart editPart) { + if (editPart instanceof IBorderItemEditPart) { + return getBorderedFigure().getBorderItemContainer(); + } return getContentPane(); } + /** + * @generated + */ + @Override + protected void addBorderItem(IFigure borderItemContainer, IBorderItemEditPart borderItemEditPart) { + if (borderItemEditPart instanceof InterfaceFloatingLabelEditPart) { + IBorderItemLocator locator = new RoundedRectangleLabelPositionLocator(getMainFigure()); + borderItemContainer.add(borderItemEditPart.getFigure(), locator); + } else + { + super.addBorderItem(borderItemContainer, borderItemEditPart); + } + } + /** * @generated */ @Override protected NodeFigure createNodePlate() { - DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(40, 40); + RoundedRectangleNodePlateFigure result = new RoundedRectangleNodePlateFigure(40, 40); return result; } @@ -210,7 +267,7 @@ public class InterfaceEditPart extends NamedElementEditPart { * @generated */ @Override - protected NodeFigure createNodeFigure() { + protected NodeFigure createMainFigure() { return new SelectableBorderedNodeFigure(createMainFigureWithSVG()); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InterfaceEditPartCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InterfaceEditPartCN.java index c898ea8d785..85eb6cd0e71 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InterfaceEditPartCN.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InterfaceEditPartCN.java @@ -11,29 +11,41 @@ */ package org.eclipse.papyrus.uml.diagram.composite.edit.parts; +import java.util.Collections; +import java.util.List; + import org.eclipse.draw2d.IFigure; import org.eclipse.emf.common.notify.Notification; import org.eclipse.gef.EditPart; import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.GraphicalEditPart; 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.handles.MoveHandle; import org.eclipse.gef.requests.CreateRequest; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.BorderItemSelectionEditPolicy; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles; +import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; -import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure; import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure; +import org.eclipse.gmf.runtime.notation.Edge; +import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.GetChildLayoutEditPolicy; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.IPapyrusNodeFigure; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.RoundedRectangleNodePlateFigure; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.SelectableBorderedNodeFigure; -import org.eclipse.papyrus.uml.diagram.common.editparts.NamedElementEditPart; +import org.eclipse.papyrus.uml.diagram.common.editparts.RoundedCompartmentEditPart; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeNodeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.QualifiedNameDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.ShowHideClassifierContentsEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.ShowHideCompartmentEditPolicy; +import org.eclipse.papyrus.uml.diagram.common.locator.RoundedRectangleLabelPositionLocator; import org.eclipse.papyrus.uml.diagram.composite.custom.figures.InterfaceCompositeFigure; import org.eclipse.papyrus.uml.diagram.composite.edit.policies.InterfaceItemSemanticEditPolicyCN; import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; @@ -42,7 +54,7 @@ import org.eclipse.swt.graphics.Color; /** * @generated */ -public class InterfaceEditPartCN extends NamedElementEditPart { +public class InterfaceEditPartCN extends RoundedCompartmentEditPart { /** * @generated @@ -78,6 +90,7 @@ public class InterfaceEditPartCN extends NamedElementEditPart { installEditPolicy(AppliedStereotypeLabelDisplayEditPolicy.STEREOTYPE_LABEL_POLICY, new AppliedStereotypeNodeLabelDisplayEditPolicy()); installEditPolicy(ShowHideClassifierContentsEditPolicy.SHOW_HIDE_CLASSIFIER_CONTENTS_POLICY, new ShowHideClassifierContentsEditPolicy()); installEditPolicy(ShowHideCompartmentEditPolicy.SHOW_HIDE_COMPARTMENT_POLICY, new ShowHideCompartmentEditPolicy()); + installEditPolicy(EditPolicy.LAYOUT_ROLE, new GetChildLayoutEditPolicy()); // XXX need an SCR to runtime to have another abstract superclass that would let children add reasonable editpolicies // removeEditPolicy(org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles.CONNECTION_HANDLES_ROLE); } @@ -90,6 +103,20 @@ public class InterfaceEditPartCN extends NamedElementEditPart { @Override protected EditPolicy createChildEditPolicy(EditPart child) { + View childView = (View) child.getModel(); + switch (UMLVisualIDRegistry.getVisualID(childView)) { + case InterfaceFloatingLabelEditPartCN.VISUAL_ID: + return new BorderItemSelectionEditPolicy() { + + @Override + protected List createSelectionHandles() { + MoveHandle mh = new MoveHandle((GraphicalEditPart) getHost()); + mh.setBorder(null); + return Collections.singletonList(mh); + } + } + ; + } EditPolicy result = child.getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); if (result == null) { result = new NonResizableEditPolicy(); @@ -117,6 +144,19 @@ public class InterfaceEditPartCN extends NamedElementEditPart { **/ @Override protected void handleNotificationEvent(Notification event) { + /* + * when a node have external node labels, the methods refreshChildren() remove the EditPart corresponding to the Label from the EditPart + * Registry. After that, we can't reset the visibility to true (using the Show/Hide Label Action)! + */ + if (NotationPackage.eINSTANCE.getView_Visible().equals(event.getFeature())) { + Object notifier = event.getNotifier(); + List modelChildren = ((View) getModel()).getChildren(); + if (!(notifier instanceof Edge)) { + if (modelChildren.contains(event.getNotifier())) { + return; + } + } + } super.handleNotificationEvent(event); } @@ -189,15 +229,32 @@ public class InterfaceEditPartCN extends NamedElementEditPart { */ @Override protected IFigure getContentPaneFor(IGraphicalEditPart editPart) { + if (editPart instanceof IBorderItemEditPart) { + return getBorderedFigure().getBorderItemContainer(); + } return getContentPane(); } + /** + * @generated + */ + @Override + protected void addBorderItem(IFigure borderItemContainer, IBorderItemEditPart borderItemEditPart) { + if (borderItemEditPart instanceof InterfaceFloatingLabelEditPartCN) { + IBorderItemLocator locator = new RoundedRectangleLabelPositionLocator(getMainFigure()); + borderItemContainer.add(borderItemEditPart.getFigure(), locator); + } else + { + super.addBorderItem(borderItemContainer, borderItemEditPart); + } + } + /** * @generated */ @Override protected NodeFigure createNodePlate() { - DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(40, 40); + RoundedRectangleNodePlateFigure result = new RoundedRectangleNodePlateFigure(40, 40); return result; } @@ -210,7 +267,7 @@ public class InterfaceEditPartCN extends NamedElementEditPart { * @generated */ @Override - protected NodeFigure createNodeFigure() { + protected NodeFigure createMainFigure() { return new SelectableBorderedNodeFigure(createMainFigureWithSVG()); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InterfaceFloatingLabelEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InterfaceFloatingLabelEditPart.java new file mode 100644 index 00000000000..5bc47c0ea87 --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InterfaceFloatingLabelEditPart.java @@ -0,0 +1,860 @@ +/** + * 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.uml.diagram.composite.edit.parts; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.Label; +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.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.RunnableWithResult; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gef.AccessibleEditPart; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.Request; +import org.eclipse.gef.requests.DirectEditRequest; +import org.eclipse.gef.tools.DirectEditManager; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; +import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; +import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; +import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; +import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; +import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; +import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; +import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; +import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; +import org.eclipse.gmf.runtime.notation.FontStyle; +import org.eclipse.gmf.runtime.notation.NotationPackage; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.text.contentassist.IContentAssistProcessor; +import org.eclipse.jface.viewers.ICellEditorValidator; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.extensionpoints.editors.Activator; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; +import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; +import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.ExternalLabelPrimaryDragRoleEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.PapyrusWrappingLabel; +import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; +import org.eclipse.papyrus.uml.diagram.common.editparts.FloatingLabelEditPart; +import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; +import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; +import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; +import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.accessibility.AccessibleEvent; +import org.eclipse.swt.custom.BusyIndicator; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; +import org.eclipse.uml2.uml.Feature; + +/** + * @generated + */ +public class InterfaceFloatingLabelEditPart extends FloatingLabelEditPart + implements ITextAwareEditPart, IBorderItemEditPart +{ + + /** + * @generated + */ + public static final int VISUAL_ID = 6091; + + /** + * @generated + */ + private DirectEditManager manager; + + /** + * @generated + */ + private IParser parser; + + /** + * @generated + */ + private List parserElements; + + /** + * @generated + */ + private String defaultText; + + /** + * direct edition mode (default, undefined, registered editor, etc.) + * + * @generated + */ + protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; + + /** + * configuration from a registered edit dialog + * + * @generated + */ + protected IDirectEditorConfiguration configuration; + + + /** + * @generated + */ + static { + registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.InterfaceFloatingLabelEditPart.VISUAL_ID), new Point(0, 0)); + } + + /** + * @generated + */ + public InterfaceFloatingLabelEditPart(View view) { + super(view); + } + + /** + * @generated + */ + @Override + protected void createDefaultEditPolicies() { + super.createDefaultEditPolicies(); + installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); + installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ExternalLabelPrimaryDragRoleEditPolicy()); + } + + /** + * @generated + */ + @Override + public IBorderItemLocator getBorderItemLocator() { + IFigure parentFigure = getFigure().getParent(); + if (parentFigure != null && parentFigure.getLayoutManager() != null) { + Object constraint = parentFigure.getLayoutManager().getConstraint(getFigure()); + return (IBorderItemLocator) constraint; + } + return null; + } + + /** + * @generated + */ + @Override + public void refreshBounds() { + int x = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_X())).intValue(); + int y = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_Y())).intValue(); + int width = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Width())).intValue(); + int height = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Height())).intValue(); + getBorderItemLocator().setConstraint(new Rectangle(x, y, width, height)); + } + + + /** + * @generated + */ + protected String getLabelTextHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getText(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getText(); + } else { + return ((Label) figure).getText(); + } + } + + /** + * @generated + */ + protected void setLabelTextHelper(IFigure figure, String text) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setText(text); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setText(text); + } else { + ((Label) figure).setText(text); + } + } + + /** + * @generated + */ + protected Image getLabelIconHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getIcon(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getIcon(); + } else { + return ((Label) figure).getIcon(); + } + } + + /** + * @generated + */ + protected void setLabelIconHelper(IFigure figure, Image icon) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setIcon(icon); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setIcon(icon); + } else { + ((Label) figure).setIcon(icon); + } + } + + /** + * @generated + */ + public void setLabel(IFigure + figure) { + unregisterVisuals(); + setFigure(figure); + defaultText = getLabelTextHelper(figure); + registerVisuals(); + refreshVisuals(); + } + + /** + * @generated + */ + @Override + protected List getModelChildren() { + return Collections.EMPTY_LIST; + } + + /** + * @generated + */ + @Override + public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { + return null; + } + + /** + * @generated + */ + public void setParser(IParser parser) { + this.parser = parser; + } + + /** + * @generated + */ + protected EObject getParserElement() { + return resolveSemanticElement(); + } + + /** + * @generated + */ + protected Image getLabelIcon() { + return null; + } + + /** + * @generated + */ + protected String getLabelText() { + String text = null; + EObject parserElement = getParserElement(); + if (parserElement != null && getParser() != null) { + text = getParser().getPrintString( + new EObjectAdapter(parserElement), + getParserOptions().intValue()); + } + if (text == null || text.length() == 0) { + text = defaultText; + } + return text; + } + + /** + * @generated + */ + @Override + public void setLabelText(String text) { + setLabelTextHelper(getFigure(), text); + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + @Override + public String getEditText() { + if (getParserElement() == null || getParser() == null) { + return ""; //$NON-NLS-1$ + } + return getParser().getEditString( + new EObjectAdapter(getParserElement()), + getParserOptions().intValue()); + } + + /** + * @generated + */ + protected boolean isEditable() { + return getParser() != null; + } + + /** + * @generated + */ + @Override + public ICellEditorValidator getEditTextValidator() { + return new ICellEditorValidator() { + + @Override + public String isValid(final Object value) { + if (value instanceof String) { + final EObject element = getParserElement(); + final IParser parser = getParser(); + try { + IParserEditStatus valid = + (IParserEditStatus) getEditingDomain().runExclusive( + new RunnableWithResult.Impl() { + + @Override + public void run() { + setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); + } + }); + return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); + } catch (InterruptedException ie) { + ie.printStackTrace(); + } + } + + // shouldn't get here + return null; + } + }; + } + + /** + * @generated + */ + @Override + public IContentAssistProcessor getCompletionProcessor() { + if (getParserElement() == null || getParser() == null) { + return null; + } + return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); + } + + /** + * @generated + */ + @Override + public ParserOptions getParserOptions() { + return ParserOptions.NONE; + } + + /** + * @generated + */ + @Override + public IParser getParser() { + if (parser == null) { + parser = UMLParserProvider.getParser(UMLElementTypes.Interface_2076, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.InterfaceFloatingLabelEditPart.VISUAL_ID)); + } + return parser; + } + + /** + * @generated + */ + protected DirectEditManager getManager() { + if (manager == null) { + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + } + return manager; + } + + /** + * @generated + */ + protected void setManager(DirectEditManager manager) { + this.manager = manager; + } + + /** + * @generated + */ + protected void performDirectEdit() { + BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { + + @Override + public void run() { + getManager().show(); + } + }); + } + + /** + * @generated + */ + protected void performDirectEdit(Point eventLocation) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); + } + } + + /** + * @generated + */ + private void performDirectEdit(char initialCharacter) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(initialCharacter); + } else { + performDirectEdit(); + } + } + + /** + * @generated + */ + @Override + protected void performDirectEditRequest(Request request) { + + final Request theRequest = request; + + if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { + directEditionMode = getDirectEditionType(); + } + switch (directEditionMode) { + case IDirectEdition.NO_DIRECT_EDITION: + // no direct edition mode => does nothing + return; + case IDirectEdition.EXTENDED_DIRECT_EDITOR: + updateExtendedEditorConfiguration(); + if (configuration == null || configuration.getLanguage() == null) { + // Create default edit manager + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + performDefaultDirectEditorEdit(theRequest); + } else { + configuration.preEditAction(resolveSemanticElement()); + Dialog dialog = null; + if (configuration instanceof ICustomDirectEditorConfiguration) { + setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); + initializeDirectEditManager(theRequest); + return; + } else if (configuration instanceof IPopupEditorConfiguration) { + IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); + helper.showEditor(); + return; + } + else if (configuration instanceof IAdvancedEditorConfiguration) { + dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); + } else if (configuration instanceof IDirectEditorConfiguration) { + dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), + configuration); + } else { + return; + } + final Dialog finalDialog = dialog; + + if (Window.OK == dialog.open()) { + TransactionalEditingDomain domain = getEditingDomain(); + RecordingCommand command = new RecordingCommand(domain, "Edit Label") { + + @Override + protected void doExecute() { + configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); + + } + }; + domain.getCommandStack().execute(command); + } + } + break; + case IDirectEdition.DEFAULT_DIRECT_EDITOR: + initializeDirectEditManager(theRequest); + break; + default: + break; + } + } + + /** + * @generated + */ + protected void initializeDirectEditManager(final Request request) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + @Override + public void run() { + if (isActive() && isEditable()) { + if (request.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } + else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void refreshVisuals() { + super.refreshVisuals(); + refreshLabel(); + refreshFont(); + refreshFontColor(); + refreshUnderline(); + refreshStrikeThrough(); + } + + /** + * @generated + */ + protected void refreshLabel() { + EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); + if (maskLabelPolicy == null) { + maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); + } + if (maskLabelPolicy == null) { + View view = (View) getModel(); + if (view.isVisible()) { + setLabelTextHelper(getFigure(), getLabelText()); + setLabelIconHelper(getFigure(), getLabelIcon()); + } + else { + setLabelTextHelper(getFigure(), ""); //$NON-NLS-1$ + setLabelIconHelper(getFigure(), null); + } + } + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + protected void refreshUnderline() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); + } + if (resolveSemanticElement() instanceof Feature) { + if (((Feature) resolveSemanticElement()).isStatic()) { + ((WrappingLabel) getFigure()).setTextUnderline(true); + } + else { + ((WrappingLabel) getFigure()).setTextUnderline(false); + } + } + } + + /** + * @generated + */ + protected void refreshStrikeThrough() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); + } + } + + /** + * @generated + */ + @Override + protected void refreshFont() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null) { + FontData fontData = new FontData( + style.getFontName(), style.getFontHeight(), + (style.isBold() ? SWT.BOLD : SWT.NORMAL) | + (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); + setFont(fontData); + } + } + + /** + * @generated + */ + @Override + protected void setFontColor(Color color) { + getFigure().setForegroundColor(color); + } + + /** + * @generated + */ + @Override + protected void addSemanticListeners() { + if (getParser() instanceof ISemanticParser) { + EObject element = resolveSemanticElement(); + parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); + for (int i = 0; i < parserElements.size(); i++) { + addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ + } + } else { + super.addSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected void removeSemanticListeners() { + if (parserElements != null) { + for (int i = 0; i < parserElements.size(); i++) { + removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ + } + } else { + super.removeSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected AccessibleEditPart getAccessibleEditPart() { + if (accessibleEP == null) { + accessibleEP = new AccessibleGraphicalEditPart() { + + @Override + public void getName(AccessibleEvent e) { + e.result = getLabelTextHelper(getFigure()); + } + }; + } + return accessibleEP; + } + + /** + * @generated + */ + private View getFontStyleOwnerView() { + return getPrimaryView(); + } + + /** + * Returns the kind of associated editor for direct edition. + * + * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition + * @generated + */ + public int getDirectEditionType() { + if (checkExtendedEditor()) { + initExtendedEditorConfiguration(); + return IDirectEdition.EXTENDED_DIRECT_EDITOR; + } + if (checkDefaultEdition()) { + return IDirectEdition.DEFAULT_DIRECT_EDITOR; + } + + // not a named element. no specific editor => do nothing + return IDirectEdition.NO_DIRECT_EDITION; + } + + /** + * Checks if an extended editor is present. + * + * @return true if an extended editor is present. + * @generated + */ + protected boolean checkExtendedEditor() { + if (resolveSemanticElement() != null) { + return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); + } + return false; + } + + /** + * Checks if a default direct edition is available + * + * @return true if a default direct edition is available + * @generated + */ + protected boolean checkDefaultEdition() { + return (getParser() != null); + } + + /** + * Initializes the extended editor configuration + * + * @generated + */ + protected void initExtendedEditorConfiguration() { + if (configuration == null) { + final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("")) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); + } else { + configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); + } + } + } + + /** + * Updates the preference configuration + * + * @generated + */ + protected void updateExtendedEditorConfiguration() { + String languagePreferred = Activator.getDefault().getPreferenceStore().getString( + IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() + .eClass().getInstanceClassName()); + } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { + configuration = null; + } + } + + /** + * Performs the direct edit usually used by GMF editors. + * + * @param theRequest + * the direct edit request that starts the direct edit system + * @generated + */ + protected void performDefaultDirectEditorEdit(final Request theRequest) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + + @Override + public void run() { + if (isActive() && isEditable()) { + if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) theRequest.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { + DirectEditRequest editRequest = (DirectEditRequest) theRequest; + performDirectEdit(editRequest.getLocation()); + } else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + + /** + * @generated + */ + @Override + protected void handleNotificationEvent(Notification event) { + Object feature = event.getFeature(); + if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { + Integer c = (Integer) event.getNewValue(); + setFontColor(DiagramColorRegistry.getInstance().getColor(c)); + } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { + refreshUnderline(); + } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { + refreshStrikeThrough(); + } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { + refreshFont(); + } else { + if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { + refreshLabel(); + } + if (getParser() instanceof ISemanticParser) { + ISemanticParser modelParser = + (ISemanticParser) getParser(); + if (modelParser.areSemanticElementsAffected(null, event)) { + removeSemanticListeners(); + if (resolveSemanticElement() != null) { + addSemanticListeners(); + } + refreshLabel(); + } + } + } + super.handleNotificationEvent(event); + } + + /** + * @generated + */ + @Override + protected IFigure createFigure() { + IFigure label = createFigurePrim(); + defaultText = getLabelTextHelper(label); + return label; + } + + /** + * @generated + */ + protected IFigure createFigurePrim() { + return new PapyrusWrappingLabel(); + } + +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InterfaceFloatingLabelEditPartCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InterfaceFloatingLabelEditPartCN.java new file mode 100644 index 00000000000..013bae3b94b --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InterfaceFloatingLabelEditPartCN.java @@ -0,0 +1,860 @@ +/** + * 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.uml.diagram.composite.edit.parts; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.Label; +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.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.RunnableWithResult; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gef.AccessibleEditPart; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.Request; +import org.eclipse.gef.requests.DirectEditRequest; +import org.eclipse.gef.tools.DirectEditManager; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; +import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; +import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; +import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; +import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; +import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; +import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; +import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; +import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; +import org.eclipse.gmf.runtime.notation.FontStyle; +import org.eclipse.gmf.runtime.notation.NotationPackage; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.text.contentassist.IContentAssistProcessor; +import org.eclipse.jface.viewers.ICellEditorValidator; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.extensionpoints.editors.Activator; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; +import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; +import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.ExternalLabelPrimaryDragRoleEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.PapyrusWrappingLabel; +import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; +import org.eclipse.papyrus.uml.diagram.common.editparts.FloatingLabelEditPart; +import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; +import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; +import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; +import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.accessibility.AccessibleEvent; +import org.eclipse.swt.custom.BusyIndicator; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; +import org.eclipse.uml2.uml.Feature; + +/** + * @generated + */ +public class InterfaceFloatingLabelEditPartCN extends FloatingLabelEditPart + implements ITextAwareEditPart, IBorderItemEditPart +{ + + /** + * @generated + */ + public static final int VISUAL_ID = 6069; + + /** + * @generated + */ + private DirectEditManager manager; + + /** + * @generated + */ + private IParser parser; + + /** + * @generated + */ + private List parserElements; + + /** + * @generated + */ + private String defaultText; + + /** + * direct edition mode (default, undefined, registered editor, etc.) + * + * @generated + */ + protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; + + /** + * configuration from a registered edit dialog + * + * @generated + */ + protected IDirectEditorConfiguration configuration; + + + /** + * @generated + */ + static { + registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.InterfaceFloatingLabelEditPartCN.VISUAL_ID), new Point(0, 0)); + } + + /** + * @generated + */ + public InterfaceFloatingLabelEditPartCN(View view) { + super(view); + } + + /** + * @generated + */ + @Override + protected void createDefaultEditPolicies() { + super.createDefaultEditPolicies(); + installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); + installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ExternalLabelPrimaryDragRoleEditPolicy()); + } + + /** + * @generated + */ + @Override + public IBorderItemLocator getBorderItemLocator() { + IFigure parentFigure = getFigure().getParent(); + if (parentFigure != null && parentFigure.getLayoutManager() != null) { + Object constraint = parentFigure.getLayoutManager().getConstraint(getFigure()); + return (IBorderItemLocator) constraint; + } + return null; + } + + /** + * @generated + */ + @Override + public void refreshBounds() { + int x = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_X())).intValue(); + int y = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_Y())).intValue(); + int width = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Width())).intValue(); + int height = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Height())).intValue(); + getBorderItemLocator().setConstraint(new Rectangle(x, y, width, height)); + } + + + /** + * @generated + */ + protected String getLabelTextHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getText(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getText(); + } else { + return ((Label) figure).getText(); + } + } + + /** + * @generated + */ + protected void setLabelTextHelper(IFigure figure, String text) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setText(text); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setText(text); + } else { + ((Label) figure).setText(text); + } + } + + /** + * @generated + */ + protected Image getLabelIconHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getIcon(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getIcon(); + } else { + return ((Label) figure).getIcon(); + } + } + + /** + * @generated + */ + protected void setLabelIconHelper(IFigure figure, Image icon) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setIcon(icon); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setIcon(icon); + } else { + ((Label) figure).setIcon(icon); + } + } + + /** + * @generated + */ + public void setLabel(IFigure + figure) { + unregisterVisuals(); + setFigure(figure); + defaultText = getLabelTextHelper(figure); + registerVisuals(); + refreshVisuals(); + } + + /** + * @generated + */ + @Override + protected List getModelChildren() { + return Collections.EMPTY_LIST; + } + + /** + * @generated + */ + @Override + public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { + return null; + } + + /** + * @generated + */ + public void setParser(IParser parser) { + this.parser = parser; + } + + /** + * @generated + */ + protected EObject getParserElement() { + return resolveSemanticElement(); + } + + /** + * @generated + */ + protected Image getLabelIcon() { + return null; + } + + /** + * @generated + */ + protected String getLabelText() { + String text = null; + EObject parserElement = getParserElement(); + if (parserElement != null && getParser() != null) { + text = getParser().getPrintString( + new EObjectAdapter(parserElement), + getParserOptions().intValue()); + } + if (text == null || text.length() == 0) { + text = defaultText; + } + return text; + } + + /** + * @generated + */ + @Override + public void setLabelText(String text) { + setLabelTextHelper(getFigure(), text); + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + @Override + public String getEditText() { + if (getParserElement() == null || getParser() == null) { + return ""; //$NON-NLS-1$ + } + return getParser().getEditString( + new EObjectAdapter(getParserElement()), + getParserOptions().intValue()); + } + + /** + * @generated + */ + protected boolean isEditable() { + return getParser() != null; + } + + /** + * @generated + */ + @Override + public ICellEditorValidator getEditTextValidator() { + return new ICellEditorValidator() { + + @Override + public String isValid(final Object value) { + if (value instanceof String) { + final EObject element = getParserElement(); + final IParser parser = getParser(); + try { + IParserEditStatus valid = + (IParserEditStatus) getEditingDomain().runExclusive( + new RunnableWithResult.Impl() { + + @Override + public void run() { + setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); + } + }); + return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); + } catch (InterruptedException ie) { + ie.printStackTrace(); + } + } + + // shouldn't get here + return null; + } + }; + } + + /** + * @generated + */ + @Override + public IContentAssistProcessor getCompletionProcessor() { + if (getParserElement() == null || getParser() == null) { + return null; + } + return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); + } + + /** + * @generated + */ + @Override + public ParserOptions getParserOptions() { + return ParserOptions.NONE; + } + + /** + * @generated + */ + @Override + public IParser getParser() { + if (parser == null) { + parser = UMLParserProvider.getParser(UMLElementTypes.Interface_3087, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.InterfaceFloatingLabelEditPartCN.VISUAL_ID)); + } + return parser; + } + + /** + * @generated + */ + protected DirectEditManager getManager() { + if (manager == null) { + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + } + return manager; + } + + /** + * @generated + */ + protected void setManager(DirectEditManager manager) { + this.manager = manager; + } + + /** + * @generated + */ + protected void performDirectEdit() { + BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { + + @Override + public void run() { + getManager().show(); + } + }); + } + + /** + * @generated + */ + protected void performDirectEdit(Point eventLocation) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); + } + } + + /** + * @generated + */ + private void performDirectEdit(char initialCharacter) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(initialCharacter); + } else { + performDirectEdit(); + } + } + + /** + * @generated + */ + @Override + protected void performDirectEditRequest(Request request) { + + final Request theRequest = request; + + if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { + directEditionMode = getDirectEditionType(); + } + switch (directEditionMode) { + case IDirectEdition.NO_DIRECT_EDITION: + // no direct edition mode => does nothing + return; + case IDirectEdition.EXTENDED_DIRECT_EDITOR: + updateExtendedEditorConfiguration(); + if (configuration == null || configuration.getLanguage() == null) { + // Create default edit manager + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + performDefaultDirectEditorEdit(theRequest); + } else { + configuration.preEditAction(resolveSemanticElement()); + Dialog dialog = null; + if (configuration instanceof ICustomDirectEditorConfiguration) { + setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); + initializeDirectEditManager(theRequest); + return; + } else if (configuration instanceof IPopupEditorConfiguration) { + IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); + helper.showEditor(); + return; + } + else if (configuration instanceof IAdvancedEditorConfiguration) { + dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); + } else if (configuration instanceof IDirectEditorConfiguration) { + dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), + configuration); + } else { + return; + } + final Dialog finalDialog = dialog; + + if (Window.OK == dialog.open()) { + TransactionalEditingDomain domain = getEditingDomain(); + RecordingCommand command = new RecordingCommand(domain, "Edit Label") { + + @Override + protected void doExecute() { + configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); + + } + }; + domain.getCommandStack().execute(command); + } + } + break; + case IDirectEdition.DEFAULT_DIRECT_EDITOR: + initializeDirectEditManager(theRequest); + break; + default: + break; + } + } + + /** + * @generated + */ + protected void initializeDirectEditManager(final Request request) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + @Override + public void run() { + if (isActive() && isEditable()) { + if (request.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } + else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void refreshVisuals() { + super.refreshVisuals(); + refreshLabel(); + refreshFont(); + refreshFontColor(); + refreshUnderline(); + refreshStrikeThrough(); + } + + /** + * @generated + */ + protected void refreshLabel() { + EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); + if (maskLabelPolicy == null) { + maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); + } + if (maskLabelPolicy == null) { + View view = (View) getModel(); + if (view.isVisible()) { + setLabelTextHelper(getFigure(), getLabelText()); + setLabelIconHelper(getFigure(), getLabelIcon()); + } + else { + setLabelTextHelper(getFigure(), ""); //$NON-NLS-1$ + setLabelIconHelper(getFigure(), null); + } + } + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + protected void refreshUnderline() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); + } + if (resolveSemanticElement() instanceof Feature) { + if (((Feature) resolveSemanticElement()).isStatic()) { + ((WrappingLabel) getFigure()).setTextUnderline(true); + } + else { + ((WrappingLabel) getFigure()).setTextUnderline(false); + } + } + } + + /** + * @generated + */ + protected void refreshStrikeThrough() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); + } + } + + /** + * @generated + */ + @Override + protected void refreshFont() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null) { + FontData fontData = new FontData( + style.getFontName(), style.getFontHeight(), + (style.isBold() ? SWT.BOLD : SWT.NORMAL) | + (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); + setFont(fontData); + } + } + + /** + * @generated + */ + @Override + protected void setFontColor(Color color) { + getFigure().setForegroundColor(color); + } + + /** + * @generated + */ + @Override + protected void addSemanticListeners() { + if (getParser() instanceof ISemanticParser) { + EObject element = resolveSemanticElement(); + parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); + for (int i = 0; i < parserElements.size(); i++) { + addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ + } + } else { + super.addSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected void removeSemanticListeners() { + if (parserElements != null) { + for (int i = 0; i < parserElements.size(); i++) { + removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ + } + } else { + super.removeSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected AccessibleEditPart getAccessibleEditPart() { + if (accessibleEP == null) { + accessibleEP = new AccessibleGraphicalEditPart() { + + @Override + public void getName(AccessibleEvent e) { + e.result = getLabelTextHelper(getFigure()); + } + }; + } + return accessibleEP; + } + + /** + * @generated + */ + private View getFontStyleOwnerView() { + return getPrimaryView(); + } + + /** + * Returns the kind of associated editor for direct edition. + * + * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition + * @generated + */ + public int getDirectEditionType() { + if (checkExtendedEditor()) { + initExtendedEditorConfiguration(); + return IDirectEdition.EXTENDED_DIRECT_EDITOR; + } + if (checkDefaultEdition()) { + return IDirectEdition.DEFAULT_DIRECT_EDITOR; + } + + // not a named element. no specific editor => do nothing + return IDirectEdition.NO_DIRECT_EDITION; + } + + /** + * Checks if an extended editor is present. + * + * @return true if an extended editor is present. + * @generated + */ + protected boolean checkExtendedEditor() { + if (resolveSemanticElement() != null) { + return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); + } + return false; + } + + /** + * Checks if a default direct edition is available + * + * @return true if a default direct edition is available + * @generated + */ + protected boolean checkDefaultEdition() { + return (getParser() != null); + } + + /** + * Initializes the extended editor configuration + * + * @generated + */ + protected void initExtendedEditorConfiguration() { + if (configuration == null) { + final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("")) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); + } else { + configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); + } + } + } + + /** + * Updates the preference configuration + * + * @generated + */ + protected void updateExtendedEditorConfiguration() { + String languagePreferred = Activator.getDefault().getPreferenceStore().getString( + IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() + .eClass().getInstanceClassName()); + } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { + configuration = null; + } + } + + /** + * Performs the direct edit usually used by GMF editors. + * + * @param theRequest + * the direct edit request that starts the direct edit system + * @generated + */ + protected void performDefaultDirectEditorEdit(final Request theRequest) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + + @Override + public void run() { + if (isActive() && isEditable()) { + if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) theRequest.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { + DirectEditRequest editRequest = (DirectEditRequest) theRequest; + performDirectEdit(editRequest.getLocation()); + } else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + + /** + * @generated + */ + @Override + protected void handleNotificationEvent(Notification event) { + Object feature = event.getFeature(); + if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { + Integer c = (Integer) event.getNewValue(); + setFontColor(DiagramColorRegistry.getInstance().getColor(c)); + } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { + refreshUnderline(); + } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { + refreshStrikeThrough(); + } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { + refreshFont(); + } else { + if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { + refreshLabel(); + } + if (getParser() instanceof ISemanticParser) { + ISemanticParser modelParser = + (ISemanticParser) getParser(); + if (modelParser.areSemanticElementsAffected(null, event)) { + removeSemanticListeners(); + if (resolveSemanticElement() != null) { + addSemanticListeners(); + } + refreshLabel(); + } + } + } + super.handleNotificationEvent(event); + } + + /** + * @generated + */ + @Override + protected IFigure createFigure() { + IFigure label = createFigurePrim(); + defaultText = getLabelTextHelper(label); + return label; + } + + /** + * @generated + */ + protected IFigure createFigurePrim() { + return new PapyrusWrappingLabel(); + } + +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InterfaceNameEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InterfaceNameEditPart.java index 1b86ba3c0a0..0e29b239a4f 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InterfaceNameEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InterfaceNameEditPart.java @@ -864,7 +864,7 @@ public class InterfaceNameEditPart extends PapyrusCompartmentEditPart implements * @generated */ protected void addOwnerElementListeners() { - addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); + addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InterfaceNameEditPartCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InterfaceNameEditPartCN.java index 5bc5cbbed8e..651352d0b81 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InterfaceNameEditPartCN.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InterfaceNameEditPartCN.java @@ -864,7 +864,7 @@ public class InterfaceNameEditPartCN extends PapyrusCompartmentEditPart implemen * @generated */ protected void addOwnerElementListeners() { - addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); + addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InterfaceRealizationAppliedStereotypeEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InterfaceRealizationAppliedStereotypeEditPart.java index d13c3909c7a..859aad761c9 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InterfaceRealizationAppliedStereotypeEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InterfaceRealizationAppliedStereotypeEditPart.java @@ -1,820 +1,815 @@ -/** - * 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.uml.diagram.composite.edit.parts; - -import java.util.Collections; -import java.util.List; - -import org.eclipse.draw2d.ConnectionLocator; -import org.eclipse.draw2d.IFigure; -import org.eclipse.draw2d.Label; -import org.eclipse.draw2d.geometry.Point; -import org.eclipse.emf.common.notify.Notification; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.transaction.RecordingCommand; -import org.eclipse.emf.transaction.RunnableWithResult; -import org.eclipse.emf.transaction.TransactionalEditingDomain; -import org.eclipse.gef.AccessibleEditPart; -import org.eclipse.gef.EditPolicy; -import org.eclipse.gef.Request; -import org.eclipse.gef.requests.DirectEditRequest; -import org.eclipse.gef.tools.DirectEditManager; -import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; -import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; -import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; -import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; -import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; -import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; -import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; -import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; -import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; -import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; -import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; -import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; -import org.eclipse.gmf.runtime.notation.FontStyle; -import org.eclipse.gmf.runtime.notation.NotationPackage; -import org.eclipse.gmf.runtime.notation.View; -import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.jface.text.contentassist.IContentAssistProcessor; -import org.eclipse.jface.viewers.ICellEditorValidator; -import org.eclipse.jface.window.Window; -import org.eclipse.papyrus.extensionpoints.editors.Activator; -import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; -import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; -import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; -import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; -import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; -import org.eclipse.papyrus.infra.gmfdiag.common.editpart.IControlParserForDirectEdit; -import org.eclipse.papyrus.infra.gmfdiag.common.editpart.PapyrusLabelEditPart; -import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; -import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; -import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.PapyrusLinkLabelDragPolicy; -import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; -import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; -import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; -import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; -import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; -import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; -import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; -import org.eclipse.swt.SWT; -import org.eclipse.swt.accessibility.AccessibleEvent; -import org.eclipse.swt.custom.BusyIndicator; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.FontData; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.widgets.Display; -import org.eclipse.ui.PlatformUI; -import org.eclipse.uml2.uml.Feature; - -/** - * @generated - */ -public class InterfaceRealizationAppliedStereotypeEditPart extends PapyrusLabelEditPart implements ITextAwareEditPart, IControlParserForDirectEdit { - - /** - * @generated - */ - public static final int VISUAL_ID = 6016; - - /** - * @generated - */ - private DirectEditManager manager; - - /** - * @generated - */ - private IParser parser; - - /** - * @generated - */ - private List parserElements; - - /** - * @generated - */ - private String defaultText; - - /** - * direct edition mode (default, undefined, registered editor, etc.) - * - * @generated - */ - protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; - - /** - * configuration from a registered edit dialog - * - * @generated - */ - protected IDirectEditorConfiguration configuration; - /** - * @generated - */ - static { - registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.InterfaceRealizationAppliedStereotypeEditPart.VISUAL_ID), new Point(0, 30)); - } - - /** - * @generated - */ - public InterfaceRealizationAppliedStereotypeEditPart(View view) { - super(view); - } - - /** - * @generated - */ - @Override - protected void createDefaultEditPolicies() { - super.createDefaultEditPolicies(); - installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); - installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); - installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new PapyrusLinkLabelDragPolicy()); - } - - /** - * @generated - */ - @Override - public int getKeyPoint() { - return ConnectionLocator.MIDDLE; - } - - /** - * @generated - */ - protected String getLabelTextHelper(IFigure figure) { - if (figure instanceof WrappingLabel) { - return ((WrappingLabel) figure).getText(); - } else if (figure instanceof ILabelFigure) { - return ((ILabelFigure) figure).getText(); - } else { - return ((Label) figure).getText(); - } - } - - /** - * @generated - */ - protected void setLabelTextHelper(IFigure figure, String text) { - if (figure instanceof WrappingLabel) { - ((WrappingLabel) figure).setText(text); - } else if (figure instanceof ILabelFigure) { - ((ILabelFigure) figure).setText(text); - } else { - ((Label) figure).setText(text); - } - } - - /** - * @generated - */ - protected Image getLabelIconHelper(IFigure figure) { - if (figure instanceof WrappingLabel) { - return ((WrappingLabel) figure).getIcon(); - } else if (figure instanceof ILabelFigure) { - return ((ILabelFigure) figure).getIcon(); - } else { - return ((Label) figure).getIcon(); - } - } - - /** - * @generated - */ - protected void setLabelIconHelper(IFigure figure, Image icon) { - if (figure instanceof WrappingLabel) { - ((WrappingLabel) figure).setIcon(icon); - } else if (figure instanceof ILabelFigure) { - ((ILabelFigure) figure).setIcon(icon); - } else { - ((Label) figure).setIcon(icon); - } - } - - /** - * @generated - */ - public void setLabel(IFigure - figure) { - unregisterVisuals(); - setFigure(figure); - defaultText = getLabelTextHelper(figure); - registerVisuals(); - refreshVisuals(); - } - - /** - * @generated - */ - @Override - protected List getModelChildren() { - return Collections.EMPTY_LIST; - } - - /** - * @generated - */ - @Override - public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { - return null; - } - - /** - * @generated - */ - @Override - public void setParser(IParser parser) { - this.parser = parser; - } - - /** - * @generated - */ - protected EObject getParserElement() { - return resolveSemanticElement(); - } - - /** - * @generated - */ - protected Image getLabelIcon() { - return null; - } - - /** - * @generated - */ - protected String getLabelText() { - String text = null; - EObject parserElement = getParserElement(); - if (parserElement != null && getParser() != null) { - text = getParser().getPrintString( - new EObjectAdapter(parserElement), - getParserOptions().intValue()); - } - if (text == null || text.length() == 0) { - text = defaultText; - } - return text; - } - - /** - * @generated - */ - @Override - public void setLabelText(String text) { - setLabelTextHelper(getFigure(), text); - Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); - if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); - } - Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); - if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); - } - } - - /** - * @generated - */ - @Override - public String getEditText() { - if (getParserElement() == null || getParser() == null) { - return ""; //$NON-NLS-1$ - } - return getParser().getEditString( - new EObjectAdapter(getParserElement()), - getParserOptions().intValue()); - } - - /** - * @generated - */ - protected boolean isEditable() { - return false; - } - - /** - * @generated - */ - @Override - public ICellEditorValidator getEditTextValidator() { - return new ICellEditorValidator() { - - @Override - public String isValid(final Object value) { - if (value instanceof String) { - final EObject element = getParserElement(); - final IParser parser = getParser(); - try { - IParserEditStatus valid = - (IParserEditStatus) getEditingDomain().runExclusive( - new RunnableWithResult.Impl() { - - @Override - public void run() { - setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); - } - }); - return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); - } catch (InterruptedException ie) { - ie.printStackTrace(); - } - } - - // shouldn't get here - return null; - } - }; - } - - /** - * @generated - */ - @Override - public IContentAssistProcessor getCompletionProcessor() { - if (getParserElement() == null || getParser() == null) { - return null; - } - return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); - } - - /** - * @generated - */ - @Override - public ParserOptions getParserOptions() { - return ParserOptions.NONE; - } - - /** - * @generated - */ - @Override - public IParser getParser() { - if (parser == null) { - parser = UMLParserProvider.getParser(UMLElementTypes.InterfaceRealization_4005, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.InterfaceRealizationAppliedStereotypeEditPart.VISUAL_ID)); - } - return parser; - } - - /** - * @generated - */ - protected DirectEditManager getManager() { - if (manager == null) { - setManager(new MultilineLabelDirectEditManager(this, - MultilineLabelDirectEditManager.getTextCellEditorClass(this), - UMLEditPartFactory.getTextCellEditorLocator(this))); - } - return manager; - } - - /** - * @generated - */ - protected void setManager(DirectEditManager manager) { - this.manager = manager; - } - - /** - * @generated - */ - protected void performDirectEdit() { - BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { - - @Override - public void run() { - getManager().show(); - } - }); - } - - /** - * @generated - */ - protected void performDirectEdit(Point eventLocation) { - if (getManager() instanceof TextDirectEditManager) { - ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); - } - } - - /** - * @generated - */ - private void performDirectEdit(char initialCharacter) { - if (getManager() instanceof TextDirectEditManager) { - ((TextDirectEditManager) getManager()).show(initialCharacter); - } else { - performDirectEdit(); - } - } - - /** - * @generated - */ - @Override - protected void performDirectEditRequest(Request request) { - - final Request theRequest = request; - - if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { - directEditionMode = getDirectEditionType(); - } - switch (directEditionMode) { - case IDirectEdition.NO_DIRECT_EDITION: - // no direct edition mode => does nothing - return; - case IDirectEdition.EXTENDED_DIRECT_EDITOR: - updateExtendedEditorConfiguration(); - if (configuration == null || configuration.getLanguage() == null) { - // Create default edit manager - setManager(new MultilineLabelDirectEditManager(this, - MultilineLabelDirectEditManager.getTextCellEditorClass(this), - UMLEditPartFactory.getTextCellEditorLocator(this))); - performDefaultDirectEditorEdit(theRequest); - } else { - configuration.preEditAction(resolveSemanticElement()); - Dialog dialog = null; - if (configuration instanceof ICustomDirectEditorConfiguration) { - setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); - initializeDirectEditManager(theRequest); - return; - } else if (configuration instanceof IPopupEditorConfiguration) { - IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); - helper.showEditor(); - return; - } - else if (configuration instanceof IAdvancedEditorConfiguration) { - dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); - } else if (configuration instanceof IDirectEditorConfiguration) { - dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), - configuration); - } else { - return; - } - final Dialog finalDialog = dialog; - - if (Window.OK == dialog.open()) { - TransactionalEditingDomain domain = getEditingDomain(); - RecordingCommand command = new RecordingCommand(domain, "Edit Label") { - - @Override - protected void doExecute() { - configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); - - } - }; - domain.getCommandStack().execute(command); - } - } - break; - case IDirectEdition.DEFAULT_DIRECT_EDITOR: - initializeDirectEditManager(theRequest); - break; - default: - break; - } - } - - /** - * @generated - */ - protected void initializeDirectEditManager(final Request request) { - // initialize the direct edit manager - try { - getEditingDomain().runExclusive(new Runnable() { - @Override - public void run() { - if (isActive() && isEditable()) { - if (request.getExtendedData().get( - RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { - Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); - performDirectEdit(initialChar.charValue()); - } - else { - performDirectEdit(); - } - } - } - }); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - - /** - * @generated - */ - @Override - protected void refreshVisuals() { - super.refreshVisuals(); - refreshLabel(); - refreshFont(); - refreshFontColor(); - refreshUnderline(); - refreshStrikeThrough(); - } - - /** - * @generated - */ - protected void refreshLabel() { - EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); - if (maskLabelPolicy == null) { - maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); - } - if (maskLabelPolicy == null) { - View view = (View) getModel(); - if (view.isVisible()) { - setLabelTextHelper(getFigure(), getLabelText()); - setLabelIconHelper(getFigure(), getLabelIcon()); - } - else { - setLabelTextHelper(getFigure(), ""); //$NON-NLS-1$ - setLabelIconHelper(getFigure(), null); - } - } - Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); - if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); - } - Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); - if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); - } - } - - /** - * @generated - */ - protected void refreshUnderline() { - FontStyle style = - (FontStyle) getFontStyleOwnerView().getStyle( - NotationPackage.eINSTANCE.getFontStyle()); - if (style != null && getFigure() instanceof WrappingLabel) { - ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); - } - if (resolveSemanticElement() instanceof Feature) { - if (((Feature) resolveSemanticElement()).isStatic()) { - ((WrappingLabel) getFigure()).setTextUnderline(true); - } - else { - ((WrappingLabel) getFigure()).setTextUnderline(false); - } - } - } - - /** - * @generated - */ - protected void refreshStrikeThrough() { - FontStyle style = - (FontStyle) getFontStyleOwnerView().getStyle( - NotationPackage.eINSTANCE.getFontStyle()); - if (style != null && getFigure() instanceof WrappingLabel) { - ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); - } - } - - /** - * @generated - */ - @Override - protected void refreshFont() { - FontStyle style = - (FontStyle) getFontStyleOwnerView().getStyle( - NotationPackage.eINSTANCE.getFontStyle()); - if (style != null) { - FontData fontData = new FontData( - style.getFontName(), style.getFontHeight(), - (style.isBold() ? SWT.BOLD : SWT.NORMAL) | - (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); - setFont(fontData); - } - } - - /** - * @generated - */ - @Override - protected void setFontColor(Color color) { - getFigure().setForegroundColor(color); - } - - /** - * @generated - */ - @Override - protected void addSemanticListeners() { - if (getParser() instanceof ISemanticParser) { - EObject element = resolveSemanticElement(); - parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); - for (int i = 0; i < parserElements.size(); i++) { - addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ - } - } else { - super.addSemanticListeners(); - } - } - - /** - * @generated - */ - @Override - protected void removeSemanticListeners() { - if (parserElements != null) { - for (int i = 0; i < parserElements.size(); i++) { - removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ - } - } else { - super.removeSemanticListeners(); - } - } - - /** - * @generated - */ - @Override - protected AccessibleEditPart getAccessibleEditPart() { - if (accessibleEP == null) { - accessibleEP = new AccessibleGraphicalEditPart() { - - @Override - public void getName(AccessibleEvent e) { - e.result = getLabelTextHelper(getFigure()); - } - }; - } - return accessibleEP; - } - - /** - * @generated - */ - private View getFontStyleOwnerView() { - return getPrimaryView(); - } - - /** - * Returns the kind of associated editor for direct edition. - * - * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition - * @generated - */ - public int getDirectEditionType() { - // The label is read-only (defined in GMFGen model) - return IDirectEdition.NO_DIRECT_EDITION; - } - - /** - * Checks if an extended editor is present. - * - * @return true if an extended editor is present. - * @generated - */ - protected boolean checkExtendedEditor() { - if (resolveSemanticElement() != null) { - return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); - } - return false; - } - - /** - * Checks if a default direct edition is available - * - * @return true if a default direct edition is available - * @generated - */ - protected boolean checkDefaultEdition() { - return (getParser() != null); - } - - /** - * Initializes the extended editor configuration - * - * @generated - */ - protected void initExtendedEditorConfiguration() { - if (configuration == null) { - final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); - if (languagePreferred != null && !languagePreferred.equals("")) { - configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); - } else { - configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); - } - } - } - - /** - * Updates the preference configuration - * - * @generated - */ - protected void updateExtendedEditorConfiguration() { - String languagePreferred = Activator.getDefault().getPreferenceStore().getString( - IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); - if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { - configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() - .eClass().getInstanceClassName()); - } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { - configuration = null; - } - } - - /** - * Performs the direct edit usually used by GMF editors. - * - * @param theRequest - * the direct edit request that starts the direct edit system - * @generated - */ - protected void performDefaultDirectEditorEdit(final Request theRequest) { - // initialize the direct edit manager - try { - getEditingDomain().runExclusive(new Runnable() { - - @Override - public void run() { - if (isActive() && isEditable()) { - if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { - Character initialChar = (Character) theRequest.getExtendedData().get( - RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); - performDirectEdit(initialChar.charValue()); - } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { - DirectEditRequest editRequest = (DirectEditRequest) theRequest; - performDirectEdit(editRequest.getLocation()); - } else { - performDirectEdit(); - } - } - } - }); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - - /** - * @generated - */ - @Override - protected void handleNotificationEvent(Notification event) { - Object feature = event.getFeature(); - if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { - Integer c = (Integer) event.getNewValue(); - setFontColor(DiagramColorRegistry.getInstance().getColor(c)); - } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { - refreshUnderline(); - } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { - refreshStrikeThrough(); - } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || - NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || - NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || - NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { - refreshFont(); - } else { - if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { - refreshLabel(); - } - if (getParser() instanceof ISemanticParser) { - ISemanticParser modelParser = - (ISemanticParser) getParser(); - if (modelParser.areSemanticElementsAffected(null, event)) { - removeSemanticListeners(); - if (resolveSemanticElement() != null) { - addSemanticListeners(); - } - refreshLabel(); - } - } - } - - super.handleNotificationEvent(event); - } - - /** - * @generated - */ - @Override - protected IFigure createFigure() { - // Parent should assign one using setLabel() method - return 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.uml.diagram.composite.edit.parts; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.draw2d.ConnectionLocator; +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.Label; +import org.eclipse.draw2d.geometry.Point; +import org.eclipse.emf.common.notify.Notification; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.RunnableWithResult; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gef.AccessibleEditPart; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.Request; +import org.eclipse.gef.requests.DirectEditRequest; +import org.eclipse.gef.tools.DirectEditManager; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; +import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; +import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; +import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; +import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; +import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; +import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; +import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; +import org.eclipse.gmf.runtime.notation.FontStyle; +import org.eclipse.gmf.runtime.notation.NotationPackage; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.gmf.tooling.runtime.edit.policies.DefaultLinkLabelDragPolicy; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.text.contentassist.IContentAssistProcessor; +import org.eclipse.jface.viewers.ICellEditorValidator; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.extensionpoints.editors.Activator; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; +import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; +import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; +import org.eclipse.papyrus.infra.gmfdiag.common.editpart.IControlParserForDirectEdit; +import org.eclipse.papyrus.infra.gmfdiag.common.editpart.PapyrusLabelEditPart; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.PapyrusLinkLabelDragPolicy; +import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; +import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; +import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; +import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; +import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.accessibility.AccessibleEvent; +import org.eclipse.swt.custom.BusyIndicator; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; +import org.eclipse.uml2.uml.Feature; + +/** + * @generated + */ +public class InterfaceRealizationAppliedStereotypeEditPart extends PapyrusLabelEditPart implements ITextAwareEditPart, IControlParserForDirectEdit { + + /** + * @generated + */ + public static final int VISUAL_ID = 6016; + + /** + * @generated + */ + private DirectEditManager manager; + + /** + * @generated + */ + private IParser parser; + + /** + * @generated + */ + private List parserElements; + + /** + * @generated + */ + private String defaultText; + + /** + * direct edition mode (default, undefined, registered editor, etc.) + * + * @generated + */ + protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; + + /** + * configuration from a registered edit dialog + * + * @generated + */ + protected IDirectEditorConfiguration configuration; + /** + * @generated + */ + static { + registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.InterfaceRealizationAppliedStereotypeEditPart.VISUAL_ID), new Point(0, 30)); + } + + /** + * @generated + */ + public InterfaceRealizationAppliedStereotypeEditPart(View view) { + super(view); + } + + /** + * @generated + */ + @Override + protected void createDefaultEditPolicies() { + super.createDefaultEditPolicies(); + installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); + installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new DefaultLinkLabelDragPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new PapyrusLinkLabelDragPolicy()); + } + + /** + * @generated + */ + @Override + public int getKeyPoint() { + return ConnectionLocator.MIDDLE; + } + + /** + * @generated + */ + protected String getLabelTextHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getText(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getText(); + } else { + return ((Label) figure).getText(); + } + } + + /** + * @generated + */ + protected void setLabelTextHelper(IFigure figure, String text) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setText(text); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setText(text); + } else { + ((Label) figure).setText(text); + } + } + + /** + * @generated + */ + protected Image getLabelIconHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getIcon(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getIcon(); + } else { + return ((Label) figure).getIcon(); + } + } + + /** + * @generated + */ + protected void setLabelIconHelper(IFigure figure, Image icon) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setIcon(icon); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setIcon(icon); + } else { + ((Label) figure).setIcon(icon); + } + } + + /** + * @generated + */ + public void setLabel(IFigure + figure) { + unregisterVisuals(); + setFigure(figure); + defaultText = getLabelTextHelper(figure); + registerVisuals(); + refreshVisuals(); + } + + /** + * @generated + */ + @Override + protected List getModelChildren() { + return Collections.EMPTY_LIST; + } + + /** + * @generated + */ + @Override + public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { + return null; + } + + /** + * @generated + */ + @Override + public void setParser(IParser parser) { + this.parser = parser; + } + + /** + * @generated + */ + protected EObject getParserElement() { + return resolveSemanticElement(); + } + + /** + * @generated + */ + protected Image getLabelIcon() { + return null; + } + + /** + * @generated + */ + protected String getLabelText() { + String text = null; + EObject parserElement = getParserElement(); + if (parserElement != null && getParser() != null) { + text = getParser().getPrintString( + new EObjectAdapter(parserElement), + getParserOptions().intValue()); + } + if (text == null || text.length() == 0) { + text = defaultText; + } + return text; + } + + /** + * @generated + */ + @Override + public void setLabelText(String text) { + setLabelTextHelper(getFigure(), text); + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + @Override + public String getEditText() { + if (getParserElement() == null || getParser() == null) { + return ""; //$NON-NLS-1$ + } + return getParser().getEditString( + new EObjectAdapter(getParserElement()), + getParserOptions().intValue()); + } + + /** + * @generated + */ + protected boolean isEditable() { + return false; + } + + /** + * @generated + */ + @Override + public ICellEditorValidator getEditTextValidator() { + return new ICellEditorValidator() { + + @Override + public String isValid(final Object value) { + if (value instanceof String) { + final EObject element = getParserElement(); + final IParser parser = getParser(); + try { + IParserEditStatus valid = + (IParserEditStatus) getEditingDomain().runExclusive( + new RunnableWithResult.Impl() { + + @Override + public void run() { + setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); + } + }); + return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); + } catch (InterruptedException ie) { + ie.printStackTrace(); + } + } + + // shouldn't get here + return null; + } + }; + } + + /** + * @generated + */ + @Override + public IContentAssistProcessor getCompletionProcessor() { + if (getParserElement() == null || getParser() == null) { + return null; + } + return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); + } + + /** + * @generated + */ + @Override + public ParserOptions getParserOptions() { + return ParserOptions.NONE; + } + + /** + * @generated + */ + @Override + public IParser getParser() { + if (parser == null) { + parser = UMLParserProvider.getParser(UMLElementTypes.InterfaceRealization_4005, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.InterfaceRealizationAppliedStereotypeEditPart.VISUAL_ID)); + } + return parser; + } + + /** + * @generated + */ + protected DirectEditManager getManager() { + if (manager == null) { + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + } + return manager; + } + + /** + * @generated + */ + protected void setManager(DirectEditManager manager) { + this.manager = manager; + } + + /** + * @generated + */ + protected void performDirectEdit() { + BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { + + @Override + public void run() { + getManager().show(); + } + }); + } + + /** + * @generated + */ + protected void performDirectEdit(Point eventLocation) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); + } + } + + /** + * @generated + */ + private void performDirectEdit(char initialCharacter) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(initialCharacter); + } else { + performDirectEdit(); + } + } + + /** + * @generated + */ + @Override + protected void performDirectEditRequest(Request request) { + + final Request theRequest = request; + + if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { + directEditionMode = getDirectEditionType(); + } + switch (directEditionMode) { + case IDirectEdition.NO_DIRECT_EDITION: + // no direct edition mode => does nothing + return; + case IDirectEdition.EXTENDED_DIRECT_EDITOR: + updateExtendedEditorConfiguration(); + if (configuration == null || configuration.getLanguage() == null) { + // Create default edit manager + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + performDefaultDirectEditorEdit(theRequest); + } else { + configuration.preEditAction(resolveSemanticElement()); + Dialog dialog = null; + if (configuration instanceof ICustomDirectEditorConfiguration) { + setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); + initializeDirectEditManager(theRequest); + return; + } else if (configuration instanceof IPopupEditorConfiguration) { + IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); + helper.showEditor(); + return; + } + else if (configuration instanceof IAdvancedEditorConfiguration) { + dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); + } else if (configuration instanceof IDirectEditorConfiguration) { + dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), + configuration); + } else { + return; + } + final Dialog finalDialog = dialog; + + if (Window.OK == dialog.open()) { + TransactionalEditingDomain domain = getEditingDomain(); + RecordingCommand command = new RecordingCommand(domain, "Edit Label") { + + @Override + protected void doExecute() { + configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); + + } + }; + domain.getCommandStack().execute(command); + } + } + break; + case IDirectEdition.DEFAULT_DIRECT_EDITOR: + initializeDirectEditManager(theRequest); + break; + default: + break; + } + } + + /** + * @generated + */ + protected void initializeDirectEditManager(final Request request) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + @Override + public void run() { + if (isActive() && isEditable()) { + if (request.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } + else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void refreshVisuals() { + super.refreshVisuals(); + refreshLabel(); + refreshFont(); + refreshFontColor(); + refreshUnderline(); + refreshStrikeThrough(); + } + + /** + * @generated + */ + protected void refreshLabel() { + EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); + if (maskLabelPolicy == null) { + maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); + } + if (maskLabelPolicy == null) { + setLabelTextHelper(getFigure(), getLabelText()); + setLabelIconHelper(getFigure(), getLabelIcon()); + } + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + protected void refreshUnderline() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); + } + if (resolveSemanticElement() instanceof Feature) { + if (((Feature) resolveSemanticElement()).isStatic()) { + ((WrappingLabel) getFigure()).setTextUnderline(true); + } + else { + ((WrappingLabel) getFigure()).setTextUnderline(false); + } + } + } + + /** + * @generated + */ + protected void refreshStrikeThrough() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); + } + } + + /** + * @generated + */ + @Override + protected void refreshFont() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null) { + FontData fontData = new FontData( + style.getFontName(), style.getFontHeight(), + (style.isBold() ? SWT.BOLD : SWT.NORMAL) | + (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); + setFont(fontData); + } + } + + /** + * @generated + */ + @Override + protected void setFontColor(Color color) { + getFigure().setForegroundColor(color); + } + + /** + * @generated + */ + @Override + protected void addSemanticListeners() { + if (getParser() instanceof ISemanticParser) { + EObject element = resolveSemanticElement(); + parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); + for (int i = 0; i < parserElements.size(); i++) { + addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ + } + } else { + super.addSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected void removeSemanticListeners() { + if (parserElements != null) { + for (int i = 0; i < parserElements.size(); i++) { + removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ + } + } else { + super.removeSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected AccessibleEditPart getAccessibleEditPart() { + if (accessibleEP == null) { + accessibleEP = new AccessibleGraphicalEditPart() { + + @Override + public void getName(AccessibleEvent e) { + e.result = getLabelTextHelper(getFigure()); + } + }; + } + return accessibleEP; + } + + /** + * @generated + */ + private View getFontStyleOwnerView() { + return getPrimaryView(); + } + + /** + * Returns the kind of associated editor for direct edition. + * + * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition + * @generated + */ + public int getDirectEditionType() { + // The label is read-only (defined in GMFGen model) + return IDirectEdition.NO_DIRECT_EDITION; + } + + /** + * Checks if an extended editor is present. + * + * @return true if an extended editor is present. + * @generated + */ + protected boolean checkExtendedEditor() { + if (resolveSemanticElement() != null) { + return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); + } + return false; + } + + /** + * Checks if a default direct edition is available + * + * @return true if a default direct edition is available + * @generated + */ + protected boolean checkDefaultEdition() { + return (getParser() != null); + } + + /** + * Initializes the extended editor configuration + * + * @generated + */ + protected void initExtendedEditorConfiguration() { + if (configuration == null) { + final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("")) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); + } else { + configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); + } + } + } + + /** + * Updates the preference configuration + * + * @generated + */ + protected void updateExtendedEditorConfiguration() { + String languagePreferred = Activator.getDefault().getPreferenceStore().getString( + IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() + .eClass().getInstanceClassName()); + } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { + configuration = null; + } + } + + /** + * Performs the direct edit usually used by GMF editors. + * + * @param theRequest + * the direct edit request that starts the direct edit system + * @generated + */ + protected void performDefaultDirectEditorEdit(final Request theRequest) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + + @Override + public void run() { + if (isActive() && isEditable()) { + if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) theRequest.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { + DirectEditRequest editRequest = (DirectEditRequest) theRequest; + performDirectEdit(editRequest.getLocation()); + } else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void handleNotificationEvent(Notification event) { + Object feature = event.getFeature(); + if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { + Integer c = (Integer) event.getNewValue(); + setFontColor(DiagramColorRegistry.getInstance().getColor(c)); + } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { + refreshUnderline(); + } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { + refreshStrikeThrough(); + } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { + refreshFont(); + } else { + if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { + refreshLabel(); + } + if (getParser() instanceof ISemanticParser) { + ISemanticParser modelParser = + (ISemanticParser) getParser(); + if (modelParser.areSemanticElementsAffected(null, event)) { + removeSemanticListeners(); + if (resolveSemanticElement() != null) { + addSemanticListeners(); + } + refreshLabel(); + } + } + } + + super.handleNotificationEvent(event); + } + + /** + * @generated + */ + @Override + protected IFigure createFigure() { + // Parent should assign one using setLabel() method + return null; + } +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InterfaceRealizationNameEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InterfaceRealizationNameEditPart.java index f111575af9d..2353003d94d 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InterfaceRealizationNameEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/InterfaceRealizationNameEditPart.java @@ -1,828 +1,823 @@ -/** - * 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.uml.diagram.composite.edit.parts; - -import java.util.Collections; -import java.util.List; - -import org.eclipse.draw2d.ConnectionLocator; -import org.eclipse.draw2d.IFigure; -import org.eclipse.draw2d.Label; -import org.eclipse.draw2d.geometry.Point; -import org.eclipse.emf.common.notify.Notification; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.transaction.RecordingCommand; -import org.eclipse.emf.transaction.RunnableWithResult; -import org.eclipse.emf.transaction.TransactionalEditingDomain; -import org.eclipse.gef.AccessibleEditPart; -import org.eclipse.gef.EditPolicy; -import org.eclipse.gef.Request; -import org.eclipse.gef.requests.DirectEditRequest; -import org.eclipse.gef.tools.DirectEditManager; -import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; -import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; -import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; -import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; -import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; -import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; -import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; -import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; -import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; -import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; -import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; -import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; -import org.eclipse.gmf.runtime.notation.FontStyle; -import org.eclipse.gmf.runtime.notation.NotationPackage; -import org.eclipse.gmf.runtime.notation.View; -import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.jface.text.contentassist.IContentAssistProcessor; -import org.eclipse.jface.viewers.ICellEditorValidator; -import org.eclipse.jface.window.Window; -import org.eclipse.papyrus.extensionpoints.editors.Activator; -import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; -import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; -import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; -import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; -import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; -import org.eclipse.papyrus.infra.gmfdiag.common.editpart.IControlParserForDirectEdit; -import org.eclipse.papyrus.infra.gmfdiag.common.editpart.PapyrusLabelEditPart; -import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; -import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; -import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.PapyrusLinkLabelDragPolicy; -import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; -import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; -import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; -import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; -import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; -import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; -import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; -import org.eclipse.swt.SWT; -import org.eclipse.swt.accessibility.AccessibleEvent; -import org.eclipse.swt.custom.BusyIndicator; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.FontData; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.widgets.Display; -import org.eclipse.ui.PlatformUI; -import org.eclipse.uml2.uml.Feature; - -/** - * @generated - */ -public class InterfaceRealizationNameEditPart extends PapyrusLabelEditPart implements ITextAwareEditPart, IControlParserForDirectEdit { - - /** - * @generated - */ - public static final int VISUAL_ID = 6002; - - /** - * @generated - */ - private DirectEditManager manager; - - /** - * @generated - */ - private IParser parser; - - /** - * @generated - */ - private List parserElements; - - /** - * @generated - */ - private String defaultText; - - /** - * direct edition mode (default, undefined, registered editor, etc.) - * - * @generated - */ - protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; - - /** - * configuration from a registered edit dialog - * - * @generated - */ - protected IDirectEditorConfiguration configuration; - /** - * @generated - */ - static { - registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.InterfaceRealizationNameEditPart.VISUAL_ID), new Point(0, 60)); - } - - /** - * @generated - */ - public InterfaceRealizationNameEditPart(View view) { - super(view); - } - - /** - * @generated - */ - @Override - protected void createDefaultEditPolicies() { - super.createDefaultEditPolicies(); - installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); - installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); - installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new PapyrusLinkLabelDragPolicy()); - } - - /** - * @generated - */ - @Override - public int getKeyPoint() { - return ConnectionLocator.MIDDLE; - } - - /** - * @generated - */ - protected String getLabelTextHelper(IFigure figure) { - if (figure instanceof WrappingLabel) { - return ((WrappingLabel) figure).getText(); - } else if (figure instanceof ILabelFigure) { - return ((ILabelFigure) figure).getText(); - } else { - return ((Label) figure).getText(); - } - } - - /** - * @generated - */ - protected void setLabelTextHelper(IFigure figure, String text) { - if (figure instanceof WrappingLabel) { - ((WrappingLabel) figure).setText(text); - } else if (figure instanceof ILabelFigure) { - ((ILabelFigure) figure).setText(text); - } else { - ((Label) figure).setText(text); - } - } - - /** - * @generated - */ - protected Image getLabelIconHelper(IFigure figure) { - if (figure instanceof WrappingLabel) { - return ((WrappingLabel) figure).getIcon(); - } else if (figure instanceof ILabelFigure) { - return ((ILabelFigure) figure).getIcon(); - } else { - return ((Label) figure).getIcon(); - } - } - - /** - * @generated - */ - protected void setLabelIconHelper(IFigure figure, Image icon) { - if (figure instanceof WrappingLabel) { - ((WrappingLabel) figure).setIcon(icon); - } else if (figure instanceof ILabelFigure) { - ((ILabelFigure) figure).setIcon(icon); - } else { - ((Label) figure).setIcon(icon); - } - } - - /** - * @generated - */ - public void setLabel(IFigure - figure) { - unregisterVisuals(); - setFigure(figure); - defaultText = getLabelTextHelper(figure); - registerVisuals(); - refreshVisuals(); - } - - /** - * @generated - */ - @Override - protected List getModelChildren() { - return Collections.EMPTY_LIST; - } - - /** - * @generated - */ - @Override - public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { - return null; - } - - /** - * @generated - */ - @Override - public void setParser(IParser parser) { - this.parser = parser; - } - - /** - * @generated - */ - protected EObject getParserElement() { - return resolveSemanticElement(); - } - - /** - * @generated - */ - protected Image getLabelIcon() { - return null; - } - - /** - * @generated - */ - protected String getLabelText() { - String text = null; - EObject parserElement = getParserElement(); - if (parserElement != null && getParser() != null) { - text = getParser().getPrintString( - new EObjectAdapter(parserElement), - getParserOptions().intValue()); - } - if (text == null || text.length() == 0) { - text = defaultText; - } - return text; - } - - /** - * @generated - */ - @Override - public void setLabelText(String text) { - setLabelTextHelper(getFigure(), text); - Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); - if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); - } - Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); - if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); - } - } - - /** - * @generated - */ - @Override - public String getEditText() { - if (getParserElement() == null || getParser() == null) { - return ""; //$NON-NLS-1$ - } - return getParser().getEditString( - new EObjectAdapter(getParserElement()), - getParserOptions().intValue()); - } - - /** - * @generated - */ - protected boolean isEditable() { - return getParser() != null; - } - - /** - * @generated - */ - @Override - public ICellEditorValidator getEditTextValidator() { - return new ICellEditorValidator() { - - @Override - public String isValid(final Object value) { - if (value instanceof String) { - final EObject element = getParserElement(); - final IParser parser = getParser(); - try { - IParserEditStatus valid = - (IParserEditStatus) getEditingDomain().runExclusive( - new RunnableWithResult.Impl() { - - @Override - public void run() { - setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); - } - }); - return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); - } catch (InterruptedException ie) { - ie.printStackTrace(); - } - } - - // shouldn't get here - return null; - } - }; - } - - /** - * @generated - */ - @Override - public IContentAssistProcessor getCompletionProcessor() { - if (getParserElement() == null || getParser() == null) { - return null; - } - return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); - } - - /** - * @generated - */ - @Override - public ParserOptions getParserOptions() { - return ParserOptions.NONE; - } - - /** - * @generated - */ - @Override - public IParser getParser() { - if (parser == null) { - parser = UMLParserProvider.getParser(UMLElementTypes.InterfaceRealization_4005, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.InterfaceRealizationNameEditPart.VISUAL_ID)); - } - return parser; - } - - /** - * @generated - */ - protected DirectEditManager getManager() { - if (manager == null) { - setManager(new MultilineLabelDirectEditManager(this, - MultilineLabelDirectEditManager.getTextCellEditorClass(this), - UMLEditPartFactory.getTextCellEditorLocator(this))); - } - return manager; - } - - /** - * @generated - */ - protected void setManager(DirectEditManager manager) { - this.manager = manager; - } - - /** - * @generated - */ - protected void performDirectEdit() { - BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { - - @Override - public void run() { - getManager().show(); - } - }); - } - - /** - * @generated - */ - protected void performDirectEdit(Point eventLocation) { - if (getManager() instanceof TextDirectEditManager) { - ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); - } - } - - /** - * @generated - */ - private void performDirectEdit(char initialCharacter) { - if (getManager() instanceof TextDirectEditManager) { - ((TextDirectEditManager) getManager()).show(initialCharacter); - } else { - performDirectEdit(); - } - } - - /** - * @generated - */ - @Override - protected void performDirectEditRequest(Request request) { - - final Request theRequest = request; - - if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { - directEditionMode = getDirectEditionType(); - } - switch (directEditionMode) { - case IDirectEdition.NO_DIRECT_EDITION: - // no direct edition mode => does nothing - return; - case IDirectEdition.EXTENDED_DIRECT_EDITOR: - updateExtendedEditorConfiguration(); - if (configuration == null || configuration.getLanguage() == null) { - // Create default edit manager - setManager(new MultilineLabelDirectEditManager(this, - MultilineLabelDirectEditManager.getTextCellEditorClass(this), - UMLEditPartFactory.getTextCellEditorLocator(this))); - performDefaultDirectEditorEdit(theRequest); - } else { - configuration.preEditAction(resolveSemanticElement()); - Dialog dialog = null; - if (configuration instanceof ICustomDirectEditorConfiguration) { - setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); - initializeDirectEditManager(theRequest); - return; - } else if (configuration instanceof IPopupEditorConfiguration) { - IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); - helper.showEditor(); - return; - } - else if (configuration instanceof IAdvancedEditorConfiguration) { - dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); - } else if (configuration instanceof IDirectEditorConfiguration) { - dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), - configuration); - } else { - return; - } - final Dialog finalDialog = dialog; - - if (Window.OK == dialog.open()) { - TransactionalEditingDomain domain = getEditingDomain(); - RecordingCommand command = new RecordingCommand(domain, "Edit Label") { - - @Override - protected void doExecute() { - configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); - - } - }; - domain.getCommandStack().execute(command); - } - } - break; - case IDirectEdition.DEFAULT_DIRECT_EDITOR: - initializeDirectEditManager(theRequest); - break; - default: - break; - } - } - - /** - * @generated - */ - protected void initializeDirectEditManager(final Request request) { - // initialize the direct edit manager - try { - getEditingDomain().runExclusive(new Runnable() { - @Override - public void run() { - if (isActive() && isEditable()) { - if (request.getExtendedData().get( - RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { - Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); - performDirectEdit(initialChar.charValue()); - } - else { - performDirectEdit(); - } - } - } - }); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - - /** - * @generated - */ - @Override - protected void refreshVisuals() { - super.refreshVisuals(); - refreshLabel(); - refreshFont(); - refreshFontColor(); - refreshUnderline(); - refreshStrikeThrough(); - } - - /** - * @generated - */ - protected void refreshLabel() { - EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); - if (maskLabelPolicy == null) { - maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); - } - if (maskLabelPolicy == null) { - View view = (View) getModel(); - if (view.isVisible()) { - setLabelTextHelper(getFigure(), getLabelText()); - setLabelIconHelper(getFigure(), getLabelIcon()); - } - else { - setLabelTextHelper(getFigure(), ""); //$NON-NLS-1$ - setLabelIconHelper(getFigure(), null); - } - } - Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); - if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); - } - Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); - if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); - } - } - - /** - * @generated - */ - protected void refreshUnderline() { - FontStyle style = - (FontStyle) getFontStyleOwnerView().getStyle( - NotationPackage.eINSTANCE.getFontStyle()); - if (style != null && getFigure() instanceof WrappingLabel) { - ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); - } - if (resolveSemanticElement() instanceof Feature) { - if (((Feature) resolveSemanticElement()).isStatic()) { - ((WrappingLabel) getFigure()).setTextUnderline(true); - } - else { - ((WrappingLabel) getFigure()).setTextUnderline(false); - } - } - } - - /** - * @generated - */ - protected void refreshStrikeThrough() { - FontStyle style = - (FontStyle) getFontStyleOwnerView().getStyle( - NotationPackage.eINSTANCE.getFontStyle()); - if (style != null && getFigure() instanceof WrappingLabel) { - ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); - } - } - - /** - * @generated - */ - @Override - protected void refreshFont() { - FontStyle style = - (FontStyle) getFontStyleOwnerView().getStyle( - NotationPackage.eINSTANCE.getFontStyle()); - if (style != null) { - FontData fontData = new FontData( - style.getFontName(), style.getFontHeight(), - (style.isBold() ? SWT.BOLD : SWT.NORMAL) | - (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); - setFont(fontData); - } - } - - /** - * @generated - */ - @Override - protected void setFontColor(Color color) { - getFigure().setForegroundColor(color); - } - - /** - * @generated - */ - @Override - protected void addSemanticListeners() { - if (getParser() instanceof ISemanticParser) { - EObject element = resolveSemanticElement(); - parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); - for (int i = 0; i < parserElements.size(); i++) { - addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ - } - } else { - super.addSemanticListeners(); - } - } - - /** - * @generated - */ - @Override - protected void removeSemanticListeners() { - if (parserElements != null) { - for (int i = 0; i < parserElements.size(); i++) { - removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ - } - } else { - super.removeSemanticListeners(); - } - } - - /** - * @generated - */ - @Override - protected AccessibleEditPart getAccessibleEditPart() { - if (accessibleEP == null) { - accessibleEP = new AccessibleGraphicalEditPart() { - - @Override - public void getName(AccessibleEvent e) { - e.result = getLabelTextHelper(getFigure()); - } - }; - } - return accessibleEP; - } - - /** - * @generated - */ - private View getFontStyleOwnerView() { - return getPrimaryView(); - } - - /** - * Returns the kind of associated editor for direct edition. - * - * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition - * @generated - */ - public int getDirectEditionType() { - if (checkExtendedEditor()) { - initExtendedEditorConfiguration(); - return IDirectEdition.EXTENDED_DIRECT_EDITOR; - } - if (checkDefaultEdition()) { - return IDirectEdition.DEFAULT_DIRECT_EDITOR; - } - - // not a named element. no specific editor => do nothing - return IDirectEdition.NO_DIRECT_EDITION; - } - - /** - * Checks if an extended editor is present. - * - * @return true if an extended editor is present. - * @generated - */ - protected boolean checkExtendedEditor() { - if (resolveSemanticElement() != null) { - return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); - } - return false; - } - - /** - * Checks if a default direct edition is available - * - * @return true if a default direct edition is available - * @generated - */ - protected boolean checkDefaultEdition() { - return (getParser() != null); - } - - /** - * Initializes the extended editor configuration - * - * @generated - */ - protected void initExtendedEditorConfiguration() { - if (configuration == null) { - final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); - if (languagePreferred != null && !languagePreferred.equals("")) { - configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); - } else { - configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); - } - } - } - - /** - * Updates the preference configuration - * - * @generated - */ - protected void updateExtendedEditorConfiguration() { - String languagePreferred = Activator.getDefault().getPreferenceStore().getString( - IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); - if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { - configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() - .eClass().getInstanceClassName()); - } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { - configuration = null; - } - } - - /** - * Performs the direct edit usually used by GMF editors. - * - * @param theRequest - * the direct edit request that starts the direct edit system - * @generated - */ - protected void performDefaultDirectEditorEdit(final Request theRequest) { - // initialize the direct edit manager - try { - getEditingDomain().runExclusive(new Runnable() { - - @Override - public void run() { - if (isActive() && isEditable()) { - if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { - Character initialChar = (Character) theRequest.getExtendedData().get( - RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); - performDirectEdit(initialChar.charValue()); - } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { - DirectEditRequest editRequest = (DirectEditRequest) theRequest; - performDirectEdit(editRequest.getLocation()); - } else { - performDirectEdit(); - } - } - } - }); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - - /** - * @generated - */ - @Override - protected void handleNotificationEvent(Notification event) { - Object feature = event.getFeature(); - if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { - Integer c = (Integer) event.getNewValue(); - setFontColor(DiagramColorRegistry.getInstance().getColor(c)); - } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { - refreshUnderline(); - } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { - refreshStrikeThrough(); - } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || - NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || - NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || - NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { - refreshFont(); - } else { - if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { - refreshLabel(); - } - if (getParser() instanceof ISemanticParser) { - ISemanticParser modelParser = - (ISemanticParser) getParser(); - if (modelParser.areSemanticElementsAffected(null, event)) { - removeSemanticListeners(); - if (resolveSemanticElement() != null) { - addSemanticListeners(); - } - refreshLabel(); - } - } - } - - super.handleNotificationEvent(event); - } - - /** - * @generated - */ - @Override - protected IFigure createFigure() { - // Parent should assign one using setLabel() method - return 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.uml.diagram.composite.edit.parts; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.draw2d.ConnectionLocator; +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.Label; +import org.eclipse.draw2d.geometry.Point; +import org.eclipse.emf.common.notify.Notification; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.RunnableWithResult; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gef.AccessibleEditPart; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.Request; +import org.eclipse.gef.requests.DirectEditRequest; +import org.eclipse.gef.tools.DirectEditManager; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; +import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; +import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; +import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; +import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; +import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; +import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; +import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; +import org.eclipse.gmf.runtime.notation.FontStyle; +import org.eclipse.gmf.runtime.notation.NotationPackage; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.gmf.tooling.runtime.edit.policies.DefaultLinkLabelDragPolicy; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.text.contentassist.IContentAssistProcessor; +import org.eclipse.jface.viewers.ICellEditorValidator; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.extensionpoints.editors.Activator; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; +import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; +import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; +import org.eclipse.papyrus.infra.gmfdiag.common.editpart.IControlParserForDirectEdit; +import org.eclipse.papyrus.infra.gmfdiag.common.editpart.PapyrusLabelEditPart; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.PapyrusLinkLabelDragPolicy; +import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; +import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; +import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; +import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; +import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.accessibility.AccessibleEvent; +import org.eclipse.swt.custom.BusyIndicator; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; +import org.eclipse.uml2.uml.Feature; + +/** + * @generated + */ +public class InterfaceRealizationNameEditPart extends PapyrusLabelEditPart implements ITextAwareEditPart, IControlParserForDirectEdit { + + /** + * @generated + */ + public static final int VISUAL_ID = 6002; + + /** + * @generated + */ + private DirectEditManager manager; + + /** + * @generated + */ + private IParser parser; + + /** + * @generated + */ + private List parserElements; + + /** + * @generated + */ + private String defaultText; + + /** + * direct edition mode (default, undefined, registered editor, etc.) + * + * @generated + */ + protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; + + /** + * configuration from a registered edit dialog + * + * @generated + */ + protected IDirectEditorConfiguration configuration; + /** + * @generated + */ + static { + registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.InterfaceRealizationNameEditPart.VISUAL_ID), new Point(0, 60)); + } + + /** + * @generated + */ + public InterfaceRealizationNameEditPart(View view) { + super(view); + } + + /** + * @generated + */ + @Override + protected void createDefaultEditPolicies() { + super.createDefaultEditPolicies(); + installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); + installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new DefaultLinkLabelDragPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new PapyrusLinkLabelDragPolicy()); + } + + /** + * @generated + */ + @Override + public int getKeyPoint() { + return ConnectionLocator.MIDDLE; + } + + /** + * @generated + */ + protected String getLabelTextHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getText(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getText(); + } else { + return ((Label) figure).getText(); + } + } + + /** + * @generated + */ + protected void setLabelTextHelper(IFigure figure, String text) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setText(text); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setText(text); + } else { + ((Label) figure).setText(text); + } + } + + /** + * @generated + */ + protected Image getLabelIconHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getIcon(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getIcon(); + } else { + return ((Label) figure).getIcon(); + } + } + + /** + * @generated + */ + protected void setLabelIconHelper(IFigure figure, Image icon) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setIcon(icon); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setIcon(icon); + } else { + ((Label) figure).setIcon(icon); + } + } + + /** + * @generated + */ + public void setLabel(IFigure + figure) { + unregisterVisuals(); + setFigure(figure); + defaultText = getLabelTextHelper(figure); + registerVisuals(); + refreshVisuals(); + } + + /** + * @generated + */ + @Override + protected List getModelChildren() { + return Collections.EMPTY_LIST; + } + + /** + * @generated + */ + @Override + public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { + return null; + } + + /** + * @generated + */ + @Override + public void setParser(IParser parser) { + this.parser = parser; + } + + /** + * @generated + */ + protected EObject getParserElement() { + return resolveSemanticElement(); + } + + /** + * @generated + */ + protected Image getLabelIcon() { + return null; + } + + /** + * @generated + */ + protected String getLabelText() { + String text = null; + EObject parserElement = getParserElement(); + if (parserElement != null && getParser() != null) { + text = getParser().getPrintString( + new EObjectAdapter(parserElement), + getParserOptions().intValue()); + } + if (text == null || text.length() == 0) { + text = defaultText; + } + return text; + } + + /** + * @generated + */ + @Override + public void setLabelText(String text) { + setLabelTextHelper(getFigure(), text); + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + @Override + public String getEditText() { + if (getParserElement() == null || getParser() == null) { + return ""; //$NON-NLS-1$ + } + return getParser().getEditString( + new EObjectAdapter(getParserElement()), + getParserOptions().intValue()); + } + + /** + * @generated + */ + protected boolean isEditable() { + return getParser() != null; + } + + /** + * @generated + */ + @Override + public ICellEditorValidator getEditTextValidator() { + return new ICellEditorValidator() { + + @Override + public String isValid(final Object value) { + if (value instanceof String) { + final EObject element = getParserElement(); + final IParser parser = getParser(); + try { + IParserEditStatus valid = + (IParserEditStatus) getEditingDomain().runExclusive( + new RunnableWithResult.Impl() { + + @Override + public void run() { + setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); + } + }); + return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); + } catch (InterruptedException ie) { + ie.printStackTrace(); + } + } + + // shouldn't get here + return null; + } + }; + } + + /** + * @generated + */ + @Override + public IContentAssistProcessor getCompletionProcessor() { + if (getParserElement() == null || getParser() == null) { + return null; + } + return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); + } + + /** + * @generated + */ + @Override + public ParserOptions getParserOptions() { + return ParserOptions.NONE; + } + + /** + * @generated + */ + @Override + public IParser getParser() { + if (parser == null) { + parser = UMLParserProvider.getParser(UMLElementTypes.InterfaceRealization_4005, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.InterfaceRealizationNameEditPart.VISUAL_ID)); + } + return parser; + } + + /** + * @generated + */ + protected DirectEditManager getManager() { + if (manager == null) { + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + } + return manager; + } + + /** + * @generated + */ + protected void setManager(DirectEditManager manager) { + this.manager = manager; + } + + /** + * @generated + */ + protected void performDirectEdit() { + BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { + + @Override + public void run() { + getManager().show(); + } + }); + } + + /** + * @generated + */ + protected void performDirectEdit(Point eventLocation) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); + } + } + + /** + * @generated + */ + private void performDirectEdit(char initialCharacter) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(initialCharacter); + } else { + performDirectEdit(); + } + } + + /** + * @generated + */ + @Override + protected void performDirectEditRequest(Request request) { + + final Request theRequest = request; + + if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { + directEditionMode = getDirectEditionType(); + } + switch (directEditionMode) { + case IDirectEdition.NO_DIRECT_EDITION: + // no direct edition mode => does nothing + return; + case IDirectEdition.EXTENDED_DIRECT_EDITOR: + updateExtendedEditorConfiguration(); + if (configuration == null || configuration.getLanguage() == null) { + // Create default edit manager + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + performDefaultDirectEditorEdit(theRequest); + } else { + configuration.preEditAction(resolveSemanticElement()); + Dialog dialog = null; + if (configuration instanceof ICustomDirectEditorConfiguration) { + setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); + initializeDirectEditManager(theRequest); + return; + } else if (configuration instanceof IPopupEditorConfiguration) { + IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); + helper.showEditor(); + return; + } + else if (configuration instanceof IAdvancedEditorConfiguration) { + dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); + } else if (configuration instanceof IDirectEditorConfiguration) { + dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), + configuration); + } else { + return; + } + final Dialog finalDialog = dialog; + + if (Window.OK == dialog.open()) { + TransactionalEditingDomain domain = getEditingDomain(); + RecordingCommand command = new RecordingCommand(domain, "Edit Label") { + + @Override + protected void doExecute() { + configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); + + } + }; + domain.getCommandStack().execute(command); + } + } + break; + case IDirectEdition.DEFAULT_DIRECT_EDITOR: + initializeDirectEditManager(theRequest); + break; + default: + break; + } + } + + /** + * @generated + */ + protected void initializeDirectEditManager(final Request request) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + @Override + public void run() { + if (isActive() && isEditable()) { + if (request.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } + else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void refreshVisuals() { + super.refreshVisuals(); + refreshLabel(); + refreshFont(); + refreshFontColor(); + refreshUnderline(); + refreshStrikeThrough(); + } + + /** + * @generated + */ + protected void refreshLabel() { + EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); + if (maskLabelPolicy == null) { + maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); + } + if (maskLabelPolicy == null) { + setLabelTextHelper(getFigure(), getLabelText()); + setLabelIconHelper(getFigure(), getLabelIcon()); + } + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + protected void refreshUnderline() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); + } + if (resolveSemanticElement() instanceof Feature) { + if (((Feature) resolveSemanticElement()).isStatic()) { + ((WrappingLabel) getFigure()).setTextUnderline(true); + } + else { + ((WrappingLabel) getFigure()).setTextUnderline(false); + } + } + } + + /** + * @generated + */ + protected void refreshStrikeThrough() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); + } + } + + /** + * @generated + */ + @Override + protected void refreshFont() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null) { + FontData fontData = new FontData( + style.getFontName(), style.getFontHeight(), + (style.isBold() ? SWT.BOLD : SWT.NORMAL) | + (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); + setFont(fontData); + } + } + + /** + * @generated + */ + @Override + protected void setFontColor(Color color) { + getFigure().setForegroundColor(color); + } + + /** + * @generated + */ + @Override + protected void addSemanticListeners() { + if (getParser() instanceof ISemanticParser) { + EObject element = resolveSemanticElement(); + parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); + for (int i = 0; i < parserElements.size(); i++) { + addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ + } + } else { + super.addSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected void removeSemanticListeners() { + if (parserElements != null) { + for (int i = 0; i < parserElements.size(); i++) { + removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ + } + } else { + super.removeSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected AccessibleEditPart getAccessibleEditPart() { + if (accessibleEP == null) { + accessibleEP = new AccessibleGraphicalEditPart() { + + @Override + public void getName(AccessibleEvent e) { + e.result = getLabelTextHelper(getFigure()); + } + }; + } + return accessibleEP; + } + + /** + * @generated + */ + private View getFontStyleOwnerView() { + return getPrimaryView(); + } + + /** + * Returns the kind of associated editor for direct edition. + * + * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition + * @generated + */ + public int getDirectEditionType() { + if (checkExtendedEditor()) { + initExtendedEditorConfiguration(); + return IDirectEdition.EXTENDED_DIRECT_EDITOR; + } + if (checkDefaultEdition()) { + return IDirectEdition.DEFAULT_DIRECT_EDITOR; + } + + // not a named element. no specific editor => do nothing + return IDirectEdition.NO_DIRECT_EDITION; + } + + /** + * Checks if an extended editor is present. + * + * @return true if an extended editor is present. + * @generated + */ + protected boolean checkExtendedEditor() { + if (resolveSemanticElement() != null) { + return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); + } + return false; + } + + /** + * Checks if a default direct edition is available + * + * @return true if a default direct edition is available + * @generated + */ + protected boolean checkDefaultEdition() { + return (getParser() != null); + } + + /** + * Initializes the extended editor configuration + * + * @generated + */ + protected void initExtendedEditorConfiguration() { + if (configuration == null) { + final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("")) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); + } else { + configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); + } + } + } + + /** + * Updates the preference configuration + * + * @generated + */ + protected void updateExtendedEditorConfiguration() { + String languagePreferred = Activator.getDefault().getPreferenceStore().getString( + IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() + .eClass().getInstanceClassName()); + } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { + configuration = null; + } + } + + /** + * Performs the direct edit usually used by GMF editors. + * + * @param theRequest + * the direct edit request that starts the direct edit system + * @generated + */ + protected void performDefaultDirectEditorEdit(final Request theRequest) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + + @Override + public void run() { + if (isActive() && isEditable()) { + if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) theRequest.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { + DirectEditRequest editRequest = (DirectEditRequest) theRequest; + performDirectEdit(editRequest.getLocation()); + } else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void handleNotificationEvent(Notification event) { + Object feature = event.getFeature(); + if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { + Integer c = (Integer) event.getNewValue(); + setFontColor(DiagramColorRegistry.getInstance().getColor(c)); + } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { + refreshUnderline(); + } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { + refreshStrikeThrough(); + } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { + refreshFont(); + } else { + if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { + refreshLabel(); + } + if (getParser() instanceof ISemanticParser) { + ISemanticParser modelParser = + (ISemanticParser) getParser(); + if (modelParser.areSemanticElementsAffected(null, event)) { + removeSemanticListeners(); + if (resolveSemanticElement() != null) { + addSemanticListeners(); + } + refreshLabel(); + } + } + } + + super.handleNotificationEvent(event); + } + + /** + * @generated + */ + @Override + protected IFigure createFigure() { + // Parent should assign one using setLabel() method + return null; + } +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/IntervalConstraintEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/IntervalConstraintEditPart.java index a2271e035eb..67e7c7d0a6f 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/IntervalConstraintEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/IntervalConstraintEditPart.java @@ -23,10 +23,10 @@ import org.eclipse.gef.requests.CreateRequest; import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles; import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; -import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure; import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure; import org.eclipse.gmf.runtime.notation.View; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.IPapyrusNodeFigure; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.RoundedRectangleNodePlateFigure; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.SelectableBorderedNodeFigure; import org.eclipse.papyrus.uml.diagram.common.editparts.AbstractConstraintEditPart; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeLabelDisplayEditPolicy; @@ -198,7 +198,7 @@ public class IntervalConstraintEditPart extends AbstractConstraintEditPart { */ @Override protected NodeFigure createNodePlate() { - DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(40, 40); + RoundedRectangleNodePlateFigure result = new RoundedRectangleNodePlateFigure(40, 40); return result; } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/IntervalConstraintEditPartCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/IntervalConstraintEditPartCN.java index 6137518de5e..fbec9622474 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/IntervalConstraintEditPartCN.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/IntervalConstraintEditPartCN.java @@ -23,10 +23,10 @@ import org.eclipse.gef.requests.CreateRequest; import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles; import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; -import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure; import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure; import org.eclipse.gmf.runtime.notation.View; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.IPapyrusNodeFigure; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.RoundedRectangleNodePlateFigure; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.SelectableBorderedNodeFigure; import org.eclipse.papyrus.uml.diagram.common.editparts.AbstractConstraintEditPart; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeLabelDisplayEditPolicy; @@ -198,7 +198,7 @@ public class IntervalConstraintEditPartCN extends AbstractConstraintEditPart { */ @Override protected NodeFigure createNodePlate() { - DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(40, 40); + RoundedRectangleNodePlateFigure result = new RoundedRectangleNodePlateFigure(40, 40); return result; } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/IntervalConstraintNameEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/IntervalConstraintNameEditPart.java index df8ea2ae3c8..8369335930f 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/IntervalConstraintNameEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/IntervalConstraintNameEditPart.java @@ -864,7 +864,7 @@ public class IntervalConstraintNameEditPart extends PapyrusCompartmentEditPart i * @generated */ protected void addOwnerElementListeners() { - addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); + addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/IntervalConstraintNameEditPartCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/IntervalConstraintNameEditPartCN.java index d8e6c20773b..fcdb6fcf551 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/IntervalConstraintNameEditPartCN.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/IntervalConstraintNameEditPartCN.java @@ -864,7 +864,7 @@ public class IntervalConstraintNameEditPartCN extends PapyrusCompartmentEditPart * @generated */ protected void addOwnerElementListeners() { - addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); + addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/IntervalConstraintSpecificationEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/IntervalConstraintSpecificationEditPart.java index 9df48119132..a99fbaf297e 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/IntervalConstraintSpecificationEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/IntervalConstraintSpecificationEditPart.java @@ -847,7 +847,7 @@ public class IntervalConstraintSpecificationEditPart extends PapyrusCompartmentE * @generated */ protected void addOwnerElementListeners() { - addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); + addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/IntervalConstraintSpecificationEditPartCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/IntervalConstraintSpecificationEditPartCN.java index 2a48fd0cbe0..7b571cc1e61 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/IntervalConstraintSpecificationEditPartCN.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/IntervalConstraintSpecificationEditPartCN.java @@ -847,7 +847,7 @@ public class IntervalConstraintSpecificationEditPartCN extends PapyrusCompartmen * @generated */ protected void addOwnerElementListeners() { - addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); + addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/IntervalEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/IntervalEditPart.java index b6f27354aa8..477eec1e9e9 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/IntervalEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/IntervalEditPart.java @@ -11,27 +11,40 @@ */ package org.eclipse.papyrus.uml.diagram.composite.edit.parts; +import java.util.Collections; +import java.util.List; + import org.eclipse.draw2d.IFigure; +import org.eclipse.emf.common.notify.Notification; import org.eclipse.gef.EditPart; import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.GraphicalEditPart; 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.handles.MoveHandle; import org.eclipse.gef.requests.CreateRequest; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.BorderItemSelectionEditPolicy; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles; +import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; -import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure; import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure; +import org.eclipse.gmf.runtime.notation.Edge; +import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.gmf.runtime.notation.View; -import org.eclipse.papyrus.infra.gmfdiag.common.editpart.NodeEditPart; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.GetChildLayoutEditPolicy; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.IPapyrusNodeFigure; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.RoundedRectangleNodePlateFigure; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.SelectableBorderedNodeFigure; +import org.eclipse.papyrus.uml.diagram.common.editparts.RoundedCompartmentEditPart; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeNodeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.QualifiedNameDisplayEditPolicy; -import org.eclipse.papyrus.uml.diagram.common.figure.node.NodeNamedElementFigure; +import org.eclipse.papyrus.uml.diagram.common.figure.node.RoundedCompartmentFigure; +import org.eclipse.papyrus.uml.diagram.common.locator.RoundedRectangleLabelPositionLocator; import org.eclipse.papyrus.uml.diagram.composite.edit.policies.IntervalItemSemanticEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; import org.eclipse.swt.graphics.Color; @@ -39,7 +52,7 @@ import org.eclipse.swt.graphics.Color; /** * @generated */ -public class IntervalEditPart extends NodeEditPart { +public class IntervalEditPart extends RoundedCompartmentEditPart { /** * @generated @@ -73,6 +86,7 @@ public class IntervalEditPart extends NodeEditPart { installEditPolicy(EditPolicy.LAYOUT_ROLE, createLayoutEditPolicy()); installEditPolicy(QualifiedNameDisplayEditPolicy.QUALIFIED_NAME_POLICY, new QualifiedNameDisplayEditPolicy()); installEditPolicy(AppliedStereotypeLabelDisplayEditPolicy.STEREOTYPE_LABEL_POLICY, new AppliedStereotypeNodeLabelDisplayEditPolicy()); + installEditPolicy(EditPolicy.LAYOUT_ROLE, new GetChildLayoutEditPolicy()); // XXX need an SCR to runtime to have another abstract superclass that would let children add reasonable editpolicies // removeEditPolicy(org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles.CONNECTION_HANDLES_ROLE); } @@ -85,6 +99,20 @@ public class IntervalEditPart extends NodeEditPart { @Override protected EditPolicy createChildEditPolicy(EditPart child) { + View childView = (View) child.getModel(); + switch (UMLVisualIDRegistry.getVisualID(childView)) { + case IntervalFloatingLabelEditPart.VISUAL_ID: + return new BorderItemSelectionEditPolicy() { + + @Override + protected List createSelectionHandles() { + MoveHandle mh = new MoveHandle((GraphicalEditPart) getHost()); + mh.setBorder(null); + return Collections.singletonList(mh); + } + } + ; + } EditPolicy result = child.getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); if (result == null) { result = new NonResizableEditPolicy(); @@ -105,12 +133,36 @@ public class IntervalEditPart extends NodeEditPart { return lep; } + /** + * Papyrus codeGen + * + * @generated + **/ + @Override + protected void handleNotificationEvent(Notification event) { + /* + * when a node have external node labels, the methods refreshChildren() remove the EditPart corresponding to the Label from the EditPart + * Registry. After that, we can't reset the visibility to true (using the Show/Hide Label Action)! + */ + if (NotationPackage.eINSTANCE.getView_Visible().equals(event.getFeature())) { + Object notifier = event.getNotifier(); + List modelChildren = ((View) getModel()).getChildren(); + if (!(notifier instanceof Edge)) { + if (modelChildren.contains(event.getNotifier())) { + return; + } + } + } + super.handleNotificationEvent(event); + + } + /** * @generated */ @Override protected IFigure createNodeShape() { - return primaryShape = new NodeNamedElementFigure(); + return primaryShape = new RoundedCompartmentFigure(); } /** @@ -119,8 +171,8 @@ public class IntervalEditPart extends NodeEditPart { * @generated */ @Override - public NodeNamedElementFigure getPrimaryShape() { - return (NodeNamedElementFigure) primaryShape; + public RoundedCompartmentFigure getPrimaryShape() { + return (RoundedCompartmentFigure) primaryShape; } /** @@ -173,15 +225,32 @@ public class IntervalEditPart extends NodeEditPart { */ @Override protected IFigure getContentPaneFor(IGraphicalEditPart editPart) { + if (editPart instanceof IBorderItemEditPart) { + return getBorderedFigure().getBorderItemContainer(); + } return getContentPane(); } + /** + * @generated + */ + @Override + protected void addBorderItem(IFigure borderItemContainer, IBorderItemEditPart borderItemEditPart) { + if (borderItemEditPart instanceof IntervalFloatingLabelEditPart) { + IBorderItemLocator locator = new RoundedRectangleLabelPositionLocator(getMainFigure()); + borderItemContainer.add(borderItemEditPart.getFigure(), locator); + } else + { + super.addBorderItem(borderItemContainer, borderItemEditPart); + } + } + /** * @generated */ @Override protected NodeFigure createNodePlate() { - DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(40, 40); + RoundedRectangleNodePlateFigure result = new RoundedRectangleNodePlateFigure(40, 40); return result; } @@ -194,7 +263,7 @@ public class IntervalEditPart extends NodeEditPart { * @generated */ @Override - protected NodeFigure createNodeFigure() { + protected NodeFigure createMainFigure() { return new SelectableBorderedNodeFigure(createMainFigureWithSVG()); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/IntervalFloatingLabelEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/IntervalFloatingLabelEditPart.java new file mode 100644 index 00000000000..f59e0f08359 --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/IntervalFloatingLabelEditPart.java @@ -0,0 +1,860 @@ +/** + * 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.uml.diagram.composite.edit.parts; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.Label; +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.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.RunnableWithResult; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gef.AccessibleEditPart; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.Request; +import org.eclipse.gef.requests.DirectEditRequest; +import org.eclipse.gef.tools.DirectEditManager; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; +import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; +import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; +import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; +import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; +import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; +import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; +import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; +import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; +import org.eclipse.gmf.runtime.notation.FontStyle; +import org.eclipse.gmf.runtime.notation.NotationPackage; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.text.contentassist.IContentAssistProcessor; +import org.eclipse.jface.viewers.ICellEditorValidator; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.extensionpoints.editors.Activator; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; +import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; +import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.ExternalLabelPrimaryDragRoleEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.PapyrusWrappingLabel; +import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; +import org.eclipse.papyrus.uml.diagram.common.editparts.FloatingLabelEditPart; +import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; +import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; +import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; +import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.accessibility.AccessibleEvent; +import org.eclipse.swt.custom.BusyIndicator; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; +import org.eclipse.uml2.uml.Feature; + +/** + * @generated + */ +public class IntervalFloatingLabelEditPart extends FloatingLabelEditPart + implements ITextAwareEditPart, IBorderItemEditPart +{ + + /** + * @generated + */ + public static final int VISUAL_ID = 6118; + + /** + * @generated + */ + private DirectEditManager manager; + + /** + * @generated + */ + private IParser parser; + + /** + * @generated + */ + private List parserElements; + + /** + * @generated + */ + private String defaultText; + + /** + * direct edition mode (default, undefined, registered editor, etc.) + * + * @generated + */ + protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; + + /** + * configuration from a registered edit dialog + * + * @generated + */ + protected IDirectEditorConfiguration configuration; + + + /** + * @generated + */ + static { + registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.IntervalFloatingLabelEditPart.VISUAL_ID), new Point(0, 0)); + } + + /** + * @generated + */ + public IntervalFloatingLabelEditPart(View view) { + super(view); + } + + /** + * @generated + */ + @Override + protected void createDefaultEditPolicies() { + super.createDefaultEditPolicies(); + installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); + installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ExternalLabelPrimaryDragRoleEditPolicy()); + } + + /** + * @generated + */ + @Override + public IBorderItemLocator getBorderItemLocator() { + IFigure parentFigure = getFigure().getParent(); + if (parentFigure != null && parentFigure.getLayoutManager() != null) { + Object constraint = parentFigure.getLayoutManager().getConstraint(getFigure()); + return (IBorderItemLocator) constraint; + } + return null; + } + + /** + * @generated + */ + @Override + public void refreshBounds() { + int x = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_X())).intValue(); + int y = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_Y())).intValue(); + int width = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Width())).intValue(); + int height = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Height())).intValue(); + getBorderItemLocator().setConstraint(new Rectangle(x, y, width, height)); + } + + + /** + * @generated + */ + protected String getLabelTextHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getText(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getText(); + } else { + return ((Label) figure).getText(); + } + } + + /** + * @generated + */ + protected void setLabelTextHelper(IFigure figure, String text) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setText(text); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setText(text); + } else { + ((Label) figure).setText(text); + } + } + + /** + * @generated + */ + protected Image getLabelIconHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getIcon(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getIcon(); + } else { + return ((Label) figure).getIcon(); + } + } + + /** + * @generated + */ + protected void setLabelIconHelper(IFigure figure, Image icon) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setIcon(icon); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setIcon(icon); + } else { + ((Label) figure).setIcon(icon); + } + } + + /** + * @generated + */ + public void setLabel(IFigure + figure) { + unregisterVisuals(); + setFigure(figure); + defaultText = getLabelTextHelper(figure); + registerVisuals(); + refreshVisuals(); + } + + /** + * @generated + */ + @Override + protected List getModelChildren() { + return Collections.EMPTY_LIST; + } + + /** + * @generated + */ + @Override + public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { + return null; + } + + /** + * @generated + */ + public void setParser(IParser parser) { + this.parser = parser; + } + + /** + * @generated + */ + protected EObject getParserElement() { + return resolveSemanticElement(); + } + + /** + * @generated + */ + protected Image getLabelIcon() { + return null; + } + + /** + * @generated + */ + protected String getLabelText() { + String text = null; + EObject parserElement = getParserElement(); + if (parserElement != null && getParser() != null) { + text = getParser().getPrintString( + new EObjectAdapter(parserElement), + getParserOptions().intValue()); + } + if (text == null || text.length() == 0) { + text = defaultText; + } + return text; + } + + /** + * @generated + */ + @Override + public void setLabelText(String text) { + setLabelTextHelper(getFigure(), text); + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + @Override + public String getEditText() { + if (getParserElement() == null || getParser() == null) { + return ""; //$NON-NLS-1$ + } + return getParser().getEditString( + new EObjectAdapter(getParserElement()), + getParserOptions().intValue()); + } + + /** + * @generated + */ + protected boolean isEditable() { + return getParser() != null; + } + + /** + * @generated + */ + @Override + public ICellEditorValidator getEditTextValidator() { + return new ICellEditorValidator() { + + @Override + public String isValid(final Object value) { + if (value instanceof String) { + final EObject element = getParserElement(); + final IParser parser = getParser(); + try { + IParserEditStatus valid = + (IParserEditStatus) getEditingDomain().runExclusive( + new RunnableWithResult.Impl() { + + @Override + public void run() { + setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); + } + }); + return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); + } catch (InterruptedException ie) { + ie.printStackTrace(); + } + } + + // shouldn't get here + return null; + } + }; + } + + /** + * @generated + */ + @Override + public IContentAssistProcessor getCompletionProcessor() { + if (getParserElement() == null || getParser() == null) { + return null; + } + return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); + } + + /** + * @generated + */ + @Override + public ParserOptions getParserOptions() { + return ParserOptions.NONE; + } + + /** + * @generated + */ + @Override + public IParser getParser() { + if (parser == null) { + parser = UMLParserProvider.getParser(UMLElementTypes.Interval_2107, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.IntervalFloatingLabelEditPart.VISUAL_ID)); + } + return parser; + } + + /** + * @generated + */ + protected DirectEditManager getManager() { + if (manager == null) { + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + } + return manager; + } + + /** + * @generated + */ + protected void setManager(DirectEditManager manager) { + this.manager = manager; + } + + /** + * @generated + */ + protected void performDirectEdit() { + BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { + + @Override + public void run() { + getManager().show(); + } + }); + } + + /** + * @generated + */ + protected void performDirectEdit(Point eventLocation) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); + } + } + + /** + * @generated + */ + private void performDirectEdit(char initialCharacter) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(initialCharacter); + } else { + performDirectEdit(); + } + } + + /** + * @generated + */ + @Override + protected void performDirectEditRequest(Request request) { + + final Request theRequest = request; + + if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { + directEditionMode = getDirectEditionType(); + } + switch (directEditionMode) { + case IDirectEdition.NO_DIRECT_EDITION: + // no direct edition mode => does nothing + return; + case IDirectEdition.EXTENDED_DIRECT_EDITOR: + updateExtendedEditorConfiguration(); + if (configuration == null || configuration.getLanguage() == null) { + // Create default edit manager + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + performDefaultDirectEditorEdit(theRequest); + } else { + configuration.preEditAction(resolveSemanticElement()); + Dialog dialog = null; + if (configuration instanceof ICustomDirectEditorConfiguration) { + setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); + initializeDirectEditManager(theRequest); + return; + } else if (configuration instanceof IPopupEditorConfiguration) { + IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); + helper.showEditor(); + return; + } + else if (configuration instanceof IAdvancedEditorConfiguration) { + dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); + } else if (configuration instanceof IDirectEditorConfiguration) { + dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), + configuration); + } else { + return; + } + final Dialog finalDialog = dialog; + + if (Window.OK == dialog.open()) { + TransactionalEditingDomain domain = getEditingDomain(); + RecordingCommand command = new RecordingCommand(domain, "Edit Label") { + + @Override + protected void doExecute() { + configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); + + } + }; + domain.getCommandStack().execute(command); + } + } + break; + case IDirectEdition.DEFAULT_DIRECT_EDITOR: + initializeDirectEditManager(theRequest); + break; + default: + break; + } + } + + /** + * @generated + */ + protected void initializeDirectEditManager(final Request request) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + @Override + public void run() { + if (isActive() && isEditable()) { + if (request.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } + else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void refreshVisuals() { + super.refreshVisuals(); + refreshLabel(); + refreshFont(); + refreshFontColor(); + refreshUnderline(); + refreshStrikeThrough(); + } + + /** + * @generated + */ + protected void refreshLabel() { + EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); + if (maskLabelPolicy == null) { + maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); + } + if (maskLabelPolicy == null) { + View view = (View) getModel(); + if (view.isVisible()) { + setLabelTextHelper(getFigure(), getLabelText()); + setLabelIconHelper(getFigure(), getLabelIcon()); + } + else { + setLabelTextHelper(getFigure(), ""); //$NON-NLS-1$ + setLabelIconHelper(getFigure(), null); + } + } + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + protected void refreshUnderline() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); + } + if (resolveSemanticElement() instanceof Feature) { + if (((Feature) resolveSemanticElement()).isStatic()) { + ((WrappingLabel) getFigure()).setTextUnderline(true); + } + else { + ((WrappingLabel) getFigure()).setTextUnderline(false); + } + } + } + + /** + * @generated + */ + protected void refreshStrikeThrough() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); + } + } + + /** + * @generated + */ + @Override + protected void refreshFont() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null) { + FontData fontData = new FontData( + style.getFontName(), style.getFontHeight(), + (style.isBold() ? SWT.BOLD : SWT.NORMAL) | + (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); + setFont(fontData); + } + } + + /** + * @generated + */ + @Override + protected void setFontColor(Color color) { + getFigure().setForegroundColor(color); + } + + /** + * @generated + */ + @Override + protected void addSemanticListeners() { + if (getParser() instanceof ISemanticParser) { + EObject element = resolveSemanticElement(); + parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); + for (int i = 0; i < parserElements.size(); i++) { + addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ + } + } else { + super.addSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected void removeSemanticListeners() { + if (parserElements != null) { + for (int i = 0; i < parserElements.size(); i++) { + removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ + } + } else { + super.removeSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected AccessibleEditPart getAccessibleEditPart() { + if (accessibleEP == null) { + accessibleEP = new AccessibleGraphicalEditPart() { + + @Override + public void getName(AccessibleEvent e) { + e.result = getLabelTextHelper(getFigure()); + } + }; + } + return accessibleEP; + } + + /** + * @generated + */ + private View getFontStyleOwnerView() { + return getPrimaryView(); + } + + /** + * Returns the kind of associated editor for direct edition. + * + * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition + * @generated + */ + public int getDirectEditionType() { + if (checkExtendedEditor()) { + initExtendedEditorConfiguration(); + return IDirectEdition.EXTENDED_DIRECT_EDITOR; + } + if (checkDefaultEdition()) { + return IDirectEdition.DEFAULT_DIRECT_EDITOR; + } + + // not a named element. no specific editor => do nothing + return IDirectEdition.NO_DIRECT_EDITION; + } + + /** + * Checks if an extended editor is present. + * + * @return true if an extended editor is present. + * @generated + */ + protected boolean checkExtendedEditor() { + if (resolveSemanticElement() != null) { + return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); + } + return false; + } + + /** + * Checks if a default direct edition is available + * + * @return true if a default direct edition is available + * @generated + */ + protected boolean checkDefaultEdition() { + return (getParser() != null); + } + + /** + * Initializes the extended editor configuration + * + * @generated + */ + protected void initExtendedEditorConfiguration() { + if (configuration == null) { + final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("")) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); + } else { + configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); + } + } + } + + /** + * Updates the preference configuration + * + * @generated + */ + protected void updateExtendedEditorConfiguration() { + String languagePreferred = Activator.getDefault().getPreferenceStore().getString( + IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() + .eClass().getInstanceClassName()); + } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { + configuration = null; + } + } + + /** + * Performs the direct edit usually used by GMF editors. + * + * @param theRequest + * the direct edit request that starts the direct edit system + * @generated + */ + protected void performDefaultDirectEditorEdit(final Request theRequest) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + + @Override + public void run() { + if (isActive() && isEditable()) { + if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) theRequest.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { + DirectEditRequest editRequest = (DirectEditRequest) theRequest; + performDirectEdit(editRequest.getLocation()); + } else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + + /** + * @generated + */ + @Override + protected void handleNotificationEvent(Notification event) { + Object feature = event.getFeature(); + if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { + Integer c = (Integer) event.getNewValue(); + setFontColor(DiagramColorRegistry.getInstance().getColor(c)); + } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { + refreshUnderline(); + } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { + refreshStrikeThrough(); + } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { + refreshFont(); + } else { + if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { + refreshLabel(); + } + if (getParser() instanceof ISemanticParser) { + ISemanticParser modelParser = + (ISemanticParser) getParser(); + if (modelParser.areSemanticElementsAffected(null, event)) { + removeSemanticListeners(); + if (resolveSemanticElement() != null) { + addSemanticListeners(); + } + refreshLabel(); + } + } + } + super.handleNotificationEvent(event); + } + + /** + * @generated + */ + @Override + protected IFigure createFigure() { + IFigure label = createFigurePrim(); + defaultText = getLabelTextHelper(label); + return label; + } + + /** + * @generated + */ + protected IFigure createFigurePrim() { + return new PapyrusWrappingLabel(); + } + +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/IntervalNameEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/IntervalNameEditPart.java index 25618c4fe08..baca353fad7 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/IntervalNameEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/IntervalNameEditPart.java @@ -864,7 +864,7 @@ public class IntervalNameEditPart extends PapyrusCompartmentEditPart implements * @generated */ protected void addOwnerElementListeners() { - addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); + addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/LiteralBooleanEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/LiteralBooleanEditPart.java index fdd874ec375..d94b8755944 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/LiteralBooleanEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/LiteralBooleanEditPart.java @@ -11,27 +11,40 @@ */ package org.eclipse.papyrus.uml.diagram.composite.edit.parts; +import java.util.Collections; +import java.util.List; + import org.eclipse.draw2d.IFigure; +import org.eclipse.emf.common.notify.Notification; import org.eclipse.gef.EditPart; import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.GraphicalEditPart; 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.handles.MoveHandle; import org.eclipse.gef.requests.CreateRequest; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.BorderItemSelectionEditPolicy; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles; +import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; -import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure; import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure; +import org.eclipse.gmf.runtime.notation.Edge; +import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.gmf.runtime.notation.View; -import org.eclipse.papyrus.infra.gmfdiag.common.editpart.NodeEditPart; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.GetChildLayoutEditPolicy; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.IPapyrusNodeFigure; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.RoundedRectangleNodePlateFigure; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.SelectableBorderedNodeFigure; +import org.eclipse.papyrus.uml.diagram.common.editparts.RoundedCompartmentEditPart; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeNodeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.QualifiedNameDisplayEditPolicy; -import org.eclipse.papyrus.uml.diagram.common.figure.node.NodeNamedElementFigure; +import org.eclipse.papyrus.uml.diagram.common.figure.node.RoundedCompartmentFigure; +import org.eclipse.papyrus.uml.diagram.common.locator.RoundedRectangleLabelPositionLocator; import org.eclipse.papyrus.uml.diagram.composite.edit.policies.LiteralBooleanItemSemanticEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; import org.eclipse.swt.graphics.Color; @@ -39,7 +52,7 @@ import org.eclipse.swt.graphics.Color; /** * @generated */ -public class LiteralBooleanEditPart extends NodeEditPart { +public class LiteralBooleanEditPart extends RoundedCompartmentEditPart { /** * @generated @@ -73,6 +86,7 @@ public class LiteralBooleanEditPart extends NodeEditPart { installEditPolicy(EditPolicy.LAYOUT_ROLE, createLayoutEditPolicy()); installEditPolicy(QualifiedNameDisplayEditPolicy.QUALIFIED_NAME_POLICY, new QualifiedNameDisplayEditPolicy()); installEditPolicy(AppliedStereotypeLabelDisplayEditPolicy.STEREOTYPE_LABEL_POLICY, new AppliedStereotypeNodeLabelDisplayEditPolicy()); + installEditPolicy(EditPolicy.LAYOUT_ROLE, new GetChildLayoutEditPolicy()); // XXX need an SCR to runtime to have another abstract superclass that would let children add reasonable editpolicies // removeEditPolicy(org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles.CONNECTION_HANDLES_ROLE); } @@ -85,6 +99,20 @@ public class LiteralBooleanEditPart extends NodeEditPart { @Override protected EditPolicy createChildEditPolicy(EditPart child) { + View childView = (View) child.getModel(); + switch (UMLVisualIDRegistry.getVisualID(childView)) { + case LiteralBooleanFloatingLabelEditPart.VISUAL_ID: + return new BorderItemSelectionEditPolicy() { + + @Override + protected List createSelectionHandles() { + MoveHandle mh = new MoveHandle((GraphicalEditPart) getHost()); + mh.setBorder(null); + return Collections.singletonList(mh); + } + } + ; + } EditPolicy result = child.getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); if (result == null) { result = new NonResizableEditPolicy(); @@ -105,12 +133,36 @@ public class LiteralBooleanEditPart extends NodeEditPart { return lep; } + /** + * Papyrus codeGen + * + * @generated + **/ + @Override + protected void handleNotificationEvent(Notification event) { + /* + * when a node have external node labels, the methods refreshChildren() remove the EditPart corresponding to the Label from the EditPart + * Registry. After that, we can't reset the visibility to true (using the Show/Hide Label Action)! + */ + if (NotationPackage.eINSTANCE.getView_Visible().equals(event.getFeature())) { + Object notifier = event.getNotifier(); + List modelChildren = ((View) getModel()).getChildren(); + if (!(notifier instanceof Edge)) { + if (modelChildren.contains(event.getNotifier())) { + return; + } + } + } + super.handleNotificationEvent(event); + + } + /** * @generated */ @Override protected IFigure createNodeShape() { - return primaryShape = new NodeNamedElementFigure(); + return primaryShape = new RoundedCompartmentFigure(); } /** @@ -119,8 +171,8 @@ public class LiteralBooleanEditPart extends NodeEditPart { * @generated */ @Override - public NodeNamedElementFigure getPrimaryShape() { - return (NodeNamedElementFigure) primaryShape; + public RoundedCompartmentFigure getPrimaryShape() { + return (RoundedCompartmentFigure) primaryShape; } /** @@ -173,15 +225,32 @@ public class LiteralBooleanEditPart extends NodeEditPart { */ @Override protected IFigure getContentPaneFor(IGraphicalEditPart editPart) { + if (editPart instanceof IBorderItemEditPart) { + return getBorderedFigure().getBorderItemContainer(); + } return getContentPane(); } + /** + * @generated + */ + @Override + protected void addBorderItem(IFigure borderItemContainer, IBorderItemEditPart borderItemEditPart) { + if (borderItemEditPart instanceof LiteralBooleanFloatingLabelEditPart) { + IBorderItemLocator locator = new RoundedRectangleLabelPositionLocator(getMainFigure()); + borderItemContainer.add(borderItemEditPart.getFigure(), locator); + } else + { + super.addBorderItem(borderItemContainer, borderItemEditPart); + } + } + /** * @generated */ @Override protected NodeFigure createNodePlate() { - DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(40, 40); + RoundedRectangleNodePlateFigure result = new RoundedRectangleNodePlateFigure(40, 40); return result; } @@ -194,7 +263,7 @@ public class LiteralBooleanEditPart extends NodeEditPart { * @generated */ @Override - protected NodeFigure createNodeFigure() { + protected NodeFigure createMainFigure() { return new SelectableBorderedNodeFigure(createMainFigureWithSVG()); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/LiteralBooleanFloatingLabelEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/LiteralBooleanFloatingLabelEditPart.java new file mode 100644 index 00000000000..79bf741824b --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/LiteralBooleanFloatingLabelEditPart.java @@ -0,0 +1,860 @@ +/** + * 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.uml.diagram.composite.edit.parts; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.Label; +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.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.RunnableWithResult; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gef.AccessibleEditPart; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.Request; +import org.eclipse.gef.requests.DirectEditRequest; +import org.eclipse.gef.tools.DirectEditManager; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; +import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; +import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; +import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; +import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; +import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; +import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; +import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; +import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; +import org.eclipse.gmf.runtime.notation.FontStyle; +import org.eclipse.gmf.runtime.notation.NotationPackage; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.text.contentassist.IContentAssistProcessor; +import org.eclipse.jface.viewers.ICellEditorValidator; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.extensionpoints.editors.Activator; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; +import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; +import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.ExternalLabelPrimaryDragRoleEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.PapyrusWrappingLabel; +import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; +import org.eclipse.papyrus.uml.diagram.common.editparts.FloatingLabelEditPart; +import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; +import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; +import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; +import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.accessibility.AccessibleEvent; +import org.eclipse.swt.custom.BusyIndicator; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; +import org.eclipse.uml2.uml.Feature; + +/** + * @generated + */ +public class LiteralBooleanFloatingLabelEditPart extends FloatingLabelEditPart + implements ITextAwareEditPart, IBorderItemEditPart +{ + + /** + * @generated + */ + public static final int VISUAL_ID = 6106; + + /** + * @generated + */ + private DirectEditManager manager; + + /** + * @generated + */ + private IParser parser; + + /** + * @generated + */ + private List parserElements; + + /** + * @generated + */ + private String defaultText; + + /** + * direct edition mode (default, undefined, registered editor, etc.) + * + * @generated + */ + protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; + + /** + * configuration from a registered edit dialog + * + * @generated + */ + protected IDirectEditorConfiguration configuration; + + + /** + * @generated + */ + static { + registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.LiteralBooleanFloatingLabelEditPart.VISUAL_ID), new Point(0, 0)); + } + + /** + * @generated + */ + public LiteralBooleanFloatingLabelEditPart(View view) { + super(view); + } + + /** + * @generated + */ + @Override + protected void createDefaultEditPolicies() { + super.createDefaultEditPolicies(); + installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); + installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ExternalLabelPrimaryDragRoleEditPolicy()); + } + + /** + * @generated + */ + @Override + public IBorderItemLocator getBorderItemLocator() { + IFigure parentFigure = getFigure().getParent(); + if (parentFigure != null && parentFigure.getLayoutManager() != null) { + Object constraint = parentFigure.getLayoutManager().getConstraint(getFigure()); + return (IBorderItemLocator) constraint; + } + return null; + } + + /** + * @generated + */ + @Override + public void refreshBounds() { + int x = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_X())).intValue(); + int y = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_Y())).intValue(); + int width = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Width())).intValue(); + int height = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Height())).intValue(); + getBorderItemLocator().setConstraint(new Rectangle(x, y, width, height)); + } + + + /** + * @generated + */ + protected String getLabelTextHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getText(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getText(); + } else { + return ((Label) figure).getText(); + } + } + + /** + * @generated + */ + protected void setLabelTextHelper(IFigure figure, String text) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setText(text); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setText(text); + } else { + ((Label) figure).setText(text); + } + } + + /** + * @generated + */ + protected Image getLabelIconHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getIcon(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getIcon(); + } else { + return ((Label) figure).getIcon(); + } + } + + /** + * @generated + */ + protected void setLabelIconHelper(IFigure figure, Image icon) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setIcon(icon); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setIcon(icon); + } else { + ((Label) figure).setIcon(icon); + } + } + + /** + * @generated + */ + public void setLabel(IFigure + figure) { + unregisterVisuals(); + setFigure(figure); + defaultText = getLabelTextHelper(figure); + registerVisuals(); + refreshVisuals(); + } + + /** + * @generated + */ + @Override + protected List getModelChildren() { + return Collections.EMPTY_LIST; + } + + /** + * @generated + */ + @Override + public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { + return null; + } + + /** + * @generated + */ + public void setParser(IParser parser) { + this.parser = parser; + } + + /** + * @generated + */ + protected EObject getParserElement() { + return resolveSemanticElement(); + } + + /** + * @generated + */ + protected Image getLabelIcon() { + return null; + } + + /** + * @generated + */ + protected String getLabelText() { + String text = null; + EObject parserElement = getParserElement(); + if (parserElement != null && getParser() != null) { + text = getParser().getPrintString( + new EObjectAdapter(parserElement), + getParserOptions().intValue()); + } + if (text == null || text.length() == 0) { + text = defaultText; + } + return text; + } + + /** + * @generated + */ + @Override + public void setLabelText(String text) { + setLabelTextHelper(getFigure(), text); + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + @Override + public String getEditText() { + if (getParserElement() == null || getParser() == null) { + return ""; //$NON-NLS-1$ + } + return getParser().getEditString( + new EObjectAdapter(getParserElement()), + getParserOptions().intValue()); + } + + /** + * @generated + */ + protected boolean isEditable() { + return getParser() != null; + } + + /** + * @generated + */ + @Override + public ICellEditorValidator getEditTextValidator() { + return new ICellEditorValidator() { + + @Override + public String isValid(final Object value) { + if (value instanceof String) { + final EObject element = getParserElement(); + final IParser parser = getParser(); + try { + IParserEditStatus valid = + (IParserEditStatus) getEditingDomain().runExclusive( + new RunnableWithResult.Impl() { + + @Override + public void run() { + setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); + } + }); + return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); + } catch (InterruptedException ie) { + ie.printStackTrace(); + } + } + + // shouldn't get here + return null; + } + }; + } + + /** + * @generated + */ + @Override + public IContentAssistProcessor getCompletionProcessor() { + if (getParserElement() == null || getParser() == null) { + return null; + } + return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); + } + + /** + * @generated + */ + @Override + public ParserOptions getParserOptions() { + return ParserOptions.NONE; + } + + /** + * @generated + */ + @Override + public IParser getParser() { + if (parser == null) { + parser = UMLParserProvider.getParser(UMLElementTypes.LiteralBoolean_2095, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.LiteralBooleanFloatingLabelEditPart.VISUAL_ID)); + } + return parser; + } + + /** + * @generated + */ + protected DirectEditManager getManager() { + if (manager == null) { + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + } + return manager; + } + + /** + * @generated + */ + protected void setManager(DirectEditManager manager) { + this.manager = manager; + } + + /** + * @generated + */ + protected void performDirectEdit() { + BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { + + @Override + public void run() { + getManager().show(); + } + }); + } + + /** + * @generated + */ + protected void performDirectEdit(Point eventLocation) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); + } + } + + /** + * @generated + */ + private void performDirectEdit(char initialCharacter) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(initialCharacter); + } else { + performDirectEdit(); + } + } + + /** + * @generated + */ + @Override + protected void performDirectEditRequest(Request request) { + + final Request theRequest = request; + + if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { + directEditionMode = getDirectEditionType(); + } + switch (directEditionMode) { + case IDirectEdition.NO_DIRECT_EDITION: + // no direct edition mode => does nothing + return; + case IDirectEdition.EXTENDED_DIRECT_EDITOR: + updateExtendedEditorConfiguration(); + if (configuration == null || configuration.getLanguage() == null) { + // Create default edit manager + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + performDefaultDirectEditorEdit(theRequest); + } else { + configuration.preEditAction(resolveSemanticElement()); + Dialog dialog = null; + if (configuration instanceof ICustomDirectEditorConfiguration) { + setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); + initializeDirectEditManager(theRequest); + return; + } else if (configuration instanceof IPopupEditorConfiguration) { + IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); + helper.showEditor(); + return; + } + else if (configuration instanceof IAdvancedEditorConfiguration) { + dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); + } else if (configuration instanceof IDirectEditorConfiguration) { + dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), + configuration); + } else { + return; + } + final Dialog finalDialog = dialog; + + if (Window.OK == dialog.open()) { + TransactionalEditingDomain domain = getEditingDomain(); + RecordingCommand command = new RecordingCommand(domain, "Edit Label") { + + @Override + protected void doExecute() { + configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); + + } + }; + domain.getCommandStack().execute(command); + } + } + break; + case IDirectEdition.DEFAULT_DIRECT_EDITOR: + initializeDirectEditManager(theRequest); + break; + default: + break; + } + } + + /** + * @generated + */ + protected void initializeDirectEditManager(final Request request) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + @Override + public void run() { + if (isActive() && isEditable()) { + if (request.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } + else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void refreshVisuals() { + super.refreshVisuals(); + refreshLabel(); + refreshFont(); + refreshFontColor(); + refreshUnderline(); + refreshStrikeThrough(); + } + + /** + * @generated + */ + protected void refreshLabel() { + EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); + if (maskLabelPolicy == null) { + maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); + } + if (maskLabelPolicy == null) { + View view = (View) getModel(); + if (view.isVisible()) { + setLabelTextHelper(getFigure(), getLabelText()); + setLabelIconHelper(getFigure(), getLabelIcon()); + } + else { + setLabelTextHelper(getFigure(), ""); //$NON-NLS-1$ + setLabelIconHelper(getFigure(), null); + } + } + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + protected void refreshUnderline() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); + } + if (resolveSemanticElement() instanceof Feature) { + if (((Feature) resolveSemanticElement()).isStatic()) { + ((WrappingLabel) getFigure()).setTextUnderline(true); + } + else { + ((WrappingLabel) getFigure()).setTextUnderline(false); + } + } + } + + /** + * @generated + */ + protected void refreshStrikeThrough() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); + } + } + + /** + * @generated + */ + @Override + protected void refreshFont() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null) { + FontData fontData = new FontData( + style.getFontName(), style.getFontHeight(), + (style.isBold() ? SWT.BOLD : SWT.NORMAL) | + (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); + setFont(fontData); + } + } + + /** + * @generated + */ + @Override + protected void setFontColor(Color color) { + getFigure().setForegroundColor(color); + } + + /** + * @generated + */ + @Override + protected void addSemanticListeners() { + if (getParser() instanceof ISemanticParser) { + EObject element = resolveSemanticElement(); + parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); + for (int i = 0; i < parserElements.size(); i++) { + addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ + } + } else { + super.addSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected void removeSemanticListeners() { + if (parserElements != null) { + for (int i = 0; i < parserElements.size(); i++) { + removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ + } + } else { + super.removeSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected AccessibleEditPart getAccessibleEditPart() { + if (accessibleEP == null) { + accessibleEP = new AccessibleGraphicalEditPart() { + + @Override + public void getName(AccessibleEvent e) { + e.result = getLabelTextHelper(getFigure()); + } + }; + } + return accessibleEP; + } + + /** + * @generated + */ + private View getFontStyleOwnerView() { + return getPrimaryView(); + } + + /** + * Returns the kind of associated editor for direct edition. + * + * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition + * @generated + */ + public int getDirectEditionType() { + if (checkExtendedEditor()) { + initExtendedEditorConfiguration(); + return IDirectEdition.EXTENDED_DIRECT_EDITOR; + } + if (checkDefaultEdition()) { + return IDirectEdition.DEFAULT_DIRECT_EDITOR; + } + + // not a named element. no specific editor => do nothing + return IDirectEdition.NO_DIRECT_EDITION; + } + + /** + * Checks if an extended editor is present. + * + * @return true if an extended editor is present. + * @generated + */ + protected boolean checkExtendedEditor() { + if (resolveSemanticElement() != null) { + return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); + } + return false; + } + + /** + * Checks if a default direct edition is available + * + * @return true if a default direct edition is available + * @generated + */ + protected boolean checkDefaultEdition() { + return (getParser() != null); + } + + /** + * Initializes the extended editor configuration + * + * @generated + */ + protected void initExtendedEditorConfiguration() { + if (configuration == null) { + final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("")) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); + } else { + configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); + } + } + } + + /** + * Updates the preference configuration + * + * @generated + */ + protected void updateExtendedEditorConfiguration() { + String languagePreferred = Activator.getDefault().getPreferenceStore().getString( + IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() + .eClass().getInstanceClassName()); + } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { + configuration = null; + } + } + + /** + * Performs the direct edit usually used by GMF editors. + * + * @param theRequest + * the direct edit request that starts the direct edit system + * @generated + */ + protected void performDefaultDirectEditorEdit(final Request theRequest) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + + @Override + public void run() { + if (isActive() && isEditable()) { + if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) theRequest.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { + DirectEditRequest editRequest = (DirectEditRequest) theRequest; + performDirectEdit(editRequest.getLocation()); + } else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + + /** + * @generated + */ + @Override + protected void handleNotificationEvent(Notification event) { + Object feature = event.getFeature(); + if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { + Integer c = (Integer) event.getNewValue(); + setFontColor(DiagramColorRegistry.getInstance().getColor(c)); + } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { + refreshUnderline(); + } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { + refreshStrikeThrough(); + } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { + refreshFont(); + } else { + if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { + refreshLabel(); + } + if (getParser() instanceof ISemanticParser) { + ISemanticParser modelParser = + (ISemanticParser) getParser(); + if (modelParser.areSemanticElementsAffected(null, event)) { + removeSemanticListeners(); + if (resolveSemanticElement() != null) { + addSemanticListeners(); + } + refreshLabel(); + } + } + } + super.handleNotificationEvent(event); + } + + /** + * @generated + */ + @Override + protected IFigure createFigure() { + IFigure label = createFigurePrim(); + defaultText = getLabelTextHelper(label); + return label; + } + + /** + * @generated + */ + protected IFigure createFigurePrim() { + return new PapyrusWrappingLabel(); + } + +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/LiteralBooleanNameEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/LiteralBooleanNameEditPart.java index bdcc3c9ff21..4784c7dc024 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/LiteralBooleanNameEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/LiteralBooleanNameEditPart.java @@ -864,7 +864,7 @@ public class LiteralBooleanNameEditPart extends PapyrusCompartmentEditPart imple * @generated */ protected void addOwnerElementListeners() { - addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); + addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/LiteralIntegerEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/LiteralIntegerEditPart.java index 51274169406..ad5fb3f52bb 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/LiteralIntegerEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/LiteralIntegerEditPart.java @@ -11,27 +11,40 @@ */ package org.eclipse.papyrus.uml.diagram.composite.edit.parts; +import java.util.Collections; +import java.util.List; + import org.eclipse.draw2d.IFigure; +import org.eclipse.emf.common.notify.Notification; import org.eclipse.gef.EditPart; import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.GraphicalEditPart; 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.handles.MoveHandle; import org.eclipse.gef.requests.CreateRequest; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.BorderItemSelectionEditPolicy; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles; +import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; -import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure; import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure; +import org.eclipse.gmf.runtime.notation.Edge; +import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.gmf.runtime.notation.View; -import org.eclipse.papyrus.infra.gmfdiag.common.editpart.NodeEditPart; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.GetChildLayoutEditPolicy; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.IPapyrusNodeFigure; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.RoundedRectangleNodePlateFigure; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.SelectableBorderedNodeFigure; +import org.eclipse.papyrus.uml.diagram.common.editparts.RoundedCompartmentEditPart; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeNodeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.QualifiedNameDisplayEditPolicy; -import org.eclipse.papyrus.uml.diagram.common.figure.node.NodeNamedElementFigure; +import org.eclipse.papyrus.uml.diagram.common.figure.node.RoundedCompartmentFigure; +import org.eclipse.papyrus.uml.diagram.common.locator.RoundedRectangleLabelPositionLocator; import org.eclipse.papyrus.uml.diagram.composite.edit.policies.LiteralIntegerItemSemanticEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; import org.eclipse.swt.graphics.Color; @@ -39,7 +52,7 @@ import org.eclipse.swt.graphics.Color; /** * @generated */ -public class LiteralIntegerEditPart extends NodeEditPart { +public class LiteralIntegerEditPart extends RoundedCompartmentEditPart { /** * @generated @@ -73,6 +86,7 @@ public class LiteralIntegerEditPart extends NodeEditPart { installEditPolicy(EditPolicy.LAYOUT_ROLE, createLayoutEditPolicy()); installEditPolicy(QualifiedNameDisplayEditPolicy.QUALIFIED_NAME_POLICY, new QualifiedNameDisplayEditPolicy()); installEditPolicy(AppliedStereotypeLabelDisplayEditPolicy.STEREOTYPE_LABEL_POLICY, new AppliedStereotypeNodeLabelDisplayEditPolicy()); + installEditPolicy(EditPolicy.LAYOUT_ROLE, new GetChildLayoutEditPolicy()); // XXX need an SCR to runtime to have another abstract superclass that would let children add reasonable editpolicies // removeEditPolicy(org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles.CONNECTION_HANDLES_ROLE); } @@ -85,6 +99,20 @@ public class LiteralIntegerEditPart extends NodeEditPart { @Override protected EditPolicy createChildEditPolicy(EditPart child) { + View childView = (View) child.getModel(); + switch (UMLVisualIDRegistry.getVisualID(childView)) { + case LiteralIntegerFloatingLabelEditPart.VISUAL_ID: + return new BorderItemSelectionEditPolicy() { + + @Override + protected List createSelectionHandles() { + MoveHandle mh = new MoveHandle((GraphicalEditPart) getHost()); + mh.setBorder(null); + return Collections.singletonList(mh); + } + } + ; + } EditPolicy result = child.getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); if (result == null) { result = new NonResizableEditPolicy(); @@ -105,12 +133,36 @@ public class LiteralIntegerEditPart extends NodeEditPart { return lep; } + /** + * Papyrus codeGen + * + * @generated + **/ + @Override + protected void handleNotificationEvent(Notification event) { + /* + * when a node have external node labels, the methods refreshChildren() remove the EditPart corresponding to the Label from the EditPart + * Registry. After that, we can't reset the visibility to true (using the Show/Hide Label Action)! + */ + if (NotationPackage.eINSTANCE.getView_Visible().equals(event.getFeature())) { + Object notifier = event.getNotifier(); + List modelChildren = ((View) getModel()).getChildren(); + if (!(notifier instanceof Edge)) { + if (modelChildren.contains(event.getNotifier())) { + return; + } + } + } + super.handleNotificationEvent(event); + + } + /** * @generated */ @Override protected IFigure createNodeShape() { - return primaryShape = new NodeNamedElementFigure(); + return primaryShape = new RoundedCompartmentFigure(); } /** @@ -119,8 +171,8 @@ public class LiteralIntegerEditPart extends NodeEditPart { * @generated */ @Override - public NodeNamedElementFigure getPrimaryShape() { - return (NodeNamedElementFigure) primaryShape; + public RoundedCompartmentFigure getPrimaryShape() { + return (RoundedCompartmentFigure) primaryShape; } /** @@ -173,15 +225,32 @@ public class LiteralIntegerEditPart extends NodeEditPart { */ @Override protected IFigure getContentPaneFor(IGraphicalEditPart editPart) { + if (editPart instanceof IBorderItemEditPart) { + return getBorderedFigure().getBorderItemContainer(); + } return getContentPane(); } + /** + * @generated + */ + @Override + protected void addBorderItem(IFigure borderItemContainer, IBorderItemEditPart borderItemEditPart) { + if (borderItemEditPart instanceof LiteralIntegerFloatingLabelEditPart) { + IBorderItemLocator locator = new RoundedRectangleLabelPositionLocator(getMainFigure()); + borderItemContainer.add(borderItemEditPart.getFigure(), locator); + } else + { + super.addBorderItem(borderItemContainer, borderItemEditPart); + } + } + /** * @generated */ @Override protected NodeFigure createNodePlate() { - DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(40, 40); + RoundedRectangleNodePlateFigure result = new RoundedRectangleNodePlateFigure(40, 40); return result; } @@ -194,7 +263,7 @@ public class LiteralIntegerEditPart extends NodeEditPart { * @generated */ @Override - protected NodeFigure createNodeFigure() { + protected NodeFigure createMainFigure() { return new SelectableBorderedNodeFigure(createMainFigureWithSVG()); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/LiteralIntegerFloatingLabelEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/LiteralIntegerFloatingLabelEditPart.java new file mode 100644 index 00000000000..fe3c0f033f8 --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/LiteralIntegerFloatingLabelEditPart.java @@ -0,0 +1,860 @@ +/** + * 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.uml.diagram.composite.edit.parts; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.Label; +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.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.RunnableWithResult; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gef.AccessibleEditPart; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.Request; +import org.eclipse.gef.requests.DirectEditRequest; +import org.eclipse.gef.tools.DirectEditManager; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; +import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; +import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; +import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; +import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; +import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; +import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; +import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; +import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; +import org.eclipse.gmf.runtime.notation.FontStyle; +import org.eclipse.gmf.runtime.notation.NotationPackage; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.text.contentassist.IContentAssistProcessor; +import org.eclipse.jface.viewers.ICellEditorValidator; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.extensionpoints.editors.Activator; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; +import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; +import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.ExternalLabelPrimaryDragRoleEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.PapyrusWrappingLabel; +import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; +import org.eclipse.papyrus.uml.diagram.common.editparts.FloatingLabelEditPart; +import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; +import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; +import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; +import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.accessibility.AccessibleEvent; +import org.eclipse.swt.custom.BusyIndicator; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; +import org.eclipse.uml2.uml.Feature; + +/** + * @generated + */ +public class LiteralIntegerFloatingLabelEditPart extends FloatingLabelEditPart + implements ITextAwareEditPart, IBorderItemEditPart +{ + + /** + * @generated + */ + public static final int VISUAL_ID = 6107; + + /** + * @generated + */ + private DirectEditManager manager; + + /** + * @generated + */ + private IParser parser; + + /** + * @generated + */ + private List parserElements; + + /** + * @generated + */ + private String defaultText; + + /** + * direct edition mode (default, undefined, registered editor, etc.) + * + * @generated + */ + protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; + + /** + * configuration from a registered edit dialog + * + * @generated + */ + protected IDirectEditorConfiguration configuration; + + + /** + * @generated + */ + static { + registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.LiteralIntegerFloatingLabelEditPart.VISUAL_ID), new Point(0, 0)); + } + + /** + * @generated + */ + public LiteralIntegerFloatingLabelEditPart(View view) { + super(view); + } + + /** + * @generated + */ + @Override + protected void createDefaultEditPolicies() { + super.createDefaultEditPolicies(); + installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); + installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ExternalLabelPrimaryDragRoleEditPolicy()); + } + + /** + * @generated + */ + @Override + public IBorderItemLocator getBorderItemLocator() { + IFigure parentFigure = getFigure().getParent(); + if (parentFigure != null && parentFigure.getLayoutManager() != null) { + Object constraint = parentFigure.getLayoutManager().getConstraint(getFigure()); + return (IBorderItemLocator) constraint; + } + return null; + } + + /** + * @generated + */ + @Override + public void refreshBounds() { + int x = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_X())).intValue(); + int y = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_Y())).intValue(); + int width = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Width())).intValue(); + int height = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Height())).intValue(); + getBorderItemLocator().setConstraint(new Rectangle(x, y, width, height)); + } + + + /** + * @generated + */ + protected String getLabelTextHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getText(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getText(); + } else { + return ((Label) figure).getText(); + } + } + + /** + * @generated + */ + protected void setLabelTextHelper(IFigure figure, String text) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setText(text); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setText(text); + } else { + ((Label) figure).setText(text); + } + } + + /** + * @generated + */ + protected Image getLabelIconHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getIcon(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getIcon(); + } else { + return ((Label) figure).getIcon(); + } + } + + /** + * @generated + */ + protected void setLabelIconHelper(IFigure figure, Image icon) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setIcon(icon); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setIcon(icon); + } else { + ((Label) figure).setIcon(icon); + } + } + + /** + * @generated + */ + public void setLabel(IFigure + figure) { + unregisterVisuals(); + setFigure(figure); + defaultText = getLabelTextHelper(figure); + registerVisuals(); + refreshVisuals(); + } + + /** + * @generated + */ + @Override + protected List getModelChildren() { + return Collections.EMPTY_LIST; + } + + /** + * @generated + */ + @Override + public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { + return null; + } + + /** + * @generated + */ + public void setParser(IParser parser) { + this.parser = parser; + } + + /** + * @generated + */ + protected EObject getParserElement() { + return resolveSemanticElement(); + } + + /** + * @generated + */ + protected Image getLabelIcon() { + return null; + } + + /** + * @generated + */ + protected String getLabelText() { + String text = null; + EObject parserElement = getParserElement(); + if (parserElement != null && getParser() != null) { + text = getParser().getPrintString( + new EObjectAdapter(parserElement), + getParserOptions().intValue()); + } + if (text == null || text.length() == 0) { + text = defaultText; + } + return text; + } + + /** + * @generated + */ + @Override + public void setLabelText(String text) { + setLabelTextHelper(getFigure(), text); + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + @Override + public String getEditText() { + if (getParserElement() == null || getParser() == null) { + return ""; //$NON-NLS-1$ + } + return getParser().getEditString( + new EObjectAdapter(getParserElement()), + getParserOptions().intValue()); + } + + /** + * @generated + */ + protected boolean isEditable() { + return getParser() != null; + } + + /** + * @generated + */ + @Override + public ICellEditorValidator getEditTextValidator() { + return new ICellEditorValidator() { + + @Override + public String isValid(final Object value) { + if (value instanceof String) { + final EObject element = getParserElement(); + final IParser parser = getParser(); + try { + IParserEditStatus valid = + (IParserEditStatus) getEditingDomain().runExclusive( + new RunnableWithResult.Impl() { + + @Override + public void run() { + setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); + } + }); + return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); + } catch (InterruptedException ie) { + ie.printStackTrace(); + } + } + + // shouldn't get here + return null; + } + }; + } + + /** + * @generated + */ + @Override + public IContentAssistProcessor getCompletionProcessor() { + if (getParserElement() == null || getParser() == null) { + return null; + } + return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); + } + + /** + * @generated + */ + @Override + public ParserOptions getParserOptions() { + return ParserOptions.NONE; + } + + /** + * @generated + */ + @Override + public IParser getParser() { + if (parser == null) { + parser = UMLParserProvider.getParser(UMLElementTypes.LiteralInteger_2096, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.LiteralIntegerFloatingLabelEditPart.VISUAL_ID)); + } + return parser; + } + + /** + * @generated + */ + protected DirectEditManager getManager() { + if (manager == null) { + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + } + return manager; + } + + /** + * @generated + */ + protected void setManager(DirectEditManager manager) { + this.manager = manager; + } + + /** + * @generated + */ + protected void performDirectEdit() { + BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { + + @Override + public void run() { + getManager().show(); + } + }); + } + + /** + * @generated + */ + protected void performDirectEdit(Point eventLocation) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); + } + } + + /** + * @generated + */ + private void performDirectEdit(char initialCharacter) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(initialCharacter); + } else { + performDirectEdit(); + } + } + + /** + * @generated + */ + @Override + protected void performDirectEditRequest(Request request) { + + final Request theRequest = request; + + if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { + directEditionMode = getDirectEditionType(); + } + switch (directEditionMode) { + case IDirectEdition.NO_DIRECT_EDITION: + // no direct edition mode => does nothing + return; + case IDirectEdition.EXTENDED_DIRECT_EDITOR: + updateExtendedEditorConfiguration(); + if (configuration == null || configuration.getLanguage() == null) { + // Create default edit manager + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + performDefaultDirectEditorEdit(theRequest); + } else { + configuration.preEditAction(resolveSemanticElement()); + Dialog dialog = null; + if (configuration instanceof ICustomDirectEditorConfiguration) { + setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); + initializeDirectEditManager(theRequest); + return; + } else if (configuration instanceof IPopupEditorConfiguration) { + IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); + helper.showEditor(); + return; + } + else if (configuration instanceof IAdvancedEditorConfiguration) { + dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); + } else if (configuration instanceof IDirectEditorConfiguration) { + dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), + configuration); + } else { + return; + } + final Dialog finalDialog = dialog; + + if (Window.OK == dialog.open()) { + TransactionalEditingDomain domain = getEditingDomain(); + RecordingCommand command = new RecordingCommand(domain, "Edit Label") { + + @Override + protected void doExecute() { + configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); + + } + }; + domain.getCommandStack().execute(command); + } + } + break; + case IDirectEdition.DEFAULT_DIRECT_EDITOR: + initializeDirectEditManager(theRequest); + break; + default: + break; + } + } + + /** + * @generated + */ + protected void initializeDirectEditManager(final Request request) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + @Override + public void run() { + if (isActive() && isEditable()) { + if (request.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } + else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void refreshVisuals() { + super.refreshVisuals(); + refreshLabel(); + refreshFont(); + refreshFontColor(); + refreshUnderline(); + refreshStrikeThrough(); + } + + /** + * @generated + */ + protected void refreshLabel() { + EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); + if (maskLabelPolicy == null) { + maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); + } + if (maskLabelPolicy == null) { + View view = (View) getModel(); + if (view.isVisible()) { + setLabelTextHelper(getFigure(), getLabelText()); + setLabelIconHelper(getFigure(), getLabelIcon()); + } + else { + setLabelTextHelper(getFigure(), ""); //$NON-NLS-1$ + setLabelIconHelper(getFigure(), null); + } + } + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + protected void refreshUnderline() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); + } + if (resolveSemanticElement() instanceof Feature) { + if (((Feature) resolveSemanticElement()).isStatic()) { + ((WrappingLabel) getFigure()).setTextUnderline(true); + } + else { + ((WrappingLabel) getFigure()).setTextUnderline(false); + } + } + } + + /** + * @generated + */ + protected void refreshStrikeThrough() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); + } + } + + /** + * @generated + */ + @Override + protected void refreshFont() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null) { + FontData fontData = new FontData( + style.getFontName(), style.getFontHeight(), + (style.isBold() ? SWT.BOLD : SWT.NORMAL) | + (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); + setFont(fontData); + } + } + + /** + * @generated + */ + @Override + protected void setFontColor(Color color) { + getFigure().setForegroundColor(color); + } + + /** + * @generated + */ + @Override + protected void addSemanticListeners() { + if (getParser() instanceof ISemanticParser) { + EObject element = resolveSemanticElement(); + parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); + for (int i = 0; i < parserElements.size(); i++) { + addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ + } + } else { + super.addSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected void removeSemanticListeners() { + if (parserElements != null) { + for (int i = 0; i < parserElements.size(); i++) { + removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ + } + } else { + super.removeSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected AccessibleEditPart getAccessibleEditPart() { + if (accessibleEP == null) { + accessibleEP = new AccessibleGraphicalEditPart() { + + @Override + public void getName(AccessibleEvent e) { + e.result = getLabelTextHelper(getFigure()); + } + }; + } + return accessibleEP; + } + + /** + * @generated + */ + private View getFontStyleOwnerView() { + return getPrimaryView(); + } + + /** + * Returns the kind of associated editor for direct edition. + * + * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition + * @generated + */ + public int getDirectEditionType() { + if (checkExtendedEditor()) { + initExtendedEditorConfiguration(); + return IDirectEdition.EXTENDED_DIRECT_EDITOR; + } + if (checkDefaultEdition()) { + return IDirectEdition.DEFAULT_DIRECT_EDITOR; + } + + // not a named element. no specific editor => do nothing + return IDirectEdition.NO_DIRECT_EDITION; + } + + /** + * Checks if an extended editor is present. + * + * @return true if an extended editor is present. + * @generated + */ + protected boolean checkExtendedEditor() { + if (resolveSemanticElement() != null) { + return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); + } + return false; + } + + /** + * Checks if a default direct edition is available + * + * @return true if a default direct edition is available + * @generated + */ + protected boolean checkDefaultEdition() { + return (getParser() != null); + } + + /** + * Initializes the extended editor configuration + * + * @generated + */ + protected void initExtendedEditorConfiguration() { + if (configuration == null) { + final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("")) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); + } else { + configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); + } + } + } + + /** + * Updates the preference configuration + * + * @generated + */ + protected void updateExtendedEditorConfiguration() { + String languagePreferred = Activator.getDefault().getPreferenceStore().getString( + IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() + .eClass().getInstanceClassName()); + } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { + configuration = null; + } + } + + /** + * Performs the direct edit usually used by GMF editors. + * + * @param theRequest + * the direct edit request that starts the direct edit system + * @generated + */ + protected void performDefaultDirectEditorEdit(final Request theRequest) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + + @Override + public void run() { + if (isActive() && isEditable()) { + if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) theRequest.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { + DirectEditRequest editRequest = (DirectEditRequest) theRequest; + performDirectEdit(editRequest.getLocation()); + } else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + + /** + * @generated + */ + @Override + protected void handleNotificationEvent(Notification event) { + Object feature = event.getFeature(); + if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { + Integer c = (Integer) event.getNewValue(); + setFontColor(DiagramColorRegistry.getInstance().getColor(c)); + } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { + refreshUnderline(); + } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { + refreshStrikeThrough(); + } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { + refreshFont(); + } else { + if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { + refreshLabel(); + } + if (getParser() instanceof ISemanticParser) { + ISemanticParser modelParser = + (ISemanticParser) getParser(); + if (modelParser.areSemanticElementsAffected(null, event)) { + removeSemanticListeners(); + if (resolveSemanticElement() != null) { + addSemanticListeners(); + } + refreshLabel(); + } + } + } + super.handleNotificationEvent(event); + } + + /** + * @generated + */ + @Override + protected IFigure createFigure() { + IFigure label = createFigurePrim(); + defaultText = getLabelTextHelper(label); + return label; + } + + /** + * @generated + */ + protected IFigure createFigurePrim() { + return new PapyrusWrappingLabel(); + } + +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/LiteralIntegerNameEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/LiteralIntegerNameEditPart.java index 4aeb9fb162f..fd9f805a3ce 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/LiteralIntegerNameEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/LiteralIntegerNameEditPart.java @@ -864,7 +864,7 @@ public class LiteralIntegerNameEditPart extends PapyrusCompartmentEditPart imple * @generated */ protected void addOwnerElementListeners() { - addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); + addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/LiteralNullEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/LiteralNullEditPart.java index cc320371fb0..41f9dd82924 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/LiteralNullEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/LiteralNullEditPart.java @@ -11,27 +11,40 @@ */ package org.eclipse.papyrus.uml.diagram.composite.edit.parts; +import java.util.Collections; +import java.util.List; + import org.eclipse.draw2d.IFigure; +import org.eclipse.emf.common.notify.Notification; import org.eclipse.gef.EditPart; import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.GraphicalEditPart; 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.handles.MoveHandle; import org.eclipse.gef.requests.CreateRequest; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.BorderItemSelectionEditPolicy; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles; +import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; -import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure; import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure; +import org.eclipse.gmf.runtime.notation.Edge; +import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.gmf.runtime.notation.View; -import org.eclipse.papyrus.infra.gmfdiag.common.editpart.NodeEditPart; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.GetChildLayoutEditPolicy; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.IPapyrusNodeFigure; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.RoundedRectangleNodePlateFigure; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.SelectableBorderedNodeFigure; +import org.eclipse.papyrus.uml.diagram.common.editparts.RoundedCompartmentEditPart; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeNodeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.QualifiedNameDisplayEditPolicy; -import org.eclipse.papyrus.uml.diagram.common.figure.node.NodeNamedElementFigure; +import org.eclipse.papyrus.uml.diagram.common.figure.node.RoundedCompartmentFigure; +import org.eclipse.papyrus.uml.diagram.common.locator.RoundedRectangleLabelPositionLocator; import org.eclipse.papyrus.uml.diagram.composite.edit.policies.LiteralNullItemSemanticEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; import org.eclipse.swt.graphics.Color; @@ -39,7 +52,7 @@ import org.eclipse.swt.graphics.Color; /** * @generated */ -public class LiteralNullEditPart extends NodeEditPart { +public class LiteralNullEditPart extends RoundedCompartmentEditPart { /** * @generated @@ -73,6 +86,7 @@ public class LiteralNullEditPart extends NodeEditPart { installEditPolicy(EditPolicy.LAYOUT_ROLE, createLayoutEditPolicy()); installEditPolicy(QualifiedNameDisplayEditPolicy.QUALIFIED_NAME_POLICY, new QualifiedNameDisplayEditPolicy()); installEditPolicy(AppliedStereotypeLabelDisplayEditPolicy.STEREOTYPE_LABEL_POLICY, new AppliedStereotypeNodeLabelDisplayEditPolicy()); + installEditPolicy(EditPolicy.LAYOUT_ROLE, new GetChildLayoutEditPolicy()); // XXX need an SCR to runtime to have another abstract superclass that would let children add reasonable editpolicies // removeEditPolicy(org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles.CONNECTION_HANDLES_ROLE); } @@ -85,6 +99,20 @@ public class LiteralNullEditPart extends NodeEditPart { @Override protected EditPolicy createChildEditPolicy(EditPart child) { + View childView = (View) child.getModel(); + switch (UMLVisualIDRegistry.getVisualID(childView)) { + case LiteralNullFloatingLabelEditPart.VISUAL_ID: + return new BorderItemSelectionEditPolicy() { + + @Override + protected List createSelectionHandles() { + MoveHandle mh = new MoveHandle((GraphicalEditPart) getHost()); + mh.setBorder(null); + return Collections.singletonList(mh); + } + } + ; + } EditPolicy result = child.getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); if (result == null) { result = new NonResizableEditPolicy(); @@ -105,12 +133,36 @@ public class LiteralNullEditPart extends NodeEditPart { return lep; } + /** + * Papyrus codeGen + * + * @generated + **/ + @Override + protected void handleNotificationEvent(Notification event) { + /* + * when a node have external node labels, the methods refreshChildren() remove the EditPart corresponding to the Label from the EditPart + * Registry. After that, we can't reset the visibility to true (using the Show/Hide Label Action)! + */ + if (NotationPackage.eINSTANCE.getView_Visible().equals(event.getFeature())) { + Object notifier = event.getNotifier(); + List modelChildren = ((View) getModel()).getChildren(); + if (!(notifier instanceof Edge)) { + if (modelChildren.contains(event.getNotifier())) { + return; + } + } + } + super.handleNotificationEvent(event); + + } + /** * @generated */ @Override protected IFigure createNodeShape() { - return primaryShape = new NodeNamedElementFigure(); + return primaryShape = new RoundedCompartmentFigure(); } /** @@ -119,8 +171,8 @@ public class LiteralNullEditPart extends NodeEditPart { * @generated */ @Override - public NodeNamedElementFigure getPrimaryShape() { - return (NodeNamedElementFigure) primaryShape; + public RoundedCompartmentFigure getPrimaryShape() { + return (RoundedCompartmentFigure) primaryShape; } /** @@ -173,15 +225,32 @@ public class LiteralNullEditPart extends NodeEditPart { */ @Override protected IFigure getContentPaneFor(IGraphicalEditPart editPart) { + if (editPart instanceof IBorderItemEditPart) { + return getBorderedFigure().getBorderItemContainer(); + } return getContentPane(); } + /** + * @generated + */ + @Override + protected void addBorderItem(IFigure borderItemContainer, IBorderItemEditPart borderItemEditPart) { + if (borderItemEditPart instanceof LiteralNullFloatingLabelEditPart) { + IBorderItemLocator locator = new RoundedRectangleLabelPositionLocator(getMainFigure()); + borderItemContainer.add(borderItemEditPart.getFigure(), locator); + } else + { + super.addBorderItem(borderItemContainer, borderItemEditPart); + } + } + /** * @generated */ @Override protected NodeFigure createNodePlate() { - DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(40, 40); + RoundedRectangleNodePlateFigure result = new RoundedRectangleNodePlateFigure(40, 40); return result; } @@ -194,7 +263,7 @@ public class LiteralNullEditPart extends NodeEditPart { * @generated */ @Override - protected NodeFigure createNodeFigure() { + protected NodeFigure createMainFigure() { return new SelectableBorderedNodeFigure(createMainFigureWithSVG()); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/LiteralNullFloatingLabelEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/LiteralNullFloatingLabelEditPart.java new file mode 100644 index 00000000000..bcd84930e60 --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/LiteralNullFloatingLabelEditPart.java @@ -0,0 +1,860 @@ +/** + * 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.uml.diagram.composite.edit.parts; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.Label; +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.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.RunnableWithResult; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gef.AccessibleEditPart; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.Request; +import org.eclipse.gef.requests.DirectEditRequest; +import org.eclipse.gef.tools.DirectEditManager; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; +import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; +import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; +import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; +import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; +import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; +import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; +import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; +import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; +import org.eclipse.gmf.runtime.notation.FontStyle; +import org.eclipse.gmf.runtime.notation.NotationPackage; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.text.contentassist.IContentAssistProcessor; +import org.eclipse.jface.viewers.ICellEditorValidator; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.extensionpoints.editors.Activator; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; +import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; +import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.ExternalLabelPrimaryDragRoleEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.PapyrusWrappingLabel; +import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; +import org.eclipse.papyrus.uml.diagram.common.editparts.FloatingLabelEditPart; +import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; +import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; +import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; +import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.accessibility.AccessibleEvent; +import org.eclipse.swt.custom.BusyIndicator; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; +import org.eclipse.uml2.uml.Feature; + +/** + * @generated + */ +public class LiteralNullFloatingLabelEditPart extends FloatingLabelEditPart + implements ITextAwareEditPart, IBorderItemEditPart +{ + + /** + * @generated + */ + public static final int VISUAL_ID = 6108; + + /** + * @generated + */ + private DirectEditManager manager; + + /** + * @generated + */ + private IParser parser; + + /** + * @generated + */ + private List parserElements; + + /** + * @generated + */ + private String defaultText; + + /** + * direct edition mode (default, undefined, registered editor, etc.) + * + * @generated + */ + protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; + + /** + * configuration from a registered edit dialog + * + * @generated + */ + protected IDirectEditorConfiguration configuration; + + + /** + * @generated + */ + static { + registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.LiteralNullFloatingLabelEditPart.VISUAL_ID), new Point(0, 0)); + } + + /** + * @generated + */ + public LiteralNullFloatingLabelEditPart(View view) { + super(view); + } + + /** + * @generated + */ + @Override + protected void createDefaultEditPolicies() { + super.createDefaultEditPolicies(); + installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); + installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ExternalLabelPrimaryDragRoleEditPolicy()); + } + + /** + * @generated + */ + @Override + public IBorderItemLocator getBorderItemLocator() { + IFigure parentFigure = getFigure().getParent(); + if (parentFigure != null && parentFigure.getLayoutManager() != null) { + Object constraint = parentFigure.getLayoutManager().getConstraint(getFigure()); + return (IBorderItemLocator) constraint; + } + return null; + } + + /** + * @generated + */ + @Override + public void refreshBounds() { + int x = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_X())).intValue(); + int y = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_Y())).intValue(); + int width = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Width())).intValue(); + int height = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Height())).intValue(); + getBorderItemLocator().setConstraint(new Rectangle(x, y, width, height)); + } + + + /** + * @generated + */ + protected String getLabelTextHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getText(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getText(); + } else { + return ((Label) figure).getText(); + } + } + + /** + * @generated + */ + protected void setLabelTextHelper(IFigure figure, String text) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setText(text); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setText(text); + } else { + ((Label) figure).setText(text); + } + } + + /** + * @generated + */ + protected Image getLabelIconHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getIcon(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getIcon(); + } else { + return ((Label) figure).getIcon(); + } + } + + /** + * @generated + */ + protected void setLabelIconHelper(IFigure figure, Image icon) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setIcon(icon); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setIcon(icon); + } else { + ((Label) figure).setIcon(icon); + } + } + + /** + * @generated + */ + public void setLabel(IFigure + figure) { + unregisterVisuals(); + setFigure(figure); + defaultText = getLabelTextHelper(figure); + registerVisuals(); + refreshVisuals(); + } + + /** + * @generated + */ + @Override + protected List getModelChildren() { + return Collections.EMPTY_LIST; + } + + /** + * @generated + */ + @Override + public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { + return null; + } + + /** + * @generated + */ + public void setParser(IParser parser) { + this.parser = parser; + } + + /** + * @generated + */ + protected EObject getParserElement() { + return resolveSemanticElement(); + } + + /** + * @generated + */ + protected Image getLabelIcon() { + return null; + } + + /** + * @generated + */ + protected String getLabelText() { + String text = null; + EObject parserElement = getParserElement(); + if (parserElement != null && getParser() != null) { + text = getParser().getPrintString( + new EObjectAdapter(parserElement), + getParserOptions().intValue()); + } + if (text == null || text.length() == 0) { + text = defaultText; + } + return text; + } + + /** + * @generated + */ + @Override + public void setLabelText(String text) { + setLabelTextHelper(getFigure(), text); + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + @Override + public String getEditText() { + if (getParserElement() == null || getParser() == null) { + return ""; //$NON-NLS-1$ + } + return getParser().getEditString( + new EObjectAdapter(getParserElement()), + getParserOptions().intValue()); + } + + /** + * @generated + */ + protected boolean isEditable() { + return getParser() != null; + } + + /** + * @generated + */ + @Override + public ICellEditorValidator getEditTextValidator() { + return new ICellEditorValidator() { + + @Override + public String isValid(final Object value) { + if (value instanceof String) { + final EObject element = getParserElement(); + final IParser parser = getParser(); + try { + IParserEditStatus valid = + (IParserEditStatus) getEditingDomain().runExclusive( + new RunnableWithResult.Impl() { + + @Override + public void run() { + setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); + } + }); + return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); + } catch (InterruptedException ie) { + ie.printStackTrace(); + } + } + + // shouldn't get here + return null; + } + }; + } + + /** + * @generated + */ + @Override + public IContentAssistProcessor getCompletionProcessor() { + if (getParserElement() == null || getParser() == null) { + return null; + } + return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); + } + + /** + * @generated + */ + @Override + public ParserOptions getParserOptions() { + return ParserOptions.NONE; + } + + /** + * @generated + */ + @Override + public IParser getParser() { + if (parser == null) { + parser = UMLParserProvider.getParser(UMLElementTypes.LiteralNull_2097, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.LiteralNullFloatingLabelEditPart.VISUAL_ID)); + } + return parser; + } + + /** + * @generated + */ + protected DirectEditManager getManager() { + if (manager == null) { + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + } + return manager; + } + + /** + * @generated + */ + protected void setManager(DirectEditManager manager) { + this.manager = manager; + } + + /** + * @generated + */ + protected void performDirectEdit() { + BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { + + @Override + public void run() { + getManager().show(); + } + }); + } + + /** + * @generated + */ + protected void performDirectEdit(Point eventLocation) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); + } + } + + /** + * @generated + */ + private void performDirectEdit(char initialCharacter) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(initialCharacter); + } else { + performDirectEdit(); + } + } + + /** + * @generated + */ + @Override + protected void performDirectEditRequest(Request request) { + + final Request theRequest = request; + + if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { + directEditionMode = getDirectEditionType(); + } + switch (directEditionMode) { + case IDirectEdition.NO_DIRECT_EDITION: + // no direct edition mode => does nothing + return; + case IDirectEdition.EXTENDED_DIRECT_EDITOR: + updateExtendedEditorConfiguration(); + if (configuration == null || configuration.getLanguage() == null) { + // Create default edit manager + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + performDefaultDirectEditorEdit(theRequest); + } else { + configuration.preEditAction(resolveSemanticElement()); + Dialog dialog = null; + if (configuration instanceof ICustomDirectEditorConfiguration) { + setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); + initializeDirectEditManager(theRequest); + return; + } else if (configuration instanceof IPopupEditorConfiguration) { + IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); + helper.showEditor(); + return; + } + else if (configuration instanceof IAdvancedEditorConfiguration) { + dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); + } else if (configuration instanceof IDirectEditorConfiguration) { + dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), + configuration); + } else { + return; + } + final Dialog finalDialog = dialog; + + if (Window.OK == dialog.open()) { + TransactionalEditingDomain domain = getEditingDomain(); + RecordingCommand command = new RecordingCommand(domain, "Edit Label") { + + @Override + protected void doExecute() { + configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); + + } + }; + domain.getCommandStack().execute(command); + } + } + break; + case IDirectEdition.DEFAULT_DIRECT_EDITOR: + initializeDirectEditManager(theRequest); + break; + default: + break; + } + } + + /** + * @generated + */ + protected void initializeDirectEditManager(final Request request) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + @Override + public void run() { + if (isActive() && isEditable()) { + if (request.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } + else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void refreshVisuals() { + super.refreshVisuals(); + refreshLabel(); + refreshFont(); + refreshFontColor(); + refreshUnderline(); + refreshStrikeThrough(); + } + + /** + * @generated + */ + protected void refreshLabel() { + EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); + if (maskLabelPolicy == null) { + maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); + } + if (maskLabelPolicy == null) { + View view = (View) getModel(); + if (view.isVisible()) { + setLabelTextHelper(getFigure(), getLabelText()); + setLabelIconHelper(getFigure(), getLabelIcon()); + } + else { + setLabelTextHelper(getFigure(), ""); //$NON-NLS-1$ + setLabelIconHelper(getFigure(), null); + } + } + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + protected void refreshUnderline() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); + } + if (resolveSemanticElement() instanceof Feature) { + if (((Feature) resolveSemanticElement()).isStatic()) { + ((WrappingLabel) getFigure()).setTextUnderline(true); + } + else { + ((WrappingLabel) getFigure()).setTextUnderline(false); + } + } + } + + /** + * @generated + */ + protected void refreshStrikeThrough() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); + } + } + + /** + * @generated + */ + @Override + protected void refreshFont() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null) { + FontData fontData = new FontData( + style.getFontName(), style.getFontHeight(), + (style.isBold() ? SWT.BOLD : SWT.NORMAL) | + (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); + setFont(fontData); + } + } + + /** + * @generated + */ + @Override + protected void setFontColor(Color color) { + getFigure().setForegroundColor(color); + } + + /** + * @generated + */ + @Override + protected void addSemanticListeners() { + if (getParser() instanceof ISemanticParser) { + EObject element = resolveSemanticElement(); + parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); + for (int i = 0; i < parserElements.size(); i++) { + addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ + } + } else { + super.addSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected void removeSemanticListeners() { + if (parserElements != null) { + for (int i = 0; i < parserElements.size(); i++) { + removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ + } + } else { + super.removeSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected AccessibleEditPart getAccessibleEditPart() { + if (accessibleEP == null) { + accessibleEP = new AccessibleGraphicalEditPart() { + + @Override + public void getName(AccessibleEvent e) { + e.result = getLabelTextHelper(getFigure()); + } + }; + } + return accessibleEP; + } + + /** + * @generated + */ + private View getFontStyleOwnerView() { + return getPrimaryView(); + } + + /** + * Returns the kind of associated editor for direct edition. + * + * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition + * @generated + */ + public int getDirectEditionType() { + if (checkExtendedEditor()) { + initExtendedEditorConfiguration(); + return IDirectEdition.EXTENDED_DIRECT_EDITOR; + } + if (checkDefaultEdition()) { + return IDirectEdition.DEFAULT_DIRECT_EDITOR; + } + + // not a named element. no specific editor => do nothing + return IDirectEdition.NO_DIRECT_EDITION; + } + + /** + * Checks if an extended editor is present. + * + * @return true if an extended editor is present. + * @generated + */ + protected boolean checkExtendedEditor() { + if (resolveSemanticElement() != null) { + return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); + } + return false; + } + + /** + * Checks if a default direct edition is available + * + * @return true if a default direct edition is available + * @generated + */ + protected boolean checkDefaultEdition() { + return (getParser() != null); + } + + /** + * Initializes the extended editor configuration + * + * @generated + */ + protected void initExtendedEditorConfiguration() { + if (configuration == null) { + final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("")) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); + } else { + configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); + } + } + } + + /** + * Updates the preference configuration + * + * @generated + */ + protected void updateExtendedEditorConfiguration() { + String languagePreferred = Activator.getDefault().getPreferenceStore().getString( + IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() + .eClass().getInstanceClassName()); + } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { + configuration = null; + } + } + + /** + * Performs the direct edit usually used by GMF editors. + * + * @param theRequest + * the direct edit request that starts the direct edit system + * @generated + */ + protected void performDefaultDirectEditorEdit(final Request theRequest) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + + @Override + public void run() { + if (isActive() && isEditable()) { + if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) theRequest.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { + DirectEditRequest editRequest = (DirectEditRequest) theRequest; + performDirectEdit(editRequest.getLocation()); + } else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + + /** + * @generated + */ + @Override + protected void handleNotificationEvent(Notification event) { + Object feature = event.getFeature(); + if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { + Integer c = (Integer) event.getNewValue(); + setFontColor(DiagramColorRegistry.getInstance().getColor(c)); + } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { + refreshUnderline(); + } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { + refreshStrikeThrough(); + } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { + refreshFont(); + } else { + if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { + refreshLabel(); + } + if (getParser() instanceof ISemanticParser) { + ISemanticParser modelParser = + (ISemanticParser) getParser(); + if (modelParser.areSemanticElementsAffected(null, event)) { + removeSemanticListeners(); + if (resolveSemanticElement() != null) { + addSemanticListeners(); + } + refreshLabel(); + } + } + } + super.handleNotificationEvent(event); + } + + /** + * @generated + */ + @Override + protected IFigure createFigure() { + IFigure label = createFigurePrim(); + defaultText = getLabelTextHelper(label); + return label; + } + + /** + * @generated + */ + protected IFigure createFigurePrim() { + return new PapyrusWrappingLabel(); + } + +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/LiteralNullNameEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/LiteralNullNameEditPart.java index fc3a1e2fc0f..57955df40f6 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/LiteralNullNameEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/LiteralNullNameEditPart.java @@ -864,7 +864,7 @@ public class LiteralNullNameEditPart extends PapyrusCompartmentEditPart implemen * @generated */ protected void addOwnerElementListeners() { - addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); + addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/LiteralStringEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/LiteralStringEditPart.java index 5113d671b38..fc5d6f5d5a9 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/LiteralStringEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/LiteralStringEditPart.java @@ -11,27 +11,40 @@ */ package org.eclipse.papyrus.uml.diagram.composite.edit.parts; +import java.util.Collections; +import java.util.List; + import org.eclipse.draw2d.IFigure; +import org.eclipse.emf.common.notify.Notification; import org.eclipse.gef.EditPart; import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.GraphicalEditPart; 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.handles.MoveHandle; import org.eclipse.gef.requests.CreateRequest; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.BorderItemSelectionEditPolicy; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles; +import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; -import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure; import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure; +import org.eclipse.gmf.runtime.notation.Edge; +import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.gmf.runtime.notation.View; -import org.eclipse.papyrus.infra.gmfdiag.common.editpart.NodeEditPart; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.GetChildLayoutEditPolicy; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.IPapyrusNodeFigure; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.RoundedRectangleNodePlateFigure; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.SelectableBorderedNodeFigure; +import org.eclipse.papyrus.uml.diagram.common.editparts.RoundedCompartmentEditPart; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeNodeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.QualifiedNameDisplayEditPolicy; -import org.eclipse.papyrus.uml.diagram.common.figure.node.NodeNamedElementFigure; +import org.eclipse.papyrus.uml.diagram.common.figure.node.RoundedCompartmentFigure; +import org.eclipse.papyrus.uml.diagram.common.locator.RoundedRectangleLabelPositionLocator; import org.eclipse.papyrus.uml.diagram.composite.edit.policies.LiteralStringItemSemanticEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; import org.eclipse.swt.graphics.Color; @@ -39,7 +52,7 @@ import org.eclipse.swt.graphics.Color; /** * @generated */ -public class LiteralStringEditPart extends NodeEditPart { +public class LiteralStringEditPart extends RoundedCompartmentEditPart { /** * @generated @@ -73,6 +86,7 @@ public class LiteralStringEditPart extends NodeEditPart { installEditPolicy(EditPolicy.LAYOUT_ROLE, createLayoutEditPolicy()); installEditPolicy(QualifiedNameDisplayEditPolicy.QUALIFIED_NAME_POLICY, new QualifiedNameDisplayEditPolicy()); installEditPolicy(AppliedStereotypeLabelDisplayEditPolicy.STEREOTYPE_LABEL_POLICY, new AppliedStereotypeNodeLabelDisplayEditPolicy()); + installEditPolicy(EditPolicy.LAYOUT_ROLE, new GetChildLayoutEditPolicy()); // XXX need an SCR to runtime to have another abstract superclass that would let children add reasonable editpolicies // removeEditPolicy(org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles.CONNECTION_HANDLES_ROLE); } @@ -85,6 +99,20 @@ public class LiteralStringEditPart extends NodeEditPart { @Override protected EditPolicy createChildEditPolicy(EditPart child) { + View childView = (View) child.getModel(); + switch (UMLVisualIDRegistry.getVisualID(childView)) { + case LiteralStringFloatingLabelEditPart.VISUAL_ID: + return new BorderItemSelectionEditPolicy() { + + @Override + protected List createSelectionHandles() { + MoveHandle mh = new MoveHandle((GraphicalEditPart) getHost()); + mh.setBorder(null); + return Collections.singletonList(mh); + } + } + ; + } EditPolicy result = child.getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); if (result == null) { result = new NonResizableEditPolicy(); @@ -105,12 +133,36 @@ public class LiteralStringEditPart extends NodeEditPart { return lep; } + /** + * Papyrus codeGen + * + * @generated + **/ + @Override + protected void handleNotificationEvent(Notification event) { + /* + * when a node have external node labels, the methods refreshChildren() remove the EditPart corresponding to the Label from the EditPart + * Registry. After that, we can't reset the visibility to true (using the Show/Hide Label Action)! + */ + if (NotationPackage.eINSTANCE.getView_Visible().equals(event.getFeature())) { + Object notifier = event.getNotifier(); + List modelChildren = ((View) getModel()).getChildren(); + if (!(notifier instanceof Edge)) { + if (modelChildren.contains(event.getNotifier())) { + return; + } + } + } + super.handleNotificationEvent(event); + + } + /** * @generated */ @Override protected IFigure createNodeShape() { - return primaryShape = new NodeNamedElementFigure(); + return primaryShape = new RoundedCompartmentFigure(); } /** @@ -119,8 +171,8 @@ public class LiteralStringEditPart extends NodeEditPart { * @generated */ @Override - public NodeNamedElementFigure getPrimaryShape() { - return (NodeNamedElementFigure) primaryShape; + public RoundedCompartmentFigure getPrimaryShape() { + return (RoundedCompartmentFigure) primaryShape; } /** @@ -173,15 +225,32 @@ public class LiteralStringEditPart extends NodeEditPart { */ @Override protected IFigure getContentPaneFor(IGraphicalEditPart editPart) { + if (editPart instanceof IBorderItemEditPart) { + return getBorderedFigure().getBorderItemContainer(); + } return getContentPane(); } + /** + * @generated + */ + @Override + protected void addBorderItem(IFigure borderItemContainer, IBorderItemEditPart borderItemEditPart) { + if (borderItemEditPart instanceof LiteralStringFloatingLabelEditPart) { + IBorderItemLocator locator = new RoundedRectangleLabelPositionLocator(getMainFigure()); + borderItemContainer.add(borderItemEditPart.getFigure(), locator); + } else + { + super.addBorderItem(borderItemContainer, borderItemEditPart); + } + } + /** * @generated */ @Override protected NodeFigure createNodePlate() { - DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(40, 40); + RoundedRectangleNodePlateFigure result = new RoundedRectangleNodePlateFigure(40, 40); return result; } @@ -194,7 +263,7 @@ public class LiteralStringEditPart extends NodeEditPart { * @generated */ @Override - protected NodeFigure createNodeFigure() { + protected NodeFigure createMainFigure() { return new SelectableBorderedNodeFigure(createMainFigureWithSVG()); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/LiteralStringFloatingLabelEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/LiteralStringFloatingLabelEditPart.java new file mode 100644 index 00000000000..32c66f2a180 --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/LiteralStringFloatingLabelEditPart.java @@ -0,0 +1,860 @@ +/** + * 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.uml.diagram.composite.edit.parts; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.Label; +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.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.RunnableWithResult; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gef.AccessibleEditPart; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.Request; +import org.eclipse.gef.requests.DirectEditRequest; +import org.eclipse.gef.tools.DirectEditManager; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; +import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; +import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; +import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; +import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; +import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; +import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; +import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; +import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; +import org.eclipse.gmf.runtime.notation.FontStyle; +import org.eclipse.gmf.runtime.notation.NotationPackage; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.text.contentassist.IContentAssistProcessor; +import org.eclipse.jface.viewers.ICellEditorValidator; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.extensionpoints.editors.Activator; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; +import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; +import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.ExternalLabelPrimaryDragRoleEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.PapyrusWrappingLabel; +import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; +import org.eclipse.papyrus.uml.diagram.common.editparts.FloatingLabelEditPart; +import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; +import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; +import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; +import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.accessibility.AccessibleEvent; +import org.eclipse.swt.custom.BusyIndicator; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; +import org.eclipse.uml2.uml.Feature; + +/** + * @generated + */ +public class LiteralStringFloatingLabelEditPart extends FloatingLabelEditPart + implements ITextAwareEditPart, IBorderItemEditPart +{ + + /** + * @generated + */ + public static final int VISUAL_ID = 6109; + + /** + * @generated + */ + private DirectEditManager manager; + + /** + * @generated + */ + private IParser parser; + + /** + * @generated + */ + private List parserElements; + + /** + * @generated + */ + private String defaultText; + + /** + * direct edition mode (default, undefined, registered editor, etc.) + * + * @generated + */ + protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; + + /** + * configuration from a registered edit dialog + * + * @generated + */ + protected IDirectEditorConfiguration configuration; + + + /** + * @generated + */ + static { + registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.LiteralStringFloatingLabelEditPart.VISUAL_ID), new Point(0, 0)); + } + + /** + * @generated + */ + public LiteralStringFloatingLabelEditPart(View view) { + super(view); + } + + /** + * @generated + */ + @Override + protected void createDefaultEditPolicies() { + super.createDefaultEditPolicies(); + installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); + installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ExternalLabelPrimaryDragRoleEditPolicy()); + } + + /** + * @generated + */ + @Override + public IBorderItemLocator getBorderItemLocator() { + IFigure parentFigure = getFigure().getParent(); + if (parentFigure != null && parentFigure.getLayoutManager() != null) { + Object constraint = parentFigure.getLayoutManager().getConstraint(getFigure()); + return (IBorderItemLocator) constraint; + } + return null; + } + + /** + * @generated + */ + @Override + public void refreshBounds() { + int x = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_X())).intValue(); + int y = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_Y())).intValue(); + int width = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Width())).intValue(); + int height = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Height())).intValue(); + getBorderItemLocator().setConstraint(new Rectangle(x, y, width, height)); + } + + + /** + * @generated + */ + protected String getLabelTextHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getText(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getText(); + } else { + return ((Label) figure).getText(); + } + } + + /** + * @generated + */ + protected void setLabelTextHelper(IFigure figure, String text) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setText(text); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setText(text); + } else { + ((Label) figure).setText(text); + } + } + + /** + * @generated + */ + protected Image getLabelIconHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getIcon(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getIcon(); + } else { + return ((Label) figure).getIcon(); + } + } + + /** + * @generated + */ + protected void setLabelIconHelper(IFigure figure, Image icon) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setIcon(icon); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setIcon(icon); + } else { + ((Label) figure).setIcon(icon); + } + } + + /** + * @generated + */ + public void setLabel(IFigure + figure) { + unregisterVisuals(); + setFigure(figure); + defaultText = getLabelTextHelper(figure); + registerVisuals(); + refreshVisuals(); + } + + /** + * @generated + */ + @Override + protected List getModelChildren() { + return Collections.EMPTY_LIST; + } + + /** + * @generated + */ + @Override + public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { + return null; + } + + /** + * @generated + */ + public void setParser(IParser parser) { + this.parser = parser; + } + + /** + * @generated + */ + protected EObject getParserElement() { + return resolveSemanticElement(); + } + + /** + * @generated + */ + protected Image getLabelIcon() { + return null; + } + + /** + * @generated + */ + protected String getLabelText() { + String text = null; + EObject parserElement = getParserElement(); + if (parserElement != null && getParser() != null) { + text = getParser().getPrintString( + new EObjectAdapter(parserElement), + getParserOptions().intValue()); + } + if (text == null || text.length() == 0) { + text = defaultText; + } + return text; + } + + /** + * @generated + */ + @Override + public void setLabelText(String text) { + setLabelTextHelper(getFigure(), text); + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + @Override + public String getEditText() { + if (getParserElement() == null || getParser() == null) { + return ""; //$NON-NLS-1$ + } + return getParser().getEditString( + new EObjectAdapter(getParserElement()), + getParserOptions().intValue()); + } + + /** + * @generated + */ + protected boolean isEditable() { + return getParser() != null; + } + + /** + * @generated + */ + @Override + public ICellEditorValidator getEditTextValidator() { + return new ICellEditorValidator() { + + @Override + public String isValid(final Object value) { + if (value instanceof String) { + final EObject element = getParserElement(); + final IParser parser = getParser(); + try { + IParserEditStatus valid = + (IParserEditStatus) getEditingDomain().runExclusive( + new RunnableWithResult.Impl() { + + @Override + public void run() { + setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); + } + }); + return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); + } catch (InterruptedException ie) { + ie.printStackTrace(); + } + } + + // shouldn't get here + return null; + } + }; + } + + /** + * @generated + */ + @Override + public IContentAssistProcessor getCompletionProcessor() { + if (getParserElement() == null || getParser() == null) { + return null; + } + return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); + } + + /** + * @generated + */ + @Override + public ParserOptions getParserOptions() { + return ParserOptions.NONE; + } + + /** + * @generated + */ + @Override + public IParser getParser() { + if (parser == null) { + parser = UMLParserProvider.getParser(UMLElementTypes.LiteralString_2098, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.LiteralStringFloatingLabelEditPart.VISUAL_ID)); + } + return parser; + } + + /** + * @generated + */ + protected DirectEditManager getManager() { + if (manager == null) { + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + } + return manager; + } + + /** + * @generated + */ + protected void setManager(DirectEditManager manager) { + this.manager = manager; + } + + /** + * @generated + */ + protected void performDirectEdit() { + BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { + + @Override + public void run() { + getManager().show(); + } + }); + } + + /** + * @generated + */ + protected void performDirectEdit(Point eventLocation) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); + } + } + + /** + * @generated + */ + private void performDirectEdit(char initialCharacter) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(initialCharacter); + } else { + performDirectEdit(); + } + } + + /** + * @generated + */ + @Override + protected void performDirectEditRequest(Request request) { + + final Request theRequest = request; + + if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { + directEditionMode = getDirectEditionType(); + } + switch (directEditionMode) { + case IDirectEdition.NO_DIRECT_EDITION: + // no direct edition mode => does nothing + return; + case IDirectEdition.EXTENDED_DIRECT_EDITOR: + updateExtendedEditorConfiguration(); + if (configuration == null || configuration.getLanguage() == null) { + // Create default edit manager + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + performDefaultDirectEditorEdit(theRequest); + } else { + configuration.preEditAction(resolveSemanticElement()); + Dialog dialog = null; + if (configuration instanceof ICustomDirectEditorConfiguration) { + setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); + initializeDirectEditManager(theRequest); + return; + } else if (configuration instanceof IPopupEditorConfiguration) { + IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); + helper.showEditor(); + return; + } + else if (configuration instanceof IAdvancedEditorConfiguration) { + dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); + } else if (configuration instanceof IDirectEditorConfiguration) { + dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), + configuration); + } else { + return; + } + final Dialog finalDialog = dialog; + + if (Window.OK == dialog.open()) { + TransactionalEditingDomain domain = getEditingDomain(); + RecordingCommand command = new RecordingCommand(domain, "Edit Label") { + + @Override + protected void doExecute() { + configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); + + } + }; + domain.getCommandStack().execute(command); + } + } + break; + case IDirectEdition.DEFAULT_DIRECT_EDITOR: + initializeDirectEditManager(theRequest); + break; + default: + break; + } + } + + /** + * @generated + */ + protected void initializeDirectEditManager(final Request request) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + @Override + public void run() { + if (isActive() && isEditable()) { + if (request.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } + else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void refreshVisuals() { + super.refreshVisuals(); + refreshLabel(); + refreshFont(); + refreshFontColor(); + refreshUnderline(); + refreshStrikeThrough(); + } + + /** + * @generated + */ + protected void refreshLabel() { + EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); + if (maskLabelPolicy == null) { + maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); + } + if (maskLabelPolicy == null) { + View view = (View) getModel(); + if (view.isVisible()) { + setLabelTextHelper(getFigure(), getLabelText()); + setLabelIconHelper(getFigure(), getLabelIcon()); + } + else { + setLabelTextHelper(getFigure(), ""); //$NON-NLS-1$ + setLabelIconHelper(getFigure(), null); + } + } + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + protected void refreshUnderline() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); + } + if (resolveSemanticElement() instanceof Feature) { + if (((Feature) resolveSemanticElement()).isStatic()) { + ((WrappingLabel) getFigure()).setTextUnderline(true); + } + else { + ((WrappingLabel) getFigure()).setTextUnderline(false); + } + } + } + + /** + * @generated + */ + protected void refreshStrikeThrough() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); + } + } + + /** + * @generated + */ + @Override + protected void refreshFont() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null) { + FontData fontData = new FontData( + style.getFontName(), style.getFontHeight(), + (style.isBold() ? SWT.BOLD : SWT.NORMAL) | + (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); + setFont(fontData); + } + } + + /** + * @generated + */ + @Override + protected void setFontColor(Color color) { + getFigure().setForegroundColor(color); + } + + /** + * @generated + */ + @Override + protected void addSemanticListeners() { + if (getParser() instanceof ISemanticParser) { + EObject element = resolveSemanticElement(); + parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); + for (int i = 0; i < parserElements.size(); i++) { + addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ + } + } else { + super.addSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected void removeSemanticListeners() { + if (parserElements != null) { + for (int i = 0; i < parserElements.size(); i++) { + removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ + } + } else { + super.removeSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected AccessibleEditPart getAccessibleEditPart() { + if (accessibleEP == null) { + accessibleEP = new AccessibleGraphicalEditPart() { + + @Override + public void getName(AccessibleEvent e) { + e.result = getLabelTextHelper(getFigure()); + } + }; + } + return accessibleEP; + } + + /** + * @generated + */ + private View getFontStyleOwnerView() { + return getPrimaryView(); + } + + /** + * Returns the kind of associated editor for direct edition. + * + * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition + * @generated + */ + public int getDirectEditionType() { + if (checkExtendedEditor()) { + initExtendedEditorConfiguration(); + return IDirectEdition.EXTENDED_DIRECT_EDITOR; + } + if (checkDefaultEdition()) { + return IDirectEdition.DEFAULT_DIRECT_EDITOR; + } + + // not a named element. no specific editor => do nothing + return IDirectEdition.NO_DIRECT_EDITION; + } + + /** + * Checks if an extended editor is present. + * + * @return true if an extended editor is present. + * @generated + */ + protected boolean checkExtendedEditor() { + if (resolveSemanticElement() != null) { + return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); + } + return false; + } + + /** + * Checks if a default direct edition is available + * + * @return true if a default direct edition is available + * @generated + */ + protected boolean checkDefaultEdition() { + return (getParser() != null); + } + + /** + * Initializes the extended editor configuration + * + * @generated + */ + protected void initExtendedEditorConfiguration() { + if (configuration == null) { + final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("")) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); + } else { + configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); + } + } + } + + /** + * Updates the preference configuration + * + * @generated + */ + protected void updateExtendedEditorConfiguration() { + String languagePreferred = Activator.getDefault().getPreferenceStore().getString( + IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() + .eClass().getInstanceClassName()); + } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { + configuration = null; + } + } + + /** + * Performs the direct edit usually used by GMF editors. + * + * @param theRequest + * the direct edit request that starts the direct edit system + * @generated + */ + protected void performDefaultDirectEditorEdit(final Request theRequest) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + + @Override + public void run() { + if (isActive() && isEditable()) { + if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) theRequest.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { + DirectEditRequest editRequest = (DirectEditRequest) theRequest; + performDirectEdit(editRequest.getLocation()); + } else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + + /** + * @generated + */ + @Override + protected void handleNotificationEvent(Notification event) { + Object feature = event.getFeature(); + if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { + Integer c = (Integer) event.getNewValue(); + setFontColor(DiagramColorRegistry.getInstance().getColor(c)); + } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { + refreshUnderline(); + } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { + refreshStrikeThrough(); + } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { + refreshFont(); + } else { + if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { + refreshLabel(); + } + if (getParser() instanceof ISemanticParser) { + ISemanticParser modelParser = + (ISemanticParser) getParser(); + if (modelParser.areSemanticElementsAffected(null, event)) { + removeSemanticListeners(); + if (resolveSemanticElement() != null) { + addSemanticListeners(); + } + refreshLabel(); + } + } + } + super.handleNotificationEvent(event); + } + + /** + * @generated + */ + @Override + protected IFigure createFigure() { + IFigure label = createFigurePrim(); + defaultText = getLabelTextHelper(label); + return label; + } + + /** + * @generated + */ + protected IFigure createFigurePrim() { + return new PapyrusWrappingLabel(); + } + +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/LiteralStringNameEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/LiteralStringNameEditPart.java index b3310c77d1a..fbf4f4be616 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/LiteralStringNameEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/LiteralStringNameEditPart.java @@ -864,7 +864,7 @@ public class LiteralStringNameEditPart extends PapyrusCompartmentEditPart implem * @generated */ protected void addOwnerElementListeners() { - addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); + addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/LiteralUnlimitedNaturalEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/LiteralUnlimitedNaturalEditPart.java index 32bb82558af..6caf9e1511c 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/LiteralUnlimitedNaturalEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/LiteralUnlimitedNaturalEditPart.java @@ -11,27 +11,40 @@ */ package org.eclipse.papyrus.uml.diagram.composite.edit.parts; +import java.util.Collections; +import java.util.List; + import org.eclipse.draw2d.IFigure; +import org.eclipse.emf.common.notify.Notification; import org.eclipse.gef.EditPart; import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.GraphicalEditPart; 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.handles.MoveHandle; import org.eclipse.gef.requests.CreateRequest; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.BorderItemSelectionEditPolicy; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles; +import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; -import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure; import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure; +import org.eclipse.gmf.runtime.notation.Edge; +import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.gmf.runtime.notation.View; -import org.eclipse.papyrus.infra.gmfdiag.common.editpart.NodeEditPart; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.GetChildLayoutEditPolicy; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.IPapyrusNodeFigure; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.RoundedRectangleNodePlateFigure; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.SelectableBorderedNodeFigure; +import org.eclipse.papyrus.uml.diagram.common.editparts.RoundedCompartmentEditPart; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeNodeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.QualifiedNameDisplayEditPolicy; -import org.eclipse.papyrus.uml.diagram.common.figure.node.NodeNamedElementFigure; +import org.eclipse.papyrus.uml.diagram.common.figure.node.RoundedCompartmentFigure; +import org.eclipse.papyrus.uml.diagram.common.locator.RoundedRectangleLabelPositionLocator; import org.eclipse.papyrus.uml.diagram.composite.edit.policies.LiteralUnlimitedNaturalItemSemanticEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; import org.eclipse.swt.graphics.Color; @@ -39,7 +52,7 @@ import org.eclipse.swt.graphics.Color; /** * @generated */ -public class LiteralUnlimitedNaturalEditPart extends NodeEditPart { +public class LiteralUnlimitedNaturalEditPart extends RoundedCompartmentEditPart { /** * @generated @@ -73,6 +86,7 @@ public class LiteralUnlimitedNaturalEditPart extends NodeEditPart { installEditPolicy(EditPolicy.LAYOUT_ROLE, createLayoutEditPolicy()); installEditPolicy(QualifiedNameDisplayEditPolicy.QUALIFIED_NAME_POLICY, new QualifiedNameDisplayEditPolicy()); installEditPolicy(AppliedStereotypeLabelDisplayEditPolicy.STEREOTYPE_LABEL_POLICY, new AppliedStereotypeNodeLabelDisplayEditPolicy()); + installEditPolicy(EditPolicy.LAYOUT_ROLE, new GetChildLayoutEditPolicy()); // XXX need an SCR to runtime to have another abstract superclass that would let children add reasonable editpolicies // removeEditPolicy(org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles.CONNECTION_HANDLES_ROLE); } @@ -85,6 +99,20 @@ public class LiteralUnlimitedNaturalEditPart extends NodeEditPart { @Override protected EditPolicy createChildEditPolicy(EditPart child) { + View childView = (View) child.getModel(); + switch (UMLVisualIDRegistry.getVisualID(childView)) { + case LiteralUnlimitedNaturalFloatingLabelEditPart.VISUAL_ID: + return new BorderItemSelectionEditPolicy() { + + @Override + protected List createSelectionHandles() { + MoveHandle mh = new MoveHandle((GraphicalEditPart) getHost()); + mh.setBorder(null); + return Collections.singletonList(mh); + } + } + ; + } EditPolicy result = child.getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); if (result == null) { result = new NonResizableEditPolicy(); @@ -105,12 +133,36 @@ public class LiteralUnlimitedNaturalEditPart extends NodeEditPart { return lep; } + /** + * Papyrus codeGen + * + * @generated + **/ + @Override + protected void handleNotificationEvent(Notification event) { + /* + * when a node have external node labels, the methods refreshChildren() remove the EditPart corresponding to the Label from the EditPart + * Registry. After that, we can't reset the visibility to true (using the Show/Hide Label Action)! + */ + if (NotationPackage.eINSTANCE.getView_Visible().equals(event.getFeature())) { + Object notifier = event.getNotifier(); + List modelChildren = ((View) getModel()).getChildren(); + if (!(notifier instanceof Edge)) { + if (modelChildren.contains(event.getNotifier())) { + return; + } + } + } + super.handleNotificationEvent(event); + + } + /** * @generated */ @Override protected IFigure createNodeShape() { - return primaryShape = new NodeNamedElementFigure(); + return primaryShape = new RoundedCompartmentFigure(); } /** @@ -119,8 +171,8 @@ public class LiteralUnlimitedNaturalEditPart extends NodeEditPart { * @generated */ @Override - public NodeNamedElementFigure getPrimaryShape() { - return (NodeNamedElementFigure) primaryShape; + public RoundedCompartmentFigure getPrimaryShape() { + return (RoundedCompartmentFigure) primaryShape; } /** @@ -173,15 +225,32 @@ public class LiteralUnlimitedNaturalEditPart extends NodeEditPart { */ @Override protected IFigure getContentPaneFor(IGraphicalEditPart editPart) { + if (editPart instanceof IBorderItemEditPart) { + return getBorderedFigure().getBorderItemContainer(); + } return getContentPane(); } + /** + * @generated + */ + @Override + protected void addBorderItem(IFigure borderItemContainer, IBorderItemEditPart borderItemEditPart) { + if (borderItemEditPart instanceof LiteralUnlimitedNaturalFloatingLabelEditPart) { + IBorderItemLocator locator = new RoundedRectangleLabelPositionLocator(getMainFigure()); + borderItemContainer.add(borderItemEditPart.getFigure(), locator); + } else + { + super.addBorderItem(borderItemContainer, borderItemEditPart); + } + } + /** * @generated */ @Override protected NodeFigure createNodePlate() { - DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(40, 40); + RoundedRectangleNodePlateFigure result = new RoundedRectangleNodePlateFigure(40, 40); return result; } @@ -194,7 +263,7 @@ public class LiteralUnlimitedNaturalEditPart extends NodeEditPart { * @generated */ @Override - protected NodeFigure createNodeFigure() { + protected NodeFigure createMainFigure() { return new SelectableBorderedNodeFigure(createMainFigureWithSVG()); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/LiteralUnlimitedNaturalFloatingLabelEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/LiteralUnlimitedNaturalFloatingLabelEditPart.java new file mode 100644 index 00000000000..1875fe2414a --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/LiteralUnlimitedNaturalFloatingLabelEditPart.java @@ -0,0 +1,860 @@ +/** + * 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.uml.diagram.composite.edit.parts; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.Label; +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.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.RunnableWithResult; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gef.AccessibleEditPart; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.Request; +import org.eclipse.gef.requests.DirectEditRequest; +import org.eclipse.gef.tools.DirectEditManager; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; +import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; +import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; +import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; +import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; +import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; +import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; +import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; +import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; +import org.eclipse.gmf.runtime.notation.FontStyle; +import org.eclipse.gmf.runtime.notation.NotationPackage; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.text.contentassist.IContentAssistProcessor; +import org.eclipse.jface.viewers.ICellEditorValidator; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.extensionpoints.editors.Activator; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; +import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; +import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.ExternalLabelPrimaryDragRoleEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.PapyrusWrappingLabel; +import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; +import org.eclipse.papyrus.uml.diagram.common.editparts.FloatingLabelEditPart; +import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; +import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; +import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; +import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.accessibility.AccessibleEvent; +import org.eclipse.swt.custom.BusyIndicator; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; +import org.eclipse.uml2.uml.Feature; + +/** + * @generated + */ +public class LiteralUnlimitedNaturalFloatingLabelEditPart extends FloatingLabelEditPart + implements ITextAwareEditPart, IBorderItemEditPart +{ + + /** + * @generated + */ + public static final int VISUAL_ID = 6110; + + /** + * @generated + */ + private DirectEditManager manager; + + /** + * @generated + */ + private IParser parser; + + /** + * @generated + */ + private List parserElements; + + /** + * @generated + */ + private String defaultText; + + /** + * direct edition mode (default, undefined, registered editor, etc.) + * + * @generated + */ + protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; + + /** + * configuration from a registered edit dialog + * + * @generated + */ + protected IDirectEditorConfiguration configuration; + + + /** + * @generated + */ + static { + registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.LiteralUnlimitedNaturalFloatingLabelEditPart.VISUAL_ID), new Point(0, 0)); + } + + /** + * @generated + */ + public LiteralUnlimitedNaturalFloatingLabelEditPart(View view) { + super(view); + } + + /** + * @generated + */ + @Override + protected void createDefaultEditPolicies() { + super.createDefaultEditPolicies(); + installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); + installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ExternalLabelPrimaryDragRoleEditPolicy()); + } + + /** + * @generated + */ + @Override + public IBorderItemLocator getBorderItemLocator() { + IFigure parentFigure = getFigure().getParent(); + if (parentFigure != null && parentFigure.getLayoutManager() != null) { + Object constraint = parentFigure.getLayoutManager().getConstraint(getFigure()); + return (IBorderItemLocator) constraint; + } + return null; + } + + /** + * @generated + */ + @Override + public void refreshBounds() { + int x = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_X())).intValue(); + int y = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_Y())).intValue(); + int width = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Width())).intValue(); + int height = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Height())).intValue(); + getBorderItemLocator().setConstraint(new Rectangle(x, y, width, height)); + } + + + /** + * @generated + */ + protected String getLabelTextHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getText(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getText(); + } else { + return ((Label) figure).getText(); + } + } + + /** + * @generated + */ + protected void setLabelTextHelper(IFigure figure, String text) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setText(text); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setText(text); + } else { + ((Label) figure).setText(text); + } + } + + /** + * @generated + */ + protected Image getLabelIconHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getIcon(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getIcon(); + } else { + return ((Label) figure).getIcon(); + } + } + + /** + * @generated + */ + protected void setLabelIconHelper(IFigure figure, Image icon) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setIcon(icon); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setIcon(icon); + } else { + ((Label) figure).setIcon(icon); + } + } + + /** + * @generated + */ + public void setLabel(IFigure + figure) { + unregisterVisuals(); + setFigure(figure); + defaultText = getLabelTextHelper(figure); + registerVisuals(); + refreshVisuals(); + } + + /** + * @generated + */ + @Override + protected List getModelChildren() { + return Collections.EMPTY_LIST; + } + + /** + * @generated + */ + @Override + public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { + return null; + } + + /** + * @generated + */ + public void setParser(IParser parser) { + this.parser = parser; + } + + /** + * @generated + */ + protected EObject getParserElement() { + return resolveSemanticElement(); + } + + /** + * @generated + */ + protected Image getLabelIcon() { + return null; + } + + /** + * @generated + */ + protected String getLabelText() { + String text = null; + EObject parserElement = getParserElement(); + if (parserElement != null && getParser() != null) { + text = getParser().getPrintString( + new EObjectAdapter(parserElement), + getParserOptions().intValue()); + } + if (text == null || text.length() == 0) { + text = defaultText; + } + return text; + } + + /** + * @generated + */ + @Override + public void setLabelText(String text) { + setLabelTextHelper(getFigure(), text); + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + @Override + public String getEditText() { + if (getParserElement() == null || getParser() == null) { + return ""; //$NON-NLS-1$ + } + return getParser().getEditString( + new EObjectAdapter(getParserElement()), + getParserOptions().intValue()); + } + + /** + * @generated + */ + protected boolean isEditable() { + return getParser() != null; + } + + /** + * @generated + */ + @Override + public ICellEditorValidator getEditTextValidator() { + return new ICellEditorValidator() { + + @Override + public String isValid(final Object value) { + if (value instanceof String) { + final EObject element = getParserElement(); + final IParser parser = getParser(); + try { + IParserEditStatus valid = + (IParserEditStatus) getEditingDomain().runExclusive( + new RunnableWithResult.Impl() { + + @Override + public void run() { + setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); + } + }); + return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); + } catch (InterruptedException ie) { + ie.printStackTrace(); + } + } + + // shouldn't get here + return null; + } + }; + } + + /** + * @generated + */ + @Override + public IContentAssistProcessor getCompletionProcessor() { + if (getParserElement() == null || getParser() == null) { + return null; + } + return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); + } + + /** + * @generated + */ + @Override + public ParserOptions getParserOptions() { + return ParserOptions.NONE; + } + + /** + * @generated + */ + @Override + public IParser getParser() { + if (parser == null) { + parser = UMLParserProvider.getParser(UMLElementTypes.LiteralUnlimitedNatural_2099, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.LiteralUnlimitedNaturalFloatingLabelEditPart.VISUAL_ID)); + } + return parser; + } + + /** + * @generated + */ + protected DirectEditManager getManager() { + if (manager == null) { + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + } + return manager; + } + + /** + * @generated + */ + protected void setManager(DirectEditManager manager) { + this.manager = manager; + } + + /** + * @generated + */ + protected void performDirectEdit() { + BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { + + @Override + public void run() { + getManager().show(); + } + }); + } + + /** + * @generated + */ + protected void performDirectEdit(Point eventLocation) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); + } + } + + /** + * @generated + */ + private void performDirectEdit(char initialCharacter) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(initialCharacter); + } else { + performDirectEdit(); + } + } + + /** + * @generated + */ + @Override + protected void performDirectEditRequest(Request request) { + + final Request theRequest = request; + + if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { + directEditionMode = getDirectEditionType(); + } + switch (directEditionMode) { + case IDirectEdition.NO_DIRECT_EDITION: + // no direct edition mode => does nothing + return; + case IDirectEdition.EXTENDED_DIRECT_EDITOR: + updateExtendedEditorConfiguration(); + if (configuration == null || configuration.getLanguage() == null) { + // Create default edit manager + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + performDefaultDirectEditorEdit(theRequest); + } else { + configuration.preEditAction(resolveSemanticElement()); + Dialog dialog = null; + if (configuration instanceof ICustomDirectEditorConfiguration) { + setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); + initializeDirectEditManager(theRequest); + return; + } else if (configuration instanceof IPopupEditorConfiguration) { + IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); + helper.showEditor(); + return; + } + else if (configuration instanceof IAdvancedEditorConfiguration) { + dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); + } else if (configuration instanceof IDirectEditorConfiguration) { + dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), + configuration); + } else { + return; + } + final Dialog finalDialog = dialog; + + if (Window.OK == dialog.open()) { + TransactionalEditingDomain domain = getEditingDomain(); + RecordingCommand command = new RecordingCommand(domain, "Edit Label") { + + @Override + protected void doExecute() { + configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); + + } + }; + domain.getCommandStack().execute(command); + } + } + break; + case IDirectEdition.DEFAULT_DIRECT_EDITOR: + initializeDirectEditManager(theRequest); + break; + default: + break; + } + } + + /** + * @generated + */ + protected void initializeDirectEditManager(final Request request) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + @Override + public void run() { + if (isActive() && isEditable()) { + if (request.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } + else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void refreshVisuals() { + super.refreshVisuals(); + refreshLabel(); + refreshFont(); + refreshFontColor(); + refreshUnderline(); + refreshStrikeThrough(); + } + + /** + * @generated + */ + protected void refreshLabel() { + EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); + if (maskLabelPolicy == null) { + maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); + } + if (maskLabelPolicy == null) { + View view = (View) getModel(); + if (view.isVisible()) { + setLabelTextHelper(getFigure(), getLabelText()); + setLabelIconHelper(getFigure(), getLabelIcon()); + } + else { + setLabelTextHelper(getFigure(), ""); //$NON-NLS-1$ + setLabelIconHelper(getFigure(), null); + } + } + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + protected void refreshUnderline() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); + } + if (resolveSemanticElement() instanceof Feature) { + if (((Feature) resolveSemanticElement()).isStatic()) { + ((WrappingLabel) getFigure()).setTextUnderline(true); + } + else { + ((WrappingLabel) getFigure()).setTextUnderline(false); + } + } + } + + /** + * @generated + */ + protected void refreshStrikeThrough() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); + } + } + + /** + * @generated + */ + @Override + protected void refreshFont() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null) { + FontData fontData = new FontData( + style.getFontName(), style.getFontHeight(), + (style.isBold() ? SWT.BOLD : SWT.NORMAL) | + (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); + setFont(fontData); + } + } + + /** + * @generated + */ + @Override + protected void setFontColor(Color color) { + getFigure().setForegroundColor(color); + } + + /** + * @generated + */ + @Override + protected void addSemanticListeners() { + if (getParser() instanceof ISemanticParser) { + EObject element = resolveSemanticElement(); + parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); + for (int i = 0; i < parserElements.size(); i++) { + addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ + } + } else { + super.addSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected void removeSemanticListeners() { + if (parserElements != null) { + for (int i = 0; i < parserElements.size(); i++) { + removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ + } + } else { + super.removeSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected AccessibleEditPart getAccessibleEditPart() { + if (accessibleEP == null) { + accessibleEP = new AccessibleGraphicalEditPart() { + + @Override + public void getName(AccessibleEvent e) { + e.result = getLabelTextHelper(getFigure()); + } + }; + } + return accessibleEP; + } + + /** + * @generated + */ + private View getFontStyleOwnerView() { + return getPrimaryView(); + } + + /** + * Returns the kind of associated editor for direct edition. + * + * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition + * @generated + */ + public int getDirectEditionType() { + if (checkExtendedEditor()) { + initExtendedEditorConfiguration(); + return IDirectEdition.EXTENDED_DIRECT_EDITOR; + } + if (checkDefaultEdition()) { + return IDirectEdition.DEFAULT_DIRECT_EDITOR; + } + + // not a named element. no specific editor => do nothing + return IDirectEdition.NO_DIRECT_EDITION; + } + + /** + * Checks if an extended editor is present. + * + * @return true if an extended editor is present. + * @generated + */ + protected boolean checkExtendedEditor() { + if (resolveSemanticElement() != null) { + return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); + } + return false; + } + + /** + * Checks if a default direct edition is available + * + * @return true if a default direct edition is available + * @generated + */ + protected boolean checkDefaultEdition() { + return (getParser() != null); + } + + /** + * Initializes the extended editor configuration + * + * @generated + */ + protected void initExtendedEditorConfiguration() { + if (configuration == null) { + final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("")) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); + } else { + configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); + } + } + } + + /** + * Updates the preference configuration + * + * @generated + */ + protected void updateExtendedEditorConfiguration() { + String languagePreferred = Activator.getDefault().getPreferenceStore().getString( + IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() + .eClass().getInstanceClassName()); + } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { + configuration = null; + } + } + + /** + * Performs the direct edit usually used by GMF editors. + * + * @param theRequest + * the direct edit request that starts the direct edit system + * @generated + */ + protected void performDefaultDirectEditorEdit(final Request theRequest) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + + @Override + public void run() { + if (isActive() && isEditable()) { + if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) theRequest.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { + DirectEditRequest editRequest = (DirectEditRequest) theRequest; + performDirectEdit(editRequest.getLocation()); + } else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + + /** + * @generated + */ + @Override + protected void handleNotificationEvent(Notification event) { + Object feature = event.getFeature(); + if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { + Integer c = (Integer) event.getNewValue(); + setFontColor(DiagramColorRegistry.getInstance().getColor(c)); + } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { + refreshUnderline(); + } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { + refreshStrikeThrough(); + } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { + refreshFont(); + } else { + if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { + refreshLabel(); + } + if (getParser() instanceof ISemanticParser) { + ISemanticParser modelParser = + (ISemanticParser) getParser(); + if (modelParser.areSemanticElementsAffected(null, event)) { + removeSemanticListeners(); + if (resolveSemanticElement() != null) { + addSemanticListeners(); + } + refreshLabel(); + } + } + } + super.handleNotificationEvent(event); + } + + /** + * @generated + */ + @Override + protected IFigure createFigure() { + IFigure label = createFigurePrim(); + defaultText = getLabelTextHelper(label); + return label; + } + + /** + * @generated + */ + protected IFigure createFigurePrim() { + return new PapyrusWrappingLabel(); + } + +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/LiteralUnlimitedNaturalNameEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/LiteralUnlimitedNaturalNameEditPart.java index ae66e5256c6..42ad4885d15 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/LiteralUnlimitedNaturalNameEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/LiteralUnlimitedNaturalNameEditPart.java @@ -864,7 +864,7 @@ public class LiteralUnlimitedNaturalNameEditPart extends PapyrusCompartmentEditP * @generated */ protected void addOwnerElementListeners() { - addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); + addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ManifestationAppliedStereotypeEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ManifestationAppliedStereotypeEditPart.java index 448ad6ea697..331e660a3a4 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ManifestationAppliedStereotypeEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ManifestationAppliedStereotypeEditPart.java @@ -1,820 +1,815 @@ -/** - * 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.uml.diagram.composite.edit.parts; - -import java.util.Collections; -import java.util.List; - -import org.eclipse.draw2d.ConnectionLocator; -import org.eclipse.draw2d.IFigure; -import org.eclipse.draw2d.Label; -import org.eclipse.draw2d.geometry.Point; -import org.eclipse.emf.common.notify.Notification; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.transaction.RecordingCommand; -import org.eclipse.emf.transaction.RunnableWithResult; -import org.eclipse.emf.transaction.TransactionalEditingDomain; -import org.eclipse.gef.AccessibleEditPart; -import org.eclipse.gef.EditPolicy; -import org.eclipse.gef.Request; -import org.eclipse.gef.requests.DirectEditRequest; -import org.eclipse.gef.tools.DirectEditManager; -import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; -import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; -import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; -import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; -import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; -import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; -import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; -import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; -import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; -import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; -import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; -import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; -import org.eclipse.gmf.runtime.notation.FontStyle; -import org.eclipse.gmf.runtime.notation.NotationPackage; -import org.eclipse.gmf.runtime.notation.View; -import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.jface.text.contentassist.IContentAssistProcessor; -import org.eclipse.jface.viewers.ICellEditorValidator; -import org.eclipse.jface.window.Window; -import org.eclipse.papyrus.extensionpoints.editors.Activator; -import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; -import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; -import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; -import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; -import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; -import org.eclipse.papyrus.infra.gmfdiag.common.editpart.IControlParserForDirectEdit; -import org.eclipse.papyrus.infra.gmfdiag.common.editpart.PapyrusLabelEditPart; -import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; -import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; -import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.PapyrusLinkLabelDragPolicy; -import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; -import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; -import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; -import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; -import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; -import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; -import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; -import org.eclipse.swt.SWT; -import org.eclipse.swt.accessibility.AccessibleEvent; -import org.eclipse.swt.custom.BusyIndicator; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.FontData; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.widgets.Display; -import org.eclipse.ui.PlatformUI; -import org.eclipse.uml2.uml.Feature; - -/** - * @generated - */ -public class ManifestationAppliedStereotypeEditPart extends PapyrusLabelEditPart implements ITextAwareEditPart, IControlParserForDirectEdit { - - /** - * @generated - */ - public static final int VISUAL_ID = 6019; - - /** - * @generated - */ - private DirectEditManager manager; - - /** - * @generated - */ - private IParser parser; - - /** - * @generated - */ - private List parserElements; - - /** - * @generated - */ - private String defaultText; - - /** - * direct edition mode (default, undefined, registered editor, etc.) - * - * @generated - */ - protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; - - /** - * configuration from a registered edit dialog - * - * @generated - */ - protected IDirectEditorConfiguration configuration; - /** - * @generated - */ - static { - registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.ManifestationAppliedStereotypeEditPart.VISUAL_ID), new Point(0, 30)); - } - - /** - * @generated - */ - public ManifestationAppliedStereotypeEditPart(View view) { - super(view); - } - - /** - * @generated - */ - @Override - protected void createDefaultEditPolicies() { - super.createDefaultEditPolicies(); - installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); - installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); - installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new PapyrusLinkLabelDragPolicy()); - } - - /** - * @generated - */ - @Override - public int getKeyPoint() { - return ConnectionLocator.MIDDLE; - } - - /** - * @generated - */ - protected String getLabelTextHelper(IFigure figure) { - if (figure instanceof WrappingLabel) { - return ((WrappingLabel) figure).getText(); - } else if (figure instanceof ILabelFigure) { - return ((ILabelFigure) figure).getText(); - } else { - return ((Label) figure).getText(); - } - } - - /** - * @generated - */ - protected void setLabelTextHelper(IFigure figure, String text) { - if (figure instanceof WrappingLabel) { - ((WrappingLabel) figure).setText(text); - } else if (figure instanceof ILabelFigure) { - ((ILabelFigure) figure).setText(text); - } else { - ((Label) figure).setText(text); - } - } - - /** - * @generated - */ - protected Image getLabelIconHelper(IFigure figure) { - if (figure instanceof WrappingLabel) { - return ((WrappingLabel) figure).getIcon(); - } else if (figure instanceof ILabelFigure) { - return ((ILabelFigure) figure).getIcon(); - } else { - return ((Label) figure).getIcon(); - } - } - - /** - * @generated - */ - protected void setLabelIconHelper(IFigure figure, Image icon) { - if (figure instanceof WrappingLabel) { - ((WrappingLabel) figure).setIcon(icon); - } else if (figure instanceof ILabelFigure) { - ((ILabelFigure) figure).setIcon(icon); - } else { - ((Label) figure).setIcon(icon); - } - } - - /** - * @generated - */ - public void setLabel(IFigure - figure) { - unregisterVisuals(); - setFigure(figure); - defaultText = getLabelTextHelper(figure); - registerVisuals(); - refreshVisuals(); - } - - /** - * @generated - */ - @Override - protected List getModelChildren() { - return Collections.EMPTY_LIST; - } - - /** - * @generated - */ - @Override - public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { - return null; - } - - /** - * @generated - */ - @Override - public void setParser(IParser parser) { - this.parser = parser; - } - - /** - * @generated - */ - protected EObject getParserElement() { - return resolveSemanticElement(); - } - - /** - * @generated - */ - protected Image getLabelIcon() { - return null; - } - - /** - * @generated - */ - protected String getLabelText() { - String text = null; - EObject parserElement = getParserElement(); - if (parserElement != null && getParser() != null) { - text = getParser().getPrintString( - new EObjectAdapter(parserElement), - getParserOptions().intValue()); - } - if (text == null || text.length() == 0) { - text = defaultText; - } - return text; - } - - /** - * @generated - */ - @Override - public void setLabelText(String text) { - setLabelTextHelper(getFigure(), text); - Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); - if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); - } - Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); - if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); - } - } - - /** - * @generated - */ - @Override - public String getEditText() { - if (getParserElement() == null || getParser() == null) { - return ""; //$NON-NLS-1$ - } - return getParser().getEditString( - new EObjectAdapter(getParserElement()), - getParserOptions().intValue()); - } - - /** - * @generated - */ - protected boolean isEditable() { - return false; - } - - /** - * @generated - */ - @Override - public ICellEditorValidator getEditTextValidator() { - return new ICellEditorValidator() { - - @Override - public String isValid(final Object value) { - if (value instanceof String) { - final EObject element = getParserElement(); - final IParser parser = getParser(); - try { - IParserEditStatus valid = - (IParserEditStatus) getEditingDomain().runExclusive( - new RunnableWithResult.Impl() { - - @Override - public void run() { - setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); - } - }); - return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); - } catch (InterruptedException ie) { - ie.printStackTrace(); - } - } - - // shouldn't get here - return null; - } - }; - } - - /** - * @generated - */ - @Override - public IContentAssistProcessor getCompletionProcessor() { - if (getParserElement() == null || getParser() == null) { - return null; - } - return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); - } - - /** - * @generated - */ - @Override - public ParserOptions getParserOptions() { - return ParserOptions.NONE; - } - - /** - * @generated - */ - @Override - public IParser getParser() { - if (parser == null) { - parser = UMLParserProvider.getParser(UMLElementTypes.Manifestation_4012, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.ManifestationAppliedStereotypeEditPart.VISUAL_ID)); - } - return parser; - } - - /** - * @generated - */ - protected DirectEditManager getManager() { - if (manager == null) { - setManager(new MultilineLabelDirectEditManager(this, - MultilineLabelDirectEditManager.getTextCellEditorClass(this), - UMLEditPartFactory.getTextCellEditorLocator(this))); - } - return manager; - } - - /** - * @generated - */ - protected void setManager(DirectEditManager manager) { - this.manager = manager; - } - - /** - * @generated - */ - protected void performDirectEdit() { - BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { - - @Override - public void run() { - getManager().show(); - } - }); - } - - /** - * @generated - */ - protected void performDirectEdit(Point eventLocation) { - if (getManager() instanceof TextDirectEditManager) { - ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); - } - } - - /** - * @generated - */ - private void performDirectEdit(char initialCharacter) { - if (getManager() instanceof TextDirectEditManager) { - ((TextDirectEditManager) getManager()).show(initialCharacter); - } else { - performDirectEdit(); - } - } - - /** - * @generated - */ - @Override - protected void performDirectEditRequest(Request request) { - - final Request theRequest = request; - - if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { - directEditionMode = getDirectEditionType(); - } - switch (directEditionMode) { - case IDirectEdition.NO_DIRECT_EDITION: - // no direct edition mode => does nothing - return; - case IDirectEdition.EXTENDED_DIRECT_EDITOR: - updateExtendedEditorConfiguration(); - if (configuration == null || configuration.getLanguage() == null) { - // Create default edit manager - setManager(new MultilineLabelDirectEditManager(this, - MultilineLabelDirectEditManager.getTextCellEditorClass(this), - UMLEditPartFactory.getTextCellEditorLocator(this))); - performDefaultDirectEditorEdit(theRequest); - } else { - configuration.preEditAction(resolveSemanticElement()); - Dialog dialog = null; - if (configuration instanceof ICustomDirectEditorConfiguration) { - setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); - initializeDirectEditManager(theRequest); - return; - } else if (configuration instanceof IPopupEditorConfiguration) { - IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); - helper.showEditor(); - return; - } - else if (configuration instanceof IAdvancedEditorConfiguration) { - dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); - } else if (configuration instanceof IDirectEditorConfiguration) { - dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), - configuration); - } else { - return; - } - final Dialog finalDialog = dialog; - - if (Window.OK == dialog.open()) { - TransactionalEditingDomain domain = getEditingDomain(); - RecordingCommand command = new RecordingCommand(domain, "Edit Label") { - - @Override - protected void doExecute() { - configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); - - } - }; - domain.getCommandStack().execute(command); - } - } - break; - case IDirectEdition.DEFAULT_DIRECT_EDITOR: - initializeDirectEditManager(theRequest); - break; - default: - break; - } - } - - /** - * @generated - */ - protected void initializeDirectEditManager(final Request request) { - // initialize the direct edit manager - try { - getEditingDomain().runExclusive(new Runnable() { - @Override - public void run() { - if (isActive() && isEditable()) { - if (request.getExtendedData().get( - RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { - Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); - performDirectEdit(initialChar.charValue()); - } - else { - performDirectEdit(); - } - } - } - }); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - - /** - * @generated - */ - @Override - protected void refreshVisuals() { - super.refreshVisuals(); - refreshLabel(); - refreshFont(); - refreshFontColor(); - refreshUnderline(); - refreshStrikeThrough(); - } - - /** - * @generated - */ - protected void refreshLabel() { - EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); - if (maskLabelPolicy == null) { - maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); - } - if (maskLabelPolicy == null) { - View view = (View) getModel(); - if (view.isVisible()) { - setLabelTextHelper(getFigure(), getLabelText()); - setLabelIconHelper(getFigure(), getLabelIcon()); - } - else { - setLabelTextHelper(getFigure(), ""); //$NON-NLS-1$ - setLabelIconHelper(getFigure(), null); - } - } - Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); - if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); - } - Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); - if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); - } - } - - /** - * @generated - */ - protected void refreshUnderline() { - FontStyle style = - (FontStyle) getFontStyleOwnerView().getStyle( - NotationPackage.eINSTANCE.getFontStyle()); - if (style != null && getFigure() instanceof WrappingLabel) { - ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); - } - if (resolveSemanticElement() instanceof Feature) { - if (((Feature) resolveSemanticElement()).isStatic()) { - ((WrappingLabel) getFigure()).setTextUnderline(true); - } - else { - ((WrappingLabel) getFigure()).setTextUnderline(false); - } - } - } - - /** - * @generated - */ - protected void refreshStrikeThrough() { - FontStyle style = - (FontStyle) getFontStyleOwnerView().getStyle( - NotationPackage.eINSTANCE.getFontStyle()); - if (style != null && getFigure() instanceof WrappingLabel) { - ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); - } - } - - /** - * @generated - */ - @Override - protected void refreshFont() { - FontStyle style = - (FontStyle) getFontStyleOwnerView().getStyle( - NotationPackage.eINSTANCE.getFontStyle()); - if (style != null) { - FontData fontData = new FontData( - style.getFontName(), style.getFontHeight(), - (style.isBold() ? SWT.BOLD : SWT.NORMAL) | - (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); - setFont(fontData); - } - } - - /** - * @generated - */ - @Override - protected void setFontColor(Color color) { - getFigure().setForegroundColor(color); - } - - /** - * @generated - */ - @Override - protected void addSemanticListeners() { - if (getParser() instanceof ISemanticParser) { - EObject element = resolveSemanticElement(); - parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); - for (int i = 0; i < parserElements.size(); i++) { - addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ - } - } else { - super.addSemanticListeners(); - } - } - - /** - * @generated - */ - @Override - protected void removeSemanticListeners() { - if (parserElements != null) { - for (int i = 0; i < parserElements.size(); i++) { - removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ - } - } else { - super.removeSemanticListeners(); - } - } - - /** - * @generated - */ - @Override - protected AccessibleEditPart getAccessibleEditPart() { - if (accessibleEP == null) { - accessibleEP = new AccessibleGraphicalEditPart() { - - @Override - public void getName(AccessibleEvent e) { - e.result = getLabelTextHelper(getFigure()); - } - }; - } - return accessibleEP; - } - - /** - * @generated - */ - private View getFontStyleOwnerView() { - return getPrimaryView(); - } - - /** - * Returns the kind of associated editor for direct edition. - * - * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition - * @generated - */ - public int getDirectEditionType() { - // The label is read-only (defined in GMFGen model) - return IDirectEdition.NO_DIRECT_EDITION; - } - - /** - * Checks if an extended editor is present. - * - * @return true if an extended editor is present. - * @generated - */ - protected boolean checkExtendedEditor() { - if (resolveSemanticElement() != null) { - return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); - } - return false; - } - - /** - * Checks if a default direct edition is available - * - * @return true if a default direct edition is available - * @generated - */ - protected boolean checkDefaultEdition() { - return (getParser() != null); - } - - /** - * Initializes the extended editor configuration - * - * @generated - */ - protected void initExtendedEditorConfiguration() { - if (configuration == null) { - final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); - if (languagePreferred != null && !languagePreferred.equals("")) { - configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); - } else { - configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); - } - } - } - - /** - * Updates the preference configuration - * - * @generated - */ - protected void updateExtendedEditorConfiguration() { - String languagePreferred = Activator.getDefault().getPreferenceStore().getString( - IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); - if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { - configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() - .eClass().getInstanceClassName()); - } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { - configuration = null; - } - } - - /** - * Performs the direct edit usually used by GMF editors. - * - * @param theRequest - * the direct edit request that starts the direct edit system - * @generated - */ - protected void performDefaultDirectEditorEdit(final Request theRequest) { - // initialize the direct edit manager - try { - getEditingDomain().runExclusive(new Runnable() { - - @Override - public void run() { - if (isActive() && isEditable()) { - if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { - Character initialChar = (Character) theRequest.getExtendedData().get( - RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); - performDirectEdit(initialChar.charValue()); - } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { - DirectEditRequest editRequest = (DirectEditRequest) theRequest; - performDirectEdit(editRequest.getLocation()); - } else { - performDirectEdit(); - } - } - } - }); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - - /** - * @generated - */ - @Override - protected void handleNotificationEvent(Notification event) { - Object feature = event.getFeature(); - if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { - Integer c = (Integer) event.getNewValue(); - setFontColor(DiagramColorRegistry.getInstance().getColor(c)); - } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { - refreshUnderline(); - } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { - refreshStrikeThrough(); - } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || - NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || - NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || - NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { - refreshFont(); - } else { - if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { - refreshLabel(); - } - if (getParser() instanceof ISemanticParser) { - ISemanticParser modelParser = - (ISemanticParser) getParser(); - if (modelParser.areSemanticElementsAffected(null, event)) { - removeSemanticListeners(); - if (resolveSemanticElement() != null) { - addSemanticListeners(); - } - refreshLabel(); - } - } - } - - super.handleNotificationEvent(event); - } - - /** - * @generated - */ - @Override - protected IFigure createFigure() { - // Parent should assign one using setLabel() method - return 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.uml.diagram.composite.edit.parts; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.draw2d.ConnectionLocator; +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.Label; +import org.eclipse.draw2d.geometry.Point; +import org.eclipse.emf.common.notify.Notification; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.RunnableWithResult; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gef.AccessibleEditPart; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.Request; +import org.eclipse.gef.requests.DirectEditRequest; +import org.eclipse.gef.tools.DirectEditManager; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; +import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; +import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; +import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; +import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; +import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; +import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; +import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; +import org.eclipse.gmf.runtime.notation.FontStyle; +import org.eclipse.gmf.runtime.notation.NotationPackage; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.gmf.tooling.runtime.edit.policies.DefaultLinkLabelDragPolicy; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.text.contentassist.IContentAssistProcessor; +import org.eclipse.jface.viewers.ICellEditorValidator; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.extensionpoints.editors.Activator; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; +import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; +import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; +import org.eclipse.papyrus.infra.gmfdiag.common.editpart.IControlParserForDirectEdit; +import org.eclipse.papyrus.infra.gmfdiag.common.editpart.PapyrusLabelEditPart; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.PapyrusLinkLabelDragPolicy; +import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; +import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; +import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; +import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; +import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.accessibility.AccessibleEvent; +import org.eclipse.swt.custom.BusyIndicator; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; +import org.eclipse.uml2.uml.Feature; + +/** + * @generated + */ +public class ManifestationAppliedStereotypeEditPart extends PapyrusLabelEditPart implements ITextAwareEditPart, IControlParserForDirectEdit { + + /** + * @generated + */ + public static final int VISUAL_ID = 6019; + + /** + * @generated + */ + private DirectEditManager manager; + + /** + * @generated + */ + private IParser parser; + + /** + * @generated + */ + private List parserElements; + + /** + * @generated + */ + private String defaultText; + + /** + * direct edition mode (default, undefined, registered editor, etc.) + * + * @generated + */ + protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; + + /** + * configuration from a registered edit dialog + * + * @generated + */ + protected IDirectEditorConfiguration configuration; + /** + * @generated + */ + static { + registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.ManifestationAppliedStereotypeEditPart.VISUAL_ID), new Point(0, 30)); + } + + /** + * @generated + */ + public ManifestationAppliedStereotypeEditPart(View view) { + super(view); + } + + /** + * @generated + */ + @Override + protected void createDefaultEditPolicies() { + super.createDefaultEditPolicies(); + installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); + installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new DefaultLinkLabelDragPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new PapyrusLinkLabelDragPolicy()); + } + + /** + * @generated + */ + @Override + public int getKeyPoint() { + return ConnectionLocator.MIDDLE; + } + + /** + * @generated + */ + protected String getLabelTextHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getText(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getText(); + } else { + return ((Label) figure).getText(); + } + } + + /** + * @generated + */ + protected void setLabelTextHelper(IFigure figure, String text) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setText(text); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setText(text); + } else { + ((Label) figure).setText(text); + } + } + + /** + * @generated + */ + protected Image getLabelIconHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getIcon(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getIcon(); + } else { + return ((Label) figure).getIcon(); + } + } + + /** + * @generated + */ + protected void setLabelIconHelper(IFigure figure, Image icon) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setIcon(icon); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setIcon(icon); + } else { + ((Label) figure).setIcon(icon); + } + } + + /** + * @generated + */ + public void setLabel(IFigure + figure) { + unregisterVisuals(); + setFigure(figure); + defaultText = getLabelTextHelper(figure); + registerVisuals(); + refreshVisuals(); + } + + /** + * @generated + */ + @Override + protected List getModelChildren() { + return Collections.EMPTY_LIST; + } + + /** + * @generated + */ + @Override + public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { + return null; + } + + /** + * @generated + */ + @Override + public void setParser(IParser parser) { + this.parser = parser; + } + + /** + * @generated + */ + protected EObject getParserElement() { + return resolveSemanticElement(); + } + + /** + * @generated + */ + protected Image getLabelIcon() { + return null; + } + + /** + * @generated + */ + protected String getLabelText() { + String text = null; + EObject parserElement = getParserElement(); + if (parserElement != null && getParser() != null) { + text = getParser().getPrintString( + new EObjectAdapter(parserElement), + getParserOptions().intValue()); + } + if (text == null || text.length() == 0) { + text = defaultText; + } + return text; + } + + /** + * @generated + */ + @Override + public void setLabelText(String text) { + setLabelTextHelper(getFigure(), text); + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + @Override + public String getEditText() { + if (getParserElement() == null || getParser() == null) { + return ""; //$NON-NLS-1$ + } + return getParser().getEditString( + new EObjectAdapter(getParserElement()), + getParserOptions().intValue()); + } + + /** + * @generated + */ + protected boolean isEditable() { + return false; + } + + /** + * @generated + */ + @Override + public ICellEditorValidator getEditTextValidator() { + return new ICellEditorValidator() { + + @Override + public String isValid(final Object value) { + if (value instanceof String) { + final EObject element = getParserElement(); + final IParser parser = getParser(); + try { + IParserEditStatus valid = + (IParserEditStatus) getEditingDomain().runExclusive( + new RunnableWithResult.Impl() { + + @Override + public void run() { + setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); + } + }); + return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); + } catch (InterruptedException ie) { + ie.printStackTrace(); + } + } + + // shouldn't get here + return null; + } + }; + } + + /** + * @generated + */ + @Override + public IContentAssistProcessor getCompletionProcessor() { + if (getParserElement() == null || getParser() == null) { + return null; + } + return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); + } + + /** + * @generated + */ + @Override + public ParserOptions getParserOptions() { + return ParserOptions.NONE; + } + + /** + * @generated + */ + @Override + public IParser getParser() { + if (parser == null) { + parser = UMLParserProvider.getParser(UMLElementTypes.Manifestation_4012, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.ManifestationAppliedStereotypeEditPart.VISUAL_ID)); + } + return parser; + } + + /** + * @generated + */ + protected DirectEditManager getManager() { + if (manager == null) { + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + } + return manager; + } + + /** + * @generated + */ + protected void setManager(DirectEditManager manager) { + this.manager = manager; + } + + /** + * @generated + */ + protected void performDirectEdit() { + BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { + + @Override + public void run() { + getManager().show(); + } + }); + } + + /** + * @generated + */ + protected void performDirectEdit(Point eventLocation) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); + } + } + + /** + * @generated + */ + private void performDirectEdit(char initialCharacter) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(initialCharacter); + } else { + performDirectEdit(); + } + } + + /** + * @generated + */ + @Override + protected void performDirectEditRequest(Request request) { + + final Request theRequest = request; + + if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { + directEditionMode = getDirectEditionType(); + } + switch (directEditionMode) { + case IDirectEdition.NO_DIRECT_EDITION: + // no direct edition mode => does nothing + return; + case IDirectEdition.EXTENDED_DIRECT_EDITOR: + updateExtendedEditorConfiguration(); + if (configuration == null || configuration.getLanguage() == null) { + // Create default edit manager + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + performDefaultDirectEditorEdit(theRequest); + } else { + configuration.preEditAction(resolveSemanticElement()); + Dialog dialog = null; + if (configuration instanceof ICustomDirectEditorConfiguration) { + setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); + initializeDirectEditManager(theRequest); + return; + } else if (configuration instanceof IPopupEditorConfiguration) { + IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); + helper.showEditor(); + return; + } + else if (configuration instanceof IAdvancedEditorConfiguration) { + dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); + } else if (configuration instanceof IDirectEditorConfiguration) { + dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), + configuration); + } else { + return; + } + final Dialog finalDialog = dialog; + + if (Window.OK == dialog.open()) { + TransactionalEditingDomain domain = getEditingDomain(); + RecordingCommand command = new RecordingCommand(domain, "Edit Label") { + + @Override + protected void doExecute() { + configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); + + } + }; + domain.getCommandStack().execute(command); + } + } + break; + case IDirectEdition.DEFAULT_DIRECT_EDITOR: + initializeDirectEditManager(theRequest); + break; + default: + break; + } + } + + /** + * @generated + */ + protected void initializeDirectEditManager(final Request request) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + @Override + public void run() { + if (isActive() && isEditable()) { + if (request.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } + else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void refreshVisuals() { + super.refreshVisuals(); + refreshLabel(); + refreshFont(); + refreshFontColor(); + refreshUnderline(); + refreshStrikeThrough(); + } + + /** + * @generated + */ + protected void refreshLabel() { + EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); + if (maskLabelPolicy == null) { + maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); + } + if (maskLabelPolicy == null) { + setLabelTextHelper(getFigure(), getLabelText()); + setLabelIconHelper(getFigure(), getLabelIcon()); + } + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + protected void refreshUnderline() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); + } + if (resolveSemanticElement() instanceof Feature) { + if (((Feature) resolveSemanticElement()).isStatic()) { + ((WrappingLabel) getFigure()).setTextUnderline(true); + } + else { + ((WrappingLabel) getFigure()).setTextUnderline(false); + } + } + } + + /** + * @generated + */ + protected void refreshStrikeThrough() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); + } + } + + /** + * @generated + */ + @Override + protected void refreshFont() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null) { + FontData fontData = new FontData( + style.getFontName(), style.getFontHeight(), + (style.isBold() ? SWT.BOLD : SWT.NORMAL) | + (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); + setFont(fontData); + } + } + + /** + * @generated + */ + @Override + protected void setFontColor(Color color) { + getFigure().setForegroundColor(color); + } + + /** + * @generated + */ + @Override + protected void addSemanticListeners() { + if (getParser() instanceof ISemanticParser) { + EObject element = resolveSemanticElement(); + parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); + for (int i = 0; i < parserElements.size(); i++) { + addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ + } + } else { + super.addSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected void removeSemanticListeners() { + if (parserElements != null) { + for (int i = 0; i < parserElements.size(); i++) { + removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ + } + } else { + super.removeSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected AccessibleEditPart getAccessibleEditPart() { + if (accessibleEP == null) { + accessibleEP = new AccessibleGraphicalEditPart() { + + @Override + public void getName(AccessibleEvent e) { + e.result = getLabelTextHelper(getFigure()); + } + }; + } + return accessibleEP; + } + + /** + * @generated + */ + private View getFontStyleOwnerView() { + return getPrimaryView(); + } + + /** + * Returns the kind of associated editor for direct edition. + * + * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition + * @generated + */ + public int getDirectEditionType() { + // The label is read-only (defined in GMFGen model) + return IDirectEdition.NO_DIRECT_EDITION; + } + + /** + * Checks if an extended editor is present. + * + * @return true if an extended editor is present. + * @generated + */ + protected boolean checkExtendedEditor() { + if (resolveSemanticElement() != null) { + return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); + } + return false; + } + + /** + * Checks if a default direct edition is available + * + * @return true if a default direct edition is available + * @generated + */ + protected boolean checkDefaultEdition() { + return (getParser() != null); + } + + /** + * Initializes the extended editor configuration + * + * @generated + */ + protected void initExtendedEditorConfiguration() { + if (configuration == null) { + final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("")) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); + } else { + configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); + } + } + } + + /** + * Updates the preference configuration + * + * @generated + */ + protected void updateExtendedEditorConfiguration() { + String languagePreferred = Activator.getDefault().getPreferenceStore().getString( + IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() + .eClass().getInstanceClassName()); + } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { + configuration = null; + } + } + + /** + * Performs the direct edit usually used by GMF editors. + * + * @param theRequest + * the direct edit request that starts the direct edit system + * @generated + */ + protected void performDefaultDirectEditorEdit(final Request theRequest) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + + @Override + public void run() { + if (isActive() && isEditable()) { + if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) theRequest.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { + DirectEditRequest editRequest = (DirectEditRequest) theRequest; + performDirectEdit(editRequest.getLocation()); + } else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void handleNotificationEvent(Notification event) { + Object feature = event.getFeature(); + if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { + Integer c = (Integer) event.getNewValue(); + setFontColor(DiagramColorRegistry.getInstance().getColor(c)); + } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { + refreshUnderline(); + } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { + refreshStrikeThrough(); + } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { + refreshFont(); + } else { + if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { + refreshLabel(); + } + if (getParser() instanceof ISemanticParser) { + ISemanticParser modelParser = + (ISemanticParser) getParser(); + if (modelParser.areSemanticElementsAffected(null, event)) { + removeSemanticListeners(); + if (resolveSemanticElement() != null) { + addSemanticListeners(); + } + refreshLabel(); + } + } + } + + super.handleNotificationEvent(event); + } + + /** + * @generated + */ + @Override + protected IFigure createFigure() { + // Parent should assign one using setLabel() method + return null; + } +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ManifestationNameEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ManifestationNameEditPart.java index a63cf45f9dd..a084683eb13 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ManifestationNameEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ManifestationNameEditPart.java @@ -1,828 +1,823 @@ -/** - * 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.uml.diagram.composite.edit.parts; - -import java.util.Collections; -import java.util.List; - -import org.eclipse.draw2d.ConnectionLocator; -import org.eclipse.draw2d.IFigure; -import org.eclipse.draw2d.Label; -import org.eclipse.draw2d.geometry.Point; -import org.eclipse.emf.common.notify.Notification; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.transaction.RecordingCommand; -import org.eclipse.emf.transaction.RunnableWithResult; -import org.eclipse.emf.transaction.TransactionalEditingDomain; -import org.eclipse.gef.AccessibleEditPart; -import org.eclipse.gef.EditPolicy; -import org.eclipse.gef.Request; -import org.eclipse.gef.requests.DirectEditRequest; -import org.eclipse.gef.tools.DirectEditManager; -import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; -import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; -import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; -import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; -import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; -import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; -import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; -import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; -import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; -import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; -import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; -import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; -import org.eclipse.gmf.runtime.notation.FontStyle; -import org.eclipse.gmf.runtime.notation.NotationPackage; -import org.eclipse.gmf.runtime.notation.View; -import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.jface.text.contentassist.IContentAssistProcessor; -import org.eclipse.jface.viewers.ICellEditorValidator; -import org.eclipse.jface.window.Window; -import org.eclipse.papyrus.extensionpoints.editors.Activator; -import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; -import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; -import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; -import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; -import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; -import org.eclipse.papyrus.infra.gmfdiag.common.editpart.IControlParserForDirectEdit; -import org.eclipse.papyrus.infra.gmfdiag.common.editpart.PapyrusLabelEditPart; -import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; -import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; -import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.PapyrusLinkLabelDragPolicy; -import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; -import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; -import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; -import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; -import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; -import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; -import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; -import org.eclipse.swt.SWT; -import org.eclipse.swt.accessibility.AccessibleEvent; -import org.eclipse.swt.custom.BusyIndicator; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.FontData; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.widgets.Display; -import org.eclipse.ui.PlatformUI; -import org.eclipse.uml2.uml.Feature; - -/** - * @generated - */ -public class ManifestationNameEditPart extends PapyrusLabelEditPart implements ITextAwareEditPart, IControlParserForDirectEdit { - - /** - * @generated - */ - public static final int VISUAL_ID = 6005; - - /** - * @generated - */ - private DirectEditManager manager; - - /** - * @generated - */ - private IParser parser; - - /** - * @generated - */ - private List parserElements; - - /** - * @generated - */ - private String defaultText; - - /** - * direct edition mode (default, undefined, registered editor, etc.) - * - * @generated - */ - protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; - - /** - * configuration from a registered edit dialog - * - * @generated - */ - protected IDirectEditorConfiguration configuration; - /** - * @generated - */ - static { - registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.ManifestationNameEditPart.VISUAL_ID), new Point(0, 60)); - } - - /** - * @generated - */ - public ManifestationNameEditPart(View view) { - super(view); - } - - /** - * @generated - */ - @Override - protected void createDefaultEditPolicies() { - super.createDefaultEditPolicies(); - installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); - installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); - installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new PapyrusLinkLabelDragPolicy()); - } - - /** - * @generated - */ - @Override - public int getKeyPoint() { - return ConnectionLocator.MIDDLE; - } - - /** - * @generated - */ - protected String getLabelTextHelper(IFigure figure) { - if (figure instanceof WrappingLabel) { - return ((WrappingLabel) figure).getText(); - } else if (figure instanceof ILabelFigure) { - return ((ILabelFigure) figure).getText(); - } else { - return ((Label) figure).getText(); - } - } - - /** - * @generated - */ - protected void setLabelTextHelper(IFigure figure, String text) { - if (figure instanceof WrappingLabel) { - ((WrappingLabel) figure).setText(text); - } else if (figure instanceof ILabelFigure) { - ((ILabelFigure) figure).setText(text); - } else { - ((Label) figure).setText(text); - } - } - - /** - * @generated - */ - protected Image getLabelIconHelper(IFigure figure) { - if (figure instanceof WrappingLabel) { - return ((WrappingLabel) figure).getIcon(); - } else if (figure instanceof ILabelFigure) { - return ((ILabelFigure) figure).getIcon(); - } else { - return ((Label) figure).getIcon(); - } - } - - /** - * @generated - */ - protected void setLabelIconHelper(IFigure figure, Image icon) { - if (figure instanceof WrappingLabel) { - ((WrappingLabel) figure).setIcon(icon); - } else if (figure instanceof ILabelFigure) { - ((ILabelFigure) figure).setIcon(icon); - } else { - ((Label) figure).setIcon(icon); - } - } - - /** - * @generated - */ - public void setLabel(IFigure - figure) { - unregisterVisuals(); - setFigure(figure); - defaultText = getLabelTextHelper(figure); - registerVisuals(); - refreshVisuals(); - } - - /** - * @generated - */ - @Override - protected List getModelChildren() { - return Collections.EMPTY_LIST; - } - - /** - * @generated - */ - @Override - public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { - return null; - } - - /** - * @generated - */ - @Override - public void setParser(IParser parser) { - this.parser = parser; - } - - /** - * @generated - */ - protected EObject getParserElement() { - return resolveSemanticElement(); - } - - /** - * @generated - */ - protected Image getLabelIcon() { - return null; - } - - /** - * @generated - */ - protected String getLabelText() { - String text = null; - EObject parserElement = getParserElement(); - if (parserElement != null && getParser() != null) { - text = getParser().getPrintString( - new EObjectAdapter(parserElement), - getParserOptions().intValue()); - } - if (text == null || text.length() == 0) { - text = defaultText; - } - return text; - } - - /** - * @generated - */ - @Override - public void setLabelText(String text) { - setLabelTextHelper(getFigure(), text); - Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); - if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); - } - Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); - if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); - } - } - - /** - * @generated - */ - @Override - public String getEditText() { - if (getParserElement() == null || getParser() == null) { - return ""; //$NON-NLS-1$ - } - return getParser().getEditString( - new EObjectAdapter(getParserElement()), - getParserOptions().intValue()); - } - - /** - * @generated - */ - protected boolean isEditable() { - return getParser() != null; - } - - /** - * @generated - */ - @Override - public ICellEditorValidator getEditTextValidator() { - return new ICellEditorValidator() { - - @Override - public String isValid(final Object value) { - if (value instanceof String) { - final EObject element = getParserElement(); - final IParser parser = getParser(); - try { - IParserEditStatus valid = - (IParserEditStatus) getEditingDomain().runExclusive( - new RunnableWithResult.Impl() { - - @Override - public void run() { - setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); - } - }); - return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); - } catch (InterruptedException ie) { - ie.printStackTrace(); - } - } - - // shouldn't get here - return null; - } - }; - } - - /** - * @generated - */ - @Override - public IContentAssistProcessor getCompletionProcessor() { - if (getParserElement() == null || getParser() == null) { - return null; - } - return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); - } - - /** - * @generated - */ - @Override - public ParserOptions getParserOptions() { - return ParserOptions.NONE; - } - - /** - * @generated - */ - @Override - public IParser getParser() { - if (parser == null) { - parser = UMLParserProvider.getParser(UMLElementTypes.Manifestation_4012, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.ManifestationNameEditPart.VISUAL_ID)); - } - return parser; - } - - /** - * @generated - */ - protected DirectEditManager getManager() { - if (manager == null) { - setManager(new MultilineLabelDirectEditManager(this, - MultilineLabelDirectEditManager.getTextCellEditorClass(this), - UMLEditPartFactory.getTextCellEditorLocator(this))); - } - return manager; - } - - /** - * @generated - */ - protected void setManager(DirectEditManager manager) { - this.manager = manager; - } - - /** - * @generated - */ - protected void performDirectEdit() { - BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { - - @Override - public void run() { - getManager().show(); - } - }); - } - - /** - * @generated - */ - protected void performDirectEdit(Point eventLocation) { - if (getManager() instanceof TextDirectEditManager) { - ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); - } - } - - /** - * @generated - */ - private void performDirectEdit(char initialCharacter) { - if (getManager() instanceof TextDirectEditManager) { - ((TextDirectEditManager) getManager()).show(initialCharacter); - } else { - performDirectEdit(); - } - } - - /** - * @generated - */ - @Override - protected void performDirectEditRequest(Request request) { - - final Request theRequest = request; - - if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { - directEditionMode = getDirectEditionType(); - } - switch (directEditionMode) { - case IDirectEdition.NO_DIRECT_EDITION: - // no direct edition mode => does nothing - return; - case IDirectEdition.EXTENDED_DIRECT_EDITOR: - updateExtendedEditorConfiguration(); - if (configuration == null || configuration.getLanguage() == null) { - // Create default edit manager - setManager(new MultilineLabelDirectEditManager(this, - MultilineLabelDirectEditManager.getTextCellEditorClass(this), - UMLEditPartFactory.getTextCellEditorLocator(this))); - performDefaultDirectEditorEdit(theRequest); - } else { - configuration.preEditAction(resolveSemanticElement()); - Dialog dialog = null; - if (configuration instanceof ICustomDirectEditorConfiguration) { - setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); - initializeDirectEditManager(theRequest); - return; - } else if (configuration instanceof IPopupEditorConfiguration) { - IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); - helper.showEditor(); - return; - } - else if (configuration instanceof IAdvancedEditorConfiguration) { - dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); - } else if (configuration instanceof IDirectEditorConfiguration) { - dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), - configuration); - } else { - return; - } - final Dialog finalDialog = dialog; - - if (Window.OK == dialog.open()) { - TransactionalEditingDomain domain = getEditingDomain(); - RecordingCommand command = new RecordingCommand(domain, "Edit Label") { - - @Override - protected void doExecute() { - configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); - - } - }; - domain.getCommandStack().execute(command); - } - } - break; - case IDirectEdition.DEFAULT_DIRECT_EDITOR: - initializeDirectEditManager(theRequest); - break; - default: - break; - } - } - - /** - * @generated - */ - protected void initializeDirectEditManager(final Request request) { - // initialize the direct edit manager - try { - getEditingDomain().runExclusive(new Runnable() { - @Override - public void run() { - if (isActive() && isEditable()) { - if (request.getExtendedData().get( - RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { - Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); - performDirectEdit(initialChar.charValue()); - } - else { - performDirectEdit(); - } - } - } - }); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - - /** - * @generated - */ - @Override - protected void refreshVisuals() { - super.refreshVisuals(); - refreshLabel(); - refreshFont(); - refreshFontColor(); - refreshUnderline(); - refreshStrikeThrough(); - } - - /** - * @generated - */ - protected void refreshLabel() { - EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); - if (maskLabelPolicy == null) { - maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); - } - if (maskLabelPolicy == null) { - View view = (View) getModel(); - if (view.isVisible()) { - setLabelTextHelper(getFigure(), getLabelText()); - setLabelIconHelper(getFigure(), getLabelIcon()); - } - else { - setLabelTextHelper(getFigure(), ""); //$NON-NLS-1$ - setLabelIconHelper(getFigure(), null); - } - } - Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); - if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); - } - Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); - if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); - } - } - - /** - * @generated - */ - protected void refreshUnderline() { - FontStyle style = - (FontStyle) getFontStyleOwnerView().getStyle( - NotationPackage.eINSTANCE.getFontStyle()); - if (style != null && getFigure() instanceof WrappingLabel) { - ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); - } - if (resolveSemanticElement() instanceof Feature) { - if (((Feature) resolveSemanticElement()).isStatic()) { - ((WrappingLabel) getFigure()).setTextUnderline(true); - } - else { - ((WrappingLabel) getFigure()).setTextUnderline(false); - } - } - } - - /** - * @generated - */ - protected void refreshStrikeThrough() { - FontStyle style = - (FontStyle) getFontStyleOwnerView().getStyle( - NotationPackage.eINSTANCE.getFontStyle()); - if (style != null && getFigure() instanceof WrappingLabel) { - ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); - } - } - - /** - * @generated - */ - @Override - protected void refreshFont() { - FontStyle style = - (FontStyle) getFontStyleOwnerView().getStyle( - NotationPackage.eINSTANCE.getFontStyle()); - if (style != null) { - FontData fontData = new FontData( - style.getFontName(), style.getFontHeight(), - (style.isBold() ? SWT.BOLD : SWT.NORMAL) | - (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); - setFont(fontData); - } - } - - /** - * @generated - */ - @Override - protected void setFontColor(Color color) { - getFigure().setForegroundColor(color); - } - - /** - * @generated - */ - @Override - protected void addSemanticListeners() { - if (getParser() instanceof ISemanticParser) { - EObject element = resolveSemanticElement(); - parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); - for (int i = 0; i < parserElements.size(); i++) { - addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ - } - } else { - super.addSemanticListeners(); - } - } - - /** - * @generated - */ - @Override - protected void removeSemanticListeners() { - if (parserElements != null) { - for (int i = 0; i < parserElements.size(); i++) { - removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ - } - } else { - super.removeSemanticListeners(); - } - } - - /** - * @generated - */ - @Override - protected AccessibleEditPart getAccessibleEditPart() { - if (accessibleEP == null) { - accessibleEP = new AccessibleGraphicalEditPart() { - - @Override - public void getName(AccessibleEvent e) { - e.result = getLabelTextHelper(getFigure()); - } - }; - } - return accessibleEP; - } - - /** - * @generated - */ - private View getFontStyleOwnerView() { - return getPrimaryView(); - } - - /** - * Returns the kind of associated editor for direct edition. - * - * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition - * @generated - */ - public int getDirectEditionType() { - if (checkExtendedEditor()) { - initExtendedEditorConfiguration(); - return IDirectEdition.EXTENDED_DIRECT_EDITOR; - } - if (checkDefaultEdition()) { - return IDirectEdition.DEFAULT_DIRECT_EDITOR; - } - - // not a named element. no specific editor => do nothing - return IDirectEdition.NO_DIRECT_EDITION; - } - - /** - * Checks if an extended editor is present. - * - * @return true if an extended editor is present. - * @generated - */ - protected boolean checkExtendedEditor() { - if (resolveSemanticElement() != null) { - return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); - } - return false; - } - - /** - * Checks if a default direct edition is available - * - * @return true if a default direct edition is available - * @generated - */ - protected boolean checkDefaultEdition() { - return (getParser() != null); - } - - /** - * Initializes the extended editor configuration - * - * @generated - */ - protected void initExtendedEditorConfiguration() { - if (configuration == null) { - final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); - if (languagePreferred != null && !languagePreferred.equals("")) { - configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); - } else { - configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); - } - } - } - - /** - * Updates the preference configuration - * - * @generated - */ - protected void updateExtendedEditorConfiguration() { - String languagePreferred = Activator.getDefault().getPreferenceStore().getString( - IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); - if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { - configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() - .eClass().getInstanceClassName()); - } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { - configuration = null; - } - } - - /** - * Performs the direct edit usually used by GMF editors. - * - * @param theRequest - * the direct edit request that starts the direct edit system - * @generated - */ - protected void performDefaultDirectEditorEdit(final Request theRequest) { - // initialize the direct edit manager - try { - getEditingDomain().runExclusive(new Runnable() { - - @Override - public void run() { - if (isActive() && isEditable()) { - if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { - Character initialChar = (Character) theRequest.getExtendedData().get( - RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); - performDirectEdit(initialChar.charValue()); - } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { - DirectEditRequest editRequest = (DirectEditRequest) theRequest; - performDirectEdit(editRequest.getLocation()); - } else { - performDirectEdit(); - } - } - } - }); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - - /** - * @generated - */ - @Override - protected void handleNotificationEvent(Notification event) { - Object feature = event.getFeature(); - if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { - Integer c = (Integer) event.getNewValue(); - setFontColor(DiagramColorRegistry.getInstance().getColor(c)); - } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { - refreshUnderline(); - } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { - refreshStrikeThrough(); - } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || - NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || - NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || - NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { - refreshFont(); - } else { - if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { - refreshLabel(); - } - if (getParser() instanceof ISemanticParser) { - ISemanticParser modelParser = - (ISemanticParser) getParser(); - if (modelParser.areSemanticElementsAffected(null, event)) { - removeSemanticListeners(); - if (resolveSemanticElement() != null) { - addSemanticListeners(); - } - refreshLabel(); - } - } - } - - super.handleNotificationEvent(event); - } - - /** - * @generated - */ - @Override - protected IFigure createFigure() { - // Parent should assign one using setLabel() method - return 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.uml.diagram.composite.edit.parts; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.draw2d.ConnectionLocator; +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.Label; +import org.eclipse.draw2d.geometry.Point; +import org.eclipse.emf.common.notify.Notification; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.RunnableWithResult; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gef.AccessibleEditPart; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.Request; +import org.eclipse.gef.requests.DirectEditRequest; +import org.eclipse.gef.tools.DirectEditManager; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; +import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; +import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; +import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; +import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; +import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; +import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; +import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; +import org.eclipse.gmf.runtime.notation.FontStyle; +import org.eclipse.gmf.runtime.notation.NotationPackage; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.gmf.tooling.runtime.edit.policies.DefaultLinkLabelDragPolicy; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.text.contentassist.IContentAssistProcessor; +import org.eclipse.jface.viewers.ICellEditorValidator; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.extensionpoints.editors.Activator; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; +import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; +import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; +import org.eclipse.papyrus.infra.gmfdiag.common.editpart.IControlParserForDirectEdit; +import org.eclipse.papyrus.infra.gmfdiag.common.editpart.PapyrusLabelEditPart; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.PapyrusLinkLabelDragPolicy; +import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; +import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; +import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; +import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; +import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.accessibility.AccessibleEvent; +import org.eclipse.swt.custom.BusyIndicator; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; +import org.eclipse.uml2.uml.Feature; + +/** + * @generated + */ +public class ManifestationNameEditPart extends PapyrusLabelEditPart implements ITextAwareEditPart, IControlParserForDirectEdit { + + /** + * @generated + */ + public static final int VISUAL_ID = 6005; + + /** + * @generated + */ + private DirectEditManager manager; + + /** + * @generated + */ + private IParser parser; + + /** + * @generated + */ + private List parserElements; + + /** + * @generated + */ + private String defaultText; + + /** + * direct edition mode (default, undefined, registered editor, etc.) + * + * @generated + */ + protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; + + /** + * configuration from a registered edit dialog + * + * @generated + */ + protected IDirectEditorConfiguration configuration; + /** + * @generated + */ + static { + registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.ManifestationNameEditPart.VISUAL_ID), new Point(0, 60)); + } + + /** + * @generated + */ + public ManifestationNameEditPart(View view) { + super(view); + } + + /** + * @generated + */ + @Override + protected void createDefaultEditPolicies() { + super.createDefaultEditPolicies(); + installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); + installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new DefaultLinkLabelDragPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new PapyrusLinkLabelDragPolicy()); + } + + /** + * @generated + */ + @Override + public int getKeyPoint() { + return ConnectionLocator.MIDDLE; + } + + /** + * @generated + */ + protected String getLabelTextHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getText(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getText(); + } else { + return ((Label) figure).getText(); + } + } + + /** + * @generated + */ + protected void setLabelTextHelper(IFigure figure, String text) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setText(text); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setText(text); + } else { + ((Label) figure).setText(text); + } + } + + /** + * @generated + */ + protected Image getLabelIconHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getIcon(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getIcon(); + } else { + return ((Label) figure).getIcon(); + } + } + + /** + * @generated + */ + protected void setLabelIconHelper(IFigure figure, Image icon) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setIcon(icon); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setIcon(icon); + } else { + ((Label) figure).setIcon(icon); + } + } + + /** + * @generated + */ + public void setLabel(IFigure + figure) { + unregisterVisuals(); + setFigure(figure); + defaultText = getLabelTextHelper(figure); + registerVisuals(); + refreshVisuals(); + } + + /** + * @generated + */ + @Override + protected List getModelChildren() { + return Collections.EMPTY_LIST; + } + + /** + * @generated + */ + @Override + public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { + return null; + } + + /** + * @generated + */ + @Override + public void setParser(IParser parser) { + this.parser = parser; + } + + /** + * @generated + */ + protected EObject getParserElement() { + return resolveSemanticElement(); + } + + /** + * @generated + */ + protected Image getLabelIcon() { + return null; + } + + /** + * @generated + */ + protected String getLabelText() { + String text = null; + EObject parserElement = getParserElement(); + if (parserElement != null && getParser() != null) { + text = getParser().getPrintString( + new EObjectAdapter(parserElement), + getParserOptions().intValue()); + } + if (text == null || text.length() == 0) { + text = defaultText; + } + return text; + } + + /** + * @generated + */ + @Override + public void setLabelText(String text) { + setLabelTextHelper(getFigure(), text); + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + @Override + public String getEditText() { + if (getParserElement() == null || getParser() == null) { + return ""; //$NON-NLS-1$ + } + return getParser().getEditString( + new EObjectAdapter(getParserElement()), + getParserOptions().intValue()); + } + + /** + * @generated + */ + protected boolean isEditable() { + return getParser() != null; + } + + /** + * @generated + */ + @Override + public ICellEditorValidator getEditTextValidator() { + return new ICellEditorValidator() { + + @Override + public String isValid(final Object value) { + if (value instanceof String) { + final EObject element = getParserElement(); + final IParser parser = getParser(); + try { + IParserEditStatus valid = + (IParserEditStatus) getEditingDomain().runExclusive( + new RunnableWithResult.Impl() { + + @Override + public void run() { + setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); + } + }); + return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); + } catch (InterruptedException ie) { + ie.printStackTrace(); + } + } + + // shouldn't get here + return null; + } + }; + } + + /** + * @generated + */ + @Override + public IContentAssistProcessor getCompletionProcessor() { + if (getParserElement() == null || getParser() == null) { + return null; + } + return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); + } + + /** + * @generated + */ + @Override + public ParserOptions getParserOptions() { + return ParserOptions.NONE; + } + + /** + * @generated + */ + @Override + public IParser getParser() { + if (parser == null) { + parser = UMLParserProvider.getParser(UMLElementTypes.Manifestation_4012, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.ManifestationNameEditPart.VISUAL_ID)); + } + return parser; + } + + /** + * @generated + */ + protected DirectEditManager getManager() { + if (manager == null) { + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + } + return manager; + } + + /** + * @generated + */ + protected void setManager(DirectEditManager manager) { + this.manager = manager; + } + + /** + * @generated + */ + protected void performDirectEdit() { + BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { + + @Override + public void run() { + getManager().show(); + } + }); + } + + /** + * @generated + */ + protected void performDirectEdit(Point eventLocation) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); + } + } + + /** + * @generated + */ + private void performDirectEdit(char initialCharacter) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(initialCharacter); + } else { + performDirectEdit(); + } + } + + /** + * @generated + */ + @Override + protected void performDirectEditRequest(Request request) { + + final Request theRequest = request; + + if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { + directEditionMode = getDirectEditionType(); + } + switch (directEditionMode) { + case IDirectEdition.NO_DIRECT_EDITION: + // no direct edition mode => does nothing + return; + case IDirectEdition.EXTENDED_DIRECT_EDITOR: + updateExtendedEditorConfiguration(); + if (configuration == null || configuration.getLanguage() == null) { + // Create default edit manager + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + performDefaultDirectEditorEdit(theRequest); + } else { + configuration.preEditAction(resolveSemanticElement()); + Dialog dialog = null; + if (configuration instanceof ICustomDirectEditorConfiguration) { + setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); + initializeDirectEditManager(theRequest); + return; + } else if (configuration instanceof IPopupEditorConfiguration) { + IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); + helper.showEditor(); + return; + } + else if (configuration instanceof IAdvancedEditorConfiguration) { + dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); + } else if (configuration instanceof IDirectEditorConfiguration) { + dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), + configuration); + } else { + return; + } + final Dialog finalDialog = dialog; + + if (Window.OK == dialog.open()) { + TransactionalEditingDomain domain = getEditingDomain(); + RecordingCommand command = new RecordingCommand(domain, "Edit Label") { + + @Override + protected void doExecute() { + configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); + + } + }; + domain.getCommandStack().execute(command); + } + } + break; + case IDirectEdition.DEFAULT_DIRECT_EDITOR: + initializeDirectEditManager(theRequest); + break; + default: + break; + } + } + + /** + * @generated + */ + protected void initializeDirectEditManager(final Request request) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + @Override + public void run() { + if (isActive() && isEditable()) { + if (request.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } + else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void refreshVisuals() { + super.refreshVisuals(); + refreshLabel(); + refreshFont(); + refreshFontColor(); + refreshUnderline(); + refreshStrikeThrough(); + } + + /** + * @generated + */ + protected void refreshLabel() { + EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); + if (maskLabelPolicy == null) { + maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); + } + if (maskLabelPolicy == null) { + setLabelTextHelper(getFigure(), getLabelText()); + setLabelIconHelper(getFigure(), getLabelIcon()); + } + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + protected void refreshUnderline() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); + } + if (resolveSemanticElement() instanceof Feature) { + if (((Feature) resolveSemanticElement()).isStatic()) { + ((WrappingLabel) getFigure()).setTextUnderline(true); + } + else { + ((WrappingLabel) getFigure()).setTextUnderline(false); + } + } + } + + /** + * @generated + */ + protected void refreshStrikeThrough() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); + } + } + + /** + * @generated + */ + @Override + protected void refreshFont() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null) { + FontData fontData = new FontData( + style.getFontName(), style.getFontHeight(), + (style.isBold() ? SWT.BOLD : SWT.NORMAL) | + (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); + setFont(fontData); + } + } + + /** + * @generated + */ + @Override + protected void setFontColor(Color color) { + getFigure().setForegroundColor(color); + } + + /** + * @generated + */ + @Override + protected void addSemanticListeners() { + if (getParser() instanceof ISemanticParser) { + EObject element = resolveSemanticElement(); + parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); + for (int i = 0; i < parserElements.size(); i++) { + addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ + } + } else { + super.addSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected void removeSemanticListeners() { + if (parserElements != null) { + for (int i = 0; i < parserElements.size(); i++) { + removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ + } + } else { + super.removeSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected AccessibleEditPart getAccessibleEditPart() { + if (accessibleEP == null) { + accessibleEP = new AccessibleGraphicalEditPart() { + + @Override + public void getName(AccessibleEvent e) { + e.result = getLabelTextHelper(getFigure()); + } + }; + } + return accessibleEP; + } + + /** + * @generated + */ + private View getFontStyleOwnerView() { + return getPrimaryView(); + } + + /** + * Returns the kind of associated editor for direct edition. + * + * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition + * @generated + */ + public int getDirectEditionType() { + if (checkExtendedEditor()) { + initExtendedEditorConfiguration(); + return IDirectEdition.EXTENDED_DIRECT_EDITOR; + } + if (checkDefaultEdition()) { + return IDirectEdition.DEFAULT_DIRECT_EDITOR; + } + + // not a named element. no specific editor => do nothing + return IDirectEdition.NO_DIRECT_EDITION; + } + + /** + * Checks if an extended editor is present. + * + * @return true if an extended editor is present. + * @generated + */ + protected boolean checkExtendedEditor() { + if (resolveSemanticElement() != null) { + return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); + } + return false; + } + + /** + * Checks if a default direct edition is available + * + * @return true if a default direct edition is available + * @generated + */ + protected boolean checkDefaultEdition() { + return (getParser() != null); + } + + /** + * Initializes the extended editor configuration + * + * @generated + */ + protected void initExtendedEditorConfiguration() { + if (configuration == null) { + final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("")) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); + } else { + configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); + } + } + } + + /** + * Updates the preference configuration + * + * @generated + */ + protected void updateExtendedEditorConfiguration() { + String languagePreferred = Activator.getDefault().getPreferenceStore().getString( + IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() + .eClass().getInstanceClassName()); + } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { + configuration = null; + } + } + + /** + * Performs the direct edit usually used by GMF editors. + * + * @param theRequest + * the direct edit request that starts the direct edit system + * @generated + */ + protected void performDefaultDirectEditorEdit(final Request theRequest) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + + @Override + public void run() { + if (isActive() && isEditable()) { + if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) theRequest.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { + DirectEditRequest editRequest = (DirectEditRequest) theRequest; + performDirectEdit(editRequest.getLocation()); + } else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void handleNotificationEvent(Notification event) { + Object feature = event.getFeature(); + if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { + Integer c = (Integer) event.getNewValue(); + setFontColor(DiagramColorRegistry.getInstance().getColor(c)); + } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { + refreshUnderline(); + } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { + refreshStrikeThrough(); + } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { + refreshFont(); + } else { + if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { + refreshLabel(); + } + if (getParser() instanceof ISemanticParser) { + ISemanticParser modelParser = + (ISemanticParser) getParser(); + if (modelParser.areSemanticElementsAffected(null, event)) { + removeSemanticListeners(); + if (resolveSemanticElement() != null) { + addSemanticListeners(); + } + refreshLabel(); + } + } + } + + super.handleNotificationEvent(event); + } + + /** + * @generated + */ + @Override + protected IFigure createFigure() { + // Parent should assign one using setLabel() method + return null; + } +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/NodeCompositeCompartmentEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/NodeCompositeCompartmentEditPart.java index 1f78bf78525..48fecc3e2ab 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/NodeCompositeCompartmentEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/NodeCompositeCompartmentEditPart.java @@ -26,6 +26,7 @@ import org.eclipse.gmf.runtime.diagram.ui.editpolicies.ResizableCompartmentEditP import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.BorderDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.CustomContainerEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.DuplicatePasteEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.PapyrusCreationEditPolicy; @@ -75,6 +76,7 @@ public class NodeCompositeCompartmentEditPart extends ShapeCompartmentEditPart { installEditPolicy(EditPolicy.GRAPHICAL_NODE_ROLE, new CustomContainerEditPolicy()); installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, new CustomDiagramDragDropEditPolicy()); installEditPolicy(EditPolicyRoles.CREATION_ROLE, new PortInCompartmentCreationEditPolicy()); + installEditPolicy(BorderDisplayEditPolicy.BORDER_DISPLAY_EDITPOLICY, new BorderDisplayEditPolicy()); } /** diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/NodeCompositeCompartmentEditPartCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/NodeCompositeCompartmentEditPartCN.java index 2668f8a42c9..a12771d4c0a 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/NodeCompositeCompartmentEditPartCN.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/NodeCompositeCompartmentEditPartCN.java @@ -26,6 +26,7 @@ import org.eclipse.gmf.runtime.diagram.ui.editpolicies.ResizableCompartmentEditP import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.BorderDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.CustomContainerEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.DuplicatePasteEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.PapyrusCreationEditPolicy; @@ -75,6 +76,7 @@ public class NodeCompositeCompartmentEditPartCN extends ShapeCompartmentEditPart installEditPolicy(EditPolicy.GRAPHICAL_NODE_ROLE, new CustomContainerEditPolicy()); installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, new CustomDiagramDragDropEditPolicy()); installEditPolicy(EditPolicyRoles.CREATION_ROLE, new PortInCompartmentCreationEditPolicy()); + installEditPolicy(BorderDisplayEditPolicy.BORDER_DISPLAY_EDITPOLICY, new BorderDisplayEditPolicy()); } /** diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/NodeCompositeEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/NodeCompositeEditPart.java index ae09d34aaa4..7d85b2a9959 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/NodeCompositeEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/NodeCompositeEditPart.java @@ -11,28 +11,37 @@ */ package org.eclipse.papyrus.uml.diagram.composite.edit.parts; +import java.util.Collections; +import java.util.List; + import org.eclipse.draw2d.IFigure; import org.eclipse.draw2d.PositionConstants; import org.eclipse.emf.common.notify.Notification; import org.eclipse.gef.EditPart; import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.GraphicalEditPart; 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.handles.MoveHandle; import org.eclipse.gef.requests.CreateRequest; import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.BorderItemSelectionEditPolicy; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.DragDropEditPolicy; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles; import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; -import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure; import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure; +import org.eclipse.gmf.runtime.notation.Edge; +import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.GetChildLayoutEditPolicy; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.IPapyrusNodeFigure; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.RoundedRectangleNodePlateFigure; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.SelectableBorderedNodeFigure; -import org.eclipse.papyrus.uml.diagram.common.editparts.NamedElementEditPart; +import org.eclipse.papyrus.uml.diagram.common.editparts.RoundedCompartmentEditPart; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AffixedNodeAlignmentEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeNodeLabelDisplayEditPolicy; @@ -41,12 +50,12 @@ import org.eclipse.papyrus.uml.diagram.common.editpolicies.PapyrusCreationEditPo import org.eclipse.papyrus.uml.diagram.common.editpolicies.QualifiedNameDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.ShowHideClassifierContentsEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.ShowHideCompartmentEditPolicy; +import org.eclipse.papyrus.uml.diagram.common.locator.RoundedRectangleLabelPositionLocator; import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.CustomDiagramDragDropEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.CustomGraphicalNodeEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.RemoveOrphanViewPolicy; import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.StructuredClassifierLayoutEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.custom.figures.NodeCompositeFigure; -import org.eclipse.papyrus.uml.diagram.composite.custom.locators.PortPositionLocator; import org.eclipse.papyrus.uml.diagram.composite.edit.policies.NodeCompositeItemSemanticEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; import org.eclipse.swt.graphics.Color; @@ -54,7 +63,7 @@ import org.eclipse.swt.graphics.Color; /** * @generated */ -public class NodeCompositeEditPart extends NamedElementEditPart { +public class NodeCompositeEditPart extends RoundedCompartmentEditPart { /** * @generated @@ -97,6 +106,7 @@ public class NodeCompositeEditPart extends NamedElementEditPart { installEditPolicy(ShowHideCompartmentEditPolicy.SHOW_HIDE_COMPARTMENT_POLICY, new ShowHideCompartmentEditPolicy()); installEditPolicy(AffixedNodeAlignmentEditPolicy.AFFIXED_CHILD_ALIGNMENT_ROLE, new AffixedNodeAlignmentEditPolicy()); installEditPolicy("REMOVE_ORPHAN_VIEW", new RemoveOrphanViewPolicy()); //$NON-NLS-1$ + installEditPolicy(EditPolicy.LAYOUT_ROLE, new GetChildLayoutEditPolicy()); // XXX need an SCR to runtime to have another abstract superclass that would let children add reasonable editpolicies // removeEditPolicy(org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles.CONNECTION_HANDLES_ROLE); } @@ -111,6 +121,17 @@ public class NodeCompositeEditPart extends NamedElementEditPart { protected EditPolicy createChildEditPolicy(EditPart child) { View childView = (View) child.getModel(); switch (UMLVisualIDRegistry.getVisualID(childView)) { + case NodeCompositeFloatingLabelEditPart.VISUAL_ID: + return new BorderItemSelectionEditPolicy() { + + @Override + protected List createSelectionHandles() { + MoveHandle mh = new MoveHandle((GraphicalEditPart) getHost()); + mh.setBorder(null); + return Collections.singletonList(mh); + } + } + ; case PortEditPart.VISUAL_ID: return new BorderItemResizableEditPolicy(); } @@ -141,6 +162,19 @@ public class NodeCompositeEditPart extends NamedElementEditPart { **/ @Override protected void handleNotificationEvent(Notification event) { + /* + * when a node have external node labels, the methods refreshChildren() remove the EditPart corresponding to the Label from the EditPart + * Registry. After that, we can't reset the visibility to true (using the Show/Hide Label Action)! + */ + if (NotationPackage.eINSTANCE.getView_Visible().equals(event.getFeature())) { + Object notifier = event.getNotifier(); + List modelChildren = ((View) getModel()).getChildren(); + if (!(notifier instanceof Edge)) { + if (modelChildren.contains(event.getNotifier())) { + return; + } + } + } super.handleNotificationEvent(event); } @@ -182,9 +216,9 @@ public class NodeCompositeEditPart extends NamedElementEditPart { - //Papyrus Gencode :Affixed Port locator + // Papyrus Gencode :Affixed Port locator if (childEditPart instanceof PortEditPart) { - IBorderItemLocator locator = new PortPositionLocator(getMainFigure(), PositionConstants.NONE); + IBorderItemLocator locator = new org.eclipse.papyrus.uml.diagram.common.locator.PortPositionLocator(getMainFigure(), PositionConstants.NONE); getBorderedFigure().getBorderItemContainer().add(((PortEditPart) childEditPart).getFigure(), locator); return true; } @@ -248,12 +282,26 @@ public class NodeCompositeEditPart extends NamedElementEditPart { return getContentPane(); } + /** + * @generated + */ + @Override + protected void addBorderItem(IFigure borderItemContainer, IBorderItemEditPart borderItemEditPart) { + if (borderItemEditPart instanceof NodeCompositeFloatingLabelEditPart) { + IBorderItemLocator locator = new RoundedRectangleLabelPositionLocator(getMainFigure()); + borderItemContainer.add(borderItemEditPart.getFigure(), locator); + } else + { + super.addBorderItem(borderItemContainer, borderItemEditPart); + } + } + /** * @generated */ @Override protected NodeFigure createNodePlate() { - DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(40, 40); + RoundedRectangleNodePlateFigure result = new RoundedRectangleNodePlateFigure(40, 40); return result; } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/NodeCompositeEditPartCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/NodeCompositeEditPartCN.java index d1da4d99872..c605b7b88ef 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/NodeCompositeEditPartCN.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/NodeCompositeEditPartCN.java @@ -11,28 +11,37 @@ */ package org.eclipse.papyrus.uml.diagram.composite.edit.parts; +import java.util.Collections; +import java.util.List; + import org.eclipse.draw2d.IFigure; import org.eclipse.draw2d.PositionConstants; import org.eclipse.emf.common.notify.Notification; import org.eclipse.gef.EditPart; import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.GraphicalEditPart; 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.handles.MoveHandle; import org.eclipse.gef.requests.CreateRequest; import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.BorderItemSelectionEditPolicy; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.DragDropEditPolicy; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles; import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; -import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure; import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure; +import org.eclipse.gmf.runtime.notation.Edge; +import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.GetChildLayoutEditPolicy; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.IPapyrusNodeFigure; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.RoundedRectangleNodePlateFigure; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.SelectableBorderedNodeFigure; -import org.eclipse.papyrus.uml.diagram.common.editparts.NamedElementEditPart; +import org.eclipse.papyrus.uml.diagram.common.editparts.RoundedCompartmentEditPart; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AffixedNodeAlignmentEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeNodeLabelDisplayEditPolicy; @@ -41,12 +50,12 @@ import org.eclipse.papyrus.uml.diagram.common.editpolicies.PapyrusCreationEditPo import org.eclipse.papyrus.uml.diagram.common.editpolicies.QualifiedNameDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.ShowHideClassifierContentsEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.ShowHideCompartmentEditPolicy; +import org.eclipse.papyrus.uml.diagram.common.locator.RoundedRectangleLabelPositionLocator; import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.CustomDiagramDragDropEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.CustomGraphicalNodeEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.RemoveOrphanViewPolicy; import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.StructuredClassifierLayoutEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.custom.figures.NodeCompositeFigure; -import org.eclipse.papyrus.uml.diagram.composite.custom.locators.PortPositionLocator; import org.eclipse.papyrus.uml.diagram.composite.edit.policies.NodeCompositeItemSemanticEditPolicycN; import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; import org.eclipse.swt.graphics.Color; @@ -54,7 +63,7 @@ import org.eclipse.swt.graphics.Color; /** * @generated */ -public class NodeCompositeEditPartCN extends NamedElementEditPart { +public class NodeCompositeEditPartCN extends RoundedCompartmentEditPart { /** * @generated @@ -97,6 +106,7 @@ public class NodeCompositeEditPartCN extends NamedElementEditPart { installEditPolicy(ShowHideCompartmentEditPolicy.SHOW_HIDE_COMPARTMENT_POLICY, new ShowHideCompartmentEditPolicy()); installEditPolicy(AffixedNodeAlignmentEditPolicy.AFFIXED_CHILD_ALIGNMENT_ROLE, new AffixedNodeAlignmentEditPolicy()); installEditPolicy("REMOVE_ORPHAN_VIEW", new RemoveOrphanViewPolicy()); //$NON-NLS-1$ + installEditPolicy(EditPolicy.LAYOUT_ROLE, new GetChildLayoutEditPolicy()); // XXX need an SCR to runtime to have another abstract superclass that would let children add reasonable editpolicies // removeEditPolicy(org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles.CONNECTION_HANDLES_ROLE); } @@ -111,6 +121,17 @@ public class NodeCompositeEditPartCN extends NamedElementEditPart { protected EditPolicy createChildEditPolicy(EditPart child) { View childView = (View) child.getModel(); switch (UMLVisualIDRegistry.getVisualID(childView)) { + case NodeCompositeFloatingLabelEditPartCN.VISUAL_ID: + return new BorderItemSelectionEditPolicy() { + + @Override + protected List createSelectionHandles() { + MoveHandle mh = new MoveHandle((GraphicalEditPart) getHost()); + mh.setBorder(null); + return Collections.singletonList(mh); + } + } + ; case PortEditPart.VISUAL_ID: return new BorderItemResizableEditPolicy(); } @@ -141,6 +162,19 @@ public class NodeCompositeEditPartCN extends NamedElementEditPart { **/ @Override protected void handleNotificationEvent(Notification event) { + /* + * when a node have external node labels, the methods refreshChildren() remove the EditPart corresponding to the Label from the EditPart + * Registry. After that, we can't reset the visibility to true (using the Show/Hide Label Action)! + */ + if (NotationPackage.eINSTANCE.getView_Visible().equals(event.getFeature())) { + Object notifier = event.getNotifier(); + List modelChildren = ((View) getModel()).getChildren(); + if (!(notifier instanceof Edge)) { + if (modelChildren.contains(event.getNotifier())) { + return; + } + } + } super.handleNotificationEvent(event); } @@ -182,9 +216,9 @@ public class NodeCompositeEditPartCN extends NamedElementEditPart { - //Papyrus Gencode :Affixed Port locator + // Papyrus Gencode :Affixed Port locator if (childEditPart instanceof PortEditPart) { - IBorderItemLocator locator = new PortPositionLocator(getMainFigure(), PositionConstants.NONE); + IBorderItemLocator locator = new org.eclipse.papyrus.uml.diagram.common.locator.PortPositionLocator(getMainFigure(), PositionConstants.NONE); getBorderedFigure().getBorderItemContainer().add(((PortEditPart) childEditPart).getFigure(), locator); return true; } @@ -248,12 +282,26 @@ public class NodeCompositeEditPartCN extends NamedElementEditPart { return getContentPane(); } + /** + * @generated + */ + @Override + protected void addBorderItem(IFigure borderItemContainer, IBorderItemEditPart borderItemEditPart) { + if (borderItemEditPart instanceof NodeCompositeFloatingLabelEditPartCN) { + IBorderItemLocator locator = new RoundedRectangleLabelPositionLocator(getMainFigure()); + borderItemContainer.add(borderItemEditPart.getFigure(), locator); + } else + { + super.addBorderItem(borderItemContainer, borderItemEditPart); + } + } + /** * @generated */ @Override protected NodeFigure createNodePlate() { - DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(40, 40); + RoundedRectangleNodePlateFigure result = new RoundedRectangleNodePlateFigure(40, 40); return result; } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/NodeCompositeFloatingLabelEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/NodeCompositeFloatingLabelEditPart.java new file mode 100644 index 00000000000..1ac4a928684 --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/NodeCompositeFloatingLabelEditPart.java @@ -0,0 +1,860 @@ +/** + * 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.uml.diagram.composite.edit.parts; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.Label; +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.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.RunnableWithResult; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gef.AccessibleEditPart; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.Request; +import org.eclipse.gef.requests.DirectEditRequest; +import org.eclipse.gef.tools.DirectEditManager; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; +import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; +import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; +import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; +import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; +import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; +import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; +import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; +import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; +import org.eclipse.gmf.runtime.notation.FontStyle; +import org.eclipse.gmf.runtime.notation.NotationPackage; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.text.contentassist.IContentAssistProcessor; +import org.eclipse.jface.viewers.ICellEditorValidator; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.extensionpoints.editors.Activator; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; +import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; +import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.ExternalLabelPrimaryDragRoleEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.PapyrusWrappingLabel; +import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; +import org.eclipse.papyrus.uml.diagram.common.editparts.FloatingLabelEditPart; +import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; +import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; +import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; +import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.accessibility.AccessibleEvent; +import org.eclipse.swt.custom.BusyIndicator; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; +import org.eclipse.uml2.uml.Feature; + +/** + * @generated + */ +public class NodeCompositeFloatingLabelEditPart extends FloatingLabelEditPart + implements ITextAwareEditPart, IBorderItemEditPart +{ + + /** + * @generated + */ + public static final int VISUAL_ID = 6088; + + /** + * @generated + */ + private DirectEditManager manager; + + /** + * @generated + */ + private IParser parser; + + /** + * @generated + */ + private List parserElements; + + /** + * @generated + */ + private String defaultText; + + /** + * direct edition mode (default, undefined, registered editor, etc.) + * + * @generated + */ + protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; + + /** + * configuration from a registered edit dialog + * + * @generated + */ + protected IDirectEditorConfiguration configuration; + + + /** + * @generated + */ + static { + registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.NodeCompositeFloatingLabelEditPart.VISUAL_ID), new Point(0, 0)); + } + + /** + * @generated + */ + public NodeCompositeFloatingLabelEditPart(View view) { + super(view); + } + + /** + * @generated + */ + @Override + protected void createDefaultEditPolicies() { + super.createDefaultEditPolicies(); + installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); + installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ExternalLabelPrimaryDragRoleEditPolicy()); + } + + /** + * @generated + */ + @Override + public IBorderItemLocator getBorderItemLocator() { + IFigure parentFigure = getFigure().getParent(); + if (parentFigure != null && parentFigure.getLayoutManager() != null) { + Object constraint = parentFigure.getLayoutManager().getConstraint(getFigure()); + return (IBorderItemLocator) constraint; + } + return null; + } + + /** + * @generated + */ + @Override + public void refreshBounds() { + int x = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_X())).intValue(); + int y = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_Y())).intValue(); + int width = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Width())).intValue(); + int height = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Height())).intValue(); + getBorderItemLocator().setConstraint(new Rectangle(x, y, width, height)); + } + + + /** + * @generated + */ + protected String getLabelTextHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getText(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getText(); + } else { + return ((Label) figure).getText(); + } + } + + /** + * @generated + */ + protected void setLabelTextHelper(IFigure figure, String text) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setText(text); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setText(text); + } else { + ((Label) figure).setText(text); + } + } + + /** + * @generated + */ + protected Image getLabelIconHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getIcon(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getIcon(); + } else { + return ((Label) figure).getIcon(); + } + } + + /** + * @generated + */ + protected void setLabelIconHelper(IFigure figure, Image icon) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setIcon(icon); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setIcon(icon); + } else { + ((Label) figure).setIcon(icon); + } + } + + /** + * @generated + */ + public void setLabel(IFigure + figure) { + unregisterVisuals(); + setFigure(figure); + defaultText = getLabelTextHelper(figure); + registerVisuals(); + refreshVisuals(); + } + + /** + * @generated + */ + @Override + protected List getModelChildren() { + return Collections.EMPTY_LIST; + } + + /** + * @generated + */ + @Override + public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { + return null; + } + + /** + * @generated + */ + public void setParser(IParser parser) { + this.parser = parser; + } + + /** + * @generated + */ + protected EObject getParserElement() { + return resolveSemanticElement(); + } + + /** + * @generated + */ + protected Image getLabelIcon() { + return null; + } + + /** + * @generated + */ + protected String getLabelText() { + String text = null; + EObject parserElement = getParserElement(); + if (parserElement != null && getParser() != null) { + text = getParser().getPrintString( + new EObjectAdapter(parserElement), + getParserOptions().intValue()); + } + if (text == null || text.length() == 0) { + text = defaultText; + } + return text; + } + + /** + * @generated + */ + @Override + public void setLabelText(String text) { + setLabelTextHelper(getFigure(), text); + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + @Override + public String getEditText() { + if (getParserElement() == null || getParser() == null) { + return ""; //$NON-NLS-1$ + } + return getParser().getEditString( + new EObjectAdapter(getParserElement()), + getParserOptions().intValue()); + } + + /** + * @generated + */ + protected boolean isEditable() { + return getParser() != null; + } + + /** + * @generated + */ + @Override + public ICellEditorValidator getEditTextValidator() { + return new ICellEditorValidator() { + + @Override + public String isValid(final Object value) { + if (value instanceof String) { + final EObject element = getParserElement(); + final IParser parser = getParser(); + try { + IParserEditStatus valid = + (IParserEditStatus) getEditingDomain().runExclusive( + new RunnableWithResult.Impl() { + + @Override + public void run() { + setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); + } + }); + return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); + } catch (InterruptedException ie) { + ie.printStackTrace(); + } + } + + // shouldn't get here + return null; + } + }; + } + + /** + * @generated + */ + @Override + public IContentAssistProcessor getCompletionProcessor() { + if (getParserElement() == null || getParser() == null) { + return null; + } + return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); + } + + /** + * @generated + */ + @Override + public ParserOptions getParserOptions() { + return ParserOptions.NONE; + } + + /** + * @generated + */ + @Override + public IParser getParser() { + if (parser == null) { + parser = UMLParserProvider.getParser(UMLElementTypes.Node_2072, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.NodeCompositeFloatingLabelEditPart.VISUAL_ID)); + } + return parser; + } + + /** + * @generated + */ + protected DirectEditManager getManager() { + if (manager == null) { + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + } + return manager; + } + + /** + * @generated + */ + protected void setManager(DirectEditManager manager) { + this.manager = manager; + } + + /** + * @generated + */ + protected void performDirectEdit() { + BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { + + @Override + public void run() { + getManager().show(); + } + }); + } + + /** + * @generated + */ + protected void performDirectEdit(Point eventLocation) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); + } + } + + /** + * @generated + */ + private void performDirectEdit(char initialCharacter) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(initialCharacter); + } else { + performDirectEdit(); + } + } + + /** + * @generated + */ + @Override + protected void performDirectEditRequest(Request request) { + + final Request theRequest = request; + + if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { + directEditionMode = getDirectEditionType(); + } + switch (directEditionMode) { + case IDirectEdition.NO_DIRECT_EDITION: + // no direct edition mode => does nothing + return; + case IDirectEdition.EXTENDED_DIRECT_EDITOR: + updateExtendedEditorConfiguration(); + if (configuration == null || configuration.getLanguage() == null) { + // Create default edit manager + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + performDefaultDirectEditorEdit(theRequest); + } else { + configuration.preEditAction(resolveSemanticElement()); + Dialog dialog = null; + if (configuration instanceof ICustomDirectEditorConfiguration) { + setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); + initializeDirectEditManager(theRequest); + return; + } else if (configuration instanceof IPopupEditorConfiguration) { + IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); + helper.showEditor(); + return; + } + else if (configuration instanceof IAdvancedEditorConfiguration) { + dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); + } else if (configuration instanceof IDirectEditorConfiguration) { + dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), + configuration); + } else { + return; + } + final Dialog finalDialog = dialog; + + if (Window.OK == dialog.open()) { + TransactionalEditingDomain domain = getEditingDomain(); + RecordingCommand command = new RecordingCommand(domain, "Edit Label") { + + @Override + protected void doExecute() { + configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); + + } + }; + domain.getCommandStack().execute(command); + } + } + break; + case IDirectEdition.DEFAULT_DIRECT_EDITOR: + initializeDirectEditManager(theRequest); + break; + default: + break; + } + } + + /** + * @generated + */ + protected void initializeDirectEditManager(final Request request) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + @Override + public void run() { + if (isActive() && isEditable()) { + if (request.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } + else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void refreshVisuals() { + super.refreshVisuals(); + refreshLabel(); + refreshFont(); + refreshFontColor(); + refreshUnderline(); + refreshStrikeThrough(); + } + + /** + * @generated + */ + protected void refreshLabel() { + EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); + if (maskLabelPolicy == null) { + maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); + } + if (maskLabelPolicy == null) { + View view = (View) getModel(); + if (view.isVisible()) { + setLabelTextHelper(getFigure(), getLabelText()); + setLabelIconHelper(getFigure(), getLabelIcon()); + } + else { + setLabelTextHelper(getFigure(), ""); //$NON-NLS-1$ + setLabelIconHelper(getFigure(), null); + } + } + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + protected void refreshUnderline() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); + } + if (resolveSemanticElement() instanceof Feature) { + if (((Feature) resolveSemanticElement()).isStatic()) { + ((WrappingLabel) getFigure()).setTextUnderline(true); + } + else { + ((WrappingLabel) getFigure()).setTextUnderline(false); + } + } + } + + /** + * @generated + */ + protected void refreshStrikeThrough() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); + } + } + + /** + * @generated + */ + @Override + protected void refreshFont() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null) { + FontData fontData = new FontData( + style.getFontName(), style.getFontHeight(), + (style.isBold() ? SWT.BOLD : SWT.NORMAL) | + (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); + setFont(fontData); + } + } + + /** + * @generated + */ + @Override + protected void setFontColor(Color color) { + getFigure().setForegroundColor(color); + } + + /** + * @generated + */ + @Override + protected void addSemanticListeners() { + if (getParser() instanceof ISemanticParser) { + EObject element = resolveSemanticElement(); + parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); + for (int i = 0; i < parserElements.size(); i++) { + addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ + } + } else { + super.addSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected void removeSemanticListeners() { + if (parserElements != null) { + for (int i = 0; i < parserElements.size(); i++) { + removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ + } + } else { + super.removeSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected AccessibleEditPart getAccessibleEditPart() { + if (accessibleEP == null) { + accessibleEP = new AccessibleGraphicalEditPart() { + + @Override + public void getName(AccessibleEvent e) { + e.result = getLabelTextHelper(getFigure()); + } + }; + } + return accessibleEP; + } + + /** + * @generated + */ + private View getFontStyleOwnerView() { + return getPrimaryView(); + } + + /** + * Returns the kind of associated editor for direct edition. + * + * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition + * @generated + */ + public int getDirectEditionType() { + if (checkExtendedEditor()) { + initExtendedEditorConfiguration(); + return IDirectEdition.EXTENDED_DIRECT_EDITOR; + } + if (checkDefaultEdition()) { + return IDirectEdition.DEFAULT_DIRECT_EDITOR; + } + + // not a named element. no specific editor => do nothing + return IDirectEdition.NO_DIRECT_EDITION; + } + + /** + * Checks if an extended editor is present. + * + * @return true if an extended editor is present. + * @generated + */ + protected boolean checkExtendedEditor() { + if (resolveSemanticElement() != null) { + return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); + } + return false; + } + + /** + * Checks if a default direct edition is available + * + * @return true if a default direct edition is available + * @generated + */ + protected boolean checkDefaultEdition() { + return (getParser() != null); + } + + /** + * Initializes the extended editor configuration + * + * @generated + */ + protected void initExtendedEditorConfiguration() { + if (configuration == null) { + final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("")) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); + } else { + configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); + } + } + } + + /** + * Updates the preference configuration + * + * @generated + */ + protected void updateExtendedEditorConfiguration() { + String languagePreferred = Activator.getDefault().getPreferenceStore().getString( + IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() + .eClass().getInstanceClassName()); + } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { + configuration = null; + } + } + + /** + * Performs the direct edit usually used by GMF editors. + * + * @param theRequest + * the direct edit request that starts the direct edit system + * @generated + */ + protected void performDefaultDirectEditorEdit(final Request theRequest) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + + @Override + public void run() { + if (isActive() && isEditable()) { + if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) theRequest.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { + DirectEditRequest editRequest = (DirectEditRequest) theRequest; + performDirectEdit(editRequest.getLocation()); + } else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + + /** + * @generated + */ + @Override + protected void handleNotificationEvent(Notification event) { + Object feature = event.getFeature(); + if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { + Integer c = (Integer) event.getNewValue(); + setFontColor(DiagramColorRegistry.getInstance().getColor(c)); + } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { + refreshUnderline(); + } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { + refreshStrikeThrough(); + } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { + refreshFont(); + } else { + if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { + refreshLabel(); + } + if (getParser() instanceof ISemanticParser) { + ISemanticParser modelParser = + (ISemanticParser) getParser(); + if (modelParser.areSemanticElementsAffected(null, event)) { + removeSemanticListeners(); + if (resolveSemanticElement() != null) { + addSemanticListeners(); + } + refreshLabel(); + } + } + } + super.handleNotificationEvent(event); + } + + /** + * @generated + */ + @Override + protected IFigure createFigure() { + IFigure label = createFigurePrim(); + defaultText = getLabelTextHelper(label); + return label; + } + + /** + * @generated + */ + protected IFigure createFigurePrim() { + return new PapyrusWrappingLabel(); + } + +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/NodeCompositeFloatingLabelEditPartCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/NodeCompositeFloatingLabelEditPartCN.java new file mode 100644 index 00000000000..00b39c94d3e --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/NodeCompositeFloatingLabelEditPartCN.java @@ -0,0 +1,860 @@ +/** + * 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.uml.diagram.composite.edit.parts; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.Label; +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.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.RunnableWithResult; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gef.AccessibleEditPart; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.Request; +import org.eclipse.gef.requests.DirectEditRequest; +import org.eclipse.gef.tools.DirectEditManager; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; +import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; +import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; +import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; +import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; +import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; +import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; +import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; +import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; +import org.eclipse.gmf.runtime.notation.FontStyle; +import org.eclipse.gmf.runtime.notation.NotationPackage; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.text.contentassist.IContentAssistProcessor; +import org.eclipse.jface.viewers.ICellEditorValidator; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.extensionpoints.editors.Activator; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; +import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; +import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.ExternalLabelPrimaryDragRoleEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.PapyrusWrappingLabel; +import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; +import org.eclipse.papyrus.uml.diagram.common.editparts.FloatingLabelEditPart; +import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; +import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; +import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; +import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.accessibility.AccessibleEvent; +import org.eclipse.swt.custom.BusyIndicator; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; +import org.eclipse.uml2.uml.Feature; + +/** + * @generated + */ +public class NodeCompositeFloatingLabelEditPartCN extends FloatingLabelEditPart + implements ITextAwareEditPart, IBorderItemEditPart +{ + + /** + * @generated + */ + public static final int VISUAL_ID = 6066; + + /** + * @generated + */ + private DirectEditManager manager; + + /** + * @generated + */ + private IParser parser; + + /** + * @generated + */ + private List parserElements; + + /** + * @generated + */ + private String defaultText; + + /** + * direct edition mode (default, undefined, registered editor, etc.) + * + * @generated + */ + protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; + + /** + * configuration from a registered edit dialog + * + * @generated + */ + protected IDirectEditorConfiguration configuration; + + + /** + * @generated + */ + static { + registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.NodeCompositeFloatingLabelEditPartCN.VISUAL_ID), new Point(0, 0)); + } + + /** + * @generated + */ + public NodeCompositeFloatingLabelEditPartCN(View view) { + super(view); + } + + /** + * @generated + */ + @Override + protected void createDefaultEditPolicies() { + super.createDefaultEditPolicies(); + installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); + installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ExternalLabelPrimaryDragRoleEditPolicy()); + } + + /** + * @generated + */ + @Override + public IBorderItemLocator getBorderItemLocator() { + IFigure parentFigure = getFigure().getParent(); + if (parentFigure != null && parentFigure.getLayoutManager() != null) { + Object constraint = parentFigure.getLayoutManager().getConstraint(getFigure()); + return (IBorderItemLocator) constraint; + } + return null; + } + + /** + * @generated + */ + @Override + public void refreshBounds() { + int x = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_X())).intValue(); + int y = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_Y())).intValue(); + int width = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Width())).intValue(); + int height = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Height())).intValue(); + getBorderItemLocator().setConstraint(new Rectangle(x, y, width, height)); + } + + + /** + * @generated + */ + protected String getLabelTextHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getText(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getText(); + } else { + return ((Label) figure).getText(); + } + } + + /** + * @generated + */ + protected void setLabelTextHelper(IFigure figure, String text) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setText(text); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setText(text); + } else { + ((Label) figure).setText(text); + } + } + + /** + * @generated + */ + protected Image getLabelIconHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getIcon(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getIcon(); + } else { + return ((Label) figure).getIcon(); + } + } + + /** + * @generated + */ + protected void setLabelIconHelper(IFigure figure, Image icon) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setIcon(icon); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setIcon(icon); + } else { + ((Label) figure).setIcon(icon); + } + } + + /** + * @generated + */ + public void setLabel(IFigure + figure) { + unregisterVisuals(); + setFigure(figure); + defaultText = getLabelTextHelper(figure); + registerVisuals(); + refreshVisuals(); + } + + /** + * @generated + */ + @Override + protected List getModelChildren() { + return Collections.EMPTY_LIST; + } + + /** + * @generated + */ + @Override + public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { + return null; + } + + /** + * @generated + */ + public void setParser(IParser parser) { + this.parser = parser; + } + + /** + * @generated + */ + protected EObject getParserElement() { + return resolveSemanticElement(); + } + + /** + * @generated + */ + protected Image getLabelIcon() { + return null; + } + + /** + * @generated + */ + protected String getLabelText() { + String text = null; + EObject parserElement = getParserElement(); + if (parserElement != null && getParser() != null) { + text = getParser().getPrintString( + new EObjectAdapter(parserElement), + getParserOptions().intValue()); + } + if (text == null || text.length() == 0) { + text = defaultText; + } + return text; + } + + /** + * @generated + */ + @Override + public void setLabelText(String text) { + setLabelTextHelper(getFigure(), text); + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + @Override + public String getEditText() { + if (getParserElement() == null || getParser() == null) { + return ""; //$NON-NLS-1$ + } + return getParser().getEditString( + new EObjectAdapter(getParserElement()), + getParserOptions().intValue()); + } + + /** + * @generated + */ + protected boolean isEditable() { + return getParser() != null; + } + + /** + * @generated + */ + @Override + public ICellEditorValidator getEditTextValidator() { + return new ICellEditorValidator() { + + @Override + public String isValid(final Object value) { + if (value instanceof String) { + final EObject element = getParserElement(); + final IParser parser = getParser(); + try { + IParserEditStatus valid = + (IParserEditStatus) getEditingDomain().runExclusive( + new RunnableWithResult.Impl() { + + @Override + public void run() { + setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); + } + }); + return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); + } catch (InterruptedException ie) { + ie.printStackTrace(); + } + } + + // shouldn't get here + return null; + } + }; + } + + /** + * @generated + */ + @Override + public IContentAssistProcessor getCompletionProcessor() { + if (getParserElement() == null || getParser() == null) { + return null; + } + return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); + } + + /** + * @generated + */ + @Override + public ParserOptions getParserOptions() { + return ParserOptions.NONE; + } + + /** + * @generated + */ + @Override + public IParser getParser() { + if (parser == null) { + parser = UMLParserProvider.getParser(UMLElementTypes.Node_3084, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.NodeCompositeFloatingLabelEditPartCN.VISUAL_ID)); + } + return parser; + } + + /** + * @generated + */ + protected DirectEditManager getManager() { + if (manager == null) { + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + } + return manager; + } + + /** + * @generated + */ + protected void setManager(DirectEditManager manager) { + this.manager = manager; + } + + /** + * @generated + */ + protected void performDirectEdit() { + BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { + + @Override + public void run() { + getManager().show(); + } + }); + } + + /** + * @generated + */ + protected void performDirectEdit(Point eventLocation) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); + } + } + + /** + * @generated + */ + private void performDirectEdit(char initialCharacter) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(initialCharacter); + } else { + performDirectEdit(); + } + } + + /** + * @generated + */ + @Override + protected void performDirectEditRequest(Request request) { + + final Request theRequest = request; + + if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { + directEditionMode = getDirectEditionType(); + } + switch (directEditionMode) { + case IDirectEdition.NO_DIRECT_EDITION: + // no direct edition mode => does nothing + return; + case IDirectEdition.EXTENDED_DIRECT_EDITOR: + updateExtendedEditorConfiguration(); + if (configuration == null || configuration.getLanguage() == null) { + // Create default edit manager + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + performDefaultDirectEditorEdit(theRequest); + } else { + configuration.preEditAction(resolveSemanticElement()); + Dialog dialog = null; + if (configuration instanceof ICustomDirectEditorConfiguration) { + setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); + initializeDirectEditManager(theRequest); + return; + } else if (configuration instanceof IPopupEditorConfiguration) { + IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); + helper.showEditor(); + return; + } + else if (configuration instanceof IAdvancedEditorConfiguration) { + dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); + } else if (configuration instanceof IDirectEditorConfiguration) { + dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), + configuration); + } else { + return; + } + final Dialog finalDialog = dialog; + + if (Window.OK == dialog.open()) { + TransactionalEditingDomain domain = getEditingDomain(); + RecordingCommand command = new RecordingCommand(domain, "Edit Label") { + + @Override + protected void doExecute() { + configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); + + } + }; + domain.getCommandStack().execute(command); + } + } + break; + case IDirectEdition.DEFAULT_DIRECT_EDITOR: + initializeDirectEditManager(theRequest); + break; + default: + break; + } + } + + /** + * @generated + */ + protected void initializeDirectEditManager(final Request request) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + @Override + public void run() { + if (isActive() && isEditable()) { + if (request.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } + else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void refreshVisuals() { + super.refreshVisuals(); + refreshLabel(); + refreshFont(); + refreshFontColor(); + refreshUnderline(); + refreshStrikeThrough(); + } + + /** + * @generated + */ + protected void refreshLabel() { + EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); + if (maskLabelPolicy == null) { + maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); + } + if (maskLabelPolicy == null) { + View view = (View) getModel(); + if (view.isVisible()) { + setLabelTextHelper(getFigure(), getLabelText()); + setLabelIconHelper(getFigure(), getLabelIcon()); + } + else { + setLabelTextHelper(getFigure(), ""); //$NON-NLS-1$ + setLabelIconHelper(getFigure(), null); + } + } + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + protected void refreshUnderline() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); + } + if (resolveSemanticElement() instanceof Feature) { + if (((Feature) resolveSemanticElement()).isStatic()) { + ((WrappingLabel) getFigure()).setTextUnderline(true); + } + else { + ((WrappingLabel) getFigure()).setTextUnderline(false); + } + } + } + + /** + * @generated + */ + protected void refreshStrikeThrough() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); + } + } + + /** + * @generated + */ + @Override + protected void refreshFont() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null) { + FontData fontData = new FontData( + style.getFontName(), style.getFontHeight(), + (style.isBold() ? SWT.BOLD : SWT.NORMAL) | + (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); + setFont(fontData); + } + } + + /** + * @generated + */ + @Override + protected void setFontColor(Color color) { + getFigure().setForegroundColor(color); + } + + /** + * @generated + */ + @Override + protected void addSemanticListeners() { + if (getParser() instanceof ISemanticParser) { + EObject element = resolveSemanticElement(); + parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); + for (int i = 0; i < parserElements.size(); i++) { + addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ + } + } else { + super.addSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected void removeSemanticListeners() { + if (parserElements != null) { + for (int i = 0; i < parserElements.size(); i++) { + removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ + } + } else { + super.removeSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected AccessibleEditPart getAccessibleEditPart() { + if (accessibleEP == null) { + accessibleEP = new AccessibleGraphicalEditPart() { + + @Override + public void getName(AccessibleEvent e) { + e.result = getLabelTextHelper(getFigure()); + } + }; + } + return accessibleEP; + } + + /** + * @generated + */ + private View getFontStyleOwnerView() { + return getPrimaryView(); + } + + /** + * Returns the kind of associated editor for direct edition. + * + * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition + * @generated + */ + public int getDirectEditionType() { + if (checkExtendedEditor()) { + initExtendedEditorConfiguration(); + return IDirectEdition.EXTENDED_DIRECT_EDITOR; + } + if (checkDefaultEdition()) { + return IDirectEdition.DEFAULT_DIRECT_EDITOR; + } + + // not a named element. no specific editor => do nothing + return IDirectEdition.NO_DIRECT_EDITION; + } + + /** + * Checks if an extended editor is present. + * + * @return true if an extended editor is present. + * @generated + */ + protected boolean checkExtendedEditor() { + if (resolveSemanticElement() != null) { + return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); + } + return false; + } + + /** + * Checks if a default direct edition is available + * + * @return true if a default direct edition is available + * @generated + */ + protected boolean checkDefaultEdition() { + return (getParser() != null); + } + + /** + * Initializes the extended editor configuration + * + * @generated + */ + protected void initExtendedEditorConfiguration() { + if (configuration == null) { + final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("")) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); + } else { + configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); + } + } + } + + /** + * Updates the preference configuration + * + * @generated + */ + protected void updateExtendedEditorConfiguration() { + String languagePreferred = Activator.getDefault().getPreferenceStore().getString( + IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() + .eClass().getInstanceClassName()); + } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { + configuration = null; + } + } + + /** + * Performs the direct edit usually used by GMF editors. + * + * @param theRequest + * the direct edit request that starts the direct edit system + * @generated + */ + protected void performDefaultDirectEditorEdit(final Request theRequest) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + + @Override + public void run() { + if (isActive() && isEditable()) { + if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) theRequest.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { + DirectEditRequest editRequest = (DirectEditRequest) theRequest; + performDirectEdit(editRequest.getLocation()); + } else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + + /** + * @generated + */ + @Override + protected void handleNotificationEvent(Notification event) { + Object feature = event.getFeature(); + if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { + Integer c = (Integer) event.getNewValue(); + setFontColor(DiagramColorRegistry.getInstance().getColor(c)); + } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { + refreshUnderline(); + } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { + refreshStrikeThrough(); + } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { + refreshFont(); + } else { + if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { + refreshLabel(); + } + if (getParser() instanceof ISemanticParser) { + ISemanticParser modelParser = + (ISemanticParser) getParser(); + if (modelParser.areSemanticElementsAffected(null, event)) { + removeSemanticListeners(); + if (resolveSemanticElement() != null) { + addSemanticListeners(); + } + refreshLabel(); + } + } + } + super.handleNotificationEvent(event); + } + + /** + * @generated + */ + @Override + protected IFigure createFigure() { + IFigure label = createFigurePrim(); + defaultText = getLabelTextHelper(label); + return label; + } + + /** + * @generated + */ + protected IFigure createFigurePrim() { + return new PapyrusWrappingLabel(); + } + +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/NodeCompositeNameEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/NodeCompositeNameEditPart.java index c4ddc52b041..09228f47048 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/NodeCompositeNameEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/NodeCompositeNameEditPart.java @@ -864,7 +864,7 @@ public class NodeCompositeNameEditPart extends PapyrusCompartmentEditPart implem * @generated */ protected void addOwnerElementListeners() { - addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); + addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/NodeCompositeNameEditPartCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/NodeCompositeNameEditPartCN.java index dec1818a094..309b3e82698 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/NodeCompositeNameEditPartCN.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/NodeCompositeNameEditPartCN.java @@ -864,7 +864,7 @@ public class NodeCompositeNameEditPartCN extends PapyrusCompartmentEditPart impl * @generated */ protected void addOwnerElementListeners() { - addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); + addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/OpaqueBehaviorCompositeCompartmentEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/OpaqueBehaviorCompositeCompartmentEditPart.java index 747ca6ae0c8..07b929a6edc 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/OpaqueBehaviorCompositeCompartmentEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/OpaqueBehaviorCompositeCompartmentEditPart.java @@ -26,6 +26,7 @@ import org.eclipse.gmf.runtime.diagram.ui.editpolicies.ResizableCompartmentEditP import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.BorderDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.CustomContainerEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.DuplicatePasteEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.PapyrusCreationEditPolicy; @@ -75,6 +76,7 @@ public class OpaqueBehaviorCompositeCompartmentEditPart extends ShapeCompartment installEditPolicy(EditPolicy.GRAPHICAL_NODE_ROLE, new CustomContainerEditPolicy()); installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, new CustomDiagramDragDropEditPolicy()); installEditPolicy(EditPolicyRoles.CREATION_ROLE, new PortInCompartmentCreationEditPolicy()); + installEditPolicy(BorderDisplayEditPolicy.BORDER_DISPLAY_EDITPOLICY, new BorderDisplayEditPolicy()); } /** diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/OpaqueBehaviorCompositeCompartmentEditPartCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/OpaqueBehaviorCompositeCompartmentEditPartCN.java index ef0dc3e5ea2..5f7f76a594c 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/OpaqueBehaviorCompositeCompartmentEditPartCN.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/OpaqueBehaviorCompositeCompartmentEditPartCN.java @@ -26,6 +26,7 @@ import org.eclipse.gmf.runtime.diagram.ui.editpolicies.ResizableCompartmentEditP import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.BorderDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.CustomContainerEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.DuplicatePasteEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.PapyrusCreationEditPolicy; @@ -75,6 +76,7 @@ public class OpaqueBehaviorCompositeCompartmentEditPartCN extends ShapeCompartme installEditPolicy(EditPolicy.GRAPHICAL_NODE_ROLE, new CustomContainerEditPolicy()); installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, new CustomDiagramDragDropEditPolicy()); installEditPolicy(EditPolicyRoles.CREATION_ROLE, new PortInCompartmentCreationEditPolicy()); + installEditPolicy(BorderDisplayEditPolicy.BORDER_DISPLAY_EDITPOLICY, new BorderDisplayEditPolicy()); } /** diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/OpaqueBehaviorCompositeEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/OpaqueBehaviorCompositeEditPart.java index fdc61444632..56a17850658 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/OpaqueBehaviorCompositeEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/OpaqueBehaviorCompositeEditPart.java @@ -11,28 +11,37 @@ */ package org.eclipse.papyrus.uml.diagram.composite.edit.parts; +import java.util.Collections; +import java.util.List; + import org.eclipse.draw2d.IFigure; import org.eclipse.draw2d.PositionConstants; import org.eclipse.emf.common.notify.Notification; import org.eclipse.gef.EditPart; import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.GraphicalEditPart; 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.handles.MoveHandle; import org.eclipse.gef.requests.CreateRequest; import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.BorderItemSelectionEditPolicy; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.DragDropEditPolicy; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles; import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; -import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure; import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure; +import org.eclipse.gmf.runtime.notation.Edge; +import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.GetChildLayoutEditPolicy; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.IPapyrusNodeFigure; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.RoundedRectangleNodePlateFigure; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.SelectableBorderedNodeFigure; -import org.eclipse.papyrus.uml.diagram.common.editparts.NamedElementEditPart; +import org.eclipse.papyrus.uml.diagram.common.editparts.RoundedCompartmentEditPart; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AffixedNodeAlignmentEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeNodeLabelDisplayEditPolicy; @@ -41,11 +50,11 @@ import org.eclipse.papyrus.uml.diagram.common.editpolicies.PapyrusCreationEditPo import org.eclipse.papyrus.uml.diagram.common.editpolicies.QualifiedNameDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.ShowHideClassifierContentsEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.ShowHideCompartmentEditPolicy; +import org.eclipse.papyrus.uml.diagram.common.locator.RoundedRectangleLabelPositionLocator; import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.BehaviorLayoutEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.CustomDiagramDragDropEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.RemoveOrphanViewPolicy; import org.eclipse.papyrus.uml.diagram.composite.custom.figures.OpaqueBehaviorCompositeFigure; -import org.eclipse.papyrus.uml.diagram.composite.custom.locators.PortPositionLocator; import org.eclipse.papyrus.uml.diagram.composite.edit.policies.OpaqueBehaviorCompositeItemSemanticEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; import org.eclipse.swt.graphics.Color; @@ -53,7 +62,7 @@ import org.eclipse.swt.graphics.Color; /** * @generated */ -public class OpaqueBehaviorCompositeEditPart extends NamedElementEditPart { +public class OpaqueBehaviorCompositeEditPart extends RoundedCompartmentEditPart { /** * @generated @@ -95,6 +104,7 @@ public class OpaqueBehaviorCompositeEditPart extends NamedElementEditPart { installEditPolicy(ShowHideCompartmentEditPolicy.SHOW_HIDE_COMPARTMENT_POLICY, new ShowHideCompartmentEditPolicy()); installEditPolicy(AffixedNodeAlignmentEditPolicy.AFFIXED_CHILD_ALIGNMENT_ROLE, new AffixedNodeAlignmentEditPolicy()); installEditPolicy("REMOVE_ORPHAN_VIEW", new RemoveOrphanViewPolicy()); //$NON-NLS-1$ + installEditPolicy(EditPolicy.LAYOUT_ROLE, new GetChildLayoutEditPolicy()); // XXX need an SCR to runtime to have another abstract superclass that would let children add reasonable editpolicies // removeEditPolicy(org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles.CONNECTION_HANDLES_ROLE); } @@ -109,6 +119,17 @@ public class OpaqueBehaviorCompositeEditPart extends NamedElementEditPart { protected EditPolicy createChildEditPolicy(EditPart child) { View childView = (View) child.getModel(); switch (UMLVisualIDRegistry.getVisualID(childView)) { + case OpaqueBehaviorCompositeFloatingLabelEditPart.VISUAL_ID: + return new BorderItemSelectionEditPolicy() { + + @Override + protected List createSelectionHandles() { + MoveHandle mh = new MoveHandle((GraphicalEditPart) getHost()); + mh.setBorder(null); + return Collections.singletonList(mh); + } + } + ; case PortEditPart.VISUAL_ID: case ParameterEditPart.VISUAL_ID: return new BorderItemResizableEditPolicy(); @@ -140,6 +161,19 @@ public class OpaqueBehaviorCompositeEditPart extends NamedElementEditPart { **/ @Override protected void handleNotificationEvent(Notification event) { + /* + * when a node have external node labels, the methods refreshChildren() remove the EditPart corresponding to the Label from the EditPart + * Registry. After that, we can't reset the visibility to true (using the Show/Hide Label Action)! + */ + if (NotationPackage.eINSTANCE.getView_Visible().equals(event.getFeature())) { + Object notifier = event.getNotifier(); + List modelChildren = ((View) getModel()).getChildren(); + if (!(notifier instanceof Edge)) { + if (modelChildren.contains(event.getNotifier())) { + return; + } + } + } super.handleNotificationEvent(event); } @@ -181,9 +215,9 @@ public class OpaqueBehaviorCompositeEditPart extends NamedElementEditPart { - //Papyrus Gencode :Affixed Port locator + // Papyrus Gencode :Affixed Port locator if (childEditPart instanceof PortEditPart) { - IBorderItemLocator locator = new PortPositionLocator(getMainFigure(), PositionConstants.NONE); + IBorderItemLocator locator = new org.eclipse.papyrus.uml.diagram.common.locator.PortPositionLocator(getMainFigure(), PositionConstants.NONE); getBorderedFigure().getBorderItemContainer().add(((PortEditPart) childEditPart).getFigure(), locator); return true; } @@ -191,9 +225,9 @@ public class OpaqueBehaviorCompositeEditPart extends NamedElementEditPart { - //Papyrus Gencode :Affixed Port locator + // Papyrus Gencode :Affixed Port locator if (childEditPart instanceof ParameterEditPart) { - IBorderItemLocator locator = new PortPositionLocator(getMainFigure(), PositionConstants.NONE); + IBorderItemLocator locator = new org.eclipse.papyrus.uml.diagram.common.locator.PortPositionLocator(getMainFigure(), PositionConstants.NONE); getBorderedFigure().getBorderItemContainer().add(((ParameterEditPart) childEditPart).getFigure(), locator); return true; } @@ -261,12 +295,26 @@ public class OpaqueBehaviorCompositeEditPart extends NamedElementEditPart { return getContentPane(); } + /** + * @generated + */ + @Override + protected void addBorderItem(IFigure borderItemContainer, IBorderItemEditPart borderItemEditPart) { + if (borderItemEditPart instanceof OpaqueBehaviorCompositeFloatingLabelEditPart) { + IBorderItemLocator locator = new RoundedRectangleLabelPositionLocator(getMainFigure()); + borderItemContainer.add(borderItemEditPart.getFigure(), locator); + } else + { + super.addBorderItem(borderItemContainer, borderItemEditPart); + } + } + /** * @generated */ @Override protected NodeFigure createNodePlate() { - DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(40, 40); + RoundedRectangleNodePlateFigure result = new RoundedRectangleNodePlateFigure(40, 40); return result; } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/OpaqueBehaviorCompositeEditPartCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/OpaqueBehaviorCompositeEditPartCN.java index 4f90075b62a..7dda7f053fd 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/OpaqueBehaviorCompositeEditPartCN.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/OpaqueBehaviorCompositeEditPartCN.java @@ -11,28 +11,37 @@ */ package org.eclipse.papyrus.uml.diagram.composite.edit.parts; +import java.util.Collections; +import java.util.List; + import org.eclipse.draw2d.IFigure; import org.eclipse.draw2d.PositionConstants; import org.eclipse.emf.common.notify.Notification; import org.eclipse.gef.EditPart; import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.GraphicalEditPart; 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.handles.MoveHandle; import org.eclipse.gef.requests.CreateRequest; import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.BorderItemSelectionEditPolicy; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.DragDropEditPolicy; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles; import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; -import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure; import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure; +import org.eclipse.gmf.runtime.notation.Edge; +import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.GetChildLayoutEditPolicy; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.IPapyrusNodeFigure; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.RoundedRectangleNodePlateFigure; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.SelectableBorderedNodeFigure; -import org.eclipse.papyrus.uml.diagram.common.editparts.NamedElementEditPart; +import org.eclipse.papyrus.uml.diagram.common.editparts.RoundedCompartmentEditPart; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AffixedNodeAlignmentEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeNodeLabelDisplayEditPolicy; @@ -41,11 +50,11 @@ import org.eclipse.papyrus.uml.diagram.common.editpolicies.PapyrusCreationEditPo import org.eclipse.papyrus.uml.diagram.common.editpolicies.QualifiedNameDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.ShowHideClassifierContentsEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.ShowHideCompartmentEditPolicy; +import org.eclipse.papyrus.uml.diagram.common.locator.RoundedRectangleLabelPositionLocator; import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.BehaviorLayoutEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.CustomDiagramDragDropEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.RemoveOrphanViewPolicy; import org.eclipse.papyrus.uml.diagram.composite.custom.figures.OpaqueBehaviorCompositeFigure; -import org.eclipse.papyrus.uml.diagram.composite.custom.locators.PortPositionLocator; import org.eclipse.papyrus.uml.diagram.composite.edit.policies.OpaqueBehaviorCompositeItemSemanticEditPolicyCN; import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; import org.eclipse.swt.graphics.Color; @@ -53,7 +62,7 @@ import org.eclipse.swt.graphics.Color; /** * @generated */ -public class OpaqueBehaviorCompositeEditPartCN extends NamedElementEditPart { +public class OpaqueBehaviorCompositeEditPartCN extends RoundedCompartmentEditPart { /** * @generated @@ -95,6 +104,7 @@ public class OpaqueBehaviorCompositeEditPartCN extends NamedElementEditPart { installEditPolicy(ShowHideCompartmentEditPolicy.SHOW_HIDE_COMPARTMENT_POLICY, new ShowHideCompartmentEditPolicy()); installEditPolicy(AffixedNodeAlignmentEditPolicy.AFFIXED_CHILD_ALIGNMENT_ROLE, new AffixedNodeAlignmentEditPolicy()); installEditPolicy("REMOVE_ORPHAN_VIEW", new RemoveOrphanViewPolicy()); //$NON-NLS-1$ + installEditPolicy(EditPolicy.LAYOUT_ROLE, new GetChildLayoutEditPolicy()); // XXX need an SCR to runtime to have another abstract superclass that would let children add reasonable editpolicies // removeEditPolicy(org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles.CONNECTION_HANDLES_ROLE); } @@ -109,6 +119,17 @@ public class OpaqueBehaviorCompositeEditPartCN extends NamedElementEditPart { protected EditPolicy createChildEditPolicy(EditPart child) { View childView = (View) child.getModel(); switch (UMLVisualIDRegistry.getVisualID(childView)) { + case OpaqueBehaviorCompositeFloatingLabelEditPartCN.VISUAL_ID: + return new BorderItemSelectionEditPolicy() { + + @Override + protected List createSelectionHandles() { + MoveHandle mh = new MoveHandle((GraphicalEditPart) getHost()); + mh.setBorder(null); + return Collections.singletonList(mh); + } + } + ; case PortEditPart.VISUAL_ID: case ParameterEditPart.VISUAL_ID: return new BorderItemResizableEditPolicy(); @@ -140,6 +161,19 @@ public class OpaqueBehaviorCompositeEditPartCN extends NamedElementEditPart { **/ @Override protected void handleNotificationEvent(Notification event) { + /* + * when a node have external node labels, the methods refreshChildren() remove the EditPart corresponding to the Label from the EditPart + * Registry. After that, we can't reset the visibility to true (using the Show/Hide Label Action)! + */ + if (NotationPackage.eINSTANCE.getView_Visible().equals(event.getFeature())) { + Object notifier = event.getNotifier(); + List modelChildren = ((View) getModel()).getChildren(); + if (!(notifier instanceof Edge)) { + if (modelChildren.contains(event.getNotifier())) { + return; + } + } + } super.handleNotificationEvent(event); } @@ -181,9 +215,9 @@ public class OpaqueBehaviorCompositeEditPartCN extends NamedElementEditPart { - //Papyrus Gencode :Affixed Port locator + // Papyrus Gencode :Affixed Port locator if (childEditPart instanceof PortEditPart) { - IBorderItemLocator locator = new PortPositionLocator(getMainFigure(), PositionConstants.NONE); + IBorderItemLocator locator = new org.eclipse.papyrus.uml.diagram.common.locator.PortPositionLocator(getMainFigure(), PositionConstants.NONE); getBorderedFigure().getBorderItemContainer().add(((PortEditPart) childEditPart).getFigure(), locator); return true; } @@ -191,9 +225,9 @@ public class OpaqueBehaviorCompositeEditPartCN extends NamedElementEditPart { - //Papyrus Gencode :Affixed Port locator + // Papyrus Gencode :Affixed Port locator if (childEditPart instanceof ParameterEditPart) { - IBorderItemLocator locator = new PortPositionLocator(getMainFigure(), PositionConstants.NONE); + IBorderItemLocator locator = new org.eclipse.papyrus.uml.diagram.common.locator.PortPositionLocator(getMainFigure(), PositionConstants.NONE); getBorderedFigure().getBorderItemContainer().add(((ParameterEditPart) childEditPart).getFigure(), locator); return true; } @@ -261,12 +295,26 @@ public class OpaqueBehaviorCompositeEditPartCN extends NamedElementEditPart { return getContentPane(); } + /** + * @generated + */ + @Override + protected void addBorderItem(IFigure borderItemContainer, IBorderItemEditPart borderItemEditPart) { + if (borderItemEditPart instanceof OpaqueBehaviorCompositeFloatingLabelEditPartCN) { + IBorderItemLocator locator = new RoundedRectangleLabelPositionLocator(getMainFigure()); + borderItemContainer.add(borderItemEditPart.getFigure(), locator); + } else + { + super.addBorderItem(borderItemContainer, borderItemEditPart); + } + } + /** * @generated */ @Override protected NodeFigure createNodePlate() { - DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(40, 40); + RoundedRectangleNodePlateFigure result = new RoundedRectangleNodePlateFigure(40, 40); return result; } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/OpaqueBehaviorCompositeFloatingLabelEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/OpaqueBehaviorCompositeFloatingLabelEditPart.java new file mode 100644 index 00000000000..932e2f7befe --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/OpaqueBehaviorCompositeFloatingLabelEditPart.java @@ -0,0 +1,860 @@ +/** + * 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.uml.diagram.composite.edit.parts; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.Label; +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.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.RunnableWithResult; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gef.AccessibleEditPart; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.Request; +import org.eclipse.gef.requests.DirectEditRequest; +import org.eclipse.gef.tools.DirectEditManager; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; +import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; +import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; +import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; +import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; +import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; +import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; +import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; +import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; +import org.eclipse.gmf.runtime.notation.FontStyle; +import org.eclipse.gmf.runtime.notation.NotationPackage; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.text.contentassist.IContentAssistProcessor; +import org.eclipse.jface.viewers.ICellEditorValidator; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.extensionpoints.editors.Activator; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; +import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; +import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.ExternalLabelPrimaryDragRoleEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.PapyrusWrappingLabel; +import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; +import org.eclipse.papyrus.uml.diagram.common.editparts.FloatingLabelEditPart; +import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; +import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; +import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; +import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.accessibility.AccessibleEvent; +import org.eclipse.swt.custom.BusyIndicator; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; +import org.eclipse.uml2.uml.Feature; + +/** + * @generated + */ +public class OpaqueBehaviorCompositeFloatingLabelEditPart extends FloatingLabelEditPart + implements ITextAwareEditPart, IBorderItemEditPart +{ + + /** + * @generated + */ + public static final int VISUAL_ID = 6084; + + /** + * @generated + */ + private DirectEditManager manager; + + /** + * @generated + */ + private IParser parser; + + /** + * @generated + */ + private List parserElements; + + /** + * @generated + */ + private String defaultText; + + /** + * direct edition mode (default, undefined, registered editor, etc.) + * + * @generated + */ + protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; + + /** + * configuration from a registered edit dialog + * + * @generated + */ + protected IDirectEditorConfiguration configuration; + + + /** + * @generated + */ + static { + registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.OpaqueBehaviorCompositeFloatingLabelEditPart.VISUAL_ID), new Point(0, 0)); + } + + /** + * @generated + */ + public OpaqueBehaviorCompositeFloatingLabelEditPart(View view) { + super(view); + } + + /** + * @generated + */ + @Override + protected void createDefaultEditPolicies() { + super.createDefaultEditPolicies(); + installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); + installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ExternalLabelPrimaryDragRoleEditPolicy()); + } + + /** + * @generated + */ + @Override + public IBorderItemLocator getBorderItemLocator() { + IFigure parentFigure = getFigure().getParent(); + if (parentFigure != null && parentFigure.getLayoutManager() != null) { + Object constraint = parentFigure.getLayoutManager().getConstraint(getFigure()); + return (IBorderItemLocator) constraint; + } + return null; + } + + /** + * @generated + */ + @Override + public void refreshBounds() { + int x = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_X())).intValue(); + int y = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_Y())).intValue(); + int width = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Width())).intValue(); + int height = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Height())).intValue(); + getBorderItemLocator().setConstraint(new Rectangle(x, y, width, height)); + } + + + /** + * @generated + */ + protected String getLabelTextHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getText(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getText(); + } else { + return ((Label) figure).getText(); + } + } + + /** + * @generated + */ + protected void setLabelTextHelper(IFigure figure, String text) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setText(text); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setText(text); + } else { + ((Label) figure).setText(text); + } + } + + /** + * @generated + */ + protected Image getLabelIconHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getIcon(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getIcon(); + } else { + return ((Label) figure).getIcon(); + } + } + + /** + * @generated + */ + protected void setLabelIconHelper(IFigure figure, Image icon) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setIcon(icon); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setIcon(icon); + } else { + ((Label) figure).setIcon(icon); + } + } + + /** + * @generated + */ + public void setLabel(IFigure + figure) { + unregisterVisuals(); + setFigure(figure); + defaultText = getLabelTextHelper(figure); + registerVisuals(); + refreshVisuals(); + } + + /** + * @generated + */ + @Override + protected List getModelChildren() { + return Collections.EMPTY_LIST; + } + + /** + * @generated + */ + @Override + public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { + return null; + } + + /** + * @generated + */ + public void setParser(IParser parser) { + this.parser = parser; + } + + /** + * @generated + */ + protected EObject getParserElement() { + return resolveSemanticElement(); + } + + /** + * @generated + */ + protected Image getLabelIcon() { + return null; + } + + /** + * @generated + */ + protected String getLabelText() { + String text = null; + EObject parserElement = getParserElement(); + if (parserElement != null && getParser() != null) { + text = getParser().getPrintString( + new EObjectAdapter(parserElement), + getParserOptions().intValue()); + } + if (text == null || text.length() == 0) { + text = defaultText; + } + return text; + } + + /** + * @generated + */ + @Override + public void setLabelText(String text) { + setLabelTextHelper(getFigure(), text); + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + @Override + public String getEditText() { + if (getParserElement() == null || getParser() == null) { + return ""; //$NON-NLS-1$ + } + return getParser().getEditString( + new EObjectAdapter(getParserElement()), + getParserOptions().intValue()); + } + + /** + * @generated + */ + protected boolean isEditable() { + return getParser() != null; + } + + /** + * @generated + */ + @Override + public ICellEditorValidator getEditTextValidator() { + return new ICellEditorValidator() { + + @Override + public String isValid(final Object value) { + if (value instanceof String) { + final EObject element = getParserElement(); + final IParser parser = getParser(); + try { + IParserEditStatus valid = + (IParserEditStatus) getEditingDomain().runExclusive( + new RunnableWithResult.Impl() { + + @Override + public void run() { + setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); + } + }); + return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); + } catch (InterruptedException ie) { + ie.printStackTrace(); + } + } + + // shouldn't get here + return null; + } + }; + } + + /** + * @generated + */ + @Override + public IContentAssistProcessor getCompletionProcessor() { + if (getParserElement() == null || getParser() == null) { + return null; + } + return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); + } + + /** + * @generated + */ + @Override + public ParserOptions getParserOptions() { + return ParserOptions.NONE; + } + + /** + * @generated + */ + @Override + public IParser getParser() { + if (parser == null) { + parser = UMLParserProvider.getParser(UMLElementTypes.OpaqueBehavior_2065, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.OpaqueBehaviorCompositeFloatingLabelEditPart.VISUAL_ID)); + } + return parser; + } + + /** + * @generated + */ + protected DirectEditManager getManager() { + if (manager == null) { + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + } + return manager; + } + + /** + * @generated + */ + protected void setManager(DirectEditManager manager) { + this.manager = manager; + } + + /** + * @generated + */ + protected void performDirectEdit() { + BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { + + @Override + public void run() { + getManager().show(); + } + }); + } + + /** + * @generated + */ + protected void performDirectEdit(Point eventLocation) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); + } + } + + /** + * @generated + */ + private void performDirectEdit(char initialCharacter) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(initialCharacter); + } else { + performDirectEdit(); + } + } + + /** + * @generated + */ + @Override + protected void performDirectEditRequest(Request request) { + + final Request theRequest = request; + + if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { + directEditionMode = getDirectEditionType(); + } + switch (directEditionMode) { + case IDirectEdition.NO_DIRECT_EDITION: + // no direct edition mode => does nothing + return; + case IDirectEdition.EXTENDED_DIRECT_EDITOR: + updateExtendedEditorConfiguration(); + if (configuration == null || configuration.getLanguage() == null) { + // Create default edit manager + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + performDefaultDirectEditorEdit(theRequest); + } else { + configuration.preEditAction(resolveSemanticElement()); + Dialog dialog = null; + if (configuration instanceof ICustomDirectEditorConfiguration) { + setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); + initializeDirectEditManager(theRequest); + return; + } else if (configuration instanceof IPopupEditorConfiguration) { + IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); + helper.showEditor(); + return; + } + else if (configuration instanceof IAdvancedEditorConfiguration) { + dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); + } else if (configuration instanceof IDirectEditorConfiguration) { + dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), + configuration); + } else { + return; + } + final Dialog finalDialog = dialog; + + if (Window.OK == dialog.open()) { + TransactionalEditingDomain domain = getEditingDomain(); + RecordingCommand command = new RecordingCommand(domain, "Edit Label") { + + @Override + protected void doExecute() { + configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); + + } + }; + domain.getCommandStack().execute(command); + } + } + break; + case IDirectEdition.DEFAULT_DIRECT_EDITOR: + initializeDirectEditManager(theRequest); + break; + default: + break; + } + } + + /** + * @generated + */ + protected void initializeDirectEditManager(final Request request) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + @Override + public void run() { + if (isActive() && isEditable()) { + if (request.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } + else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void refreshVisuals() { + super.refreshVisuals(); + refreshLabel(); + refreshFont(); + refreshFontColor(); + refreshUnderline(); + refreshStrikeThrough(); + } + + /** + * @generated + */ + protected void refreshLabel() { + EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); + if (maskLabelPolicy == null) { + maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); + } + if (maskLabelPolicy == null) { + View view = (View) getModel(); + if (view.isVisible()) { + setLabelTextHelper(getFigure(), getLabelText()); + setLabelIconHelper(getFigure(), getLabelIcon()); + } + else { + setLabelTextHelper(getFigure(), ""); //$NON-NLS-1$ + setLabelIconHelper(getFigure(), null); + } + } + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + protected void refreshUnderline() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); + } + if (resolveSemanticElement() instanceof Feature) { + if (((Feature) resolveSemanticElement()).isStatic()) { + ((WrappingLabel) getFigure()).setTextUnderline(true); + } + else { + ((WrappingLabel) getFigure()).setTextUnderline(false); + } + } + } + + /** + * @generated + */ + protected void refreshStrikeThrough() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); + } + } + + /** + * @generated + */ + @Override + protected void refreshFont() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null) { + FontData fontData = new FontData( + style.getFontName(), style.getFontHeight(), + (style.isBold() ? SWT.BOLD : SWT.NORMAL) | + (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); + setFont(fontData); + } + } + + /** + * @generated + */ + @Override + protected void setFontColor(Color color) { + getFigure().setForegroundColor(color); + } + + /** + * @generated + */ + @Override + protected void addSemanticListeners() { + if (getParser() instanceof ISemanticParser) { + EObject element = resolveSemanticElement(); + parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); + for (int i = 0; i < parserElements.size(); i++) { + addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ + } + } else { + super.addSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected void removeSemanticListeners() { + if (parserElements != null) { + for (int i = 0; i < parserElements.size(); i++) { + removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ + } + } else { + super.removeSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected AccessibleEditPart getAccessibleEditPart() { + if (accessibleEP == null) { + accessibleEP = new AccessibleGraphicalEditPart() { + + @Override + public void getName(AccessibleEvent e) { + e.result = getLabelTextHelper(getFigure()); + } + }; + } + return accessibleEP; + } + + /** + * @generated + */ + private View getFontStyleOwnerView() { + return getPrimaryView(); + } + + /** + * Returns the kind of associated editor for direct edition. + * + * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition + * @generated + */ + public int getDirectEditionType() { + if (checkExtendedEditor()) { + initExtendedEditorConfiguration(); + return IDirectEdition.EXTENDED_DIRECT_EDITOR; + } + if (checkDefaultEdition()) { + return IDirectEdition.DEFAULT_DIRECT_EDITOR; + } + + // not a named element. no specific editor => do nothing + return IDirectEdition.NO_DIRECT_EDITION; + } + + /** + * Checks if an extended editor is present. + * + * @return true if an extended editor is present. + * @generated + */ + protected boolean checkExtendedEditor() { + if (resolveSemanticElement() != null) { + return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); + } + return false; + } + + /** + * Checks if a default direct edition is available + * + * @return true if a default direct edition is available + * @generated + */ + protected boolean checkDefaultEdition() { + return (getParser() != null); + } + + /** + * Initializes the extended editor configuration + * + * @generated + */ + protected void initExtendedEditorConfiguration() { + if (configuration == null) { + final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("")) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); + } else { + configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); + } + } + } + + /** + * Updates the preference configuration + * + * @generated + */ + protected void updateExtendedEditorConfiguration() { + String languagePreferred = Activator.getDefault().getPreferenceStore().getString( + IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() + .eClass().getInstanceClassName()); + } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { + configuration = null; + } + } + + /** + * Performs the direct edit usually used by GMF editors. + * + * @param theRequest + * the direct edit request that starts the direct edit system + * @generated + */ + protected void performDefaultDirectEditorEdit(final Request theRequest) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + + @Override + public void run() { + if (isActive() && isEditable()) { + if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) theRequest.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { + DirectEditRequest editRequest = (DirectEditRequest) theRequest; + performDirectEdit(editRequest.getLocation()); + } else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + + /** + * @generated + */ + @Override + protected void handleNotificationEvent(Notification event) { + Object feature = event.getFeature(); + if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { + Integer c = (Integer) event.getNewValue(); + setFontColor(DiagramColorRegistry.getInstance().getColor(c)); + } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { + refreshUnderline(); + } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { + refreshStrikeThrough(); + } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { + refreshFont(); + } else { + if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { + refreshLabel(); + } + if (getParser() instanceof ISemanticParser) { + ISemanticParser modelParser = + (ISemanticParser) getParser(); + if (modelParser.areSemanticElementsAffected(null, event)) { + removeSemanticListeners(); + if (resolveSemanticElement() != null) { + addSemanticListeners(); + } + refreshLabel(); + } + } + } + super.handleNotificationEvent(event); + } + + /** + * @generated + */ + @Override + protected IFigure createFigure() { + IFigure label = createFigurePrim(); + defaultText = getLabelTextHelper(label); + return label; + } + + /** + * @generated + */ + protected IFigure createFigurePrim() { + return new PapyrusWrappingLabel(); + } + +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/OpaqueBehaviorCompositeFloatingLabelEditPartCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/OpaqueBehaviorCompositeFloatingLabelEditPartCN.java new file mode 100644 index 00000000000..d1460d85aa6 --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/OpaqueBehaviorCompositeFloatingLabelEditPartCN.java @@ -0,0 +1,860 @@ +/** + * 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.uml.diagram.composite.edit.parts; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.Label; +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.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.RunnableWithResult; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gef.AccessibleEditPart; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.Request; +import org.eclipse.gef.requests.DirectEditRequest; +import org.eclipse.gef.tools.DirectEditManager; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; +import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; +import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; +import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; +import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; +import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; +import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; +import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; +import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; +import org.eclipse.gmf.runtime.notation.FontStyle; +import org.eclipse.gmf.runtime.notation.NotationPackage; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.text.contentassist.IContentAssistProcessor; +import org.eclipse.jface.viewers.ICellEditorValidator; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.extensionpoints.editors.Activator; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; +import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; +import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.ExternalLabelPrimaryDragRoleEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.PapyrusWrappingLabel; +import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; +import org.eclipse.papyrus.uml.diagram.common.editparts.FloatingLabelEditPart; +import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; +import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; +import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; +import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.accessibility.AccessibleEvent; +import org.eclipse.swt.custom.BusyIndicator; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; +import org.eclipse.uml2.uml.Feature; + +/** + * @generated + */ +public class OpaqueBehaviorCompositeFloatingLabelEditPartCN extends FloatingLabelEditPart + implements ITextAwareEditPart, IBorderItemEditPart +{ + + /** + * @generated + */ + public static final int VISUAL_ID = 6062; + + /** + * @generated + */ + private DirectEditManager manager; + + /** + * @generated + */ + private IParser parser; + + /** + * @generated + */ + private List parserElements; + + /** + * @generated + */ + private String defaultText; + + /** + * direct edition mode (default, undefined, registered editor, etc.) + * + * @generated + */ + protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; + + /** + * configuration from a registered edit dialog + * + * @generated + */ + protected IDirectEditorConfiguration configuration; + + + /** + * @generated + */ + static { + registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.OpaqueBehaviorCompositeFloatingLabelEditPartCN.VISUAL_ID), new Point(0, 0)); + } + + /** + * @generated + */ + public OpaqueBehaviorCompositeFloatingLabelEditPartCN(View view) { + super(view); + } + + /** + * @generated + */ + @Override + protected void createDefaultEditPolicies() { + super.createDefaultEditPolicies(); + installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); + installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ExternalLabelPrimaryDragRoleEditPolicy()); + } + + /** + * @generated + */ + @Override + public IBorderItemLocator getBorderItemLocator() { + IFigure parentFigure = getFigure().getParent(); + if (parentFigure != null && parentFigure.getLayoutManager() != null) { + Object constraint = parentFigure.getLayoutManager().getConstraint(getFigure()); + return (IBorderItemLocator) constraint; + } + return null; + } + + /** + * @generated + */ + @Override + public void refreshBounds() { + int x = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_X())).intValue(); + int y = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_Y())).intValue(); + int width = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Width())).intValue(); + int height = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Height())).intValue(); + getBorderItemLocator().setConstraint(new Rectangle(x, y, width, height)); + } + + + /** + * @generated + */ + protected String getLabelTextHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getText(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getText(); + } else { + return ((Label) figure).getText(); + } + } + + /** + * @generated + */ + protected void setLabelTextHelper(IFigure figure, String text) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setText(text); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setText(text); + } else { + ((Label) figure).setText(text); + } + } + + /** + * @generated + */ + protected Image getLabelIconHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getIcon(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getIcon(); + } else { + return ((Label) figure).getIcon(); + } + } + + /** + * @generated + */ + protected void setLabelIconHelper(IFigure figure, Image icon) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setIcon(icon); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setIcon(icon); + } else { + ((Label) figure).setIcon(icon); + } + } + + /** + * @generated + */ + public void setLabel(IFigure + figure) { + unregisterVisuals(); + setFigure(figure); + defaultText = getLabelTextHelper(figure); + registerVisuals(); + refreshVisuals(); + } + + /** + * @generated + */ + @Override + protected List getModelChildren() { + return Collections.EMPTY_LIST; + } + + /** + * @generated + */ + @Override + public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { + return null; + } + + /** + * @generated + */ + public void setParser(IParser parser) { + this.parser = parser; + } + + /** + * @generated + */ + protected EObject getParserElement() { + return resolveSemanticElement(); + } + + /** + * @generated + */ + protected Image getLabelIcon() { + return null; + } + + /** + * @generated + */ + protected String getLabelText() { + String text = null; + EObject parserElement = getParserElement(); + if (parserElement != null && getParser() != null) { + text = getParser().getPrintString( + new EObjectAdapter(parserElement), + getParserOptions().intValue()); + } + if (text == null || text.length() == 0) { + text = defaultText; + } + return text; + } + + /** + * @generated + */ + @Override + public void setLabelText(String text) { + setLabelTextHelper(getFigure(), text); + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + @Override + public String getEditText() { + if (getParserElement() == null || getParser() == null) { + return ""; //$NON-NLS-1$ + } + return getParser().getEditString( + new EObjectAdapter(getParserElement()), + getParserOptions().intValue()); + } + + /** + * @generated + */ + protected boolean isEditable() { + return getParser() != null; + } + + /** + * @generated + */ + @Override + public ICellEditorValidator getEditTextValidator() { + return new ICellEditorValidator() { + + @Override + public String isValid(final Object value) { + if (value instanceof String) { + final EObject element = getParserElement(); + final IParser parser = getParser(); + try { + IParserEditStatus valid = + (IParserEditStatus) getEditingDomain().runExclusive( + new RunnableWithResult.Impl() { + + @Override + public void run() { + setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); + } + }); + return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); + } catch (InterruptedException ie) { + ie.printStackTrace(); + } + } + + // shouldn't get here + return null; + } + }; + } + + /** + * @generated + */ + @Override + public IContentAssistProcessor getCompletionProcessor() { + if (getParserElement() == null || getParser() == null) { + return null; + } + return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); + } + + /** + * @generated + */ + @Override + public ParserOptions getParserOptions() { + return ParserOptions.NONE; + } + + /** + * @generated + */ + @Override + public IParser getParser() { + if (parser == null) { + parser = UMLParserProvider.getParser(UMLElementTypes.OpaqueBehavior_3077, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.OpaqueBehaviorCompositeFloatingLabelEditPartCN.VISUAL_ID)); + } + return parser; + } + + /** + * @generated + */ + protected DirectEditManager getManager() { + if (manager == null) { + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + } + return manager; + } + + /** + * @generated + */ + protected void setManager(DirectEditManager manager) { + this.manager = manager; + } + + /** + * @generated + */ + protected void performDirectEdit() { + BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { + + @Override + public void run() { + getManager().show(); + } + }); + } + + /** + * @generated + */ + protected void performDirectEdit(Point eventLocation) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); + } + } + + /** + * @generated + */ + private void performDirectEdit(char initialCharacter) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(initialCharacter); + } else { + performDirectEdit(); + } + } + + /** + * @generated + */ + @Override + protected void performDirectEditRequest(Request request) { + + final Request theRequest = request; + + if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { + directEditionMode = getDirectEditionType(); + } + switch (directEditionMode) { + case IDirectEdition.NO_DIRECT_EDITION: + // no direct edition mode => does nothing + return; + case IDirectEdition.EXTENDED_DIRECT_EDITOR: + updateExtendedEditorConfiguration(); + if (configuration == null || configuration.getLanguage() == null) { + // Create default edit manager + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + performDefaultDirectEditorEdit(theRequest); + } else { + configuration.preEditAction(resolveSemanticElement()); + Dialog dialog = null; + if (configuration instanceof ICustomDirectEditorConfiguration) { + setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); + initializeDirectEditManager(theRequest); + return; + } else if (configuration instanceof IPopupEditorConfiguration) { + IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); + helper.showEditor(); + return; + } + else if (configuration instanceof IAdvancedEditorConfiguration) { + dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); + } else if (configuration instanceof IDirectEditorConfiguration) { + dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), + configuration); + } else { + return; + } + final Dialog finalDialog = dialog; + + if (Window.OK == dialog.open()) { + TransactionalEditingDomain domain = getEditingDomain(); + RecordingCommand command = new RecordingCommand(domain, "Edit Label") { + + @Override + protected void doExecute() { + configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); + + } + }; + domain.getCommandStack().execute(command); + } + } + break; + case IDirectEdition.DEFAULT_DIRECT_EDITOR: + initializeDirectEditManager(theRequest); + break; + default: + break; + } + } + + /** + * @generated + */ + protected void initializeDirectEditManager(final Request request) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + @Override + public void run() { + if (isActive() && isEditable()) { + if (request.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } + else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void refreshVisuals() { + super.refreshVisuals(); + refreshLabel(); + refreshFont(); + refreshFontColor(); + refreshUnderline(); + refreshStrikeThrough(); + } + + /** + * @generated + */ + protected void refreshLabel() { + EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); + if (maskLabelPolicy == null) { + maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); + } + if (maskLabelPolicy == null) { + View view = (View) getModel(); + if (view.isVisible()) { + setLabelTextHelper(getFigure(), getLabelText()); + setLabelIconHelper(getFigure(), getLabelIcon()); + } + else { + setLabelTextHelper(getFigure(), ""); //$NON-NLS-1$ + setLabelIconHelper(getFigure(), null); + } + } + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + protected void refreshUnderline() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); + } + if (resolveSemanticElement() instanceof Feature) { + if (((Feature) resolveSemanticElement()).isStatic()) { + ((WrappingLabel) getFigure()).setTextUnderline(true); + } + else { + ((WrappingLabel) getFigure()).setTextUnderline(false); + } + } + } + + /** + * @generated + */ + protected void refreshStrikeThrough() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); + } + } + + /** + * @generated + */ + @Override + protected void refreshFont() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null) { + FontData fontData = new FontData( + style.getFontName(), style.getFontHeight(), + (style.isBold() ? SWT.BOLD : SWT.NORMAL) | + (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); + setFont(fontData); + } + } + + /** + * @generated + */ + @Override + protected void setFontColor(Color color) { + getFigure().setForegroundColor(color); + } + + /** + * @generated + */ + @Override + protected void addSemanticListeners() { + if (getParser() instanceof ISemanticParser) { + EObject element = resolveSemanticElement(); + parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); + for (int i = 0; i < parserElements.size(); i++) { + addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ + } + } else { + super.addSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected void removeSemanticListeners() { + if (parserElements != null) { + for (int i = 0; i < parserElements.size(); i++) { + removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ + } + } else { + super.removeSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected AccessibleEditPart getAccessibleEditPart() { + if (accessibleEP == null) { + accessibleEP = new AccessibleGraphicalEditPart() { + + @Override + public void getName(AccessibleEvent e) { + e.result = getLabelTextHelper(getFigure()); + } + }; + } + return accessibleEP; + } + + /** + * @generated + */ + private View getFontStyleOwnerView() { + return getPrimaryView(); + } + + /** + * Returns the kind of associated editor for direct edition. + * + * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition + * @generated + */ + public int getDirectEditionType() { + if (checkExtendedEditor()) { + initExtendedEditorConfiguration(); + return IDirectEdition.EXTENDED_DIRECT_EDITOR; + } + if (checkDefaultEdition()) { + return IDirectEdition.DEFAULT_DIRECT_EDITOR; + } + + // not a named element. no specific editor => do nothing + return IDirectEdition.NO_DIRECT_EDITION; + } + + /** + * Checks if an extended editor is present. + * + * @return true if an extended editor is present. + * @generated + */ + protected boolean checkExtendedEditor() { + if (resolveSemanticElement() != null) { + return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); + } + return false; + } + + /** + * Checks if a default direct edition is available + * + * @return true if a default direct edition is available + * @generated + */ + protected boolean checkDefaultEdition() { + return (getParser() != null); + } + + /** + * Initializes the extended editor configuration + * + * @generated + */ + protected void initExtendedEditorConfiguration() { + if (configuration == null) { + final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("")) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); + } else { + configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); + } + } + } + + /** + * Updates the preference configuration + * + * @generated + */ + protected void updateExtendedEditorConfiguration() { + String languagePreferred = Activator.getDefault().getPreferenceStore().getString( + IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() + .eClass().getInstanceClassName()); + } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { + configuration = null; + } + } + + /** + * Performs the direct edit usually used by GMF editors. + * + * @param theRequest + * the direct edit request that starts the direct edit system + * @generated + */ + protected void performDefaultDirectEditorEdit(final Request theRequest) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + + @Override + public void run() { + if (isActive() && isEditable()) { + if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) theRequest.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { + DirectEditRequest editRequest = (DirectEditRequest) theRequest; + performDirectEdit(editRequest.getLocation()); + } else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + + /** + * @generated + */ + @Override + protected void handleNotificationEvent(Notification event) { + Object feature = event.getFeature(); + if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { + Integer c = (Integer) event.getNewValue(); + setFontColor(DiagramColorRegistry.getInstance().getColor(c)); + } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { + refreshUnderline(); + } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { + refreshStrikeThrough(); + } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { + refreshFont(); + } else { + if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { + refreshLabel(); + } + if (getParser() instanceof ISemanticParser) { + ISemanticParser modelParser = + (ISemanticParser) getParser(); + if (modelParser.areSemanticElementsAffected(null, event)) { + removeSemanticListeners(); + if (resolveSemanticElement() != null) { + addSemanticListeners(); + } + refreshLabel(); + } + } + } + super.handleNotificationEvent(event); + } + + /** + * @generated + */ + @Override + protected IFigure createFigure() { + IFigure label = createFigurePrim(); + defaultText = getLabelTextHelper(label); + return label; + } + + /** + * @generated + */ + protected IFigure createFigurePrim() { + return new PapyrusWrappingLabel(); + } + +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/OpaqueBehaviorCompositeNameEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/OpaqueBehaviorCompositeNameEditPart.java index 7fad3c13a5f..0b1344d74b7 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/OpaqueBehaviorCompositeNameEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/OpaqueBehaviorCompositeNameEditPart.java @@ -864,7 +864,7 @@ public class OpaqueBehaviorCompositeNameEditPart extends PapyrusCompartmentEditP * @generated */ protected void addOwnerElementListeners() { - addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); + addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/OpaqueBehaviorCompositeNameEditPartCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/OpaqueBehaviorCompositeNameEditPartCN.java index 238bc2dfb77..c9fff882f9c 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/OpaqueBehaviorCompositeNameEditPartCN.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/OpaqueBehaviorCompositeNameEditPartCN.java @@ -864,7 +864,7 @@ public class OpaqueBehaviorCompositeNameEditPartCN extends PapyrusCompartmentEdi * @generated */ protected void addOwnerElementListeners() { - addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); + addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/OpaqueExpressionEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/OpaqueExpressionEditPart.java index e230eed2742..4d6adf25890 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/OpaqueExpressionEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/OpaqueExpressionEditPart.java @@ -11,27 +11,40 @@ */ package org.eclipse.papyrus.uml.diagram.composite.edit.parts; +import java.util.Collections; +import java.util.List; + import org.eclipse.draw2d.IFigure; +import org.eclipse.emf.common.notify.Notification; import org.eclipse.gef.EditPart; import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.GraphicalEditPart; 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.handles.MoveHandle; import org.eclipse.gef.requests.CreateRequest; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.BorderItemSelectionEditPolicy; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles; +import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; -import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure; import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure; +import org.eclipse.gmf.runtime.notation.Edge; +import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.gmf.runtime.notation.View; -import org.eclipse.papyrus.infra.gmfdiag.common.editpart.NodeEditPart; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.GetChildLayoutEditPolicy; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.IPapyrusNodeFigure; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.RoundedRectangleNodePlateFigure; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.SelectableBorderedNodeFigure; +import org.eclipse.papyrus.uml.diagram.common.editparts.RoundedCompartmentEditPart; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeNodeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.QualifiedNameDisplayEditPolicy; -import org.eclipse.papyrus.uml.diagram.common.figure.node.NodeNamedElementFigure; +import org.eclipse.papyrus.uml.diagram.common.figure.node.RoundedCompartmentFigure; +import org.eclipse.papyrus.uml.diagram.common.locator.RoundedRectangleLabelPositionLocator; import org.eclipse.papyrus.uml.diagram.composite.edit.policies.OpaqueExpressionItemSemanticEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; import org.eclipse.swt.graphics.Color; @@ -39,7 +52,7 @@ import org.eclipse.swt.graphics.Color; /** * @generated */ -public class OpaqueExpressionEditPart extends NodeEditPart { +public class OpaqueExpressionEditPart extends RoundedCompartmentEditPart { /** * @generated @@ -73,6 +86,7 @@ public class OpaqueExpressionEditPart extends NodeEditPart { installEditPolicy(EditPolicy.LAYOUT_ROLE, createLayoutEditPolicy()); installEditPolicy(QualifiedNameDisplayEditPolicy.QUALIFIED_NAME_POLICY, new QualifiedNameDisplayEditPolicy()); installEditPolicy(AppliedStereotypeLabelDisplayEditPolicy.STEREOTYPE_LABEL_POLICY, new AppliedStereotypeNodeLabelDisplayEditPolicy()); + installEditPolicy(EditPolicy.LAYOUT_ROLE, new GetChildLayoutEditPolicy()); // XXX need an SCR to runtime to have another abstract superclass that would let children add reasonable editpolicies // removeEditPolicy(org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles.CONNECTION_HANDLES_ROLE); } @@ -85,6 +99,20 @@ public class OpaqueExpressionEditPart extends NodeEditPart { @Override protected EditPolicy createChildEditPolicy(EditPart child) { + View childView = (View) child.getModel(); + switch (UMLVisualIDRegistry.getVisualID(childView)) { + case OpaqueExpressionFloatingLabelEditPart.VISUAL_ID: + return new BorderItemSelectionEditPolicy() { + + @Override + protected List createSelectionHandles() { + MoveHandle mh = new MoveHandle((GraphicalEditPart) getHost()); + mh.setBorder(null); + return Collections.singletonList(mh); + } + } + ; + } EditPolicy result = child.getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); if (result == null) { result = new NonResizableEditPolicy(); @@ -105,12 +133,36 @@ public class OpaqueExpressionEditPart extends NodeEditPart { return lep; } + /** + * Papyrus codeGen + * + * @generated + **/ + @Override + protected void handleNotificationEvent(Notification event) { + /* + * when a node have external node labels, the methods refreshChildren() remove the EditPart corresponding to the Label from the EditPart + * Registry. After that, we can't reset the visibility to true (using the Show/Hide Label Action)! + */ + if (NotationPackage.eINSTANCE.getView_Visible().equals(event.getFeature())) { + Object notifier = event.getNotifier(); + List modelChildren = ((View) getModel()).getChildren(); + if (!(notifier instanceof Edge)) { + if (modelChildren.contains(event.getNotifier())) { + return; + } + } + } + super.handleNotificationEvent(event); + + } + /** * @generated */ @Override protected IFigure createNodeShape() { - return primaryShape = new NodeNamedElementFigure(); + return primaryShape = new RoundedCompartmentFigure(); } /** @@ -119,8 +171,8 @@ public class OpaqueExpressionEditPart extends NodeEditPart { * @generated */ @Override - public NodeNamedElementFigure getPrimaryShape() { - return (NodeNamedElementFigure) primaryShape; + public RoundedCompartmentFigure getPrimaryShape() { + return (RoundedCompartmentFigure) primaryShape; } /** @@ -173,15 +225,32 @@ public class OpaqueExpressionEditPart extends NodeEditPart { */ @Override protected IFigure getContentPaneFor(IGraphicalEditPart editPart) { + if (editPart instanceof IBorderItemEditPart) { + return getBorderedFigure().getBorderItemContainer(); + } return getContentPane(); } + /** + * @generated + */ + @Override + protected void addBorderItem(IFigure borderItemContainer, IBorderItemEditPart borderItemEditPart) { + if (borderItemEditPart instanceof OpaqueExpressionFloatingLabelEditPart) { + IBorderItemLocator locator = new RoundedRectangleLabelPositionLocator(getMainFigure()); + borderItemContainer.add(borderItemEditPart.getFigure(), locator); + } else + { + super.addBorderItem(borderItemContainer, borderItemEditPart); + } + } + /** * @generated */ @Override protected NodeFigure createNodePlate() { - DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(40, 40); + RoundedRectangleNodePlateFigure result = new RoundedRectangleNodePlateFigure(40, 40); return result; } @@ -194,7 +263,7 @@ public class OpaqueExpressionEditPart extends NodeEditPart { * @generated */ @Override - protected NodeFigure createNodeFigure() { + protected NodeFigure createMainFigure() { return new SelectableBorderedNodeFigure(createMainFigureWithSVG()); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/OpaqueExpressionFloatingLabelEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/OpaqueExpressionFloatingLabelEditPart.java new file mode 100644 index 00000000000..d080c008861 --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/OpaqueExpressionFloatingLabelEditPart.java @@ -0,0 +1,860 @@ +/** + * 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.uml.diagram.composite.edit.parts; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.Label; +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.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.RunnableWithResult; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gef.AccessibleEditPart; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.Request; +import org.eclipse.gef.requests.DirectEditRequest; +import org.eclipse.gef.tools.DirectEditManager; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; +import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; +import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; +import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; +import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; +import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; +import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; +import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; +import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; +import org.eclipse.gmf.runtime.notation.FontStyle; +import org.eclipse.gmf.runtime.notation.NotationPackage; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.text.contentassist.IContentAssistProcessor; +import org.eclipse.jface.viewers.ICellEditorValidator; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.extensionpoints.editors.Activator; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; +import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; +import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.ExternalLabelPrimaryDragRoleEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.PapyrusWrappingLabel; +import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; +import org.eclipse.papyrus.uml.diagram.common.editparts.FloatingLabelEditPart; +import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; +import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; +import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; +import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.accessibility.AccessibleEvent; +import org.eclipse.swt.custom.BusyIndicator; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; +import org.eclipse.uml2.uml.Feature; + +/** + * @generated + */ +public class OpaqueExpressionFloatingLabelEditPart extends FloatingLabelEditPart + implements ITextAwareEditPart, IBorderItemEditPart +{ + + /** + * @generated + */ + public static final int VISUAL_ID = 6112; + + /** + * @generated + */ + private DirectEditManager manager; + + /** + * @generated + */ + private IParser parser; + + /** + * @generated + */ + private List parserElements; + + /** + * @generated + */ + private String defaultText; + + /** + * direct edition mode (default, undefined, registered editor, etc.) + * + * @generated + */ + protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; + + /** + * configuration from a registered edit dialog + * + * @generated + */ + protected IDirectEditorConfiguration configuration; + + + /** + * @generated + */ + static { + registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.OpaqueExpressionFloatingLabelEditPart.VISUAL_ID), new Point(0, 0)); + } + + /** + * @generated + */ + public OpaqueExpressionFloatingLabelEditPart(View view) { + super(view); + } + + /** + * @generated + */ + @Override + protected void createDefaultEditPolicies() { + super.createDefaultEditPolicies(); + installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); + installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ExternalLabelPrimaryDragRoleEditPolicy()); + } + + /** + * @generated + */ + @Override + public IBorderItemLocator getBorderItemLocator() { + IFigure parentFigure = getFigure().getParent(); + if (parentFigure != null && parentFigure.getLayoutManager() != null) { + Object constraint = parentFigure.getLayoutManager().getConstraint(getFigure()); + return (IBorderItemLocator) constraint; + } + return null; + } + + /** + * @generated + */ + @Override + public void refreshBounds() { + int x = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_X())).intValue(); + int y = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_Y())).intValue(); + int width = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Width())).intValue(); + int height = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Height())).intValue(); + getBorderItemLocator().setConstraint(new Rectangle(x, y, width, height)); + } + + + /** + * @generated + */ + protected String getLabelTextHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getText(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getText(); + } else { + return ((Label) figure).getText(); + } + } + + /** + * @generated + */ + protected void setLabelTextHelper(IFigure figure, String text) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setText(text); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setText(text); + } else { + ((Label) figure).setText(text); + } + } + + /** + * @generated + */ + protected Image getLabelIconHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getIcon(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getIcon(); + } else { + return ((Label) figure).getIcon(); + } + } + + /** + * @generated + */ + protected void setLabelIconHelper(IFigure figure, Image icon) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setIcon(icon); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setIcon(icon); + } else { + ((Label) figure).setIcon(icon); + } + } + + /** + * @generated + */ + public void setLabel(IFigure + figure) { + unregisterVisuals(); + setFigure(figure); + defaultText = getLabelTextHelper(figure); + registerVisuals(); + refreshVisuals(); + } + + /** + * @generated + */ + @Override + protected List getModelChildren() { + return Collections.EMPTY_LIST; + } + + /** + * @generated + */ + @Override + public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { + return null; + } + + /** + * @generated + */ + public void setParser(IParser parser) { + this.parser = parser; + } + + /** + * @generated + */ + protected EObject getParserElement() { + return resolveSemanticElement(); + } + + /** + * @generated + */ + protected Image getLabelIcon() { + return null; + } + + /** + * @generated + */ + protected String getLabelText() { + String text = null; + EObject parserElement = getParserElement(); + if (parserElement != null && getParser() != null) { + text = getParser().getPrintString( + new EObjectAdapter(parserElement), + getParserOptions().intValue()); + } + if (text == null || text.length() == 0) { + text = defaultText; + } + return text; + } + + /** + * @generated + */ + @Override + public void setLabelText(String text) { + setLabelTextHelper(getFigure(), text); + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + @Override + public String getEditText() { + if (getParserElement() == null || getParser() == null) { + return ""; //$NON-NLS-1$ + } + return getParser().getEditString( + new EObjectAdapter(getParserElement()), + getParserOptions().intValue()); + } + + /** + * @generated + */ + protected boolean isEditable() { + return getParser() != null; + } + + /** + * @generated + */ + @Override + public ICellEditorValidator getEditTextValidator() { + return new ICellEditorValidator() { + + @Override + public String isValid(final Object value) { + if (value instanceof String) { + final EObject element = getParserElement(); + final IParser parser = getParser(); + try { + IParserEditStatus valid = + (IParserEditStatus) getEditingDomain().runExclusive( + new RunnableWithResult.Impl() { + + @Override + public void run() { + setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); + } + }); + return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); + } catch (InterruptedException ie) { + ie.printStackTrace(); + } + } + + // shouldn't get here + return null; + } + }; + } + + /** + * @generated + */ + @Override + public IContentAssistProcessor getCompletionProcessor() { + if (getParserElement() == null || getParser() == null) { + return null; + } + return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); + } + + /** + * @generated + */ + @Override + public ParserOptions getParserOptions() { + return ParserOptions.NONE; + } + + /** + * @generated + */ + @Override + public IParser getParser() { + if (parser == null) { + parser = UMLParserProvider.getParser(UMLElementTypes.OpaqueExpression_2101, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.OpaqueExpressionFloatingLabelEditPart.VISUAL_ID)); + } + return parser; + } + + /** + * @generated + */ + protected DirectEditManager getManager() { + if (manager == null) { + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + } + return manager; + } + + /** + * @generated + */ + protected void setManager(DirectEditManager manager) { + this.manager = manager; + } + + /** + * @generated + */ + protected void performDirectEdit() { + BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { + + @Override + public void run() { + getManager().show(); + } + }); + } + + /** + * @generated + */ + protected void performDirectEdit(Point eventLocation) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); + } + } + + /** + * @generated + */ + private void performDirectEdit(char initialCharacter) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(initialCharacter); + } else { + performDirectEdit(); + } + } + + /** + * @generated + */ + @Override + protected void performDirectEditRequest(Request request) { + + final Request theRequest = request; + + if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { + directEditionMode = getDirectEditionType(); + } + switch (directEditionMode) { + case IDirectEdition.NO_DIRECT_EDITION: + // no direct edition mode => does nothing + return; + case IDirectEdition.EXTENDED_DIRECT_EDITOR: + updateExtendedEditorConfiguration(); + if (configuration == null || configuration.getLanguage() == null) { + // Create default edit manager + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + performDefaultDirectEditorEdit(theRequest); + } else { + configuration.preEditAction(resolveSemanticElement()); + Dialog dialog = null; + if (configuration instanceof ICustomDirectEditorConfiguration) { + setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); + initializeDirectEditManager(theRequest); + return; + } else if (configuration instanceof IPopupEditorConfiguration) { + IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); + helper.showEditor(); + return; + } + else if (configuration instanceof IAdvancedEditorConfiguration) { + dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); + } else if (configuration instanceof IDirectEditorConfiguration) { + dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), + configuration); + } else { + return; + } + final Dialog finalDialog = dialog; + + if (Window.OK == dialog.open()) { + TransactionalEditingDomain domain = getEditingDomain(); + RecordingCommand command = new RecordingCommand(domain, "Edit Label") { + + @Override + protected void doExecute() { + configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); + + } + }; + domain.getCommandStack().execute(command); + } + } + break; + case IDirectEdition.DEFAULT_DIRECT_EDITOR: + initializeDirectEditManager(theRequest); + break; + default: + break; + } + } + + /** + * @generated + */ + protected void initializeDirectEditManager(final Request request) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + @Override + public void run() { + if (isActive() && isEditable()) { + if (request.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } + else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void refreshVisuals() { + super.refreshVisuals(); + refreshLabel(); + refreshFont(); + refreshFontColor(); + refreshUnderline(); + refreshStrikeThrough(); + } + + /** + * @generated + */ + protected void refreshLabel() { + EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); + if (maskLabelPolicy == null) { + maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); + } + if (maskLabelPolicy == null) { + View view = (View) getModel(); + if (view.isVisible()) { + setLabelTextHelper(getFigure(), getLabelText()); + setLabelIconHelper(getFigure(), getLabelIcon()); + } + else { + setLabelTextHelper(getFigure(), ""); //$NON-NLS-1$ + setLabelIconHelper(getFigure(), null); + } + } + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + protected void refreshUnderline() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); + } + if (resolveSemanticElement() instanceof Feature) { + if (((Feature) resolveSemanticElement()).isStatic()) { + ((WrappingLabel) getFigure()).setTextUnderline(true); + } + else { + ((WrappingLabel) getFigure()).setTextUnderline(false); + } + } + } + + /** + * @generated + */ + protected void refreshStrikeThrough() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); + } + } + + /** + * @generated + */ + @Override + protected void refreshFont() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null) { + FontData fontData = new FontData( + style.getFontName(), style.getFontHeight(), + (style.isBold() ? SWT.BOLD : SWT.NORMAL) | + (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); + setFont(fontData); + } + } + + /** + * @generated + */ + @Override + protected void setFontColor(Color color) { + getFigure().setForegroundColor(color); + } + + /** + * @generated + */ + @Override + protected void addSemanticListeners() { + if (getParser() instanceof ISemanticParser) { + EObject element = resolveSemanticElement(); + parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); + for (int i = 0; i < parserElements.size(); i++) { + addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ + } + } else { + super.addSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected void removeSemanticListeners() { + if (parserElements != null) { + for (int i = 0; i < parserElements.size(); i++) { + removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ + } + } else { + super.removeSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected AccessibleEditPart getAccessibleEditPart() { + if (accessibleEP == null) { + accessibleEP = new AccessibleGraphicalEditPart() { + + @Override + public void getName(AccessibleEvent e) { + e.result = getLabelTextHelper(getFigure()); + } + }; + } + return accessibleEP; + } + + /** + * @generated + */ + private View getFontStyleOwnerView() { + return getPrimaryView(); + } + + /** + * Returns the kind of associated editor for direct edition. + * + * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition + * @generated + */ + public int getDirectEditionType() { + if (checkExtendedEditor()) { + initExtendedEditorConfiguration(); + return IDirectEdition.EXTENDED_DIRECT_EDITOR; + } + if (checkDefaultEdition()) { + return IDirectEdition.DEFAULT_DIRECT_EDITOR; + } + + // not a named element. no specific editor => do nothing + return IDirectEdition.NO_DIRECT_EDITION; + } + + /** + * Checks if an extended editor is present. + * + * @return true if an extended editor is present. + * @generated + */ + protected boolean checkExtendedEditor() { + if (resolveSemanticElement() != null) { + return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); + } + return false; + } + + /** + * Checks if a default direct edition is available + * + * @return true if a default direct edition is available + * @generated + */ + protected boolean checkDefaultEdition() { + return (getParser() != null); + } + + /** + * Initializes the extended editor configuration + * + * @generated + */ + protected void initExtendedEditorConfiguration() { + if (configuration == null) { + final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("")) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); + } else { + configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); + } + } + } + + /** + * Updates the preference configuration + * + * @generated + */ + protected void updateExtendedEditorConfiguration() { + String languagePreferred = Activator.getDefault().getPreferenceStore().getString( + IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() + .eClass().getInstanceClassName()); + } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { + configuration = null; + } + } + + /** + * Performs the direct edit usually used by GMF editors. + * + * @param theRequest + * the direct edit request that starts the direct edit system + * @generated + */ + protected void performDefaultDirectEditorEdit(final Request theRequest) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + + @Override + public void run() { + if (isActive() && isEditable()) { + if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) theRequest.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { + DirectEditRequest editRequest = (DirectEditRequest) theRequest; + performDirectEdit(editRequest.getLocation()); + } else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + + /** + * @generated + */ + @Override + protected void handleNotificationEvent(Notification event) { + Object feature = event.getFeature(); + if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { + Integer c = (Integer) event.getNewValue(); + setFontColor(DiagramColorRegistry.getInstance().getColor(c)); + } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { + refreshUnderline(); + } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { + refreshStrikeThrough(); + } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { + refreshFont(); + } else { + if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { + refreshLabel(); + } + if (getParser() instanceof ISemanticParser) { + ISemanticParser modelParser = + (ISemanticParser) getParser(); + if (modelParser.areSemanticElementsAffected(null, event)) { + removeSemanticListeners(); + if (resolveSemanticElement() != null) { + addSemanticListeners(); + } + refreshLabel(); + } + } + } + super.handleNotificationEvent(event); + } + + /** + * @generated + */ + @Override + protected IFigure createFigure() { + IFigure label = createFigurePrim(); + defaultText = getLabelTextHelper(label); + return label; + } + + /** + * @generated + */ + protected IFigure createFigurePrim() { + return new PapyrusWrappingLabel(); + } + +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/OpaqueExpressionNameEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/OpaqueExpressionNameEditPart.java index f32fbe23cd2..886bdcc4dbe 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/OpaqueExpressionNameEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/OpaqueExpressionNameEditPart.java @@ -864,7 +864,7 @@ public class OpaqueExpressionNameEditPart extends PapyrusCompartmentEditPart imp * @generated */ protected void addOwnerElementListeners() { - addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); + addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ParameterAppliedStereotypeEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ParameterAppliedStereotypeEditPart.java index e999d97efa9..360a5dd0d55 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ParameterAppliedStereotypeEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ParameterAppliedStereotypeEditPart.java @@ -60,6 +60,7 @@ import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; import org.eclipse.papyrus.infra.gmfdiag.common.editpart.PapyrusLabelEditPart; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.ExternalLabelPrimaryDragRoleEditPolicy; import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; @@ -148,6 +149,7 @@ public class ParameterAppliedStereotypeEditPart extends PapyrusLabelEditPart imp installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); installEditPolicy(AppliedStereotypeLabelDisplayEditPolicy.STEREOTYPE_LABEL_POLICY, new AppliedStereotypeExternalNodeEditPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ExternalLabelPrimaryDragRoleEditPolicy()); } /** diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ParameterEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ParameterEditPart.java index 7619295f37f..7ea575490b7 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ParameterEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ParameterEditPart.java @@ -30,17 +30,19 @@ import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.BorderItemSelectionEditPolicy; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles; import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; -import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure; import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure; import org.eclipse.gmf.runtime.notation.Edge; import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.GetChildLayoutEditPolicy; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.IPapyrusNodeFigure; -import org.eclipse.papyrus.uml.diagram.common.editparts.AbstractBorderEditPart; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.RoundedRectangleNodePlateFigure; +import org.eclipse.papyrus.uml.diagram.common.editparts.RoundedBorderNamedElementEditPart; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeIconlDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.ShowHideLabelEditPolicy; import org.eclipse.papyrus.uml.diagram.common.locator.ExternalLabelPositionLocator; +import org.eclipse.papyrus.uml.diagram.common.locator.RoundedRectangleLabelPositionLocator; import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.CustomDiagramDragDropEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.CustomGraphicalNodeEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.CustomParameterItemSemanticEditPolicy; @@ -53,7 +55,7 @@ import org.eclipse.swt.graphics.Color; /** * @generated */ -public class ParameterEditPart extends AbstractBorderEditPart { +public class ParameterEditPart extends RoundedBorderNamedElementEditPart { /** * @generated @@ -92,6 +94,7 @@ public class ParameterEditPart extends AbstractBorderEditPart { installEditPolicy(EditPolicy.LAYOUT_ROLE, new ParameterLayoutEditPolicy()); installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, new CustomDiagramDragDropEditPolicy()); installEditPolicy(ShowHideLabelEditPolicy.SHOW_HIDE_LABEL_ROLE, new ShowHideLabelEditPolicy()); + installEditPolicy(EditPolicy.LAYOUT_ROLE, new GetChildLayoutEditPolicy()); // XXX need an SCR to runtime to have another abstract superclass that would let children add reasonable editpolicies // removeEditPolicy(org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles.CONNECTION_HANDLES_ROLE); } @@ -186,7 +189,7 @@ public class ParameterEditPart extends AbstractBorderEditPart { @Override protected void addBorderItem(IFigure borderItemContainer, IBorderItemEditPart borderItemEditPart) { if (borderItemEditPart instanceof ParameterNameEditPart) { - IBorderItemLocator locator = new ExternalLabelPositionLocator(getMainFigure()); + IBorderItemLocator locator = new RoundedRectangleLabelPositionLocator(getMainFigure()); borderItemContainer.add(borderItemEditPart.getFigure(), locator); } else if (borderItemEditPart instanceof ParameterAppliedStereotypeEditPart) { IBorderItemLocator locator = new ExternalLabelPositionLocator(getMainFigure()); @@ -201,7 +204,7 @@ public class ParameterEditPart extends AbstractBorderEditPart { * @generated */ protected NodeFigure createNodePlate() { - DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(20, 20); + RoundedRectangleNodePlateFigure result = new RoundedRectangleNodePlateFigure(20, 20); return result; } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ParameterNameEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ParameterNameEditPart.java index 4923306d8cf..e031e31f59b 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ParameterNameEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ParameterNameEditPart.java @@ -60,10 +60,11 @@ import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; import org.eclipse.papyrus.infra.emf.appearance.helper.AppearanceHelper; -import org.eclipse.papyrus.infra.gmfdiag.common.editpart.PapyrusLabelEditPart; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.ExternalLabelPrimaryDragRoleEditPolicy; import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; +import org.eclipse.papyrus.uml.diagram.common.editparts.FloatingLabelEditPart; import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; import org.eclipse.papyrus.uml.diagram.common.util.DiagramEditPartsUtil; @@ -85,7 +86,7 @@ import org.eclipse.uml2.uml.Feature; /** * @generated */ -public class ParameterNameEditPart extends PapyrusLabelEditPart implements ITextAwareEditPart, IBorderItemEditPart { +public class ParameterNameEditPart extends FloatingLabelEditPart implements ITextAwareEditPart, IBorderItemEditPart { /** * @generated @@ -148,6 +149,7 @@ public class ParameterNameEditPart extends PapyrusLabelEditPart implements IText installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); installEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY, new ParameterLabelEditPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ExternalLabelPrimaryDragRoleEditPolicy()); } /** diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/PortAppliedStereotypeEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/PortAppliedStereotypeEditPart.java index d9b8e16e672..2deb75076a6 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/PortAppliedStereotypeEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/PortAppliedStereotypeEditPart.java @@ -59,6 +59,7 @@ import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.ExternalLabelPrimaryDragRoleEditPolicy; import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; @@ -148,6 +149,7 @@ public class PortAppliedStereotypeEditPart extends AbstractLabelEditPart impleme installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); installEditPolicy(AppliedStereotypeLabelDisplayEditPolicy.STEREOTYPE_LABEL_POLICY, new AppliedStereotypeExternalNodeEditPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ExternalLabelPrimaryDragRoleEditPolicy()); } /** diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/PortEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/PortEditPart.java index e86843e5c21..3c535928dd0 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/PortEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/PortEditPart.java @@ -30,19 +30,21 @@ import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.BorderItemSelectionEditPolicy; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles; import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; -import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure; import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure; import org.eclipse.gmf.runtime.notation.Edge; import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.GetChildLayoutEditPolicy; import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.IPapyrusNodeFigure; -import org.eclipse.papyrus.uml.diagram.common.editparts.AbstractBorderEditPart; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.RoundedRectangleNodePlateFigure; +import org.eclipse.papyrus.uml.diagram.common.editparts.RoundedBorderNamedElementEditPart; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeIconlDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.MaskManagedNodeEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.ShowHideLabelEditPolicy; import org.eclipse.papyrus.uml.diagram.common.locator.ExternalLabelPositionLocator; +import org.eclipse.papyrus.uml.diagram.common.locator.RoundedRectangleLabelPositionLocator; import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.BehaviorPortEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.CustomDiagramDragDropEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.CustomGraphicalNodeEditPolicy; @@ -56,7 +58,7 @@ import org.eclipse.swt.graphics.Color; /** * @generated */ -public class PortEditPart extends AbstractBorderEditPart { +public class PortEditPart extends RoundedBorderNamedElementEditPart { /** * @generated @@ -97,6 +99,7 @@ public class PortEditPart extends AbstractBorderEditPart { installEditPolicy(ShowHideLabelEditPolicy.SHOW_HIDE_LABEL_ROLE, new ShowHideLabelEditPolicy()); installEditPolicy(BehaviorPortEditPolicy.BEHAVIOR_PORT, new BehaviorPortEditPolicy()); installEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY, new MaskManagedNodeEditPolicy()); + installEditPolicy(EditPolicy.LAYOUT_ROLE, new GetChildLayoutEditPolicy()); // XXX need an SCR to runtime to have another abstract superclass that would let children add reasonable editpolicies // removeEditPolicy(org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles.CONNECTION_HANDLES_ROLE); } @@ -191,7 +194,7 @@ public class PortEditPart extends AbstractBorderEditPart { @Override protected void addBorderItem(IFigure borderItemContainer, IBorderItemEditPart borderItemEditPart) { if (borderItemEditPart instanceof PortNameEditPart) { - IBorderItemLocator locator = new ExternalLabelPositionLocator(getMainFigure()); + IBorderItemLocator locator = new RoundedRectangleLabelPositionLocator(getMainFigure()); borderItemContainer.add(borderItemEditPart.getFigure(), locator); } else if (borderItemEditPart instanceof PortAppliedStereotypeEditPart) { IBorderItemLocator locator = new ExternalLabelPositionLocator(getMainFigure()); @@ -206,7 +209,7 @@ public class PortEditPart extends AbstractBorderEditPart { * @generated */ protected NodeFigure createNodePlate() { - DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(20, 20); + RoundedRectangleNodePlateFigure result = new RoundedRectangleNodePlateFigure(20, 20); return result; } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/PortNameEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/PortNameEditPart.java index ac85ff017e4..054bc09038e 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/PortNameEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/PortNameEditPart.java @@ -60,12 +60,13 @@ import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; import org.eclipse.papyrus.infra.emf.appearance.helper.AppearanceHelper; -import org.eclipse.papyrus.infra.gmfdiag.common.editpart.PapyrusLabelEditPart; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.ExternalLabelPrimaryDragRoleEditPolicy; import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.LabelAlignmentEditPolicy; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.PapyrusWrappingLabel; import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; +import org.eclipse.papyrus.uml.diagram.common.editparts.FloatingLabelEditPart; import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; import org.eclipse.papyrus.uml.diagram.common.editpolicies.IndirectPortLabelEditPolicy; import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; @@ -87,7 +88,7 @@ import org.eclipse.uml2.uml.Feature; /** * @generated */ -public class PortNameEditPart extends PapyrusLabelEditPart implements ITextAwareEditPart, IBorderItemEditPart { +public class PortNameEditPart extends FloatingLabelEditPart implements ITextAwareEditPart, IBorderItemEditPart { /** * @generated @@ -151,6 +152,7 @@ public class PortNameEditPart extends PapyrusLabelEditPart implements ITextAware installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); installEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL, new IndirectPortLabelEditPolicy()); installEditPolicy(LabelAlignmentEditPolicy.LABEL_ALIGNMENT_KEY, new LabelAlignmentEditPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ExternalLabelPrimaryDragRoleEditPolicy()); } /** diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/PrimitiveTypeEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/PrimitiveTypeEditPart.java index ed2a5641404..d6bbc6fcb08 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/PrimitiveTypeEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/PrimitiveTypeEditPart.java @@ -11,30 +11,42 @@ */ package org.eclipse.papyrus.uml.diagram.composite.edit.parts; +import java.util.Collections; +import java.util.List; + import org.eclipse.draw2d.IFigure; import org.eclipse.emf.common.notify.Notification; import org.eclipse.gef.EditPart; import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.GraphicalEditPart; 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.handles.MoveHandle; import org.eclipse.gef.requests.CreateRequest; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.BorderItemSelectionEditPolicy; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles; +import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; -import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure; import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure; +import org.eclipse.gmf.runtime.notation.Edge; +import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.GetChildLayoutEditPolicy; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.IPapyrusNodeFigure; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.RoundedRectangleNodePlateFigure; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.SelectableBorderedNodeFigure; -import org.eclipse.papyrus.uml.diagram.common.editparts.NamedElementEditPart; +import org.eclipse.papyrus.uml.diagram.common.editparts.RoundedCompartmentEditPart; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeNodeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.QualifiedNameDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.ShowHideClassifierContentsEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.ShowHideCompartmentEditPolicy; import org.eclipse.papyrus.uml.diagram.common.figure.node.PrimitiveTypeFigure; +import org.eclipse.papyrus.uml.diagram.common.locator.RoundedRectangleLabelPositionLocator; import org.eclipse.papyrus.uml.diagram.composite.edit.policies.PrimitiveTypeItemSemanticEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; import org.eclipse.swt.graphics.Color; @@ -42,7 +54,7 @@ import org.eclipse.swt.graphics.Color; /** * @generated */ -public class PrimitiveTypeEditPart extends NamedElementEditPart { +public class PrimitiveTypeEditPart extends RoundedCompartmentEditPart { /** * @generated @@ -78,6 +90,7 @@ public class PrimitiveTypeEditPart extends NamedElementEditPart { installEditPolicy(AppliedStereotypeLabelDisplayEditPolicy.STEREOTYPE_LABEL_POLICY, new AppliedStereotypeNodeLabelDisplayEditPolicy()); installEditPolicy(ShowHideClassifierContentsEditPolicy.SHOW_HIDE_CLASSIFIER_CONTENTS_POLICY, new ShowHideClassifierContentsEditPolicy()); installEditPolicy(ShowHideCompartmentEditPolicy.SHOW_HIDE_COMPARTMENT_POLICY, new ShowHideCompartmentEditPolicy()); + installEditPolicy(EditPolicy.LAYOUT_ROLE, new GetChildLayoutEditPolicy()); // XXX need an SCR to runtime to have another abstract superclass that would let children add reasonable editpolicies // removeEditPolicy(org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles.CONNECTION_HANDLES_ROLE); } @@ -90,6 +103,20 @@ public class PrimitiveTypeEditPart extends NamedElementEditPart { @Override protected EditPolicy createChildEditPolicy(EditPart child) { + View childView = (View) child.getModel(); + switch (UMLVisualIDRegistry.getVisualID(childView)) { + case PrimitiveTypeFloatingLabelEditPart.VISUAL_ID: + return new BorderItemSelectionEditPolicy() { + + @Override + protected List createSelectionHandles() { + MoveHandle mh = new MoveHandle((GraphicalEditPart) getHost()); + mh.setBorder(null); + return Collections.singletonList(mh); + } + } + ; + } EditPolicy result = child.getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); if (result == null) { result = new NonResizableEditPolicy(); @@ -117,6 +144,19 @@ public class PrimitiveTypeEditPart extends NamedElementEditPart { **/ @Override protected void handleNotificationEvent(Notification event) { + /* + * when a node have external node labels, the methods refreshChildren() remove the EditPart corresponding to the Label from the EditPart + * Registry. After that, we can't reset the visibility to true (using the Show/Hide Label Action)! + */ + if (NotationPackage.eINSTANCE.getView_Visible().equals(event.getFeature())) { + Object notifier = event.getNotifier(); + List modelChildren = ((View) getModel()).getChildren(); + if (!(notifier instanceof Edge)) { + if (modelChildren.contains(event.getNotifier())) { + return; + } + } + } super.handleNotificationEvent(event); } @@ -189,15 +229,32 @@ public class PrimitiveTypeEditPart extends NamedElementEditPart { */ @Override protected IFigure getContentPaneFor(IGraphicalEditPart editPart) { + if (editPart instanceof IBorderItemEditPart) { + return getBorderedFigure().getBorderItemContainer(); + } return getContentPane(); } + /** + * @generated + */ + @Override + protected void addBorderItem(IFigure borderItemContainer, IBorderItemEditPart borderItemEditPart) { + if (borderItemEditPart instanceof PrimitiveTypeFloatingLabelEditPart) { + IBorderItemLocator locator = new RoundedRectangleLabelPositionLocator(getMainFigure()); + borderItemContainer.add(borderItemEditPart.getFigure(), locator); + } else + { + super.addBorderItem(borderItemContainer, borderItemEditPart); + } + } + /** * @generated */ @Override protected NodeFigure createNodePlate() { - DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(40, 40); + RoundedRectangleNodePlateFigure result = new RoundedRectangleNodePlateFigure(40, 40); return result; } @@ -210,7 +267,7 @@ public class PrimitiveTypeEditPart extends NamedElementEditPart { * @generated */ @Override - protected NodeFigure createNodeFigure() { + protected NodeFigure createMainFigure() { return new SelectableBorderedNodeFigure(createMainFigureWithSVG()); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/PrimitiveTypeEditPartCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/PrimitiveTypeEditPartCN.java index bfae76f7b3e..0f074116f98 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/PrimitiveTypeEditPartCN.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/PrimitiveTypeEditPartCN.java @@ -11,30 +11,42 @@ */ package org.eclipse.papyrus.uml.diagram.composite.edit.parts; +import java.util.Collections; +import java.util.List; + import org.eclipse.draw2d.IFigure; import org.eclipse.emf.common.notify.Notification; import org.eclipse.gef.EditPart; import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.GraphicalEditPart; 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.handles.MoveHandle; import org.eclipse.gef.requests.CreateRequest; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.BorderItemSelectionEditPolicy; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles; +import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; -import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure; import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure; +import org.eclipse.gmf.runtime.notation.Edge; +import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.GetChildLayoutEditPolicy; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.IPapyrusNodeFigure; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.RoundedRectangleNodePlateFigure; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.SelectableBorderedNodeFigure; -import org.eclipse.papyrus.uml.diagram.common.editparts.NamedElementEditPart; +import org.eclipse.papyrus.uml.diagram.common.editparts.RoundedCompartmentEditPart; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeNodeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.QualifiedNameDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.ShowHideClassifierContentsEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.ShowHideCompartmentEditPolicy; import org.eclipse.papyrus.uml.diagram.common.figure.node.PrimitiveTypeFigure; +import org.eclipse.papyrus.uml.diagram.common.locator.RoundedRectangleLabelPositionLocator; import org.eclipse.papyrus.uml.diagram.composite.edit.policies.PrimitiveTypeItemSemanticEditPolicyCN; import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; import org.eclipse.swt.graphics.Color; @@ -42,7 +54,7 @@ import org.eclipse.swt.graphics.Color; /** * @generated */ -public class PrimitiveTypeEditPartCN extends NamedElementEditPart { +public class PrimitiveTypeEditPartCN extends RoundedCompartmentEditPart { /** * @generated @@ -78,6 +90,7 @@ public class PrimitiveTypeEditPartCN extends NamedElementEditPart { installEditPolicy(AppliedStereotypeLabelDisplayEditPolicy.STEREOTYPE_LABEL_POLICY, new AppliedStereotypeNodeLabelDisplayEditPolicy()); installEditPolicy(ShowHideClassifierContentsEditPolicy.SHOW_HIDE_CLASSIFIER_CONTENTS_POLICY, new ShowHideClassifierContentsEditPolicy()); installEditPolicy(ShowHideCompartmentEditPolicy.SHOW_HIDE_COMPARTMENT_POLICY, new ShowHideCompartmentEditPolicy()); + installEditPolicy(EditPolicy.LAYOUT_ROLE, new GetChildLayoutEditPolicy()); // XXX need an SCR to runtime to have another abstract superclass that would let children add reasonable editpolicies // removeEditPolicy(org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles.CONNECTION_HANDLES_ROLE); } @@ -90,6 +103,20 @@ public class PrimitiveTypeEditPartCN extends NamedElementEditPart { @Override protected EditPolicy createChildEditPolicy(EditPart child) { + View childView = (View) child.getModel(); + switch (UMLVisualIDRegistry.getVisualID(childView)) { + case PrimitiveTypeFloatingLabelEditPartCN.VISUAL_ID: + return new BorderItemSelectionEditPolicy() { + + @Override + protected List createSelectionHandles() { + MoveHandle mh = new MoveHandle((GraphicalEditPart) getHost()); + mh.setBorder(null); + return Collections.singletonList(mh); + } + } + ; + } EditPolicy result = child.getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); if (result == null) { result = new NonResizableEditPolicy(); @@ -117,6 +144,19 @@ public class PrimitiveTypeEditPartCN extends NamedElementEditPart { **/ @Override protected void handleNotificationEvent(Notification event) { + /* + * when a node have external node labels, the methods refreshChildren() remove the EditPart corresponding to the Label from the EditPart + * Registry. After that, we can't reset the visibility to true (using the Show/Hide Label Action)! + */ + if (NotationPackage.eINSTANCE.getView_Visible().equals(event.getFeature())) { + Object notifier = event.getNotifier(); + List modelChildren = ((View) getModel()).getChildren(); + if (!(notifier instanceof Edge)) { + if (modelChildren.contains(event.getNotifier())) { + return; + } + } + } super.handleNotificationEvent(event); } @@ -189,15 +229,32 @@ public class PrimitiveTypeEditPartCN extends NamedElementEditPart { */ @Override protected IFigure getContentPaneFor(IGraphicalEditPart editPart) { + if (editPart instanceof IBorderItemEditPart) { + return getBorderedFigure().getBorderItemContainer(); + } return getContentPane(); } + /** + * @generated + */ + @Override + protected void addBorderItem(IFigure borderItemContainer, IBorderItemEditPart borderItemEditPart) { + if (borderItemEditPart instanceof PrimitiveTypeFloatingLabelEditPartCN) { + IBorderItemLocator locator = new RoundedRectangleLabelPositionLocator(getMainFigure()); + borderItemContainer.add(borderItemEditPart.getFigure(), locator); + } else + { + super.addBorderItem(borderItemContainer, borderItemEditPart); + } + } + /** * @generated */ @Override protected NodeFigure createNodePlate() { - DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(40, 40); + RoundedRectangleNodePlateFigure result = new RoundedRectangleNodePlateFigure(40, 40); return result; } @@ -210,7 +267,7 @@ public class PrimitiveTypeEditPartCN extends NamedElementEditPart { * @generated */ @Override - protected NodeFigure createNodeFigure() { + protected NodeFigure createMainFigure() { return new SelectableBorderedNodeFigure(createMainFigureWithSVG()); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/PrimitiveTypeFloatingLabelEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/PrimitiveTypeFloatingLabelEditPart.java new file mode 100644 index 00000000000..782ac3f1eb4 --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/PrimitiveTypeFloatingLabelEditPart.java @@ -0,0 +1,860 @@ +/** + * 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.uml.diagram.composite.edit.parts; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.Label; +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.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.RunnableWithResult; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gef.AccessibleEditPart; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.Request; +import org.eclipse.gef.requests.DirectEditRequest; +import org.eclipse.gef.tools.DirectEditManager; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; +import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; +import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; +import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; +import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; +import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; +import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; +import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; +import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; +import org.eclipse.gmf.runtime.notation.FontStyle; +import org.eclipse.gmf.runtime.notation.NotationPackage; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.text.contentassist.IContentAssistProcessor; +import org.eclipse.jface.viewers.ICellEditorValidator; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.extensionpoints.editors.Activator; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; +import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; +import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.ExternalLabelPrimaryDragRoleEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.PapyrusWrappingLabel; +import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; +import org.eclipse.papyrus.uml.diagram.common.editparts.FloatingLabelEditPart; +import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; +import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; +import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; +import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.accessibility.AccessibleEvent; +import org.eclipse.swt.custom.BusyIndicator; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; +import org.eclipse.uml2.uml.Feature; + +/** + * @generated + */ +public class PrimitiveTypeFloatingLabelEditPart extends FloatingLabelEditPart + implements ITextAwareEditPart, IBorderItemEditPart +{ + + /** + * @generated + */ + public static final int VISUAL_ID = 6092; + + /** + * @generated + */ + private DirectEditManager manager; + + /** + * @generated + */ + private IParser parser; + + /** + * @generated + */ + private List parserElements; + + /** + * @generated + */ + private String defaultText; + + /** + * direct edition mode (default, undefined, registered editor, etc.) + * + * @generated + */ + protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; + + /** + * configuration from a registered edit dialog + * + * @generated + */ + protected IDirectEditorConfiguration configuration; + + + /** + * @generated + */ + static { + registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.PrimitiveTypeFloatingLabelEditPart.VISUAL_ID), new Point(0, 0)); + } + + /** + * @generated + */ + public PrimitiveTypeFloatingLabelEditPart(View view) { + super(view); + } + + /** + * @generated + */ + @Override + protected void createDefaultEditPolicies() { + super.createDefaultEditPolicies(); + installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); + installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ExternalLabelPrimaryDragRoleEditPolicy()); + } + + /** + * @generated + */ + @Override + public IBorderItemLocator getBorderItemLocator() { + IFigure parentFigure = getFigure().getParent(); + if (parentFigure != null && parentFigure.getLayoutManager() != null) { + Object constraint = parentFigure.getLayoutManager().getConstraint(getFigure()); + return (IBorderItemLocator) constraint; + } + return null; + } + + /** + * @generated + */ + @Override + public void refreshBounds() { + int x = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_X())).intValue(); + int y = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_Y())).intValue(); + int width = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Width())).intValue(); + int height = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Height())).intValue(); + getBorderItemLocator().setConstraint(new Rectangle(x, y, width, height)); + } + + + /** + * @generated + */ + protected String getLabelTextHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getText(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getText(); + } else { + return ((Label) figure).getText(); + } + } + + /** + * @generated + */ + protected void setLabelTextHelper(IFigure figure, String text) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setText(text); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setText(text); + } else { + ((Label) figure).setText(text); + } + } + + /** + * @generated + */ + protected Image getLabelIconHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getIcon(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getIcon(); + } else { + return ((Label) figure).getIcon(); + } + } + + /** + * @generated + */ + protected void setLabelIconHelper(IFigure figure, Image icon) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setIcon(icon); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setIcon(icon); + } else { + ((Label) figure).setIcon(icon); + } + } + + /** + * @generated + */ + public void setLabel(IFigure + figure) { + unregisterVisuals(); + setFigure(figure); + defaultText = getLabelTextHelper(figure); + registerVisuals(); + refreshVisuals(); + } + + /** + * @generated + */ + @Override + protected List getModelChildren() { + return Collections.EMPTY_LIST; + } + + /** + * @generated + */ + @Override + public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { + return null; + } + + /** + * @generated + */ + public void setParser(IParser parser) { + this.parser = parser; + } + + /** + * @generated + */ + protected EObject getParserElement() { + return resolveSemanticElement(); + } + + /** + * @generated + */ + protected Image getLabelIcon() { + return null; + } + + /** + * @generated + */ + protected String getLabelText() { + String text = null; + EObject parserElement = getParserElement(); + if (parserElement != null && getParser() != null) { + text = getParser().getPrintString( + new EObjectAdapter(parserElement), + getParserOptions().intValue()); + } + if (text == null || text.length() == 0) { + text = defaultText; + } + return text; + } + + /** + * @generated + */ + @Override + public void setLabelText(String text) { + setLabelTextHelper(getFigure(), text); + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + @Override + public String getEditText() { + if (getParserElement() == null || getParser() == null) { + return ""; //$NON-NLS-1$ + } + return getParser().getEditString( + new EObjectAdapter(getParserElement()), + getParserOptions().intValue()); + } + + /** + * @generated + */ + protected boolean isEditable() { + return getParser() != null; + } + + /** + * @generated + */ + @Override + public ICellEditorValidator getEditTextValidator() { + return new ICellEditorValidator() { + + @Override + public String isValid(final Object value) { + if (value instanceof String) { + final EObject element = getParserElement(); + final IParser parser = getParser(); + try { + IParserEditStatus valid = + (IParserEditStatus) getEditingDomain().runExclusive( + new RunnableWithResult.Impl() { + + @Override + public void run() { + setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); + } + }); + return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); + } catch (InterruptedException ie) { + ie.printStackTrace(); + } + } + + // shouldn't get here + return null; + } + }; + } + + /** + * @generated + */ + @Override + public IContentAssistProcessor getCompletionProcessor() { + if (getParserElement() == null || getParser() == null) { + return null; + } + return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); + } + + /** + * @generated + */ + @Override + public ParserOptions getParserOptions() { + return ParserOptions.NONE; + } + + /** + * @generated + */ + @Override + public IParser getParser() { + if (parser == null) { + parser = UMLParserProvider.getParser(UMLElementTypes.PrimitiveType_2066, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.PrimitiveTypeFloatingLabelEditPart.VISUAL_ID)); + } + return parser; + } + + /** + * @generated + */ + protected DirectEditManager getManager() { + if (manager == null) { + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + } + return manager; + } + + /** + * @generated + */ + protected void setManager(DirectEditManager manager) { + this.manager = manager; + } + + /** + * @generated + */ + protected void performDirectEdit() { + BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { + + @Override + public void run() { + getManager().show(); + } + }); + } + + /** + * @generated + */ + protected void performDirectEdit(Point eventLocation) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); + } + } + + /** + * @generated + */ + private void performDirectEdit(char initialCharacter) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(initialCharacter); + } else { + performDirectEdit(); + } + } + + /** + * @generated + */ + @Override + protected void performDirectEditRequest(Request request) { + + final Request theRequest = request; + + if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { + directEditionMode = getDirectEditionType(); + } + switch (directEditionMode) { + case IDirectEdition.NO_DIRECT_EDITION: + // no direct edition mode => does nothing + return; + case IDirectEdition.EXTENDED_DIRECT_EDITOR: + updateExtendedEditorConfiguration(); + if (configuration == null || configuration.getLanguage() == null) { + // Create default edit manager + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + performDefaultDirectEditorEdit(theRequest); + } else { + configuration.preEditAction(resolveSemanticElement()); + Dialog dialog = null; + if (configuration instanceof ICustomDirectEditorConfiguration) { + setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); + initializeDirectEditManager(theRequest); + return; + } else if (configuration instanceof IPopupEditorConfiguration) { + IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); + helper.showEditor(); + return; + } + else if (configuration instanceof IAdvancedEditorConfiguration) { + dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); + } else if (configuration instanceof IDirectEditorConfiguration) { + dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), + configuration); + } else { + return; + } + final Dialog finalDialog = dialog; + + if (Window.OK == dialog.open()) { + TransactionalEditingDomain domain = getEditingDomain(); + RecordingCommand command = new RecordingCommand(domain, "Edit Label") { + + @Override + protected void doExecute() { + configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); + + } + }; + domain.getCommandStack().execute(command); + } + } + break; + case IDirectEdition.DEFAULT_DIRECT_EDITOR: + initializeDirectEditManager(theRequest); + break; + default: + break; + } + } + + /** + * @generated + */ + protected void initializeDirectEditManager(final Request request) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + @Override + public void run() { + if (isActive() && isEditable()) { + if (request.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } + else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void refreshVisuals() { + super.refreshVisuals(); + refreshLabel(); + refreshFont(); + refreshFontColor(); + refreshUnderline(); + refreshStrikeThrough(); + } + + /** + * @generated + */ + protected void refreshLabel() { + EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); + if (maskLabelPolicy == null) { + maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); + } + if (maskLabelPolicy == null) { + View view = (View) getModel(); + if (view.isVisible()) { + setLabelTextHelper(getFigure(), getLabelText()); + setLabelIconHelper(getFigure(), getLabelIcon()); + } + else { + setLabelTextHelper(getFigure(), ""); //$NON-NLS-1$ + setLabelIconHelper(getFigure(), null); + } + } + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + protected void refreshUnderline() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); + } + if (resolveSemanticElement() instanceof Feature) { + if (((Feature) resolveSemanticElement()).isStatic()) { + ((WrappingLabel) getFigure()).setTextUnderline(true); + } + else { + ((WrappingLabel) getFigure()).setTextUnderline(false); + } + } + } + + /** + * @generated + */ + protected void refreshStrikeThrough() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); + } + } + + /** + * @generated + */ + @Override + protected void refreshFont() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null) { + FontData fontData = new FontData( + style.getFontName(), style.getFontHeight(), + (style.isBold() ? SWT.BOLD : SWT.NORMAL) | + (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); + setFont(fontData); + } + } + + /** + * @generated + */ + @Override + protected void setFontColor(Color color) { + getFigure().setForegroundColor(color); + } + + /** + * @generated + */ + @Override + protected void addSemanticListeners() { + if (getParser() instanceof ISemanticParser) { + EObject element = resolveSemanticElement(); + parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); + for (int i = 0; i < parserElements.size(); i++) { + addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ + } + } else { + super.addSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected void removeSemanticListeners() { + if (parserElements != null) { + for (int i = 0; i < parserElements.size(); i++) { + removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ + } + } else { + super.removeSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected AccessibleEditPart getAccessibleEditPart() { + if (accessibleEP == null) { + accessibleEP = new AccessibleGraphicalEditPart() { + + @Override + public void getName(AccessibleEvent e) { + e.result = getLabelTextHelper(getFigure()); + } + }; + } + return accessibleEP; + } + + /** + * @generated + */ + private View getFontStyleOwnerView() { + return getPrimaryView(); + } + + /** + * Returns the kind of associated editor for direct edition. + * + * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition + * @generated + */ + public int getDirectEditionType() { + if (checkExtendedEditor()) { + initExtendedEditorConfiguration(); + return IDirectEdition.EXTENDED_DIRECT_EDITOR; + } + if (checkDefaultEdition()) { + return IDirectEdition.DEFAULT_DIRECT_EDITOR; + } + + // not a named element. no specific editor => do nothing + return IDirectEdition.NO_DIRECT_EDITION; + } + + /** + * Checks if an extended editor is present. + * + * @return true if an extended editor is present. + * @generated + */ + protected boolean checkExtendedEditor() { + if (resolveSemanticElement() != null) { + return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); + } + return false; + } + + /** + * Checks if a default direct edition is available + * + * @return true if a default direct edition is available + * @generated + */ + protected boolean checkDefaultEdition() { + return (getParser() != null); + } + + /** + * Initializes the extended editor configuration + * + * @generated + */ + protected void initExtendedEditorConfiguration() { + if (configuration == null) { + final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("")) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); + } else { + configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); + } + } + } + + /** + * Updates the preference configuration + * + * @generated + */ + protected void updateExtendedEditorConfiguration() { + String languagePreferred = Activator.getDefault().getPreferenceStore().getString( + IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() + .eClass().getInstanceClassName()); + } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { + configuration = null; + } + } + + /** + * Performs the direct edit usually used by GMF editors. + * + * @param theRequest + * the direct edit request that starts the direct edit system + * @generated + */ + protected void performDefaultDirectEditorEdit(final Request theRequest) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + + @Override + public void run() { + if (isActive() && isEditable()) { + if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) theRequest.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { + DirectEditRequest editRequest = (DirectEditRequest) theRequest; + performDirectEdit(editRequest.getLocation()); + } else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + + /** + * @generated + */ + @Override + protected void handleNotificationEvent(Notification event) { + Object feature = event.getFeature(); + if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { + Integer c = (Integer) event.getNewValue(); + setFontColor(DiagramColorRegistry.getInstance().getColor(c)); + } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { + refreshUnderline(); + } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { + refreshStrikeThrough(); + } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { + refreshFont(); + } else { + if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { + refreshLabel(); + } + if (getParser() instanceof ISemanticParser) { + ISemanticParser modelParser = + (ISemanticParser) getParser(); + if (modelParser.areSemanticElementsAffected(null, event)) { + removeSemanticListeners(); + if (resolveSemanticElement() != null) { + addSemanticListeners(); + } + refreshLabel(); + } + } + } + super.handleNotificationEvent(event); + } + + /** + * @generated + */ + @Override + protected IFigure createFigure() { + IFigure label = createFigurePrim(); + defaultText = getLabelTextHelper(label); + return label; + } + + /** + * @generated + */ + protected IFigure createFigurePrim() { + return new PapyrusWrappingLabel(); + } + +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/PrimitiveTypeFloatingLabelEditPartCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/PrimitiveTypeFloatingLabelEditPartCN.java new file mode 100644 index 00000000000..8d5e2f38c3a --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/PrimitiveTypeFloatingLabelEditPartCN.java @@ -0,0 +1,860 @@ +/** + * 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.uml.diagram.composite.edit.parts; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.Label; +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.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.RunnableWithResult; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gef.AccessibleEditPart; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.Request; +import org.eclipse.gef.requests.DirectEditRequest; +import org.eclipse.gef.tools.DirectEditManager; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; +import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; +import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; +import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; +import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; +import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; +import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; +import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; +import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; +import org.eclipse.gmf.runtime.notation.FontStyle; +import org.eclipse.gmf.runtime.notation.NotationPackage; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.text.contentassist.IContentAssistProcessor; +import org.eclipse.jface.viewers.ICellEditorValidator; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.extensionpoints.editors.Activator; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; +import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; +import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.ExternalLabelPrimaryDragRoleEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.PapyrusWrappingLabel; +import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; +import org.eclipse.papyrus.uml.diagram.common.editparts.FloatingLabelEditPart; +import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; +import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; +import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; +import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.accessibility.AccessibleEvent; +import org.eclipse.swt.custom.BusyIndicator; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; +import org.eclipse.uml2.uml.Feature; + +/** + * @generated + */ +public class PrimitiveTypeFloatingLabelEditPartCN extends FloatingLabelEditPart + implements ITextAwareEditPart, IBorderItemEditPart +{ + + /** + * @generated + */ + public static final int VISUAL_ID = 6070; + + /** + * @generated + */ + private DirectEditManager manager; + + /** + * @generated + */ + private IParser parser; + + /** + * @generated + */ + private List parserElements; + + /** + * @generated + */ + private String defaultText; + + /** + * direct edition mode (default, undefined, registered editor, etc.) + * + * @generated + */ + protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; + + /** + * configuration from a registered edit dialog + * + * @generated + */ + protected IDirectEditorConfiguration configuration; + + + /** + * @generated + */ + static { + registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.PrimitiveTypeFloatingLabelEditPartCN.VISUAL_ID), new Point(0, 0)); + } + + /** + * @generated + */ + public PrimitiveTypeFloatingLabelEditPartCN(View view) { + super(view); + } + + /** + * @generated + */ + @Override + protected void createDefaultEditPolicies() { + super.createDefaultEditPolicies(); + installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); + installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ExternalLabelPrimaryDragRoleEditPolicy()); + } + + /** + * @generated + */ + @Override + public IBorderItemLocator getBorderItemLocator() { + IFigure parentFigure = getFigure().getParent(); + if (parentFigure != null && parentFigure.getLayoutManager() != null) { + Object constraint = parentFigure.getLayoutManager().getConstraint(getFigure()); + return (IBorderItemLocator) constraint; + } + return null; + } + + /** + * @generated + */ + @Override + public void refreshBounds() { + int x = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_X())).intValue(); + int y = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_Y())).intValue(); + int width = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Width())).intValue(); + int height = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Height())).intValue(); + getBorderItemLocator().setConstraint(new Rectangle(x, y, width, height)); + } + + + /** + * @generated + */ + protected String getLabelTextHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getText(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getText(); + } else { + return ((Label) figure).getText(); + } + } + + /** + * @generated + */ + protected void setLabelTextHelper(IFigure figure, String text) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setText(text); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setText(text); + } else { + ((Label) figure).setText(text); + } + } + + /** + * @generated + */ + protected Image getLabelIconHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getIcon(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getIcon(); + } else { + return ((Label) figure).getIcon(); + } + } + + /** + * @generated + */ + protected void setLabelIconHelper(IFigure figure, Image icon) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setIcon(icon); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setIcon(icon); + } else { + ((Label) figure).setIcon(icon); + } + } + + /** + * @generated + */ + public void setLabel(IFigure + figure) { + unregisterVisuals(); + setFigure(figure); + defaultText = getLabelTextHelper(figure); + registerVisuals(); + refreshVisuals(); + } + + /** + * @generated + */ + @Override + protected List getModelChildren() { + return Collections.EMPTY_LIST; + } + + /** + * @generated + */ + @Override + public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { + return null; + } + + /** + * @generated + */ + public void setParser(IParser parser) { + this.parser = parser; + } + + /** + * @generated + */ + protected EObject getParserElement() { + return resolveSemanticElement(); + } + + /** + * @generated + */ + protected Image getLabelIcon() { + return null; + } + + /** + * @generated + */ + protected String getLabelText() { + String text = null; + EObject parserElement = getParserElement(); + if (parserElement != null && getParser() != null) { + text = getParser().getPrintString( + new EObjectAdapter(parserElement), + getParserOptions().intValue()); + } + if (text == null || text.length() == 0) { + text = defaultText; + } + return text; + } + + /** + * @generated + */ + @Override + public void setLabelText(String text) { + setLabelTextHelper(getFigure(), text); + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + @Override + public String getEditText() { + if (getParserElement() == null || getParser() == null) { + return ""; //$NON-NLS-1$ + } + return getParser().getEditString( + new EObjectAdapter(getParserElement()), + getParserOptions().intValue()); + } + + /** + * @generated + */ + protected boolean isEditable() { + return getParser() != null; + } + + /** + * @generated + */ + @Override + public ICellEditorValidator getEditTextValidator() { + return new ICellEditorValidator() { + + @Override + public String isValid(final Object value) { + if (value instanceof String) { + final EObject element = getParserElement(); + final IParser parser = getParser(); + try { + IParserEditStatus valid = + (IParserEditStatus) getEditingDomain().runExclusive( + new RunnableWithResult.Impl() { + + @Override + public void run() { + setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); + } + }); + return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); + } catch (InterruptedException ie) { + ie.printStackTrace(); + } + } + + // shouldn't get here + return null; + } + }; + } + + /** + * @generated + */ + @Override + public IContentAssistProcessor getCompletionProcessor() { + if (getParserElement() == null || getParser() == null) { + return null; + } + return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); + } + + /** + * @generated + */ + @Override + public ParserOptions getParserOptions() { + return ParserOptions.NONE; + } + + /** + * @generated + */ + @Override + public IParser getParser() { + if (parser == null) { + parser = UMLParserProvider.getParser(UMLElementTypes.PrimitiveType_3078, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.PrimitiveTypeFloatingLabelEditPartCN.VISUAL_ID)); + } + return parser; + } + + /** + * @generated + */ + protected DirectEditManager getManager() { + if (manager == null) { + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + } + return manager; + } + + /** + * @generated + */ + protected void setManager(DirectEditManager manager) { + this.manager = manager; + } + + /** + * @generated + */ + protected void performDirectEdit() { + BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { + + @Override + public void run() { + getManager().show(); + } + }); + } + + /** + * @generated + */ + protected void performDirectEdit(Point eventLocation) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); + } + } + + /** + * @generated + */ + private void performDirectEdit(char initialCharacter) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(initialCharacter); + } else { + performDirectEdit(); + } + } + + /** + * @generated + */ + @Override + protected void performDirectEditRequest(Request request) { + + final Request theRequest = request; + + if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { + directEditionMode = getDirectEditionType(); + } + switch (directEditionMode) { + case IDirectEdition.NO_DIRECT_EDITION: + // no direct edition mode => does nothing + return; + case IDirectEdition.EXTENDED_DIRECT_EDITOR: + updateExtendedEditorConfiguration(); + if (configuration == null || configuration.getLanguage() == null) { + // Create default edit manager + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + performDefaultDirectEditorEdit(theRequest); + } else { + configuration.preEditAction(resolveSemanticElement()); + Dialog dialog = null; + if (configuration instanceof ICustomDirectEditorConfiguration) { + setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); + initializeDirectEditManager(theRequest); + return; + } else if (configuration instanceof IPopupEditorConfiguration) { + IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); + helper.showEditor(); + return; + } + else if (configuration instanceof IAdvancedEditorConfiguration) { + dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); + } else if (configuration instanceof IDirectEditorConfiguration) { + dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), + configuration); + } else { + return; + } + final Dialog finalDialog = dialog; + + if (Window.OK == dialog.open()) { + TransactionalEditingDomain domain = getEditingDomain(); + RecordingCommand command = new RecordingCommand(domain, "Edit Label") { + + @Override + protected void doExecute() { + configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); + + } + }; + domain.getCommandStack().execute(command); + } + } + break; + case IDirectEdition.DEFAULT_DIRECT_EDITOR: + initializeDirectEditManager(theRequest); + break; + default: + break; + } + } + + /** + * @generated + */ + protected void initializeDirectEditManager(final Request request) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + @Override + public void run() { + if (isActive() && isEditable()) { + if (request.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } + else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void refreshVisuals() { + super.refreshVisuals(); + refreshLabel(); + refreshFont(); + refreshFontColor(); + refreshUnderline(); + refreshStrikeThrough(); + } + + /** + * @generated + */ + protected void refreshLabel() { + EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); + if (maskLabelPolicy == null) { + maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); + } + if (maskLabelPolicy == null) { + View view = (View) getModel(); + if (view.isVisible()) { + setLabelTextHelper(getFigure(), getLabelText()); + setLabelIconHelper(getFigure(), getLabelIcon()); + } + else { + setLabelTextHelper(getFigure(), ""); //$NON-NLS-1$ + setLabelIconHelper(getFigure(), null); + } + } + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + protected void refreshUnderline() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); + } + if (resolveSemanticElement() instanceof Feature) { + if (((Feature) resolveSemanticElement()).isStatic()) { + ((WrappingLabel) getFigure()).setTextUnderline(true); + } + else { + ((WrappingLabel) getFigure()).setTextUnderline(false); + } + } + } + + /** + * @generated + */ + protected void refreshStrikeThrough() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); + } + } + + /** + * @generated + */ + @Override + protected void refreshFont() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null) { + FontData fontData = new FontData( + style.getFontName(), style.getFontHeight(), + (style.isBold() ? SWT.BOLD : SWT.NORMAL) | + (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); + setFont(fontData); + } + } + + /** + * @generated + */ + @Override + protected void setFontColor(Color color) { + getFigure().setForegroundColor(color); + } + + /** + * @generated + */ + @Override + protected void addSemanticListeners() { + if (getParser() instanceof ISemanticParser) { + EObject element = resolveSemanticElement(); + parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); + for (int i = 0; i < parserElements.size(); i++) { + addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ + } + } else { + super.addSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected void removeSemanticListeners() { + if (parserElements != null) { + for (int i = 0; i < parserElements.size(); i++) { + removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ + } + } else { + super.removeSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected AccessibleEditPart getAccessibleEditPart() { + if (accessibleEP == null) { + accessibleEP = new AccessibleGraphicalEditPart() { + + @Override + public void getName(AccessibleEvent e) { + e.result = getLabelTextHelper(getFigure()); + } + }; + } + return accessibleEP; + } + + /** + * @generated + */ + private View getFontStyleOwnerView() { + return getPrimaryView(); + } + + /** + * Returns the kind of associated editor for direct edition. + * + * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition + * @generated + */ + public int getDirectEditionType() { + if (checkExtendedEditor()) { + initExtendedEditorConfiguration(); + return IDirectEdition.EXTENDED_DIRECT_EDITOR; + } + if (checkDefaultEdition()) { + return IDirectEdition.DEFAULT_DIRECT_EDITOR; + } + + // not a named element. no specific editor => do nothing + return IDirectEdition.NO_DIRECT_EDITION; + } + + /** + * Checks if an extended editor is present. + * + * @return true if an extended editor is present. + * @generated + */ + protected boolean checkExtendedEditor() { + if (resolveSemanticElement() != null) { + return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); + } + return false; + } + + /** + * Checks if a default direct edition is available + * + * @return true if a default direct edition is available + * @generated + */ + protected boolean checkDefaultEdition() { + return (getParser() != null); + } + + /** + * Initializes the extended editor configuration + * + * @generated + */ + protected void initExtendedEditorConfiguration() { + if (configuration == null) { + final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("")) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); + } else { + configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); + } + } + } + + /** + * Updates the preference configuration + * + * @generated + */ + protected void updateExtendedEditorConfiguration() { + String languagePreferred = Activator.getDefault().getPreferenceStore().getString( + IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() + .eClass().getInstanceClassName()); + } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { + configuration = null; + } + } + + /** + * Performs the direct edit usually used by GMF editors. + * + * @param theRequest + * the direct edit request that starts the direct edit system + * @generated + */ + protected void performDefaultDirectEditorEdit(final Request theRequest) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + + @Override + public void run() { + if (isActive() && isEditable()) { + if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) theRequest.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { + DirectEditRequest editRequest = (DirectEditRequest) theRequest; + performDirectEdit(editRequest.getLocation()); + } else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + + /** + * @generated + */ + @Override + protected void handleNotificationEvent(Notification event) { + Object feature = event.getFeature(); + if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { + Integer c = (Integer) event.getNewValue(); + setFontColor(DiagramColorRegistry.getInstance().getColor(c)); + } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { + refreshUnderline(); + } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { + refreshStrikeThrough(); + } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { + refreshFont(); + } else { + if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { + refreshLabel(); + } + if (getParser() instanceof ISemanticParser) { + ISemanticParser modelParser = + (ISemanticParser) getParser(); + if (modelParser.areSemanticElementsAffected(null, event)) { + removeSemanticListeners(); + if (resolveSemanticElement() != null) { + addSemanticListeners(); + } + refreshLabel(); + } + } + } + super.handleNotificationEvent(event); + } + + /** + * @generated + */ + @Override + protected IFigure createFigure() { + IFigure label = createFigurePrim(); + defaultText = getLabelTextHelper(label); + return label; + } + + /** + * @generated + */ + protected IFigure createFigurePrim() { + return new PapyrusWrappingLabel(); + } + +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/PrimitiveTypeNameEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/PrimitiveTypeNameEditPart.java index 3bef3b162ed..bb638bc6510 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/PrimitiveTypeNameEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/PrimitiveTypeNameEditPart.java @@ -864,7 +864,7 @@ public class PrimitiveTypeNameEditPart extends PapyrusCompartmentEditPart implem * @generated */ protected void addOwnerElementListeners() { - addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); + addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/PrimitiveTypeNameEditPartCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/PrimitiveTypeNameEditPartCN.java index 169ff1378cb..6d4dec4cffb 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/PrimitiveTypeNameEditPartCN.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/PrimitiveTypeNameEditPartCN.java @@ -864,7 +864,7 @@ public class PrimitiveTypeNameEditPartCN extends PapyrusCompartmentEditPart impl * @generated */ protected void addOwnerElementListeners() { - addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); + addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/PropertyPartCompartmentEditPartCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/PropertyPartCompartmentEditPartCN.java index df70e0bf37e..27a0d388926 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/PropertyPartCompartmentEditPartCN.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/PropertyPartCompartmentEditPartCN.java @@ -26,6 +26,7 @@ import org.eclipse.gmf.runtime.diagram.ui.editpolicies.ResizableCompartmentEditP import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.BorderDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.CustomContainerEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.DuplicatePasteEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.PapyrusCreationEditPolicy; @@ -77,6 +78,7 @@ public class PropertyPartCompartmentEditPartCN extends ShapeCompartmentEditPart installEditPolicy(EditPolicy.GRAPHICAL_NODE_ROLE, new CustomContainerEditPolicy()); installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, new CustomDiagramDragDropEditPolicy()); installEditPolicy(EditPolicyRoles.CREATION_ROLE, new PortInCompartmentCreationEditPolicy()); + installEditPolicy(BorderDisplayEditPolicy.BORDER_DISPLAY_EDITPOLICY, new BorderDisplayEditPolicy()); } /** diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/PropertyPartEditPartCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/PropertyPartEditPartCN.java index 0749986f396..e278b04af2d 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/PropertyPartEditPartCN.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/PropertyPartEditPartCN.java @@ -11,28 +11,38 @@ */ package org.eclipse.papyrus.uml.diagram.composite.edit.parts; +import java.util.Collections; +import java.util.List; + import org.eclipse.draw2d.IFigure; import org.eclipse.draw2d.PositionConstants; import org.eclipse.emf.common.notify.Notification; import org.eclipse.gef.EditPart; import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.GraphicalEditPart; 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.handles.MoveHandle; import org.eclipse.gef.requests.CreateRequest; import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.BorderItemSelectionEditPolicy; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.DragDropEditPolicy; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles; import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; -import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure; import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure; +import org.eclipse.gmf.runtime.notation.Edge; +import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.GetChildLayoutEditPolicy; import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.IPapyrusNodeFigure; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.RoundedRectangleNodePlateFigure; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.SelectableBorderedNodeFigure; +import org.eclipse.papyrus.uml.diagram.common.editparts.RoundedCompartmentEditPart; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AffixedNodeAlignmentEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeNodeLabelDisplayEditPolicy; @@ -42,14 +52,14 @@ import org.eclipse.papyrus.uml.diagram.common.editpolicies.PapyrusCreationEditPo import org.eclipse.papyrus.uml.diagram.common.editpolicies.QualifiedNameDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.ShowHideCompartmentEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.ShowHideRelatedContentsEditPolicy; -import org.eclipse.papyrus.uml.diagram.composite.custom.edit.parts.CustomPropertyPartEditPartCN; +import org.eclipse.papyrus.uml.diagram.common.locator.PortPositionLocator; +import org.eclipse.papyrus.uml.diagram.common.locator.RoundedRectangleLabelPositionLocator; import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.CustomDiagramDragDropEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.CustomGraphicalNodeEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.CustomPropertyPartItemSemanticEditPolicyCN; import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.PropertyLayoutEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.RemoveOrphanViewPolicy; import org.eclipse.papyrus.uml.diagram.composite.custom.figures.PropertyPartFigure; -import org.eclipse.papyrus.uml.diagram.composite.custom.locators.PortPositionLocator; import org.eclipse.papyrus.uml.diagram.composite.edit.policies.PropertyPartItemSemanticEditPolicyCN; import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; import org.eclipse.swt.graphics.Color; @@ -57,7 +67,7 @@ import org.eclipse.swt.graphics.Color; /** * @generated */ -public class PropertyPartEditPartCN extends CustomPropertyPartEditPartCN { +public class PropertyPartEditPartCN extends RoundedCompartmentEditPart { /** * @generated @@ -103,6 +113,7 @@ public class PropertyPartEditPartCN extends CustomPropertyPartEditPartCN { installEditPolicy(ShowHideRelatedContentsEditPolicy.SHOW_HIDE_RELATED_CONTENTS_POLICY, new ShowHideRelatedContentsEditPolicy()); installEditPolicy(ShowHideRelatedContentsEditPolicy.SHOW_HIDE_RELATED_CONTENTS_POLICY, new ShowHideRelatedContentsEditPolicy()); installEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY, new MaskManagedNodeEditPolicy()); + installEditPolicy(EditPolicy.LAYOUT_ROLE, new GetChildLayoutEditPolicy()); // XXX need an SCR to runtime to have another abstract superclass that would let children add reasonable editpolicies // removeEditPolicy(org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles.CONNECTION_HANDLES_ROLE); } @@ -117,6 +128,17 @@ public class PropertyPartEditPartCN extends CustomPropertyPartEditPartCN { protected EditPolicy createChildEditPolicy(EditPart child) { View childView = (View) child.getModel(); switch (UMLVisualIDRegistry.getVisualID(childView)) { + case PropertyPartFloatingLabelEditPartCN.VISUAL_ID: + return new BorderItemSelectionEditPolicy() { + + @Override + protected List createSelectionHandles() { + MoveHandle mh = new MoveHandle((GraphicalEditPart) getHost()); + mh.setBorder(null); + return Collections.singletonList(mh); + } + } + ; case PortEditPart.VISUAL_ID: return new BorderItemResizableEditPolicy(); } @@ -147,6 +169,19 @@ public class PropertyPartEditPartCN extends CustomPropertyPartEditPartCN { **/ @Override protected void handleNotificationEvent(Notification event) { + /* + * when a node have external node labels, the methods refreshChildren() remove the EditPart corresponding to the Label from the EditPart + * Registry. After that, we can't reset the visibility to true (using the Show/Hide Label Action)! + */ + if (NotationPackage.eINSTANCE.getView_Visible().equals(event.getFeature())) { + Object notifier = event.getNotifier(); + List modelChildren = ((View) getModel()).getChildren(); + if (!(notifier instanceof Edge)) { + if (modelChildren.contains(event.getNotifier())) { + return; + } + } + } super.handleNotificationEvent(event); } @@ -188,7 +223,7 @@ public class PropertyPartEditPartCN extends CustomPropertyPartEditPartCN { - //Papyrus Gencode :Affixed Port locator + // Papyrus Gencode :Affixed Port locator if (childEditPart instanceof PortEditPart) { IBorderItemLocator locator = new PortPositionLocator(getMainFigure(), PositionConstants.NONE); getBorderedFigure().getBorderItemContainer().add(((PortEditPart) childEditPart).getFigure(), locator); @@ -254,12 +289,26 @@ public class PropertyPartEditPartCN extends CustomPropertyPartEditPartCN { return getContentPane(); } + /** + * @generated + */ + @Override + protected void addBorderItem(IFigure borderItemContainer, IBorderItemEditPart borderItemEditPart) { + if (borderItemEditPart instanceof PropertyPartFloatingLabelEditPartCN) { + IBorderItemLocator locator = new RoundedRectangleLabelPositionLocator(getMainFigure()); + borderItemContainer.add(borderItemEditPart.getFigure(), locator); + } else + { + super.addBorderItem(borderItemContainer, borderItemEditPart); + } + } + /** * @generated */ @Override protected NodeFigure createNodePlate() { - DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(40, 40); + RoundedRectangleNodePlateFigure result = new RoundedRectangleNodePlateFigure(40, 40); return result; } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/PropertyPartFloatingLabelEditPartCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/PropertyPartFloatingLabelEditPartCN.java new file mode 100644 index 00000000000..56c58c826e4 --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/PropertyPartFloatingLabelEditPartCN.java @@ -0,0 +1,860 @@ +/** + * 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.uml.diagram.composite.edit.parts; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.Label; +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.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.RunnableWithResult; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gef.AccessibleEditPart; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.Request; +import org.eclipse.gef.requests.DirectEditRequest; +import org.eclipse.gef.tools.DirectEditManager; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; +import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; +import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; +import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; +import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; +import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; +import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; +import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; +import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; +import org.eclipse.gmf.runtime.notation.FontStyle; +import org.eclipse.gmf.runtime.notation.NotationPackage; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.text.contentassist.IContentAssistProcessor; +import org.eclipse.jface.viewers.ICellEditorValidator; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.extensionpoints.editors.Activator; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; +import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; +import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.ExternalLabelPrimaryDragRoleEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.PapyrusWrappingLabel; +import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; +import org.eclipse.papyrus.uml.diagram.common.editparts.FloatingLabelEditPart; +import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; +import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; +import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; +import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.accessibility.AccessibleEvent; +import org.eclipse.swt.custom.BusyIndicator; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; +import org.eclipse.uml2.uml.Feature; + +/** + * @generated + */ +public class PropertyPartFloatingLabelEditPartCN extends FloatingLabelEditPart + implements ITextAwareEditPart, IBorderItemEditPart +{ + + /** + * @generated + */ + public static final int VISUAL_ID = 6054; + + /** + * @generated + */ + private DirectEditManager manager; + + /** + * @generated + */ + private IParser parser; + + /** + * @generated + */ + private List parserElements; + + /** + * @generated + */ + private String defaultText; + + /** + * direct edition mode (default, undefined, registered editor, etc.) + * + * @generated + */ + protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; + + /** + * configuration from a registered edit dialog + * + * @generated + */ + protected IDirectEditorConfiguration configuration; + + + /** + * @generated + */ + static { + registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.PropertyPartFloatingLabelEditPartCN.VISUAL_ID), new Point(0, 0)); + } + + /** + * @generated + */ + public PropertyPartFloatingLabelEditPartCN(View view) { + super(view); + } + + /** + * @generated + */ + @Override + protected void createDefaultEditPolicies() { + super.createDefaultEditPolicies(); + installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); + installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ExternalLabelPrimaryDragRoleEditPolicy()); + } + + /** + * @generated + */ + @Override + public IBorderItemLocator getBorderItemLocator() { + IFigure parentFigure = getFigure().getParent(); + if (parentFigure != null && parentFigure.getLayoutManager() != null) { + Object constraint = parentFigure.getLayoutManager().getConstraint(getFigure()); + return (IBorderItemLocator) constraint; + } + return null; + } + + /** + * @generated + */ + @Override + public void refreshBounds() { + int x = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_X())).intValue(); + int y = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_Y())).intValue(); + int width = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Width())).intValue(); + int height = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Height())).intValue(); + getBorderItemLocator().setConstraint(new Rectangle(x, y, width, height)); + } + + + /** + * @generated + */ + protected String getLabelTextHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getText(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getText(); + } else { + return ((Label) figure).getText(); + } + } + + /** + * @generated + */ + protected void setLabelTextHelper(IFigure figure, String text) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setText(text); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setText(text); + } else { + ((Label) figure).setText(text); + } + } + + /** + * @generated + */ + protected Image getLabelIconHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getIcon(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getIcon(); + } else { + return ((Label) figure).getIcon(); + } + } + + /** + * @generated + */ + protected void setLabelIconHelper(IFigure figure, Image icon) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setIcon(icon); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setIcon(icon); + } else { + ((Label) figure).setIcon(icon); + } + } + + /** + * @generated + */ + public void setLabel(IFigure + figure) { + unregisterVisuals(); + setFigure(figure); + defaultText = getLabelTextHelper(figure); + registerVisuals(); + refreshVisuals(); + } + + /** + * @generated + */ + @Override + protected List getModelChildren() { + return Collections.EMPTY_LIST; + } + + /** + * @generated + */ + @Override + public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { + return null; + } + + /** + * @generated + */ + public void setParser(IParser parser) { + this.parser = parser; + } + + /** + * @generated + */ + protected EObject getParserElement() { + return resolveSemanticElement(); + } + + /** + * @generated + */ + protected Image getLabelIcon() { + return null; + } + + /** + * @generated + */ + protected String getLabelText() { + String text = null; + EObject parserElement = getParserElement(); + if (parserElement != null && getParser() != null) { + text = getParser().getPrintString( + new EObjectAdapter(parserElement), + getParserOptions().intValue()); + } + if (text == null || text.length() == 0) { + text = defaultText; + } + return text; + } + + /** + * @generated + */ + @Override + public void setLabelText(String text) { + setLabelTextHelper(getFigure(), text); + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + @Override + public String getEditText() { + if (getParserElement() == null || getParser() == null) { + return ""; //$NON-NLS-1$ + } + return getParser().getEditString( + new EObjectAdapter(getParserElement()), + getParserOptions().intValue()); + } + + /** + * @generated + */ + protected boolean isEditable() { + return getParser() != null; + } + + /** + * @generated + */ + @Override + public ICellEditorValidator getEditTextValidator() { + return new ICellEditorValidator() { + + @Override + public String isValid(final Object value) { + if (value instanceof String) { + final EObject element = getParserElement(); + final IParser parser = getParser(); + try { + IParserEditStatus valid = + (IParserEditStatus) getEditingDomain().runExclusive( + new RunnableWithResult.Impl() { + + @Override + public void run() { + setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); + } + }); + return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); + } catch (InterruptedException ie) { + ie.printStackTrace(); + } + } + + // shouldn't get here + return null; + } + }; + } + + /** + * @generated + */ + @Override + public IContentAssistProcessor getCompletionProcessor() { + if (getParserElement() == null || getParser() == null) { + return null; + } + return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); + } + + /** + * @generated + */ + @Override + public ParserOptions getParserOptions() { + return ParserOptions.NONE; + } + + /** + * @generated + */ + @Override + public IParser getParser() { + if (parser == null) { + parser = UMLParserProvider.getParser(UMLElementTypes.Property_3070, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.PropertyPartFloatingLabelEditPartCN.VISUAL_ID)); + } + return parser; + } + + /** + * @generated + */ + protected DirectEditManager getManager() { + if (manager == null) { + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + } + return manager; + } + + /** + * @generated + */ + protected void setManager(DirectEditManager manager) { + this.manager = manager; + } + + /** + * @generated + */ + protected void performDirectEdit() { + BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { + + @Override + public void run() { + getManager().show(); + } + }); + } + + /** + * @generated + */ + protected void performDirectEdit(Point eventLocation) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); + } + } + + /** + * @generated + */ + private void performDirectEdit(char initialCharacter) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(initialCharacter); + } else { + performDirectEdit(); + } + } + + /** + * @generated + */ + @Override + protected void performDirectEditRequest(Request request) { + + final Request theRequest = request; + + if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { + directEditionMode = getDirectEditionType(); + } + switch (directEditionMode) { + case IDirectEdition.NO_DIRECT_EDITION: + // no direct edition mode => does nothing + return; + case IDirectEdition.EXTENDED_DIRECT_EDITOR: + updateExtendedEditorConfiguration(); + if (configuration == null || configuration.getLanguage() == null) { + // Create default edit manager + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + performDefaultDirectEditorEdit(theRequest); + } else { + configuration.preEditAction(resolveSemanticElement()); + Dialog dialog = null; + if (configuration instanceof ICustomDirectEditorConfiguration) { + setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); + initializeDirectEditManager(theRequest); + return; + } else if (configuration instanceof IPopupEditorConfiguration) { + IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); + helper.showEditor(); + return; + } + else if (configuration instanceof IAdvancedEditorConfiguration) { + dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); + } else if (configuration instanceof IDirectEditorConfiguration) { + dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), + configuration); + } else { + return; + } + final Dialog finalDialog = dialog; + + if (Window.OK == dialog.open()) { + TransactionalEditingDomain domain = getEditingDomain(); + RecordingCommand command = new RecordingCommand(domain, "Edit Label") { + + @Override + protected void doExecute() { + configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); + + } + }; + domain.getCommandStack().execute(command); + } + } + break; + case IDirectEdition.DEFAULT_DIRECT_EDITOR: + initializeDirectEditManager(theRequest); + break; + default: + break; + } + } + + /** + * @generated + */ + protected void initializeDirectEditManager(final Request request) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + @Override + public void run() { + if (isActive() && isEditable()) { + if (request.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } + else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void refreshVisuals() { + super.refreshVisuals(); + refreshLabel(); + refreshFont(); + refreshFontColor(); + refreshUnderline(); + refreshStrikeThrough(); + } + + /** + * @generated + */ + protected void refreshLabel() { + EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); + if (maskLabelPolicy == null) { + maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); + } + if (maskLabelPolicy == null) { + View view = (View) getModel(); + if (view.isVisible()) { + setLabelTextHelper(getFigure(), getLabelText()); + setLabelIconHelper(getFigure(), getLabelIcon()); + } + else { + setLabelTextHelper(getFigure(), ""); //$NON-NLS-1$ + setLabelIconHelper(getFigure(), null); + } + } + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + protected void refreshUnderline() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); + } + if (resolveSemanticElement() instanceof Feature) { + if (((Feature) resolveSemanticElement()).isStatic()) { + ((WrappingLabel) getFigure()).setTextUnderline(true); + } + else { + ((WrappingLabel) getFigure()).setTextUnderline(false); + } + } + } + + /** + * @generated + */ + protected void refreshStrikeThrough() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); + } + } + + /** + * @generated + */ + @Override + protected void refreshFont() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null) { + FontData fontData = new FontData( + style.getFontName(), style.getFontHeight(), + (style.isBold() ? SWT.BOLD : SWT.NORMAL) | + (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); + setFont(fontData); + } + } + + /** + * @generated + */ + @Override + protected void setFontColor(Color color) { + getFigure().setForegroundColor(color); + } + + /** + * @generated + */ + @Override + protected void addSemanticListeners() { + if (getParser() instanceof ISemanticParser) { + EObject element = resolveSemanticElement(); + parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); + for (int i = 0; i < parserElements.size(); i++) { + addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ + } + } else { + super.addSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected void removeSemanticListeners() { + if (parserElements != null) { + for (int i = 0; i < parserElements.size(); i++) { + removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ + } + } else { + super.removeSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected AccessibleEditPart getAccessibleEditPart() { + if (accessibleEP == null) { + accessibleEP = new AccessibleGraphicalEditPart() { + + @Override + public void getName(AccessibleEvent e) { + e.result = getLabelTextHelper(getFigure()); + } + }; + } + return accessibleEP; + } + + /** + * @generated + */ + private View getFontStyleOwnerView() { + return getPrimaryView(); + } + + /** + * Returns the kind of associated editor for direct edition. + * + * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition + * @generated + */ + public int getDirectEditionType() { + if (checkExtendedEditor()) { + initExtendedEditorConfiguration(); + return IDirectEdition.EXTENDED_DIRECT_EDITOR; + } + if (checkDefaultEdition()) { + return IDirectEdition.DEFAULT_DIRECT_EDITOR; + } + + // not a named element. no specific editor => do nothing + return IDirectEdition.NO_DIRECT_EDITION; + } + + /** + * Checks if an extended editor is present. + * + * @return true if an extended editor is present. + * @generated + */ + protected boolean checkExtendedEditor() { + if (resolveSemanticElement() != null) { + return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); + } + return false; + } + + /** + * Checks if a default direct edition is available + * + * @return true if a default direct edition is available + * @generated + */ + protected boolean checkDefaultEdition() { + return (getParser() != null); + } + + /** + * Initializes the extended editor configuration + * + * @generated + */ + protected void initExtendedEditorConfiguration() { + if (configuration == null) { + final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("")) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); + } else { + configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); + } + } + } + + /** + * Updates the preference configuration + * + * @generated + */ + protected void updateExtendedEditorConfiguration() { + String languagePreferred = Activator.getDefault().getPreferenceStore().getString( + IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() + .eClass().getInstanceClassName()); + } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { + configuration = null; + } + } + + /** + * Performs the direct edit usually used by GMF editors. + * + * @param theRequest + * the direct edit request that starts the direct edit system + * @generated + */ + protected void performDefaultDirectEditorEdit(final Request theRequest) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + + @Override + public void run() { + if (isActive() && isEditable()) { + if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) theRequest.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { + DirectEditRequest editRequest = (DirectEditRequest) theRequest; + performDirectEdit(editRequest.getLocation()); + } else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + + /** + * @generated + */ + @Override + protected void handleNotificationEvent(Notification event) { + Object feature = event.getFeature(); + if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { + Integer c = (Integer) event.getNewValue(); + setFontColor(DiagramColorRegistry.getInstance().getColor(c)); + } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { + refreshUnderline(); + } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { + refreshStrikeThrough(); + } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { + refreshFont(); + } else { + if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { + refreshLabel(); + } + if (getParser() instanceof ISemanticParser) { + ISemanticParser modelParser = + (ISemanticParser) getParser(); + if (modelParser.areSemanticElementsAffected(null, event)) { + removeSemanticListeners(); + if (resolveSemanticElement() != null) { + addSemanticListeners(); + } + refreshLabel(); + } + } + } + super.handleNotificationEvent(event); + } + + /** + * @generated + */ + @Override + protected IFigure createFigure() { + IFigure label = createFigurePrim(); + defaultText = getLabelTextHelper(label); + return label; + } + + /** + * @generated + */ + protected IFigure createFigurePrim() { + return new PapyrusWrappingLabel(); + } + +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/PropertyPartNameEditPartCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/PropertyPartNameEditPartCN.java index ea515462c86..48fccdccda3 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/PropertyPartNameEditPartCN.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/PropertyPartNameEditPartCN.java @@ -866,7 +866,7 @@ public class PropertyPartNameEditPartCN extends PapyrusCompartmentEditPart imple * @generated */ protected void addOwnerElementListeners() { - addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); + addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ProtocolStateMachineCompositeCompartmentEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ProtocolStateMachineCompositeCompartmentEditPart.java index 0ea025d3586..1e291264b25 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ProtocolStateMachineCompositeCompartmentEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ProtocolStateMachineCompositeCompartmentEditPart.java @@ -26,6 +26,7 @@ import org.eclipse.gmf.runtime.diagram.ui.editpolicies.ResizableCompartmentEditP import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.BorderDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.CustomContainerEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.DuplicatePasteEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.PapyrusCreationEditPolicy; @@ -75,6 +76,7 @@ public class ProtocolStateMachineCompositeCompartmentEditPart extends ShapeCompa installEditPolicy(EditPolicy.GRAPHICAL_NODE_ROLE, new CustomContainerEditPolicy()); installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, new CustomDiagramDragDropEditPolicy()); installEditPolicy(EditPolicyRoles.CREATION_ROLE, new PortInCompartmentCreationEditPolicy()); + installEditPolicy(BorderDisplayEditPolicy.BORDER_DISPLAY_EDITPOLICY, new BorderDisplayEditPolicy()); } /** diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ProtocolStateMachineCompositeCompartmentEditPartCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ProtocolStateMachineCompositeCompartmentEditPartCN.java index 99926bfc7f8..00579d76733 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ProtocolStateMachineCompositeCompartmentEditPartCN.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ProtocolStateMachineCompositeCompartmentEditPartCN.java @@ -26,6 +26,7 @@ import org.eclipse.gmf.runtime.diagram.ui.editpolicies.ResizableCompartmentEditP import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.BorderDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.CustomContainerEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.DuplicatePasteEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.PapyrusCreationEditPolicy; @@ -75,6 +76,7 @@ public class ProtocolStateMachineCompositeCompartmentEditPartCN extends ShapeCom installEditPolicy(EditPolicy.GRAPHICAL_NODE_ROLE, new CustomContainerEditPolicy()); installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, new CustomDiagramDragDropEditPolicy()); installEditPolicy(EditPolicyRoles.CREATION_ROLE, new PortInCompartmentCreationEditPolicy()); + installEditPolicy(BorderDisplayEditPolicy.BORDER_DISPLAY_EDITPOLICY, new BorderDisplayEditPolicy()); } /** diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ProtocolStateMachineCompositeEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ProtocolStateMachineCompositeEditPart.java index 22de104ad8a..035478d66cb 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ProtocolStateMachineCompositeEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ProtocolStateMachineCompositeEditPart.java @@ -11,28 +11,37 @@ */ package org.eclipse.papyrus.uml.diagram.composite.edit.parts; +import java.util.Collections; +import java.util.List; + import org.eclipse.draw2d.IFigure; import org.eclipse.draw2d.PositionConstants; import org.eclipse.emf.common.notify.Notification; import org.eclipse.gef.EditPart; import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.GraphicalEditPart; 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.handles.MoveHandle; import org.eclipse.gef.requests.CreateRequest; import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.BorderItemSelectionEditPolicy; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.DragDropEditPolicy; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles; import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; -import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure; import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure; +import org.eclipse.gmf.runtime.notation.Edge; +import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.GetChildLayoutEditPolicy; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.IPapyrusNodeFigure; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.RoundedRectangleNodePlateFigure; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.SelectableBorderedNodeFigure; -import org.eclipse.papyrus.uml.diagram.common.editparts.NamedElementEditPart; +import org.eclipse.papyrus.uml.diagram.common.editparts.RoundedCompartmentEditPart; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AffixedNodeAlignmentEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeNodeLabelDisplayEditPolicy; @@ -41,11 +50,11 @@ import org.eclipse.papyrus.uml.diagram.common.editpolicies.PapyrusCreationEditPo import org.eclipse.papyrus.uml.diagram.common.editpolicies.QualifiedNameDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.ShowHideClassifierContentsEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.ShowHideCompartmentEditPolicy; +import org.eclipse.papyrus.uml.diagram.common.locator.RoundedRectangleLabelPositionLocator; import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.BehaviorLayoutEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.CustomDiagramDragDropEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.RemoveOrphanViewPolicy; import org.eclipse.papyrus.uml.diagram.composite.custom.figures.ProtocolStateMachineCompositeFigure; -import org.eclipse.papyrus.uml.diagram.composite.custom.locators.PortPositionLocator; import org.eclipse.papyrus.uml.diagram.composite.edit.policies.ProtocolStateMachineCompositeItemSemanticEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; import org.eclipse.swt.graphics.Color; @@ -53,7 +62,7 @@ import org.eclipse.swt.graphics.Color; /** * @generated */ -public class ProtocolStateMachineCompositeEditPart extends NamedElementEditPart { +public class ProtocolStateMachineCompositeEditPart extends RoundedCompartmentEditPart { /** * @generated @@ -95,6 +104,7 @@ public class ProtocolStateMachineCompositeEditPart extends NamedElementEditPart installEditPolicy(ShowHideCompartmentEditPolicy.SHOW_HIDE_COMPARTMENT_POLICY, new ShowHideCompartmentEditPolicy()); installEditPolicy(AffixedNodeAlignmentEditPolicy.AFFIXED_CHILD_ALIGNMENT_ROLE, new AffixedNodeAlignmentEditPolicy()); installEditPolicy("REMOVE_ORPHAN_VIEW", new RemoveOrphanViewPolicy()); //$NON-NLS-1$ + installEditPolicy(EditPolicy.LAYOUT_ROLE, new GetChildLayoutEditPolicy()); // XXX need an SCR to runtime to have another abstract superclass that would let children add reasonable editpolicies // removeEditPolicy(org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles.CONNECTION_HANDLES_ROLE); } @@ -109,6 +119,17 @@ public class ProtocolStateMachineCompositeEditPart extends NamedElementEditPart protected EditPolicy createChildEditPolicy(EditPart child) { View childView = (View) child.getModel(); switch (UMLVisualIDRegistry.getVisualID(childView)) { + case ProtocolStateMachineCompositeFloatingLabelEditPart.VISUAL_ID: + return new BorderItemSelectionEditPolicy() { + + @Override + protected List createSelectionHandles() { + MoveHandle mh = new MoveHandle((GraphicalEditPart) getHost()); + mh.setBorder(null); + return Collections.singletonList(mh); + } + } + ; case PortEditPart.VISUAL_ID: case ParameterEditPart.VISUAL_ID: return new BorderItemResizableEditPolicy(); @@ -140,6 +161,19 @@ public class ProtocolStateMachineCompositeEditPart extends NamedElementEditPart **/ @Override protected void handleNotificationEvent(Notification event) { + /* + * when a node have external node labels, the methods refreshChildren() remove the EditPart corresponding to the Label from the EditPart + * Registry. After that, we can't reset the visibility to true (using the Show/Hide Label Action)! + */ + if (NotationPackage.eINSTANCE.getView_Visible().equals(event.getFeature())) { + Object notifier = event.getNotifier(); + List modelChildren = ((View) getModel()).getChildren(); + if (!(notifier instanceof Edge)) { + if (modelChildren.contains(event.getNotifier())) { + return; + } + } + } super.handleNotificationEvent(event); } @@ -181,9 +215,9 @@ public class ProtocolStateMachineCompositeEditPart extends NamedElementEditPart - //Papyrus Gencode :Affixed Port locator + // Papyrus Gencode :Affixed Port locator if (childEditPart instanceof PortEditPart) { - IBorderItemLocator locator = new PortPositionLocator(getMainFigure(), PositionConstants.NONE); + IBorderItemLocator locator = new org.eclipse.papyrus.uml.diagram.common.locator.PortPositionLocator(getMainFigure(), PositionConstants.NONE); getBorderedFigure().getBorderItemContainer().add(((PortEditPart) childEditPart).getFigure(), locator); return true; } @@ -191,9 +225,9 @@ public class ProtocolStateMachineCompositeEditPart extends NamedElementEditPart - //Papyrus Gencode :Affixed Port locator + // Papyrus Gencode :Affixed Port locator if (childEditPart instanceof ParameterEditPart) { - IBorderItemLocator locator = new PortPositionLocator(getMainFigure(), PositionConstants.NONE); + IBorderItemLocator locator = new org.eclipse.papyrus.uml.diagram.common.locator.PortPositionLocator(getMainFigure(), PositionConstants.NONE); getBorderedFigure().getBorderItemContainer().add(((ParameterEditPart) childEditPart).getFigure(), locator); return true; } @@ -261,12 +295,26 @@ public class ProtocolStateMachineCompositeEditPart extends NamedElementEditPart return getContentPane(); } + /** + * @generated + */ + @Override + protected void addBorderItem(IFigure borderItemContainer, IBorderItemEditPart borderItemEditPart) { + if (borderItemEditPart instanceof ProtocolStateMachineCompositeFloatingLabelEditPart) { + IBorderItemLocator locator = new RoundedRectangleLabelPositionLocator(getMainFigure()); + borderItemContainer.add(borderItemEditPart.getFigure(), locator); + } else + { + super.addBorderItem(borderItemContainer, borderItemEditPart); + } + } + /** * @generated */ @Override protected NodeFigure createNodePlate() { - DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(40, 40); + RoundedRectangleNodePlateFigure result = new RoundedRectangleNodePlateFigure(40, 40); return result; } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ProtocolStateMachineCompositeEditPartCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ProtocolStateMachineCompositeEditPartCN.java index 025f5cca13a..980f2f4630d 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ProtocolStateMachineCompositeEditPartCN.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ProtocolStateMachineCompositeEditPartCN.java @@ -11,28 +11,37 @@ */ package org.eclipse.papyrus.uml.diagram.composite.edit.parts; +import java.util.Collections; +import java.util.List; + import org.eclipse.draw2d.IFigure; import org.eclipse.draw2d.PositionConstants; import org.eclipse.emf.common.notify.Notification; import org.eclipse.gef.EditPart; import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.GraphicalEditPart; 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.handles.MoveHandle; import org.eclipse.gef.requests.CreateRequest; import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.BorderItemSelectionEditPolicy; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.DragDropEditPolicy; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles; import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; -import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure; import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure; +import org.eclipse.gmf.runtime.notation.Edge; +import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.GetChildLayoutEditPolicy; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.IPapyrusNodeFigure; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.RoundedRectangleNodePlateFigure; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.SelectableBorderedNodeFigure; -import org.eclipse.papyrus.uml.diagram.common.editparts.NamedElementEditPart; +import org.eclipse.papyrus.uml.diagram.common.editparts.RoundedCompartmentEditPart; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AffixedNodeAlignmentEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeNodeLabelDisplayEditPolicy; @@ -41,11 +50,11 @@ import org.eclipse.papyrus.uml.diagram.common.editpolicies.PapyrusCreationEditPo import org.eclipse.papyrus.uml.diagram.common.editpolicies.QualifiedNameDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.ShowHideClassifierContentsEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.ShowHideCompartmentEditPolicy; +import org.eclipse.papyrus.uml.diagram.common.locator.RoundedRectangleLabelPositionLocator; import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.BehaviorLayoutEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.CustomDiagramDragDropEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.RemoveOrphanViewPolicy; import org.eclipse.papyrus.uml.diagram.composite.custom.figures.ProtocolStateMachineCompositeFigure; -import org.eclipse.papyrus.uml.diagram.composite.custom.locators.PortPositionLocator; import org.eclipse.papyrus.uml.diagram.composite.edit.policies.ProtocolStateMachineCompositeItemSemanticEditPolicyCN; import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; import org.eclipse.swt.graphics.Color; @@ -53,7 +62,7 @@ import org.eclipse.swt.graphics.Color; /** * @generated */ -public class ProtocolStateMachineCompositeEditPartCN extends NamedElementEditPart { +public class ProtocolStateMachineCompositeEditPartCN extends RoundedCompartmentEditPart { /** * @generated @@ -95,6 +104,7 @@ public class ProtocolStateMachineCompositeEditPartCN extends NamedElementEditPar installEditPolicy(ShowHideCompartmentEditPolicy.SHOW_HIDE_COMPARTMENT_POLICY, new ShowHideCompartmentEditPolicy()); installEditPolicy(AffixedNodeAlignmentEditPolicy.AFFIXED_CHILD_ALIGNMENT_ROLE, new AffixedNodeAlignmentEditPolicy()); installEditPolicy("REMOVE_ORPHAN_VIEW", new RemoveOrphanViewPolicy()); //$NON-NLS-1$ + installEditPolicy(EditPolicy.LAYOUT_ROLE, new GetChildLayoutEditPolicy()); // XXX need an SCR to runtime to have another abstract superclass that would let children add reasonable editpolicies // removeEditPolicy(org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles.CONNECTION_HANDLES_ROLE); } @@ -109,6 +119,17 @@ public class ProtocolStateMachineCompositeEditPartCN extends NamedElementEditPar protected EditPolicy createChildEditPolicy(EditPart child) { View childView = (View) child.getModel(); switch (UMLVisualIDRegistry.getVisualID(childView)) { + case ProtocolStateMachineCompositeFloatingLabelEditPartCN.VISUAL_ID: + return new BorderItemSelectionEditPolicy() { + + @Override + protected List createSelectionHandles() { + MoveHandle mh = new MoveHandle((GraphicalEditPart) getHost()); + mh.setBorder(null); + return Collections.singletonList(mh); + } + } + ; case PortEditPart.VISUAL_ID: case ParameterEditPart.VISUAL_ID: return new BorderItemResizableEditPolicy(); @@ -140,6 +161,19 @@ public class ProtocolStateMachineCompositeEditPartCN extends NamedElementEditPar **/ @Override protected void handleNotificationEvent(Notification event) { + /* + * when a node have external node labels, the methods refreshChildren() remove the EditPart corresponding to the Label from the EditPart + * Registry. After that, we can't reset the visibility to true (using the Show/Hide Label Action)! + */ + if (NotationPackage.eINSTANCE.getView_Visible().equals(event.getFeature())) { + Object notifier = event.getNotifier(); + List modelChildren = ((View) getModel()).getChildren(); + if (!(notifier instanceof Edge)) { + if (modelChildren.contains(event.getNotifier())) { + return; + } + } + } super.handleNotificationEvent(event); } @@ -181,9 +215,9 @@ public class ProtocolStateMachineCompositeEditPartCN extends NamedElementEditPar - //Papyrus Gencode :Affixed Port locator + // Papyrus Gencode :Affixed Port locator if (childEditPart instanceof PortEditPart) { - IBorderItemLocator locator = new PortPositionLocator(getMainFigure(), PositionConstants.NONE); + IBorderItemLocator locator = new org.eclipse.papyrus.uml.diagram.common.locator.PortPositionLocator(getMainFigure(), PositionConstants.NONE); getBorderedFigure().getBorderItemContainer().add(((PortEditPart) childEditPart).getFigure(), locator); return true; } @@ -191,9 +225,9 @@ public class ProtocolStateMachineCompositeEditPartCN extends NamedElementEditPar - //Papyrus Gencode :Affixed Port locator + // Papyrus Gencode :Affixed Port locator if (childEditPart instanceof ParameterEditPart) { - IBorderItemLocator locator = new PortPositionLocator(getMainFigure(), PositionConstants.NONE); + IBorderItemLocator locator = new org.eclipse.papyrus.uml.diagram.common.locator.PortPositionLocator(getMainFigure(), PositionConstants.NONE); getBorderedFigure().getBorderItemContainer().add(((ParameterEditPart) childEditPart).getFigure(), locator); return true; } @@ -261,12 +295,26 @@ public class ProtocolStateMachineCompositeEditPartCN extends NamedElementEditPar return getContentPane(); } + /** + * @generated + */ + @Override + protected void addBorderItem(IFigure borderItemContainer, IBorderItemEditPart borderItemEditPart) { + if (borderItemEditPart instanceof ProtocolStateMachineCompositeFloatingLabelEditPartCN) { + IBorderItemLocator locator = new RoundedRectangleLabelPositionLocator(getMainFigure()); + borderItemContainer.add(borderItemEditPart.getFigure(), locator); + } else + { + super.addBorderItem(borderItemContainer, borderItemEditPart); + } + } + /** * @generated */ @Override protected NodeFigure createNodePlate() { - DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(40, 40); + RoundedRectangleNodePlateFigure result = new RoundedRectangleNodePlateFigure(40, 40); return result; } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ProtocolStateMachineCompositeFloatingLabelEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ProtocolStateMachineCompositeFloatingLabelEditPart.java new file mode 100644 index 00000000000..91bf7acf63f --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ProtocolStateMachineCompositeFloatingLabelEditPart.java @@ -0,0 +1,860 @@ +/** + * 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.uml.diagram.composite.edit.parts; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.Label; +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.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.RunnableWithResult; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gef.AccessibleEditPart; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.Request; +import org.eclipse.gef.requests.DirectEditRequest; +import org.eclipse.gef.tools.DirectEditManager; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; +import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; +import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; +import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; +import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; +import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; +import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; +import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; +import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; +import org.eclipse.gmf.runtime.notation.FontStyle; +import org.eclipse.gmf.runtime.notation.NotationPackage; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.text.contentassist.IContentAssistProcessor; +import org.eclipse.jface.viewers.ICellEditorValidator; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.extensionpoints.editors.Activator; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; +import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; +import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.ExternalLabelPrimaryDragRoleEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.PapyrusWrappingLabel; +import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; +import org.eclipse.papyrus.uml.diagram.common.editparts.FloatingLabelEditPart; +import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; +import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; +import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; +import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.accessibility.AccessibleEvent; +import org.eclipse.swt.custom.BusyIndicator; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; +import org.eclipse.uml2.uml.Feature; + +/** + * @generated + */ +public class ProtocolStateMachineCompositeFloatingLabelEditPart extends FloatingLabelEditPart + implements ITextAwareEditPart, IBorderItemEditPart +{ + + /** + * @generated + */ + public static final int VISUAL_ID = 6081; + + /** + * @generated + */ + private DirectEditManager manager; + + /** + * @generated + */ + private IParser parser; + + /** + * @generated + */ + private List parserElements; + + /** + * @generated + */ + private String defaultText; + + /** + * direct edition mode (default, undefined, registered editor, etc.) + * + * @generated + */ + protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; + + /** + * configuration from a registered edit dialog + * + * @generated + */ + protected IDirectEditorConfiguration configuration; + + + /** + * @generated + */ + static { + registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.ProtocolStateMachineCompositeFloatingLabelEditPart.VISUAL_ID), new Point(0, 0)); + } + + /** + * @generated + */ + public ProtocolStateMachineCompositeFloatingLabelEditPart(View view) { + super(view); + } + + /** + * @generated + */ + @Override + protected void createDefaultEditPolicies() { + super.createDefaultEditPolicies(); + installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); + installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ExternalLabelPrimaryDragRoleEditPolicy()); + } + + /** + * @generated + */ + @Override + public IBorderItemLocator getBorderItemLocator() { + IFigure parentFigure = getFigure().getParent(); + if (parentFigure != null && parentFigure.getLayoutManager() != null) { + Object constraint = parentFigure.getLayoutManager().getConstraint(getFigure()); + return (IBorderItemLocator) constraint; + } + return null; + } + + /** + * @generated + */ + @Override + public void refreshBounds() { + int x = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_X())).intValue(); + int y = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_Y())).intValue(); + int width = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Width())).intValue(); + int height = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Height())).intValue(); + getBorderItemLocator().setConstraint(new Rectangle(x, y, width, height)); + } + + + /** + * @generated + */ + protected String getLabelTextHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getText(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getText(); + } else { + return ((Label) figure).getText(); + } + } + + /** + * @generated + */ + protected void setLabelTextHelper(IFigure figure, String text) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setText(text); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setText(text); + } else { + ((Label) figure).setText(text); + } + } + + /** + * @generated + */ + protected Image getLabelIconHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getIcon(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getIcon(); + } else { + return ((Label) figure).getIcon(); + } + } + + /** + * @generated + */ + protected void setLabelIconHelper(IFigure figure, Image icon) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setIcon(icon); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setIcon(icon); + } else { + ((Label) figure).setIcon(icon); + } + } + + /** + * @generated + */ + public void setLabel(IFigure + figure) { + unregisterVisuals(); + setFigure(figure); + defaultText = getLabelTextHelper(figure); + registerVisuals(); + refreshVisuals(); + } + + /** + * @generated + */ + @Override + protected List getModelChildren() { + return Collections.EMPTY_LIST; + } + + /** + * @generated + */ + @Override + public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { + return null; + } + + /** + * @generated + */ + public void setParser(IParser parser) { + this.parser = parser; + } + + /** + * @generated + */ + protected EObject getParserElement() { + return resolveSemanticElement(); + } + + /** + * @generated + */ + protected Image getLabelIcon() { + return null; + } + + /** + * @generated + */ + protected String getLabelText() { + String text = null; + EObject parserElement = getParserElement(); + if (parserElement != null && getParser() != null) { + text = getParser().getPrintString( + new EObjectAdapter(parserElement), + getParserOptions().intValue()); + } + if (text == null || text.length() == 0) { + text = defaultText; + } + return text; + } + + /** + * @generated + */ + @Override + public void setLabelText(String text) { + setLabelTextHelper(getFigure(), text); + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + @Override + public String getEditText() { + if (getParserElement() == null || getParser() == null) { + return ""; //$NON-NLS-1$ + } + return getParser().getEditString( + new EObjectAdapter(getParserElement()), + getParserOptions().intValue()); + } + + /** + * @generated + */ + protected boolean isEditable() { + return getParser() != null; + } + + /** + * @generated + */ + @Override + public ICellEditorValidator getEditTextValidator() { + return new ICellEditorValidator() { + + @Override + public String isValid(final Object value) { + if (value instanceof String) { + final EObject element = getParserElement(); + final IParser parser = getParser(); + try { + IParserEditStatus valid = + (IParserEditStatus) getEditingDomain().runExclusive( + new RunnableWithResult.Impl() { + + @Override + public void run() { + setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); + } + }); + return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); + } catch (InterruptedException ie) { + ie.printStackTrace(); + } + } + + // shouldn't get here + return null; + } + }; + } + + /** + * @generated + */ + @Override + public IContentAssistProcessor getCompletionProcessor() { + if (getParserElement() == null || getParser() == null) { + return null; + } + return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); + } + + /** + * @generated + */ + @Override + public ParserOptions getParserOptions() { + return ParserOptions.NONE; + } + + /** + * @generated + */ + @Override + public IParser getParser() { + if (parser == null) { + parser = UMLParserProvider.getParser(UMLElementTypes.ProtocolStateMachine_2062, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.ProtocolStateMachineCompositeFloatingLabelEditPart.VISUAL_ID)); + } + return parser; + } + + /** + * @generated + */ + protected DirectEditManager getManager() { + if (manager == null) { + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + } + return manager; + } + + /** + * @generated + */ + protected void setManager(DirectEditManager manager) { + this.manager = manager; + } + + /** + * @generated + */ + protected void performDirectEdit() { + BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { + + @Override + public void run() { + getManager().show(); + } + }); + } + + /** + * @generated + */ + protected void performDirectEdit(Point eventLocation) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); + } + } + + /** + * @generated + */ + private void performDirectEdit(char initialCharacter) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(initialCharacter); + } else { + performDirectEdit(); + } + } + + /** + * @generated + */ + @Override + protected void performDirectEditRequest(Request request) { + + final Request theRequest = request; + + if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { + directEditionMode = getDirectEditionType(); + } + switch (directEditionMode) { + case IDirectEdition.NO_DIRECT_EDITION: + // no direct edition mode => does nothing + return; + case IDirectEdition.EXTENDED_DIRECT_EDITOR: + updateExtendedEditorConfiguration(); + if (configuration == null || configuration.getLanguage() == null) { + // Create default edit manager + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + performDefaultDirectEditorEdit(theRequest); + } else { + configuration.preEditAction(resolveSemanticElement()); + Dialog dialog = null; + if (configuration instanceof ICustomDirectEditorConfiguration) { + setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); + initializeDirectEditManager(theRequest); + return; + } else if (configuration instanceof IPopupEditorConfiguration) { + IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); + helper.showEditor(); + return; + } + else if (configuration instanceof IAdvancedEditorConfiguration) { + dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); + } else if (configuration instanceof IDirectEditorConfiguration) { + dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), + configuration); + } else { + return; + } + final Dialog finalDialog = dialog; + + if (Window.OK == dialog.open()) { + TransactionalEditingDomain domain = getEditingDomain(); + RecordingCommand command = new RecordingCommand(domain, "Edit Label") { + + @Override + protected void doExecute() { + configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); + + } + }; + domain.getCommandStack().execute(command); + } + } + break; + case IDirectEdition.DEFAULT_DIRECT_EDITOR: + initializeDirectEditManager(theRequest); + break; + default: + break; + } + } + + /** + * @generated + */ + protected void initializeDirectEditManager(final Request request) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + @Override + public void run() { + if (isActive() && isEditable()) { + if (request.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } + else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void refreshVisuals() { + super.refreshVisuals(); + refreshLabel(); + refreshFont(); + refreshFontColor(); + refreshUnderline(); + refreshStrikeThrough(); + } + + /** + * @generated + */ + protected void refreshLabel() { + EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); + if (maskLabelPolicy == null) { + maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); + } + if (maskLabelPolicy == null) { + View view = (View) getModel(); + if (view.isVisible()) { + setLabelTextHelper(getFigure(), getLabelText()); + setLabelIconHelper(getFigure(), getLabelIcon()); + } + else { + setLabelTextHelper(getFigure(), ""); //$NON-NLS-1$ + setLabelIconHelper(getFigure(), null); + } + } + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + protected void refreshUnderline() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); + } + if (resolveSemanticElement() instanceof Feature) { + if (((Feature) resolveSemanticElement()).isStatic()) { + ((WrappingLabel) getFigure()).setTextUnderline(true); + } + else { + ((WrappingLabel) getFigure()).setTextUnderline(false); + } + } + } + + /** + * @generated + */ + protected void refreshStrikeThrough() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); + } + } + + /** + * @generated + */ + @Override + protected void refreshFont() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null) { + FontData fontData = new FontData( + style.getFontName(), style.getFontHeight(), + (style.isBold() ? SWT.BOLD : SWT.NORMAL) | + (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); + setFont(fontData); + } + } + + /** + * @generated + */ + @Override + protected void setFontColor(Color color) { + getFigure().setForegroundColor(color); + } + + /** + * @generated + */ + @Override + protected void addSemanticListeners() { + if (getParser() instanceof ISemanticParser) { + EObject element = resolveSemanticElement(); + parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); + for (int i = 0; i < parserElements.size(); i++) { + addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ + } + } else { + super.addSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected void removeSemanticListeners() { + if (parserElements != null) { + for (int i = 0; i < parserElements.size(); i++) { + removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ + } + } else { + super.removeSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected AccessibleEditPart getAccessibleEditPart() { + if (accessibleEP == null) { + accessibleEP = new AccessibleGraphicalEditPart() { + + @Override + public void getName(AccessibleEvent e) { + e.result = getLabelTextHelper(getFigure()); + } + }; + } + return accessibleEP; + } + + /** + * @generated + */ + private View getFontStyleOwnerView() { + return getPrimaryView(); + } + + /** + * Returns the kind of associated editor for direct edition. + * + * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition + * @generated + */ + public int getDirectEditionType() { + if (checkExtendedEditor()) { + initExtendedEditorConfiguration(); + return IDirectEdition.EXTENDED_DIRECT_EDITOR; + } + if (checkDefaultEdition()) { + return IDirectEdition.DEFAULT_DIRECT_EDITOR; + } + + // not a named element. no specific editor => do nothing + return IDirectEdition.NO_DIRECT_EDITION; + } + + /** + * Checks if an extended editor is present. + * + * @return true if an extended editor is present. + * @generated + */ + protected boolean checkExtendedEditor() { + if (resolveSemanticElement() != null) { + return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); + } + return false; + } + + /** + * Checks if a default direct edition is available + * + * @return true if a default direct edition is available + * @generated + */ + protected boolean checkDefaultEdition() { + return (getParser() != null); + } + + /** + * Initializes the extended editor configuration + * + * @generated + */ + protected void initExtendedEditorConfiguration() { + if (configuration == null) { + final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("")) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); + } else { + configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); + } + } + } + + /** + * Updates the preference configuration + * + * @generated + */ + protected void updateExtendedEditorConfiguration() { + String languagePreferred = Activator.getDefault().getPreferenceStore().getString( + IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() + .eClass().getInstanceClassName()); + } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { + configuration = null; + } + } + + /** + * Performs the direct edit usually used by GMF editors. + * + * @param theRequest + * the direct edit request that starts the direct edit system + * @generated + */ + protected void performDefaultDirectEditorEdit(final Request theRequest) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + + @Override + public void run() { + if (isActive() && isEditable()) { + if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) theRequest.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { + DirectEditRequest editRequest = (DirectEditRequest) theRequest; + performDirectEdit(editRequest.getLocation()); + } else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + + /** + * @generated + */ + @Override + protected void handleNotificationEvent(Notification event) { + Object feature = event.getFeature(); + if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { + Integer c = (Integer) event.getNewValue(); + setFontColor(DiagramColorRegistry.getInstance().getColor(c)); + } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { + refreshUnderline(); + } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { + refreshStrikeThrough(); + } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { + refreshFont(); + } else { + if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { + refreshLabel(); + } + if (getParser() instanceof ISemanticParser) { + ISemanticParser modelParser = + (ISemanticParser) getParser(); + if (modelParser.areSemanticElementsAffected(null, event)) { + removeSemanticListeners(); + if (resolveSemanticElement() != null) { + addSemanticListeners(); + } + refreshLabel(); + } + } + } + super.handleNotificationEvent(event); + } + + /** + * @generated + */ + @Override + protected IFigure createFigure() { + IFigure label = createFigurePrim(); + defaultText = getLabelTextHelper(label); + return label; + } + + /** + * @generated + */ + protected IFigure createFigurePrim() { + return new PapyrusWrappingLabel(); + } + +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ProtocolStateMachineCompositeFloatingLabelEditPartCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ProtocolStateMachineCompositeFloatingLabelEditPartCN.java new file mode 100644 index 00000000000..a08e62330b3 --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ProtocolStateMachineCompositeFloatingLabelEditPartCN.java @@ -0,0 +1,860 @@ +/** + * 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.uml.diagram.composite.edit.parts; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.Label; +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.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.RunnableWithResult; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gef.AccessibleEditPart; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.Request; +import org.eclipse.gef.requests.DirectEditRequest; +import org.eclipse.gef.tools.DirectEditManager; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; +import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; +import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; +import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; +import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; +import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; +import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; +import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; +import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; +import org.eclipse.gmf.runtime.notation.FontStyle; +import org.eclipse.gmf.runtime.notation.NotationPackage; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.text.contentassist.IContentAssistProcessor; +import org.eclipse.jface.viewers.ICellEditorValidator; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.extensionpoints.editors.Activator; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; +import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; +import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.ExternalLabelPrimaryDragRoleEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.PapyrusWrappingLabel; +import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; +import org.eclipse.papyrus.uml.diagram.common.editparts.FloatingLabelEditPart; +import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; +import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; +import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; +import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.accessibility.AccessibleEvent; +import org.eclipse.swt.custom.BusyIndicator; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; +import org.eclipse.uml2.uml.Feature; + +/** + * @generated + */ +public class ProtocolStateMachineCompositeFloatingLabelEditPartCN extends FloatingLabelEditPart + implements ITextAwareEditPart, IBorderItemEditPart +{ + + /** + * @generated + */ + public static final int VISUAL_ID = 6059; + + /** + * @generated + */ + private DirectEditManager manager; + + /** + * @generated + */ + private IParser parser; + + /** + * @generated + */ + private List parserElements; + + /** + * @generated + */ + private String defaultText; + + /** + * direct edition mode (default, undefined, registered editor, etc.) + * + * @generated + */ + protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; + + /** + * configuration from a registered edit dialog + * + * @generated + */ + protected IDirectEditorConfiguration configuration; + + + /** + * @generated + */ + static { + registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.ProtocolStateMachineCompositeFloatingLabelEditPartCN.VISUAL_ID), new Point(0, 0)); + } + + /** + * @generated + */ + public ProtocolStateMachineCompositeFloatingLabelEditPartCN(View view) { + super(view); + } + + /** + * @generated + */ + @Override + protected void createDefaultEditPolicies() { + super.createDefaultEditPolicies(); + installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); + installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ExternalLabelPrimaryDragRoleEditPolicy()); + } + + /** + * @generated + */ + @Override + public IBorderItemLocator getBorderItemLocator() { + IFigure parentFigure = getFigure().getParent(); + if (parentFigure != null && parentFigure.getLayoutManager() != null) { + Object constraint = parentFigure.getLayoutManager().getConstraint(getFigure()); + return (IBorderItemLocator) constraint; + } + return null; + } + + /** + * @generated + */ + @Override + public void refreshBounds() { + int x = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_X())).intValue(); + int y = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_Y())).intValue(); + int width = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Width())).intValue(); + int height = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Height())).intValue(); + getBorderItemLocator().setConstraint(new Rectangle(x, y, width, height)); + } + + + /** + * @generated + */ + protected String getLabelTextHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getText(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getText(); + } else { + return ((Label) figure).getText(); + } + } + + /** + * @generated + */ + protected void setLabelTextHelper(IFigure figure, String text) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setText(text); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setText(text); + } else { + ((Label) figure).setText(text); + } + } + + /** + * @generated + */ + protected Image getLabelIconHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getIcon(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getIcon(); + } else { + return ((Label) figure).getIcon(); + } + } + + /** + * @generated + */ + protected void setLabelIconHelper(IFigure figure, Image icon) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setIcon(icon); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setIcon(icon); + } else { + ((Label) figure).setIcon(icon); + } + } + + /** + * @generated + */ + public void setLabel(IFigure + figure) { + unregisterVisuals(); + setFigure(figure); + defaultText = getLabelTextHelper(figure); + registerVisuals(); + refreshVisuals(); + } + + /** + * @generated + */ + @Override + protected List getModelChildren() { + return Collections.EMPTY_LIST; + } + + /** + * @generated + */ + @Override + public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { + return null; + } + + /** + * @generated + */ + public void setParser(IParser parser) { + this.parser = parser; + } + + /** + * @generated + */ + protected EObject getParserElement() { + return resolveSemanticElement(); + } + + /** + * @generated + */ + protected Image getLabelIcon() { + return null; + } + + /** + * @generated + */ + protected String getLabelText() { + String text = null; + EObject parserElement = getParserElement(); + if (parserElement != null && getParser() != null) { + text = getParser().getPrintString( + new EObjectAdapter(parserElement), + getParserOptions().intValue()); + } + if (text == null || text.length() == 0) { + text = defaultText; + } + return text; + } + + /** + * @generated + */ + @Override + public void setLabelText(String text) { + setLabelTextHelper(getFigure(), text); + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + @Override + public String getEditText() { + if (getParserElement() == null || getParser() == null) { + return ""; //$NON-NLS-1$ + } + return getParser().getEditString( + new EObjectAdapter(getParserElement()), + getParserOptions().intValue()); + } + + /** + * @generated + */ + protected boolean isEditable() { + return getParser() != null; + } + + /** + * @generated + */ + @Override + public ICellEditorValidator getEditTextValidator() { + return new ICellEditorValidator() { + + @Override + public String isValid(final Object value) { + if (value instanceof String) { + final EObject element = getParserElement(); + final IParser parser = getParser(); + try { + IParserEditStatus valid = + (IParserEditStatus) getEditingDomain().runExclusive( + new RunnableWithResult.Impl() { + + @Override + public void run() { + setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); + } + }); + return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); + } catch (InterruptedException ie) { + ie.printStackTrace(); + } + } + + // shouldn't get here + return null; + } + }; + } + + /** + * @generated + */ + @Override + public IContentAssistProcessor getCompletionProcessor() { + if (getParserElement() == null || getParser() == null) { + return null; + } + return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); + } + + /** + * @generated + */ + @Override + public ParserOptions getParserOptions() { + return ParserOptions.NONE; + } + + /** + * @generated + */ + @Override + public IParser getParser() { + if (parser == null) { + parser = UMLParserProvider.getParser(UMLElementTypes.ProtocolStateMachine_3074, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.ProtocolStateMachineCompositeFloatingLabelEditPartCN.VISUAL_ID)); + } + return parser; + } + + /** + * @generated + */ + protected DirectEditManager getManager() { + if (manager == null) { + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + } + return manager; + } + + /** + * @generated + */ + protected void setManager(DirectEditManager manager) { + this.manager = manager; + } + + /** + * @generated + */ + protected void performDirectEdit() { + BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { + + @Override + public void run() { + getManager().show(); + } + }); + } + + /** + * @generated + */ + protected void performDirectEdit(Point eventLocation) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); + } + } + + /** + * @generated + */ + private void performDirectEdit(char initialCharacter) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(initialCharacter); + } else { + performDirectEdit(); + } + } + + /** + * @generated + */ + @Override + protected void performDirectEditRequest(Request request) { + + final Request theRequest = request; + + if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { + directEditionMode = getDirectEditionType(); + } + switch (directEditionMode) { + case IDirectEdition.NO_DIRECT_EDITION: + // no direct edition mode => does nothing + return; + case IDirectEdition.EXTENDED_DIRECT_EDITOR: + updateExtendedEditorConfiguration(); + if (configuration == null || configuration.getLanguage() == null) { + // Create default edit manager + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + performDefaultDirectEditorEdit(theRequest); + } else { + configuration.preEditAction(resolveSemanticElement()); + Dialog dialog = null; + if (configuration instanceof ICustomDirectEditorConfiguration) { + setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); + initializeDirectEditManager(theRequest); + return; + } else if (configuration instanceof IPopupEditorConfiguration) { + IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); + helper.showEditor(); + return; + } + else if (configuration instanceof IAdvancedEditorConfiguration) { + dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); + } else if (configuration instanceof IDirectEditorConfiguration) { + dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), + configuration); + } else { + return; + } + final Dialog finalDialog = dialog; + + if (Window.OK == dialog.open()) { + TransactionalEditingDomain domain = getEditingDomain(); + RecordingCommand command = new RecordingCommand(domain, "Edit Label") { + + @Override + protected void doExecute() { + configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); + + } + }; + domain.getCommandStack().execute(command); + } + } + break; + case IDirectEdition.DEFAULT_DIRECT_EDITOR: + initializeDirectEditManager(theRequest); + break; + default: + break; + } + } + + /** + * @generated + */ + protected void initializeDirectEditManager(final Request request) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + @Override + public void run() { + if (isActive() && isEditable()) { + if (request.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } + else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void refreshVisuals() { + super.refreshVisuals(); + refreshLabel(); + refreshFont(); + refreshFontColor(); + refreshUnderline(); + refreshStrikeThrough(); + } + + /** + * @generated + */ + protected void refreshLabel() { + EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); + if (maskLabelPolicy == null) { + maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); + } + if (maskLabelPolicy == null) { + View view = (View) getModel(); + if (view.isVisible()) { + setLabelTextHelper(getFigure(), getLabelText()); + setLabelIconHelper(getFigure(), getLabelIcon()); + } + else { + setLabelTextHelper(getFigure(), ""); //$NON-NLS-1$ + setLabelIconHelper(getFigure(), null); + } + } + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + protected void refreshUnderline() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); + } + if (resolveSemanticElement() instanceof Feature) { + if (((Feature) resolveSemanticElement()).isStatic()) { + ((WrappingLabel) getFigure()).setTextUnderline(true); + } + else { + ((WrappingLabel) getFigure()).setTextUnderline(false); + } + } + } + + /** + * @generated + */ + protected void refreshStrikeThrough() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); + } + } + + /** + * @generated + */ + @Override + protected void refreshFont() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null) { + FontData fontData = new FontData( + style.getFontName(), style.getFontHeight(), + (style.isBold() ? SWT.BOLD : SWT.NORMAL) | + (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); + setFont(fontData); + } + } + + /** + * @generated + */ + @Override + protected void setFontColor(Color color) { + getFigure().setForegroundColor(color); + } + + /** + * @generated + */ + @Override + protected void addSemanticListeners() { + if (getParser() instanceof ISemanticParser) { + EObject element = resolveSemanticElement(); + parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); + for (int i = 0; i < parserElements.size(); i++) { + addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ + } + } else { + super.addSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected void removeSemanticListeners() { + if (parserElements != null) { + for (int i = 0; i < parserElements.size(); i++) { + removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ + } + } else { + super.removeSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected AccessibleEditPart getAccessibleEditPart() { + if (accessibleEP == null) { + accessibleEP = new AccessibleGraphicalEditPart() { + + @Override + public void getName(AccessibleEvent e) { + e.result = getLabelTextHelper(getFigure()); + } + }; + } + return accessibleEP; + } + + /** + * @generated + */ + private View getFontStyleOwnerView() { + return getPrimaryView(); + } + + /** + * Returns the kind of associated editor for direct edition. + * + * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition + * @generated + */ + public int getDirectEditionType() { + if (checkExtendedEditor()) { + initExtendedEditorConfiguration(); + return IDirectEdition.EXTENDED_DIRECT_EDITOR; + } + if (checkDefaultEdition()) { + return IDirectEdition.DEFAULT_DIRECT_EDITOR; + } + + // not a named element. no specific editor => do nothing + return IDirectEdition.NO_DIRECT_EDITION; + } + + /** + * Checks if an extended editor is present. + * + * @return true if an extended editor is present. + * @generated + */ + protected boolean checkExtendedEditor() { + if (resolveSemanticElement() != null) { + return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); + } + return false; + } + + /** + * Checks if a default direct edition is available + * + * @return true if a default direct edition is available + * @generated + */ + protected boolean checkDefaultEdition() { + return (getParser() != null); + } + + /** + * Initializes the extended editor configuration + * + * @generated + */ + protected void initExtendedEditorConfiguration() { + if (configuration == null) { + final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("")) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); + } else { + configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); + } + } + } + + /** + * Updates the preference configuration + * + * @generated + */ + protected void updateExtendedEditorConfiguration() { + String languagePreferred = Activator.getDefault().getPreferenceStore().getString( + IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() + .eClass().getInstanceClassName()); + } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { + configuration = null; + } + } + + /** + * Performs the direct edit usually used by GMF editors. + * + * @param theRequest + * the direct edit request that starts the direct edit system + * @generated + */ + protected void performDefaultDirectEditorEdit(final Request theRequest) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + + @Override + public void run() { + if (isActive() && isEditable()) { + if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) theRequest.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { + DirectEditRequest editRequest = (DirectEditRequest) theRequest; + performDirectEdit(editRequest.getLocation()); + } else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + + /** + * @generated + */ + @Override + protected void handleNotificationEvent(Notification event) { + Object feature = event.getFeature(); + if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { + Integer c = (Integer) event.getNewValue(); + setFontColor(DiagramColorRegistry.getInstance().getColor(c)); + } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { + refreshUnderline(); + } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { + refreshStrikeThrough(); + } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { + refreshFont(); + } else { + if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { + refreshLabel(); + } + if (getParser() instanceof ISemanticParser) { + ISemanticParser modelParser = + (ISemanticParser) getParser(); + if (modelParser.areSemanticElementsAffected(null, event)) { + removeSemanticListeners(); + if (resolveSemanticElement() != null) { + addSemanticListeners(); + } + refreshLabel(); + } + } + } + super.handleNotificationEvent(event); + } + + /** + * @generated + */ + @Override + protected IFigure createFigure() { + IFigure label = createFigurePrim(); + defaultText = getLabelTextHelper(label); + return label; + } + + /** + * @generated + */ + protected IFigure createFigurePrim() { + return new PapyrusWrappingLabel(); + } + +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ProtocolStateMachineCompositeNameEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ProtocolStateMachineCompositeNameEditPart.java index f0d3bfd00f4..86dfbebcd4b 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ProtocolStateMachineCompositeNameEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ProtocolStateMachineCompositeNameEditPart.java @@ -864,7 +864,7 @@ public class ProtocolStateMachineCompositeNameEditPart extends PapyrusCompartmen * @generated */ protected void addOwnerElementListeners() { - addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); + addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ProtocolStateMachineCompositeNameEditPartCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ProtocolStateMachineCompositeNameEditPartCN.java index a49edfc1f8f..c5a4ac5d422 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ProtocolStateMachineCompositeNameEditPartCN.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/ProtocolStateMachineCompositeNameEditPartCN.java @@ -864,7 +864,7 @@ public class ProtocolStateMachineCompositeNameEditPartCN extends PapyrusCompartm * @generated */ protected void addOwnerElementListeners() { - addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); + addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/RealizationAppliedStereotypeEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/RealizationAppliedStereotypeEditPart.java index 5a4e70011e3..59dd45d7474 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/RealizationAppliedStereotypeEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/RealizationAppliedStereotypeEditPart.java @@ -1,820 +1,815 @@ -/** - * 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.uml.diagram.composite.edit.parts; - -import java.util.Collections; -import java.util.List; - -import org.eclipse.draw2d.ConnectionLocator; -import org.eclipse.draw2d.IFigure; -import org.eclipse.draw2d.Label; -import org.eclipse.draw2d.geometry.Point; -import org.eclipse.emf.common.notify.Notification; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.transaction.RecordingCommand; -import org.eclipse.emf.transaction.RunnableWithResult; -import org.eclipse.emf.transaction.TransactionalEditingDomain; -import org.eclipse.gef.AccessibleEditPart; -import org.eclipse.gef.EditPolicy; -import org.eclipse.gef.Request; -import org.eclipse.gef.requests.DirectEditRequest; -import org.eclipse.gef.tools.DirectEditManager; -import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; -import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; -import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; -import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; -import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; -import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; -import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; -import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; -import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; -import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; -import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; -import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; -import org.eclipse.gmf.runtime.notation.FontStyle; -import org.eclipse.gmf.runtime.notation.NotationPackage; -import org.eclipse.gmf.runtime.notation.View; -import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.jface.text.contentassist.IContentAssistProcessor; -import org.eclipse.jface.viewers.ICellEditorValidator; -import org.eclipse.jface.window.Window; -import org.eclipse.papyrus.extensionpoints.editors.Activator; -import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; -import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; -import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; -import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; -import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; -import org.eclipse.papyrus.infra.gmfdiag.common.editpart.IControlParserForDirectEdit; -import org.eclipse.papyrus.infra.gmfdiag.common.editpart.PapyrusLabelEditPart; -import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; -import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; -import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.PapyrusLinkLabelDragPolicy; -import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; -import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; -import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; -import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; -import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; -import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; -import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; -import org.eclipse.swt.SWT; -import org.eclipse.swt.accessibility.AccessibleEvent; -import org.eclipse.swt.custom.BusyIndicator; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.FontData; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.widgets.Display; -import org.eclipse.ui.PlatformUI; -import org.eclipse.uml2.uml.Feature; - -/** - * @generated - */ -public class RealizationAppliedStereotypeEditPart extends PapyrusLabelEditPart implements ITextAwareEditPart, IControlParserForDirectEdit { - - /** - * @generated - */ - public static final int VISUAL_ID = 6018; - - /** - * @generated - */ - private DirectEditManager manager; - - /** - * @generated - */ - private IParser parser; - - /** - * @generated - */ - private List parserElements; - - /** - * @generated - */ - private String defaultText; - - /** - * direct edition mode (default, undefined, registered editor, etc.) - * - * @generated - */ - protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; - - /** - * configuration from a registered edit dialog - * - * @generated - */ - protected IDirectEditorConfiguration configuration; - /** - * @generated - */ - static { - registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.RealizationAppliedStereotypeEditPart.VISUAL_ID), new Point(0, 30)); - } - - /** - * @generated - */ - public RealizationAppliedStereotypeEditPart(View view) { - super(view); - } - - /** - * @generated - */ - @Override - protected void createDefaultEditPolicies() { - super.createDefaultEditPolicies(); - installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); - installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); - installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new PapyrusLinkLabelDragPolicy()); - } - - /** - * @generated - */ - @Override - public int getKeyPoint() { - return ConnectionLocator.MIDDLE; - } - - /** - * @generated - */ - protected String getLabelTextHelper(IFigure figure) { - if (figure instanceof WrappingLabel) { - return ((WrappingLabel) figure).getText(); - } else if (figure instanceof ILabelFigure) { - return ((ILabelFigure) figure).getText(); - } else { - return ((Label) figure).getText(); - } - } - - /** - * @generated - */ - protected void setLabelTextHelper(IFigure figure, String text) { - if (figure instanceof WrappingLabel) { - ((WrappingLabel) figure).setText(text); - } else if (figure instanceof ILabelFigure) { - ((ILabelFigure) figure).setText(text); - } else { - ((Label) figure).setText(text); - } - } - - /** - * @generated - */ - protected Image getLabelIconHelper(IFigure figure) { - if (figure instanceof WrappingLabel) { - return ((WrappingLabel) figure).getIcon(); - } else if (figure instanceof ILabelFigure) { - return ((ILabelFigure) figure).getIcon(); - } else { - return ((Label) figure).getIcon(); - } - } - - /** - * @generated - */ - protected void setLabelIconHelper(IFigure figure, Image icon) { - if (figure instanceof WrappingLabel) { - ((WrappingLabel) figure).setIcon(icon); - } else if (figure instanceof ILabelFigure) { - ((ILabelFigure) figure).setIcon(icon); - } else { - ((Label) figure).setIcon(icon); - } - } - - /** - * @generated - */ - public void setLabel(IFigure - figure) { - unregisterVisuals(); - setFigure(figure); - defaultText = getLabelTextHelper(figure); - registerVisuals(); - refreshVisuals(); - } - - /** - * @generated - */ - @Override - protected List getModelChildren() { - return Collections.EMPTY_LIST; - } - - /** - * @generated - */ - @Override - public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { - return null; - } - - /** - * @generated - */ - @Override - public void setParser(IParser parser) { - this.parser = parser; - } - - /** - * @generated - */ - protected EObject getParserElement() { - return resolveSemanticElement(); - } - - /** - * @generated - */ - protected Image getLabelIcon() { - return null; - } - - /** - * @generated - */ - protected String getLabelText() { - String text = null; - EObject parserElement = getParserElement(); - if (parserElement != null && getParser() != null) { - text = getParser().getPrintString( - new EObjectAdapter(parserElement), - getParserOptions().intValue()); - } - if (text == null || text.length() == 0) { - text = defaultText; - } - return text; - } - - /** - * @generated - */ - @Override - public void setLabelText(String text) { - setLabelTextHelper(getFigure(), text); - Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); - if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); - } - Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); - if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); - } - } - - /** - * @generated - */ - @Override - public String getEditText() { - if (getParserElement() == null || getParser() == null) { - return ""; //$NON-NLS-1$ - } - return getParser().getEditString( - new EObjectAdapter(getParserElement()), - getParserOptions().intValue()); - } - - /** - * @generated - */ - protected boolean isEditable() { - return false; - } - - /** - * @generated - */ - @Override - public ICellEditorValidator getEditTextValidator() { - return new ICellEditorValidator() { - - @Override - public String isValid(final Object value) { - if (value instanceof String) { - final EObject element = getParserElement(); - final IParser parser = getParser(); - try { - IParserEditStatus valid = - (IParserEditStatus) getEditingDomain().runExclusive( - new RunnableWithResult.Impl() { - - @Override - public void run() { - setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); - } - }); - return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); - } catch (InterruptedException ie) { - ie.printStackTrace(); - } - } - - // shouldn't get here - return null; - } - }; - } - - /** - * @generated - */ - @Override - public IContentAssistProcessor getCompletionProcessor() { - if (getParserElement() == null || getParser() == null) { - return null; - } - return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); - } - - /** - * @generated - */ - @Override - public ParserOptions getParserOptions() { - return ParserOptions.NONE; - } - - /** - * @generated - */ - @Override - public IParser getParser() { - if (parser == null) { - parser = UMLParserProvider.getParser(UMLElementTypes.Realization_4006, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.RealizationAppliedStereotypeEditPart.VISUAL_ID)); - } - return parser; - } - - /** - * @generated - */ - protected DirectEditManager getManager() { - if (manager == null) { - setManager(new MultilineLabelDirectEditManager(this, - MultilineLabelDirectEditManager.getTextCellEditorClass(this), - UMLEditPartFactory.getTextCellEditorLocator(this))); - } - return manager; - } - - /** - * @generated - */ - protected void setManager(DirectEditManager manager) { - this.manager = manager; - } - - /** - * @generated - */ - protected void performDirectEdit() { - BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { - - @Override - public void run() { - getManager().show(); - } - }); - } - - /** - * @generated - */ - protected void performDirectEdit(Point eventLocation) { - if (getManager() instanceof TextDirectEditManager) { - ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); - } - } - - /** - * @generated - */ - private void performDirectEdit(char initialCharacter) { - if (getManager() instanceof TextDirectEditManager) { - ((TextDirectEditManager) getManager()).show(initialCharacter); - } else { - performDirectEdit(); - } - } - - /** - * @generated - */ - @Override - protected void performDirectEditRequest(Request request) { - - final Request theRequest = request; - - if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { - directEditionMode = getDirectEditionType(); - } - switch (directEditionMode) { - case IDirectEdition.NO_DIRECT_EDITION: - // no direct edition mode => does nothing - return; - case IDirectEdition.EXTENDED_DIRECT_EDITOR: - updateExtendedEditorConfiguration(); - if (configuration == null || configuration.getLanguage() == null) { - // Create default edit manager - setManager(new MultilineLabelDirectEditManager(this, - MultilineLabelDirectEditManager.getTextCellEditorClass(this), - UMLEditPartFactory.getTextCellEditorLocator(this))); - performDefaultDirectEditorEdit(theRequest); - } else { - configuration.preEditAction(resolveSemanticElement()); - Dialog dialog = null; - if (configuration instanceof ICustomDirectEditorConfiguration) { - setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); - initializeDirectEditManager(theRequest); - return; - } else if (configuration instanceof IPopupEditorConfiguration) { - IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); - helper.showEditor(); - return; - } - else if (configuration instanceof IAdvancedEditorConfiguration) { - dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); - } else if (configuration instanceof IDirectEditorConfiguration) { - dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), - configuration); - } else { - return; - } - final Dialog finalDialog = dialog; - - if (Window.OK == dialog.open()) { - TransactionalEditingDomain domain = getEditingDomain(); - RecordingCommand command = new RecordingCommand(domain, "Edit Label") { - - @Override - protected void doExecute() { - configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); - - } - }; - domain.getCommandStack().execute(command); - } - } - break; - case IDirectEdition.DEFAULT_DIRECT_EDITOR: - initializeDirectEditManager(theRequest); - break; - default: - break; - } - } - - /** - * @generated - */ - protected void initializeDirectEditManager(final Request request) { - // initialize the direct edit manager - try { - getEditingDomain().runExclusive(new Runnable() { - @Override - public void run() { - if (isActive() && isEditable()) { - if (request.getExtendedData().get( - RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { - Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); - performDirectEdit(initialChar.charValue()); - } - else { - performDirectEdit(); - } - } - } - }); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - - /** - * @generated - */ - @Override - protected void refreshVisuals() { - super.refreshVisuals(); - refreshLabel(); - refreshFont(); - refreshFontColor(); - refreshUnderline(); - refreshStrikeThrough(); - } - - /** - * @generated - */ - protected void refreshLabel() { - EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); - if (maskLabelPolicy == null) { - maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); - } - if (maskLabelPolicy == null) { - View view = (View) getModel(); - if (view.isVisible()) { - setLabelTextHelper(getFigure(), getLabelText()); - setLabelIconHelper(getFigure(), getLabelIcon()); - } - else { - setLabelTextHelper(getFigure(), ""); //$NON-NLS-1$ - setLabelIconHelper(getFigure(), null); - } - } - Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); - if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); - } - Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); - if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); - } - } - - /** - * @generated - */ - protected void refreshUnderline() { - FontStyle style = - (FontStyle) getFontStyleOwnerView().getStyle( - NotationPackage.eINSTANCE.getFontStyle()); - if (style != null && getFigure() instanceof WrappingLabel) { - ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); - } - if (resolveSemanticElement() instanceof Feature) { - if (((Feature) resolveSemanticElement()).isStatic()) { - ((WrappingLabel) getFigure()).setTextUnderline(true); - } - else { - ((WrappingLabel) getFigure()).setTextUnderline(false); - } - } - } - - /** - * @generated - */ - protected void refreshStrikeThrough() { - FontStyle style = - (FontStyle) getFontStyleOwnerView().getStyle( - NotationPackage.eINSTANCE.getFontStyle()); - if (style != null && getFigure() instanceof WrappingLabel) { - ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); - } - } - - /** - * @generated - */ - @Override - protected void refreshFont() { - FontStyle style = - (FontStyle) getFontStyleOwnerView().getStyle( - NotationPackage.eINSTANCE.getFontStyle()); - if (style != null) { - FontData fontData = new FontData( - style.getFontName(), style.getFontHeight(), - (style.isBold() ? SWT.BOLD : SWT.NORMAL) | - (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); - setFont(fontData); - } - } - - /** - * @generated - */ - @Override - protected void setFontColor(Color color) { - getFigure().setForegroundColor(color); - } - - /** - * @generated - */ - @Override - protected void addSemanticListeners() { - if (getParser() instanceof ISemanticParser) { - EObject element = resolveSemanticElement(); - parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); - for (int i = 0; i < parserElements.size(); i++) { - addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ - } - } else { - super.addSemanticListeners(); - } - } - - /** - * @generated - */ - @Override - protected void removeSemanticListeners() { - if (parserElements != null) { - for (int i = 0; i < parserElements.size(); i++) { - removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ - } - } else { - super.removeSemanticListeners(); - } - } - - /** - * @generated - */ - @Override - protected AccessibleEditPart getAccessibleEditPart() { - if (accessibleEP == null) { - accessibleEP = new AccessibleGraphicalEditPart() { - - @Override - public void getName(AccessibleEvent e) { - e.result = getLabelTextHelper(getFigure()); - } - }; - } - return accessibleEP; - } - - /** - * @generated - */ - private View getFontStyleOwnerView() { - return getPrimaryView(); - } - - /** - * Returns the kind of associated editor for direct edition. - * - * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition - * @generated - */ - public int getDirectEditionType() { - // The label is read-only (defined in GMFGen model) - return IDirectEdition.NO_DIRECT_EDITION; - } - - /** - * Checks if an extended editor is present. - * - * @return true if an extended editor is present. - * @generated - */ - protected boolean checkExtendedEditor() { - if (resolveSemanticElement() != null) { - return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); - } - return false; - } - - /** - * Checks if a default direct edition is available - * - * @return true if a default direct edition is available - * @generated - */ - protected boolean checkDefaultEdition() { - return (getParser() != null); - } - - /** - * Initializes the extended editor configuration - * - * @generated - */ - protected void initExtendedEditorConfiguration() { - if (configuration == null) { - final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); - if (languagePreferred != null && !languagePreferred.equals("")) { - configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); - } else { - configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); - } - } - } - - /** - * Updates the preference configuration - * - * @generated - */ - protected void updateExtendedEditorConfiguration() { - String languagePreferred = Activator.getDefault().getPreferenceStore().getString( - IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); - if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { - configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() - .eClass().getInstanceClassName()); - } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { - configuration = null; - } - } - - /** - * Performs the direct edit usually used by GMF editors. - * - * @param theRequest - * the direct edit request that starts the direct edit system - * @generated - */ - protected void performDefaultDirectEditorEdit(final Request theRequest) { - // initialize the direct edit manager - try { - getEditingDomain().runExclusive(new Runnable() { - - @Override - public void run() { - if (isActive() && isEditable()) { - if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { - Character initialChar = (Character) theRequest.getExtendedData().get( - RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); - performDirectEdit(initialChar.charValue()); - } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { - DirectEditRequest editRequest = (DirectEditRequest) theRequest; - performDirectEdit(editRequest.getLocation()); - } else { - performDirectEdit(); - } - } - } - }); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - - /** - * @generated - */ - @Override - protected void handleNotificationEvent(Notification event) { - Object feature = event.getFeature(); - if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { - Integer c = (Integer) event.getNewValue(); - setFontColor(DiagramColorRegistry.getInstance().getColor(c)); - } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { - refreshUnderline(); - } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { - refreshStrikeThrough(); - } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || - NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || - NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || - NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { - refreshFont(); - } else { - if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { - refreshLabel(); - } - if (getParser() instanceof ISemanticParser) { - ISemanticParser modelParser = - (ISemanticParser) getParser(); - if (modelParser.areSemanticElementsAffected(null, event)) { - removeSemanticListeners(); - if (resolveSemanticElement() != null) { - addSemanticListeners(); - } - refreshLabel(); - } - } - } - - super.handleNotificationEvent(event); - } - - /** - * @generated - */ - @Override - protected IFigure createFigure() { - // Parent should assign one using setLabel() method - return 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.uml.diagram.composite.edit.parts; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.draw2d.ConnectionLocator; +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.Label; +import org.eclipse.draw2d.geometry.Point; +import org.eclipse.emf.common.notify.Notification; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.RunnableWithResult; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gef.AccessibleEditPart; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.Request; +import org.eclipse.gef.requests.DirectEditRequest; +import org.eclipse.gef.tools.DirectEditManager; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; +import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; +import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; +import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; +import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; +import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; +import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; +import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; +import org.eclipse.gmf.runtime.notation.FontStyle; +import org.eclipse.gmf.runtime.notation.NotationPackage; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.gmf.tooling.runtime.edit.policies.DefaultLinkLabelDragPolicy; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.text.contentassist.IContentAssistProcessor; +import org.eclipse.jface.viewers.ICellEditorValidator; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.extensionpoints.editors.Activator; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; +import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; +import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; +import org.eclipse.papyrus.infra.gmfdiag.common.editpart.IControlParserForDirectEdit; +import org.eclipse.papyrus.infra.gmfdiag.common.editpart.PapyrusLabelEditPart; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.PapyrusLinkLabelDragPolicy; +import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; +import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; +import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; +import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; +import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.accessibility.AccessibleEvent; +import org.eclipse.swt.custom.BusyIndicator; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; +import org.eclipse.uml2.uml.Feature; + +/** + * @generated + */ +public class RealizationAppliedStereotypeEditPart extends PapyrusLabelEditPart implements ITextAwareEditPart, IControlParserForDirectEdit { + + /** + * @generated + */ + public static final int VISUAL_ID = 6018; + + /** + * @generated + */ + private DirectEditManager manager; + + /** + * @generated + */ + private IParser parser; + + /** + * @generated + */ + private List parserElements; + + /** + * @generated + */ + private String defaultText; + + /** + * direct edition mode (default, undefined, registered editor, etc.) + * + * @generated + */ + protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; + + /** + * configuration from a registered edit dialog + * + * @generated + */ + protected IDirectEditorConfiguration configuration; + /** + * @generated + */ + static { + registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.RealizationAppliedStereotypeEditPart.VISUAL_ID), new Point(0, 30)); + } + + /** + * @generated + */ + public RealizationAppliedStereotypeEditPart(View view) { + super(view); + } + + /** + * @generated + */ + @Override + protected void createDefaultEditPolicies() { + super.createDefaultEditPolicies(); + installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); + installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new DefaultLinkLabelDragPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new PapyrusLinkLabelDragPolicy()); + } + + /** + * @generated + */ + @Override + public int getKeyPoint() { + return ConnectionLocator.MIDDLE; + } + + /** + * @generated + */ + protected String getLabelTextHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getText(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getText(); + } else { + return ((Label) figure).getText(); + } + } + + /** + * @generated + */ + protected void setLabelTextHelper(IFigure figure, String text) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setText(text); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setText(text); + } else { + ((Label) figure).setText(text); + } + } + + /** + * @generated + */ + protected Image getLabelIconHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getIcon(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getIcon(); + } else { + return ((Label) figure).getIcon(); + } + } + + /** + * @generated + */ + protected void setLabelIconHelper(IFigure figure, Image icon) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setIcon(icon); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setIcon(icon); + } else { + ((Label) figure).setIcon(icon); + } + } + + /** + * @generated + */ + public void setLabel(IFigure + figure) { + unregisterVisuals(); + setFigure(figure); + defaultText = getLabelTextHelper(figure); + registerVisuals(); + refreshVisuals(); + } + + /** + * @generated + */ + @Override + protected List getModelChildren() { + return Collections.EMPTY_LIST; + } + + /** + * @generated + */ + @Override + public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { + return null; + } + + /** + * @generated + */ + @Override + public void setParser(IParser parser) { + this.parser = parser; + } + + /** + * @generated + */ + protected EObject getParserElement() { + return resolveSemanticElement(); + } + + /** + * @generated + */ + protected Image getLabelIcon() { + return null; + } + + /** + * @generated + */ + protected String getLabelText() { + String text = null; + EObject parserElement = getParserElement(); + if (parserElement != null && getParser() != null) { + text = getParser().getPrintString( + new EObjectAdapter(parserElement), + getParserOptions().intValue()); + } + if (text == null || text.length() == 0) { + text = defaultText; + } + return text; + } + + /** + * @generated + */ + @Override + public void setLabelText(String text) { + setLabelTextHelper(getFigure(), text); + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + @Override + public String getEditText() { + if (getParserElement() == null || getParser() == null) { + return ""; //$NON-NLS-1$ + } + return getParser().getEditString( + new EObjectAdapter(getParserElement()), + getParserOptions().intValue()); + } + + /** + * @generated + */ + protected boolean isEditable() { + return false; + } + + /** + * @generated + */ + @Override + public ICellEditorValidator getEditTextValidator() { + return new ICellEditorValidator() { + + @Override + public String isValid(final Object value) { + if (value instanceof String) { + final EObject element = getParserElement(); + final IParser parser = getParser(); + try { + IParserEditStatus valid = + (IParserEditStatus) getEditingDomain().runExclusive( + new RunnableWithResult.Impl() { + + @Override + public void run() { + setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); + } + }); + return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); + } catch (InterruptedException ie) { + ie.printStackTrace(); + } + } + + // shouldn't get here + return null; + } + }; + } + + /** + * @generated + */ + @Override + public IContentAssistProcessor getCompletionProcessor() { + if (getParserElement() == null || getParser() == null) { + return null; + } + return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); + } + + /** + * @generated + */ + @Override + public ParserOptions getParserOptions() { + return ParserOptions.NONE; + } + + /** + * @generated + */ + @Override + public IParser getParser() { + if (parser == null) { + parser = UMLParserProvider.getParser(UMLElementTypes.Realization_4006, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.RealizationAppliedStereotypeEditPart.VISUAL_ID)); + } + return parser; + } + + /** + * @generated + */ + protected DirectEditManager getManager() { + if (manager == null) { + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + } + return manager; + } + + /** + * @generated + */ + protected void setManager(DirectEditManager manager) { + this.manager = manager; + } + + /** + * @generated + */ + protected void performDirectEdit() { + BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { + + @Override + public void run() { + getManager().show(); + } + }); + } + + /** + * @generated + */ + protected void performDirectEdit(Point eventLocation) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); + } + } + + /** + * @generated + */ + private void performDirectEdit(char initialCharacter) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(initialCharacter); + } else { + performDirectEdit(); + } + } + + /** + * @generated + */ + @Override + protected void performDirectEditRequest(Request request) { + + final Request theRequest = request; + + if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { + directEditionMode = getDirectEditionType(); + } + switch (directEditionMode) { + case IDirectEdition.NO_DIRECT_EDITION: + // no direct edition mode => does nothing + return; + case IDirectEdition.EXTENDED_DIRECT_EDITOR: + updateExtendedEditorConfiguration(); + if (configuration == null || configuration.getLanguage() == null) { + // Create default edit manager + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + performDefaultDirectEditorEdit(theRequest); + } else { + configuration.preEditAction(resolveSemanticElement()); + Dialog dialog = null; + if (configuration instanceof ICustomDirectEditorConfiguration) { + setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); + initializeDirectEditManager(theRequest); + return; + } else if (configuration instanceof IPopupEditorConfiguration) { + IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); + helper.showEditor(); + return; + } + else if (configuration instanceof IAdvancedEditorConfiguration) { + dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); + } else if (configuration instanceof IDirectEditorConfiguration) { + dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), + configuration); + } else { + return; + } + final Dialog finalDialog = dialog; + + if (Window.OK == dialog.open()) { + TransactionalEditingDomain domain = getEditingDomain(); + RecordingCommand command = new RecordingCommand(domain, "Edit Label") { + + @Override + protected void doExecute() { + configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); + + } + }; + domain.getCommandStack().execute(command); + } + } + break; + case IDirectEdition.DEFAULT_DIRECT_EDITOR: + initializeDirectEditManager(theRequest); + break; + default: + break; + } + } + + /** + * @generated + */ + protected void initializeDirectEditManager(final Request request) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + @Override + public void run() { + if (isActive() && isEditable()) { + if (request.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } + else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void refreshVisuals() { + super.refreshVisuals(); + refreshLabel(); + refreshFont(); + refreshFontColor(); + refreshUnderline(); + refreshStrikeThrough(); + } + + /** + * @generated + */ + protected void refreshLabel() { + EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); + if (maskLabelPolicy == null) { + maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); + } + if (maskLabelPolicy == null) { + setLabelTextHelper(getFigure(), getLabelText()); + setLabelIconHelper(getFigure(), getLabelIcon()); + } + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + protected void refreshUnderline() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); + } + if (resolveSemanticElement() instanceof Feature) { + if (((Feature) resolveSemanticElement()).isStatic()) { + ((WrappingLabel) getFigure()).setTextUnderline(true); + } + else { + ((WrappingLabel) getFigure()).setTextUnderline(false); + } + } + } + + /** + * @generated + */ + protected void refreshStrikeThrough() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); + } + } + + /** + * @generated + */ + @Override + protected void refreshFont() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null) { + FontData fontData = new FontData( + style.getFontName(), style.getFontHeight(), + (style.isBold() ? SWT.BOLD : SWT.NORMAL) | + (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); + setFont(fontData); + } + } + + /** + * @generated + */ + @Override + protected void setFontColor(Color color) { + getFigure().setForegroundColor(color); + } + + /** + * @generated + */ + @Override + protected void addSemanticListeners() { + if (getParser() instanceof ISemanticParser) { + EObject element = resolveSemanticElement(); + parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); + for (int i = 0; i < parserElements.size(); i++) { + addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ + } + } else { + super.addSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected void removeSemanticListeners() { + if (parserElements != null) { + for (int i = 0; i < parserElements.size(); i++) { + removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ + } + } else { + super.removeSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected AccessibleEditPart getAccessibleEditPart() { + if (accessibleEP == null) { + accessibleEP = new AccessibleGraphicalEditPart() { + + @Override + public void getName(AccessibleEvent e) { + e.result = getLabelTextHelper(getFigure()); + } + }; + } + return accessibleEP; + } + + /** + * @generated + */ + private View getFontStyleOwnerView() { + return getPrimaryView(); + } + + /** + * Returns the kind of associated editor for direct edition. + * + * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition + * @generated + */ + public int getDirectEditionType() { + // The label is read-only (defined in GMFGen model) + return IDirectEdition.NO_DIRECT_EDITION; + } + + /** + * Checks if an extended editor is present. + * + * @return true if an extended editor is present. + * @generated + */ + protected boolean checkExtendedEditor() { + if (resolveSemanticElement() != null) { + return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); + } + return false; + } + + /** + * Checks if a default direct edition is available + * + * @return true if a default direct edition is available + * @generated + */ + protected boolean checkDefaultEdition() { + return (getParser() != null); + } + + /** + * Initializes the extended editor configuration + * + * @generated + */ + protected void initExtendedEditorConfiguration() { + if (configuration == null) { + final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("")) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); + } else { + configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); + } + } + } + + /** + * Updates the preference configuration + * + * @generated + */ + protected void updateExtendedEditorConfiguration() { + String languagePreferred = Activator.getDefault().getPreferenceStore().getString( + IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() + .eClass().getInstanceClassName()); + } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { + configuration = null; + } + } + + /** + * Performs the direct edit usually used by GMF editors. + * + * @param theRequest + * the direct edit request that starts the direct edit system + * @generated + */ + protected void performDefaultDirectEditorEdit(final Request theRequest) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + + @Override + public void run() { + if (isActive() && isEditable()) { + if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) theRequest.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { + DirectEditRequest editRequest = (DirectEditRequest) theRequest; + performDirectEdit(editRequest.getLocation()); + } else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void handleNotificationEvent(Notification event) { + Object feature = event.getFeature(); + if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { + Integer c = (Integer) event.getNewValue(); + setFontColor(DiagramColorRegistry.getInstance().getColor(c)); + } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { + refreshUnderline(); + } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { + refreshStrikeThrough(); + } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { + refreshFont(); + } else { + if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { + refreshLabel(); + } + if (getParser() instanceof ISemanticParser) { + ISemanticParser modelParser = + (ISemanticParser) getParser(); + if (modelParser.areSemanticElementsAffected(null, event)) { + removeSemanticListeners(); + if (resolveSemanticElement() != null) { + addSemanticListeners(); + } + refreshLabel(); + } + } + } + + super.handleNotificationEvent(event); + } + + /** + * @generated + */ + @Override + protected IFigure createFigure() { + // Parent should assign one using setLabel() method + return null; + } +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/RealizationNameEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/RealizationNameEditPart.java index 4d9aa254d48..4de8b2658cc 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/RealizationNameEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/RealizationNameEditPart.java @@ -1,828 +1,823 @@ -/** - * 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.uml.diagram.composite.edit.parts; - -import java.util.Collections; -import java.util.List; - -import org.eclipse.draw2d.ConnectionLocator; -import org.eclipse.draw2d.IFigure; -import org.eclipse.draw2d.Label; -import org.eclipse.draw2d.geometry.Point; -import org.eclipse.emf.common.notify.Notification; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.transaction.RecordingCommand; -import org.eclipse.emf.transaction.RunnableWithResult; -import org.eclipse.emf.transaction.TransactionalEditingDomain; -import org.eclipse.gef.AccessibleEditPart; -import org.eclipse.gef.EditPolicy; -import org.eclipse.gef.Request; -import org.eclipse.gef.requests.DirectEditRequest; -import org.eclipse.gef.tools.DirectEditManager; -import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; -import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; -import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; -import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; -import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; -import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; -import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; -import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; -import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; -import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; -import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; -import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; -import org.eclipse.gmf.runtime.notation.FontStyle; -import org.eclipse.gmf.runtime.notation.NotationPackage; -import org.eclipse.gmf.runtime.notation.View; -import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.jface.text.contentassist.IContentAssistProcessor; -import org.eclipse.jface.viewers.ICellEditorValidator; -import org.eclipse.jface.window.Window; -import org.eclipse.papyrus.extensionpoints.editors.Activator; -import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; -import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; -import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; -import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; -import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; -import org.eclipse.papyrus.infra.gmfdiag.common.editpart.IControlParserForDirectEdit; -import org.eclipse.papyrus.infra.gmfdiag.common.editpart.PapyrusLabelEditPart; -import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; -import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; -import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.PapyrusLinkLabelDragPolicy; -import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; -import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; -import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; -import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; -import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; -import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; -import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; -import org.eclipse.swt.SWT; -import org.eclipse.swt.accessibility.AccessibleEvent; -import org.eclipse.swt.custom.BusyIndicator; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.FontData; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.widgets.Display; -import org.eclipse.ui.PlatformUI; -import org.eclipse.uml2.uml.Feature; - -/** - * @generated - */ -public class RealizationNameEditPart extends PapyrusLabelEditPart implements ITextAwareEditPart, IControlParserForDirectEdit { - - /** - * @generated - */ - public static final int VISUAL_ID = 6004; - - /** - * @generated - */ - private DirectEditManager manager; - - /** - * @generated - */ - private IParser parser; - - /** - * @generated - */ - private List parserElements; - - /** - * @generated - */ - private String defaultText; - - /** - * direct edition mode (default, undefined, registered editor, etc.) - * - * @generated - */ - protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; - - /** - * configuration from a registered edit dialog - * - * @generated - */ - protected IDirectEditorConfiguration configuration; - /** - * @generated - */ - static { - registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.RealizationNameEditPart.VISUAL_ID), new Point(0, 60)); - } - - /** - * @generated - */ - public RealizationNameEditPart(View view) { - super(view); - } - - /** - * @generated - */ - @Override - protected void createDefaultEditPolicies() { - super.createDefaultEditPolicies(); - installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); - installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); - installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new PapyrusLinkLabelDragPolicy()); - } - - /** - * @generated - */ - @Override - public int getKeyPoint() { - return ConnectionLocator.MIDDLE; - } - - /** - * @generated - */ - protected String getLabelTextHelper(IFigure figure) { - if (figure instanceof WrappingLabel) { - return ((WrappingLabel) figure).getText(); - } else if (figure instanceof ILabelFigure) { - return ((ILabelFigure) figure).getText(); - } else { - return ((Label) figure).getText(); - } - } - - /** - * @generated - */ - protected void setLabelTextHelper(IFigure figure, String text) { - if (figure instanceof WrappingLabel) { - ((WrappingLabel) figure).setText(text); - } else if (figure instanceof ILabelFigure) { - ((ILabelFigure) figure).setText(text); - } else { - ((Label) figure).setText(text); - } - } - - /** - * @generated - */ - protected Image getLabelIconHelper(IFigure figure) { - if (figure instanceof WrappingLabel) { - return ((WrappingLabel) figure).getIcon(); - } else if (figure instanceof ILabelFigure) { - return ((ILabelFigure) figure).getIcon(); - } else { - return ((Label) figure).getIcon(); - } - } - - /** - * @generated - */ - protected void setLabelIconHelper(IFigure figure, Image icon) { - if (figure instanceof WrappingLabel) { - ((WrappingLabel) figure).setIcon(icon); - } else if (figure instanceof ILabelFigure) { - ((ILabelFigure) figure).setIcon(icon); - } else { - ((Label) figure).setIcon(icon); - } - } - - /** - * @generated - */ - public void setLabel(IFigure - figure) { - unregisterVisuals(); - setFigure(figure); - defaultText = getLabelTextHelper(figure); - registerVisuals(); - refreshVisuals(); - } - - /** - * @generated - */ - @Override - protected List getModelChildren() { - return Collections.EMPTY_LIST; - } - - /** - * @generated - */ - @Override - public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { - return null; - } - - /** - * @generated - */ - @Override - public void setParser(IParser parser) { - this.parser = parser; - } - - /** - * @generated - */ - protected EObject getParserElement() { - return resolveSemanticElement(); - } - - /** - * @generated - */ - protected Image getLabelIcon() { - return null; - } - - /** - * @generated - */ - protected String getLabelText() { - String text = null; - EObject parserElement = getParserElement(); - if (parserElement != null && getParser() != null) { - text = getParser().getPrintString( - new EObjectAdapter(parserElement), - getParserOptions().intValue()); - } - if (text == null || text.length() == 0) { - text = defaultText; - } - return text; - } - - /** - * @generated - */ - @Override - public void setLabelText(String text) { - setLabelTextHelper(getFigure(), text); - Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); - if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); - } - Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); - if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); - } - } - - /** - * @generated - */ - @Override - public String getEditText() { - if (getParserElement() == null || getParser() == null) { - return ""; //$NON-NLS-1$ - } - return getParser().getEditString( - new EObjectAdapter(getParserElement()), - getParserOptions().intValue()); - } - - /** - * @generated - */ - protected boolean isEditable() { - return getParser() != null; - } - - /** - * @generated - */ - @Override - public ICellEditorValidator getEditTextValidator() { - return new ICellEditorValidator() { - - @Override - public String isValid(final Object value) { - if (value instanceof String) { - final EObject element = getParserElement(); - final IParser parser = getParser(); - try { - IParserEditStatus valid = - (IParserEditStatus) getEditingDomain().runExclusive( - new RunnableWithResult.Impl() { - - @Override - public void run() { - setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); - } - }); - return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); - } catch (InterruptedException ie) { - ie.printStackTrace(); - } - } - - // shouldn't get here - return null; - } - }; - } - - /** - * @generated - */ - @Override - public IContentAssistProcessor getCompletionProcessor() { - if (getParserElement() == null || getParser() == null) { - return null; - } - return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); - } - - /** - * @generated - */ - @Override - public ParserOptions getParserOptions() { - return ParserOptions.NONE; - } - - /** - * @generated - */ - @Override - public IParser getParser() { - if (parser == null) { - parser = UMLParserProvider.getParser(UMLElementTypes.Realization_4006, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.RealizationNameEditPart.VISUAL_ID)); - } - return parser; - } - - /** - * @generated - */ - protected DirectEditManager getManager() { - if (manager == null) { - setManager(new MultilineLabelDirectEditManager(this, - MultilineLabelDirectEditManager.getTextCellEditorClass(this), - UMLEditPartFactory.getTextCellEditorLocator(this))); - } - return manager; - } - - /** - * @generated - */ - protected void setManager(DirectEditManager manager) { - this.manager = manager; - } - - /** - * @generated - */ - protected void performDirectEdit() { - BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { - - @Override - public void run() { - getManager().show(); - } - }); - } - - /** - * @generated - */ - protected void performDirectEdit(Point eventLocation) { - if (getManager() instanceof TextDirectEditManager) { - ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); - } - } - - /** - * @generated - */ - private void performDirectEdit(char initialCharacter) { - if (getManager() instanceof TextDirectEditManager) { - ((TextDirectEditManager) getManager()).show(initialCharacter); - } else { - performDirectEdit(); - } - } - - /** - * @generated - */ - @Override - protected void performDirectEditRequest(Request request) { - - final Request theRequest = request; - - if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { - directEditionMode = getDirectEditionType(); - } - switch (directEditionMode) { - case IDirectEdition.NO_DIRECT_EDITION: - // no direct edition mode => does nothing - return; - case IDirectEdition.EXTENDED_DIRECT_EDITOR: - updateExtendedEditorConfiguration(); - if (configuration == null || configuration.getLanguage() == null) { - // Create default edit manager - setManager(new MultilineLabelDirectEditManager(this, - MultilineLabelDirectEditManager.getTextCellEditorClass(this), - UMLEditPartFactory.getTextCellEditorLocator(this))); - performDefaultDirectEditorEdit(theRequest); - } else { - configuration.preEditAction(resolveSemanticElement()); - Dialog dialog = null; - if (configuration instanceof ICustomDirectEditorConfiguration) { - setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); - initializeDirectEditManager(theRequest); - return; - } else if (configuration instanceof IPopupEditorConfiguration) { - IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); - helper.showEditor(); - return; - } - else if (configuration instanceof IAdvancedEditorConfiguration) { - dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); - } else if (configuration instanceof IDirectEditorConfiguration) { - dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), - configuration); - } else { - return; - } - final Dialog finalDialog = dialog; - - if (Window.OK == dialog.open()) { - TransactionalEditingDomain domain = getEditingDomain(); - RecordingCommand command = new RecordingCommand(domain, "Edit Label") { - - @Override - protected void doExecute() { - configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); - - } - }; - domain.getCommandStack().execute(command); - } - } - break; - case IDirectEdition.DEFAULT_DIRECT_EDITOR: - initializeDirectEditManager(theRequest); - break; - default: - break; - } - } - - /** - * @generated - */ - protected void initializeDirectEditManager(final Request request) { - // initialize the direct edit manager - try { - getEditingDomain().runExclusive(new Runnable() { - @Override - public void run() { - if (isActive() && isEditable()) { - if (request.getExtendedData().get( - RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { - Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); - performDirectEdit(initialChar.charValue()); - } - else { - performDirectEdit(); - } - } - } - }); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - - /** - * @generated - */ - @Override - protected void refreshVisuals() { - super.refreshVisuals(); - refreshLabel(); - refreshFont(); - refreshFontColor(); - refreshUnderline(); - refreshStrikeThrough(); - } - - /** - * @generated - */ - protected void refreshLabel() { - EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); - if (maskLabelPolicy == null) { - maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); - } - if (maskLabelPolicy == null) { - View view = (View) getModel(); - if (view.isVisible()) { - setLabelTextHelper(getFigure(), getLabelText()); - setLabelIconHelper(getFigure(), getLabelIcon()); - } - else { - setLabelTextHelper(getFigure(), ""); //$NON-NLS-1$ - setLabelIconHelper(getFigure(), null); - } - } - Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); - if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); - } - Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); - if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); - } - } - - /** - * @generated - */ - protected void refreshUnderline() { - FontStyle style = - (FontStyle) getFontStyleOwnerView().getStyle( - NotationPackage.eINSTANCE.getFontStyle()); - if (style != null && getFigure() instanceof WrappingLabel) { - ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); - } - if (resolveSemanticElement() instanceof Feature) { - if (((Feature) resolveSemanticElement()).isStatic()) { - ((WrappingLabel) getFigure()).setTextUnderline(true); - } - else { - ((WrappingLabel) getFigure()).setTextUnderline(false); - } - } - } - - /** - * @generated - */ - protected void refreshStrikeThrough() { - FontStyle style = - (FontStyle) getFontStyleOwnerView().getStyle( - NotationPackage.eINSTANCE.getFontStyle()); - if (style != null && getFigure() instanceof WrappingLabel) { - ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); - } - } - - /** - * @generated - */ - @Override - protected void refreshFont() { - FontStyle style = - (FontStyle) getFontStyleOwnerView().getStyle( - NotationPackage.eINSTANCE.getFontStyle()); - if (style != null) { - FontData fontData = new FontData( - style.getFontName(), style.getFontHeight(), - (style.isBold() ? SWT.BOLD : SWT.NORMAL) | - (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); - setFont(fontData); - } - } - - /** - * @generated - */ - @Override - protected void setFontColor(Color color) { - getFigure().setForegroundColor(color); - } - - /** - * @generated - */ - @Override - protected void addSemanticListeners() { - if (getParser() instanceof ISemanticParser) { - EObject element = resolveSemanticElement(); - parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); - for (int i = 0; i < parserElements.size(); i++) { - addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ - } - } else { - super.addSemanticListeners(); - } - } - - /** - * @generated - */ - @Override - protected void removeSemanticListeners() { - if (parserElements != null) { - for (int i = 0; i < parserElements.size(); i++) { - removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ - } - } else { - super.removeSemanticListeners(); - } - } - - /** - * @generated - */ - @Override - protected AccessibleEditPart getAccessibleEditPart() { - if (accessibleEP == null) { - accessibleEP = new AccessibleGraphicalEditPart() { - - @Override - public void getName(AccessibleEvent e) { - e.result = getLabelTextHelper(getFigure()); - } - }; - } - return accessibleEP; - } - - /** - * @generated - */ - private View getFontStyleOwnerView() { - return getPrimaryView(); - } - - /** - * Returns the kind of associated editor for direct edition. - * - * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition - * @generated - */ - public int getDirectEditionType() { - if (checkExtendedEditor()) { - initExtendedEditorConfiguration(); - return IDirectEdition.EXTENDED_DIRECT_EDITOR; - } - if (checkDefaultEdition()) { - return IDirectEdition.DEFAULT_DIRECT_EDITOR; - } - - // not a named element. no specific editor => do nothing - return IDirectEdition.NO_DIRECT_EDITION; - } - - /** - * Checks if an extended editor is present. - * - * @return true if an extended editor is present. - * @generated - */ - protected boolean checkExtendedEditor() { - if (resolveSemanticElement() != null) { - return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); - } - return false; - } - - /** - * Checks if a default direct edition is available - * - * @return true if a default direct edition is available - * @generated - */ - protected boolean checkDefaultEdition() { - return (getParser() != null); - } - - /** - * Initializes the extended editor configuration - * - * @generated - */ - protected void initExtendedEditorConfiguration() { - if (configuration == null) { - final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); - if (languagePreferred != null && !languagePreferred.equals("")) { - configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); - } else { - configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); - } - } - } - - /** - * Updates the preference configuration - * - * @generated - */ - protected void updateExtendedEditorConfiguration() { - String languagePreferred = Activator.getDefault().getPreferenceStore().getString( - IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); - if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { - configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() - .eClass().getInstanceClassName()); - } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { - configuration = null; - } - } - - /** - * Performs the direct edit usually used by GMF editors. - * - * @param theRequest - * the direct edit request that starts the direct edit system - * @generated - */ - protected void performDefaultDirectEditorEdit(final Request theRequest) { - // initialize the direct edit manager - try { - getEditingDomain().runExclusive(new Runnable() { - - @Override - public void run() { - if (isActive() && isEditable()) { - if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { - Character initialChar = (Character) theRequest.getExtendedData().get( - RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); - performDirectEdit(initialChar.charValue()); - } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { - DirectEditRequest editRequest = (DirectEditRequest) theRequest; - performDirectEdit(editRequest.getLocation()); - } else { - performDirectEdit(); - } - } - } - }); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - - /** - * @generated - */ - @Override - protected void handleNotificationEvent(Notification event) { - Object feature = event.getFeature(); - if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { - Integer c = (Integer) event.getNewValue(); - setFontColor(DiagramColorRegistry.getInstance().getColor(c)); - } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { - refreshUnderline(); - } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { - refreshStrikeThrough(); - } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || - NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || - NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || - NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { - refreshFont(); - } else { - if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { - refreshLabel(); - } - if (getParser() instanceof ISemanticParser) { - ISemanticParser modelParser = - (ISemanticParser) getParser(); - if (modelParser.areSemanticElementsAffected(null, event)) { - removeSemanticListeners(); - if (resolveSemanticElement() != null) { - addSemanticListeners(); - } - refreshLabel(); - } - } - } - - super.handleNotificationEvent(event); - } - - /** - * @generated - */ - @Override - protected IFigure createFigure() { - // Parent should assign one using setLabel() method - return 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.uml.diagram.composite.edit.parts; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.draw2d.ConnectionLocator; +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.Label; +import org.eclipse.draw2d.geometry.Point; +import org.eclipse.emf.common.notify.Notification; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.RunnableWithResult; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gef.AccessibleEditPart; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.Request; +import org.eclipse.gef.requests.DirectEditRequest; +import org.eclipse.gef.tools.DirectEditManager; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; +import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; +import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; +import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; +import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; +import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; +import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; +import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; +import org.eclipse.gmf.runtime.notation.FontStyle; +import org.eclipse.gmf.runtime.notation.NotationPackage; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.gmf.tooling.runtime.edit.policies.DefaultLinkLabelDragPolicy; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.text.contentassist.IContentAssistProcessor; +import org.eclipse.jface.viewers.ICellEditorValidator; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.extensionpoints.editors.Activator; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; +import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; +import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; +import org.eclipse.papyrus.infra.gmfdiag.common.editpart.IControlParserForDirectEdit; +import org.eclipse.papyrus.infra.gmfdiag.common.editpart.PapyrusLabelEditPart; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.PapyrusLinkLabelDragPolicy; +import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; +import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; +import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; +import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; +import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.accessibility.AccessibleEvent; +import org.eclipse.swt.custom.BusyIndicator; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; +import org.eclipse.uml2.uml.Feature; + +/** + * @generated + */ +public class RealizationNameEditPart extends PapyrusLabelEditPart implements ITextAwareEditPart, IControlParserForDirectEdit { + + /** + * @generated + */ + public static final int VISUAL_ID = 6004; + + /** + * @generated + */ + private DirectEditManager manager; + + /** + * @generated + */ + private IParser parser; + + /** + * @generated + */ + private List parserElements; + + /** + * @generated + */ + private String defaultText; + + /** + * direct edition mode (default, undefined, registered editor, etc.) + * + * @generated + */ + protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; + + /** + * configuration from a registered edit dialog + * + * @generated + */ + protected IDirectEditorConfiguration configuration; + /** + * @generated + */ + static { + registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.RealizationNameEditPart.VISUAL_ID), new Point(0, 60)); + } + + /** + * @generated + */ + public RealizationNameEditPart(View view) { + super(view); + } + + /** + * @generated + */ + @Override + protected void createDefaultEditPolicies() { + super.createDefaultEditPolicies(); + installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); + installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new DefaultLinkLabelDragPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new PapyrusLinkLabelDragPolicy()); + } + + /** + * @generated + */ + @Override + public int getKeyPoint() { + return ConnectionLocator.MIDDLE; + } + + /** + * @generated + */ + protected String getLabelTextHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getText(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getText(); + } else { + return ((Label) figure).getText(); + } + } + + /** + * @generated + */ + protected void setLabelTextHelper(IFigure figure, String text) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setText(text); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setText(text); + } else { + ((Label) figure).setText(text); + } + } + + /** + * @generated + */ + protected Image getLabelIconHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getIcon(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getIcon(); + } else { + return ((Label) figure).getIcon(); + } + } + + /** + * @generated + */ + protected void setLabelIconHelper(IFigure figure, Image icon) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setIcon(icon); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setIcon(icon); + } else { + ((Label) figure).setIcon(icon); + } + } + + /** + * @generated + */ + public void setLabel(IFigure + figure) { + unregisterVisuals(); + setFigure(figure); + defaultText = getLabelTextHelper(figure); + registerVisuals(); + refreshVisuals(); + } + + /** + * @generated + */ + @Override + protected List getModelChildren() { + return Collections.EMPTY_LIST; + } + + /** + * @generated + */ + @Override + public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { + return null; + } + + /** + * @generated + */ + @Override + public void setParser(IParser parser) { + this.parser = parser; + } + + /** + * @generated + */ + protected EObject getParserElement() { + return resolveSemanticElement(); + } + + /** + * @generated + */ + protected Image getLabelIcon() { + return null; + } + + /** + * @generated + */ + protected String getLabelText() { + String text = null; + EObject parserElement = getParserElement(); + if (parserElement != null && getParser() != null) { + text = getParser().getPrintString( + new EObjectAdapter(parserElement), + getParserOptions().intValue()); + } + if (text == null || text.length() == 0) { + text = defaultText; + } + return text; + } + + /** + * @generated + */ + @Override + public void setLabelText(String text) { + setLabelTextHelper(getFigure(), text); + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + @Override + public String getEditText() { + if (getParserElement() == null || getParser() == null) { + return ""; //$NON-NLS-1$ + } + return getParser().getEditString( + new EObjectAdapter(getParserElement()), + getParserOptions().intValue()); + } + + /** + * @generated + */ + protected boolean isEditable() { + return getParser() != null; + } + + /** + * @generated + */ + @Override + public ICellEditorValidator getEditTextValidator() { + return new ICellEditorValidator() { + + @Override + public String isValid(final Object value) { + if (value instanceof String) { + final EObject element = getParserElement(); + final IParser parser = getParser(); + try { + IParserEditStatus valid = + (IParserEditStatus) getEditingDomain().runExclusive( + new RunnableWithResult.Impl() { + + @Override + public void run() { + setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); + } + }); + return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); + } catch (InterruptedException ie) { + ie.printStackTrace(); + } + } + + // shouldn't get here + return null; + } + }; + } + + /** + * @generated + */ + @Override + public IContentAssistProcessor getCompletionProcessor() { + if (getParserElement() == null || getParser() == null) { + return null; + } + return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); + } + + /** + * @generated + */ + @Override + public ParserOptions getParserOptions() { + return ParserOptions.NONE; + } + + /** + * @generated + */ + @Override + public IParser getParser() { + if (parser == null) { + parser = UMLParserProvider.getParser(UMLElementTypes.Realization_4006, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.RealizationNameEditPart.VISUAL_ID)); + } + return parser; + } + + /** + * @generated + */ + protected DirectEditManager getManager() { + if (manager == null) { + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + } + return manager; + } + + /** + * @generated + */ + protected void setManager(DirectEditManager manager) { + this.manager = manager; + } + + /** + * @generated + */ + protected void performDirectEdit() { + BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { + + @Override + public void run() { + getManager().show(); + } + }); + } + + /** + * @generated + */ + protected void performDirectEdit(Point eventLocation) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); + } + } + + /** + * @generated + */ + private void performDirectEdit(char initialCharacter) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(initialCharacter); + } else { + performDirectEdit(); + } + } + + /** + * @generated + */ + @Override + protected void performDirectEditRequest(Request request) { + + final Request theRequest = request; + + if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { + directEditionMode = getDirectEditionType(); + } + switch (directEditionMode) { + case IDirectEdition.NO_DIRECT_EDITION: + // no direct edition mode => does nothing + return; + case IDirectEdition.EXTENDED_DIRECT_EDITOR: + updateExtendedEditorConfiguration(); + if (configuration == null || configuration.getLanguage() == null) { + // Create default edit manager + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + performDefaultDirectEditorEdit(theRequest); + } else { + configuration.preEditAction(resolveSemanticElement()); + Dialog dialog = null; + if (configuration instanceof ICustomDirectEditorConfiguration) { + setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); + initializeDirectEditManager(theRequest); + return; + } else if (configuration instanceof IPopupEditorConfiguration) { + IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); + helper.showEditor(); + return; + } + else if (configuration instanceof IAdvancedEditorConfiguration) { + dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); + } else if (configuration instanceof IDirectEditorConfiguration) { + dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), + configuration); + } else { + return; + } + final Dialog finalDialog = dialog; + + if (Window.OK == dialog.open()) { + TransactionalEditingDomain domain = getEditingDomain(); + RecordingCommand command = new RecordingCommand(domain, "Edit Label") { + + @Override + protected void doExecute() { + configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); + + } + }; + domain.getCommandStack().execute(command); + } + } + break; + case IDirectEdition.DEFAULT_DIRECT_EDITOR: + initializeDirectEditManager(theRequest); + break; + default: + break; + } + } + + /** + * @generated + */ + protected void initializeDirectEditManager(final Request request) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + @Override + public void run() { + if (isActive() && isEditable()) { + if (request.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } + else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void refreshVisuals() { + super.refreshVisuals(); + refreshLabel(); + refreshFont(); + refreshFontColor(); + refreshUnderline(); + refreshStrikeThrough(); + } + + /** + * @generated + */ + protected void refreshLabel() { + EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); + if (maskLabelPolicy == null) { + maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); + } + if (maskLabelPolicy == null) { + setLabelTextHelper(getFigure(), getLabelText()); + setLabelIconHelper(getFigure(), getLabelIcon()); + } + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + protected void refreshUnderline() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); + } + if (resolveSemanticElement() instanceof Feature) { + if (((Feature) resolveSemanticElement()).isStatic()) { + ((WrappingLabel) getFigure()).setTextUnderline(true); + } + else { + ((WrappingLabel) getFigure()).setTextUnderline(false); + } + } + } + + /** + * @generated + */ + protected void refreshStrikeThrough() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); + } + } + + /** + * @generated + */ + @Override + protected void refreshFont() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null) { + FontData fontData = new FontData( + style.getFontName(), style.getFontHeight(), + (style.isBold() ? SWT.BOLD : SWT.NORMAL) | + (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); + setFont(fontData); + } + } + + /** + * @generated + */ + @Override + protected void setFontColor(Color color) { + getFigure().setForegroundColor(color); + } + + /** + * @generated + */ + @Override + protected void addSemanticListeners() { + if (getParser() instanceof ISemanticParser) { + EObject element = resolveSemanticElement(); + parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); + for (int i = 0; i < parserElements.size(); i++) { + addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ + } + } else { + super.addSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected void removeSemanticListeners() { + if (parserElements != null) { + for (int i = 0; i < parserElements.size(); i++) { + removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ + } + } else { + super.removeSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected AccessibleEditPart getAccessibleEditPart() { + if (accessibleEP == null) { + accessibleEP = new AccessibleGraphicalEditPart() { + + @Override + public void getName(AccessibleEvent e) { + e.result = getLabelTextHelper(getFigure()); + } + }; + } + return accessibleEP; + } + + /** + * @generated + */ + private View getFontStyleOwnerView() { + return getPrimaryView(); + } + + /** + * Returns the kind of associated editor for direct edition. + * + * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition + * @generated + */ + public int getDirectEditionType() { + if (checkExtendedEditor()) { + initExtendedEditorConfiguration(); + return IDirectEdition.EXTENDED_DIRECT_EDITOR; + } + if (checkDefaultEdition()) { + return IDirectEdition.DEFAULT_DIRECT_EDITOR; + } + + // not a named element. no specific editor => do nothing + return IDirectEdition.NO_DIRECT_EDITION; + } + + /** + * Checks if an extended editor is present. + * + * @return true if an extended editor is present. + * @generated + */ + protected boolean checkExtendedEditor() { + if (resolveSemanticElement() != null) { + return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); + } + return false; + } + + /** + * Checks if a default direct edition is available + * + * @return true if a default direct edition is available + * @generated + */ + protected boolean checkDefaultEdition() { + return (getParser() != null); + } + + /** + * Initializes the extended editor configuration + * + * @generated + */ + protected void initExtendedEditorConfiguration() { + if (configuration == null) { + final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("")) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); + } else { + configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); + } + } + } + + /** + * Updates the preference configuration + * + * @generated + */ + protected void updateExtendedEditorConfiguration() { + String languagePreferred = Activator.getDefault().getPreferenceStore().getString( + IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() + .eClass().getInstanceClassName()); + } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { + configuration = null; + } + } + + /** + * Performs the direct edit usually used by GMF editors. + * + * @param theRequest + * the direct edit request that starts the direct edit system + * @generated + */ + protected void performDefaultDirectEditorEdit(final Request theRequest) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + + @Override + public void run() { + if (isActive() && isEditable()) { + if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) theRequest.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { + DirectEditRequest editRequest = (DirectEditRequest) theRequest; + performDirectEdit(editRequest.getLocation()); + } else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void handleNotificationEvent(Notification event) { + Object feature = event.getFeature(); + if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { + Integer c = (Integer) event.getNewValue(); + setFontColor(DiagramColorRegistry.getInstance().getColor(c)); + } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { + refreshUnderline(); + } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { + refreshStrikeThrough(); + } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { + refreshFont(); + } else { + if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { + refreshLabel(); + } + if (getParser() instanceof ISemanticParser) { + ISemanticParser modelParser = + (ISemanticParser) getParser(); + if (modelParser.areSemanticElementsAffected(null, event)) { + removeSemanticListeners(); + if (resolveSemanticElement() != null) { + addSemanticListeners(); + } + refreshLabel(); + } + } + } + + super.handleNotificationEvent(event); + } + + /** + * @generated + */ + @Override + protected IFigure createFigure() { + // Parent should assign one using setLabel() method + return null; + } +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/RepresentationTagLabelEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/RepresentationTagLabelEditPart.java index d501e5c337a..c37a7185782 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/RepresentationTagLabelEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/RepresentationTagLabelEditPart.java @@ -1,829 +1,824 @@ -/** - * 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.uml.diagram.composite.edit.parts; - -import java.util.Collections; -import java.util.List; - -import org.eclipse.draw2d.ConnectionLocator; -import org.eclipse.draw2d.IFigure; -import org.eclipse.draw2d.Label; -import org.eclipse.draw2d.geometry.Point; -import org.eclipse.emf.common.notify.Notification; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.transaction.RecordingCommand; -import org.eclipse.emf.transaction.RunnableWithResult; -import org.eclipse.emf.transaction.TransactionalEditingDomain; -import org.eclipse.gef.AccessibleEditPart; -import org.eclipse.gef.EditPolicy; -import org.eclipse.gef.Request; -import org.eclipse.gef.requests.DirectEditRequest; -import org.eclipse.gef.tools.DirectEditManager; -import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; -import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; -import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; -import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; -import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; -import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; -import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; -import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; -import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; -import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; -import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; -import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; -import org.eclipse.gmf.runtime.notation.FontStyle; -import org.eclipse.gmf.runtime.notation.NotationPackage; -import org.eclipse.gmf.runtime.notation.View; -import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.jface.text.contentassist.IContentAssistProcessor; -import org.eclipse.jface.viewers.ICellEditorValidator; -import org.eclipse.jface.window.Window; -import org.eclipse.papyrus.extensionpoints.editors.Activator; -import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; -import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; -import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; -import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; -import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; -import org.eclipse.papyrus.infra.gmfdiag.common.editpart.IControlParserForDirectEdit; -import org.eclipse.papyrus.infra.gmfdiag.common.editpart.PapyrusLabelEditPart; -import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; -import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; -import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.PapyrusLinkLabelDragPolicy; -import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; -import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; -import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; -import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; -import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; -import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; -import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; -import org.eclipse.swt.SWT; -import org.eclipse.swt.accessibility.AccessibleEvent; -import org.eclipse.swt.custom.BusyIndicator; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.FontData; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.widgets.Display; -import org.eclipse.ui.PlatformUI; -import org.eclipse.uml2.uml.Feature; - -/** - * @generated - */ -public class RepresentationTagLabelEditPart extends PapyrusLabelEditPart implements ITextAwareEditPart, IControlParserForDirectEdit { - - /** - * @generated - */ - public static final int VISUAL_ID = 6030; - - /** - * @generated - */ - private DirectEditManager manager; - - /** - * @generated - */ - private IParser parser; - - /** - * @generated - */ - private List parserElements; - - /** - * @generated - */ - private String defaultText; - - /** - * direct edition mode (default, undefined, registered editor, etc.) - * - * @generated - */ - protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; - - /** - * configuration from a registered edit dialog - * - * @generated - */ - protected IDirectEditorConfiguration configuration; - /** - * @generated - */ - static { - registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.RepresentationTagLabelEditPart.VISUAL_ID), new Point(0, 15)); - } - - /** - * @generated - */ - public RepresentationTagLabelEditPart(View view) { - super(view); - } - - /** - * @generated - */ - @Override - protected void createDefaultEditPolicies() { - super.createDefaultEditPolicies(); - installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); - installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); - installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new PapyrusLinkLabelDragPolicy()); - } - - /** - * @generated - */ - @Override - public int getKeyPoint() { - return ConnectionLocator.MIDDLE; - } - - /** - * @generated - */ - protected String getLabelTextHelper(IFigure figure) { - if (figure instanceof WrappingLabel) { - return ((WrappingLabel) figure).getText(); - } else if (figure instanceof ILabelFigure) { - return ((ILabelFigure) figure).getText(); - } else { - return ((Label) figure).getText(); - } - } - - /** - * @generated - */ - protected void setLabelTextHelper(IFigure figure, String text) { - if (figure instanceof WrappingLabel) { - ((WrappingLabel) figure).setText(text); - } else if (figure instanceof ILabelFigure) { - ((ILabelFigure) figure).setText(text); - } else { - ((Label) figure).setText(text); - } - } - - /** - * @generated - */ - protected Image getLabelIconHelper(IFigure figure) { - if (figure instanceof WrappingLabel) { - return ((WrappingLabel) figure).getIcon(); - } else if (figure instanceof ILabelFigure) { - return ((ILabelFigure) figure).getIcon(); - } else { - return ((Label) figure).getIcon(); - } - } - - /** - * @generated - */ - protected void setLabelIconHelper(IFigure figure, Image icon) { - if (figure instanceof WrappingLabel) { - ((WrappingLabel) figure).setIcon(icon); - } else if (figure instanceof ILabelFigure) { - ((ILabelFigure) figure).setIcon(icon); - } else { - ((Label) figure).setIcon(icon); - } - } - - /** - * @generated - */ - public void setLabel(IFigure - figure) { - unregisterVisuals(); - setFigure(figure); - defaultText = getLabelTextHelper(figure); - registerVisuals(); - refreshVisuals(); - } - - /** - * @generated - */ - @Override - protected List getModelChildren() { - return Collections.EMPTY_LIST; - } - - /** - * @generated - */ - @Override - public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { - return null; - } - - /** - * @generated - */ - @Override - public void setParser(IParser parser) { - this.parser = parser; - } - - /** - * @generated - */ - protected EObject getParserElement() { - EObject element = resolveSemanticElement(); - return element != null ? element : (View) getModel(); - } - - /** - * @generated - */ - protected Image getLabelIcon() { - return null; - } - - /** - * @generated - */ - protected String getLabelText() { - String text = null; - EObject parserElement = getParserElement(); - if (parserElement != null && getParser() != null) { - text = getParser().getPrintString( - new EObjectAdapter(parserElement), - getParserOptions().intValue()); - } - if (text == null || text.length() == 0) { - text = defaultText; - } - return text; - } - - /** - * @generated - */ - @Override - public void setLabelText(String text) { - setLabelTextHelper(getFigure(), text); - Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); - if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); - } - Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); - if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); - } - } - - /** - * @generated - */ - @Override - public String getEditText() { - if (getParserElement() == null || getParser() == null) { - return ""; //$NON-NLS-1$ - } - return getParser().getEditString( - new EObjectAdapter(getParserElement()), - getParserOptions().intValue()); - } - - /** - * @generated - */ - protected boolean isEditable() { - return getParser() != null; - } - - /** - * @generated - */ - @Override - public ICellEditorValidator getEditTextValidator() { - return new ICellEditorValidator() { - - @Override - public String isValid(final Object value) { - if (value instanceof String) { - final EObject element = getParserElement(); - final IParser parser = getParser(); - try { - IParserEditStatus valid = - (IParserEditStatus) getEditingDomain().runExclusive( - new RunnableWithResult.Impl() { - - @Override - public void run() { - setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); - } - }); - return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); - } catch (InterruptedException ie) { - ie.printStackTrace(); - } - } - - // shouldn't get here - return null; - } - }; - } - - /** - * @generated - */ - @Override - public IContentAssistProcessor getCompletionProcessor() { - if (getParserElement() == null || getParser() == null) { - return null; - } - return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); - } - - /** - * @generated - */ - @Override - public ParserOptions getParserOptions() { - return ParserOptions.NONE; - } - - /** - * @generated - */ - @Override - public IParser getParser() { - if (parser == null) { - parser = UMLParserProvider.getParser(UMLElementTypes.InformationItemRepresented_4020, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.RepresentationTagLabelEditPart.VISUAL_ID)); - } - return parser; - } - - /** - * @generated - */ - protected DirectEditManager getManager() { - if (manager == null) { - setManager(new MultilineLabelDirectEditManager(this, - MultilineLabelDirectEditManager.getTextCellEditorClass(this), - UMLEditPartFactory.getTextCellEditorLocator(this))); - } - return manager; - } - - /** - * @generated - */ - protected void setManager(DirectEditManager manager) { - this.manager = manager; - } - - /** - * @generated - */ - protected void performDirectEdit() { - BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { - - @Override - public void run() { - getManager().show(); - } - }); - } - - /** - * @generated - */ - protected void performDirectEdit(Point eventLocation) { - if (getManager() instanceof TextDirectEditManager) { - ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); - } - } - - /** - * @generated - */ - private void performDirectEdit(char initialCharacter) { - if (getManager() instanceof TextDirectEditManager) { - ((TextDirectEditManager) getManager()).show(initialCharacter); - } else { - performDirectEdit(); - } - } - - /** - * @generated - */ - @Override - protected void performDirectEditRequest(Request request) { - - final Request theRequest = request; - - if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { - directEditionMode = getDirectEditionType(); - } - switch (directEditionMode) { - case IDirectEdition.NO_DIRECT_EDITION: - // no direct edition mode => does nothing - return; - case IDirectEdition.EXTENDED_DIRECT_EDITOR: - updateExtendedEditorConfiguration(); - if (configuration == null || configuration.getLanguage() == null) { - // Create default edit manager - setManager(new MultilineLabelDirectEditManager(this, - MultilineLabelDirectEditManager.getTextCellEditorClass(this), - UMLEditPartFactory.getTextCellEditorLocator(this))); - performDefaultDirectEditorEdit(theRequest); - } else { - configuration.preEditAction(resolveSemanticElement()); - Dialog dialog = null; - if (configuration instanceof ICustomDirectEditorConfiguration) { - setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); - initializeDirectEditManager(theRequest); - return; - } else if (configuration instanceof IPopupEditorConfiguration) { - IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); - helper.showEditor(); - return; - } - else if (configuration instanceof IAdvancedEditorConfiguration) { - dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); - } else if (configuration instanceof IDirectEditorConfiguration) { - dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), - configuration); - } else { - return; - } - final Dialog finalDialog = dialog; - - if (Window.OK == dialog.open()) { - TransactionalEditingDomain domain = getEditingDomain(); - RecordingCommand command = new RecordingCommand(domain, "Edit Label") { - - @Override - protected void doExecute() { - configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); - - } - }; - domain.getCommandStack().execute(command); - } - } - break; - case IDirectEdition.DEFAULT_DIRECT_EDITOR: - initializeDirectEditManager(theRequest); - break; - default: - break; - } - } - - /** - * @generated - */ - protected void initializeDirectEditManager(final Request request) { - // initialize the direct edit manager - try { - getEditingDomain().runExclusive(new Runnable() { - @Override - public void run() { - if (isActive() && isEditable()) { - if (request.getExtendedData().get( - RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { - Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); - performDirectEdit(initialChar.charValue()); - } - else { - performDirectEdit(); - } - } - } - }); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - - /** - * @generated - */ - @Override - protected void refreshVisuals() { - super.refreshVisuals(); - refreshLabel(); - refreshFont(); - refreshFontColor(); - refreshUnderline(); - refreshStrikeThrough(); - } - - /** - * @generated - */ - protected void refreshLabel() { - EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); - if (maskLabelPolicy == null) { - maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); - } - if (maskLabelPolicy == null) { - View view = (View) getModel(); - if (view.isVisible()) { - setLabelTextHelper(getFigure(), getLabelText()); - setLabelIconHelper(getFigure(), getLabelIcon()); - } - else { - setLabelTextHelper(getFigure(), ""); //$NON-NLS-1$ - setLabelIconHelper(getFigure(), null); - } - } - Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); - if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); - } - Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); - if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); - } - } - - /** - * @generated - */ - protected void refreshUnderline() { - FontStyle style = - (FontStyle) getFontStyleOwnerView().getStyle( - NotationPackage.eINSTANCE.getFontStyle()); - if (style != null && getFigure() instanceof WrappingLabel) { - ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); - } - if (resolveSemanticElement() instanceof Feature) { - if (((Feature) resolveSemanticElement()).isStatic()) { - ((WrappingLabel) getFigure()).setTextUnderline(true); - } - else { - ((WrappingLabel) getFigure()).setTextUnderline(false); - } - } - } - - /** - * @generated - */ - protected void refreshStrikeThrough() { - FontStyle style = - (FontStyle) getFontStyleOwnerView().getStyle( - NotationPackage.eINSTANCE.getFontStyle()); - if (style != null && getFigure() instanceof WrappingLabel) { - ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); - } - } - - /** - * @generated - */ - @Override - protected void refreshFont() { - FontStyle style = - (FontStyle) getFontStyleOwnerView().getStyle( - NotationPackage.eINSTANCE.getFontStyle()); - if (style != null) { - FontData fontData = new FontData( - style.getFontName(), style.getFontHeight(), - (style.isBold() ? SWT.BOLD : SWT.NORMAL) | - (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); - setFont(fontData); - } - } - - /** - * @generated - */ - @Override - protected void setFontColor(Color color) { - getFigure().setForegroundColor(color); - } - - /** - * @generated - */ - @Override - protected void addSemanticListeners() { - if (getParser() instanceof ISemanticParser) { - EObject element = resolveSemanticElement(); - parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); - for (int i = 0; i < parserElements.size(); i++) { - addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ - } - } else { - super.addSemanticListeners(); - } - } - - /** - * @generated - */ - @Override - protected void removeSemanticListeners() { - if (parserElements != null) { - for (int i = 0; i < parserElements.size(); i++) { - removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ - } - } else { - super.removeSemanticListeners(); - } - } - - /** - * @generated - */ - @Override - protected AccessibleEditPart getAccessibleEditPart() { - if (accessibleEP == null) { - accessibleEP = new AccessibleGraphicalEditPart() { - - @Override - public void getName(AccessibleEvent e) { - e.result = getLabelTextHelper(getFigure()); - } - }; - } - return accessibleEP; - } - - /** - * @generated - */ - private View getFontStyleOwnerView() { - return getPrimaryView(); - } - - /** - * Returns the kind of associated editor for direct edition. - * - * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition - * @generated - */ - public int getDirectEditionType() { - if (checkExtendedEditor()) { - initExtendedEditorConfiguration(); - return IDirectEdition.EXTENDED_DIRECT_EDITOR; - } - if (checkDefaultEdition()) { - return IDirectEdition.DEFAULT_DIRECT_EDITOR; - } - - // not a named element. no specific editor => do nothing - return IDirectEdition.NO_DIRECT_EDITION; - } - - /** - * Checks if an extended editor is present. - * - * @return true if an extended editor is present. - * @generated - */ - protected boolean checkExtendedEditor() { - if (resolveSemanticElement() != null) { - return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); - } - return false; - } - - /** - * Checks if a default direct edition is available - * - * @return true if a default direct edition is available - * @generated - */ - protected boolean checkDefaultEdition() { - return (getParser() != null); - } - - /** - * Initializes the extended editor configuration - * - * @generated - */ - protected void initExtendedEditorConfiguration() { - if (configuration == null) { - final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); - if (languagePreferred != null && !languagePreferred.equals("")) { - configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); - } else { - configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); - } - } - } - - /** - * Updates the preference configuration - * - * @generated - */ - protected void updateExtendedEditorConfiguration() { - String languagePreferred = Activator.getDefault().getPreferenceStore().getString( - IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); - if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { - configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() - .eClass().getInstanceClassName()); - } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { - configuration = null; - } - } - - /** - * Performs the direct edit usually used by GMF editors. - * - * @param theRequest - * the direct edit request that starts the direct edit system - * @generated - */ - protected void performDefaultDirectEditorEdit(final Request theRequest) { - // initialize the direct edit manager - try { - getEditingDomain().runExclusive(new Runnable() { - - @Override - public void run() { - if (isActive() && isEditable()) { - if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { - Character initialChar = (Character) theRequest.getExtendedData().get( - RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); - performDirectEdit(initialChar.charValue()); - } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { - DirectEditRequest editRequest = (DirectEditRequest) theRequest; - performDirectEdit(editRequest.getLocation()); - } else { - performDirectEdit(); - } - } - } - }); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - - /** - * @generated - */ - @Override - protected void handleNotificationEvent(Notification event) { - Object feature = event.getFeature(); - if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { - Integer c = (Integer) event.getNewValue(); - setFontColor(DiagramColorRegistry.getInstance().getColor(c)); - } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { - refreshUnderline(); - } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { - refreshStrikeThrough(); - } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || - NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || - NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || - NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { - refreshFont(); - } else { - if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { - refreshLabel(); - } - if (getParser() instanceof ISemanticParser) { - ISemanticParser modelParser = - (ISemanticParser) getParser(); - if (modelParser.areSemanticElementsAffected(null, event)) { - removeSemanticListeners(); - if (resolveSemanticElement() != null) { - addSemanticListeners(); - } - refreshLabel(); - } - } - } - - super.handleNotificationEvent(event); - } - - /** - * @generated - */ - @Override - protected IFigure createFigure() { - // Parent should assign one using setLabel() method - return 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.uml.diagram.composite.edit.parts; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.draw2d.ConnectionLocator; +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.Label; +import org.eclipse.draw2d.geometry.Point; +import org.eclipse.emf.common.notify.Notification; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.RunnableWithResult; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gef.AccessibleEditPart; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.Request; +import org.eclipse.gef.requests.DirectEditRequest; +import org.eclipse.gef.tools.DirectEditManager; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; +import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; +import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; +import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; +import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; +import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; +import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; +import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; +import org.eclipse.gmf.runtime.notation.FontStyle; +import org.eclipse.gmf.runtime.notation.NotationPackage; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.gmf.tooling.runtime.edit.policies.DefaultLinkLabelDragPolicy; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.text.contentassist.IContentAssistProcessor; +import org.eclipse.jface.viewers.ICellEditorValidator; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.extensionpoints.editors.Activator; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; +import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; +import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; +import org.eclipse.papyrus.infra.gmfdiag.common.editpart.IControlParserForDirectEdit; +import org.eclipse.papyrus.infra.gmfdiag.common.editpart.PapyrusLabelEditPart; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.PapyrusLinkLabelDragPolicy; +import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; +import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; +import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; +import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; +import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.accessibility.AccessibleEvent; +import org.eclipse.swt.custom.BusyIndicator; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; +import org.eclipse.uml2.uml.Feature; + +/** + * @generated + */ +public class RepresentationTagLabelEditPart extends PapyrusLabelEditPart implements ITextAwareEditPart, IControlParserForDirectEdit { + + /** + * @generated + */ + public static final int VISUAL_ID = 6030; + + /** + * @generated + */ + private DirectEditManager manager; + + /** + * @generated + */ + private IParser parser; + + /** + * @generated + */ + private List parserElements; + + /** + * @generated + */ + private String defaultText; + + /** + * direct edition mode (default, undefined, registered editor, etc.) + * + * @generated + */ + protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; + + /** + * configuration from a registered edit dialog + * + * @generated + */ + protected IDirectEditorConfiguration configuration; + /** + * @generated + */ + static { + registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.RepresentationTagLabelEditPart.VISUAL_ID), new Point(0, 15)); + } + + /** + * @generated + */ + public RepresentationTagLabelEditPart(View view) { + super(view); + } + + /** + * @generated + */ + @Override + protected void createDefaultEditPolicies() { + super.createDefaultEditPolicies(); + installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); + installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new DefaultLinkLabelDragPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new PapyrusLinkLabelDragPolicy()); + } + + /** + * @generated + */ + @Override + public int getKeyPoint() { + return ConnectionLocator.MIDDLE; + } + + /** + * @generated + */ + protected String getLabelTextHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getText(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getText(); + } else { + return ((Label) figure).getText(); + } + } + + /** + * @generated + */ + protected void setLabelTextHelper(IFigure figure, String text) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setText(text); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setText(text); + } else { + ((Label) figure).setText(text); + } + } + + /** + * @generated + */ + protected Image getLabelIconHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getIcon(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getIcon(); + } else { + return ((Label) figure).getIcon(); + } + } + + /** + * @generated + */ + protected void setLabelIconHelper(IFigure figure, Image icon) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setIcon(icon); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setIcon(icon); + } else { + ((Label) figure).setIcon(icon); + } + } + + /** + * @generated + */ + public void setLabel(IFigure + figure) { + unregisterVisuals(); + setFigure(figure); + defaultText = getLabelTextHelper(figure); + registerVisuals(); + refreshVisuals(); + } + + /** + * @generated + */ + @Override + protected List getModelChildren() { + return Collections.EMPTY_LIST; + } + + /** + * @generated + */ + @Override + public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { + return null; + } + + /** + * @generated + */ + @Override + public void setParser(IParser parser) { + this.parser = parser; + } + + /** + * @generated + */ + protected EObject getParserElement() { + EObject element = resolveSemanticElement(); + return element != null ? element : (View) getModel(); + } + + /** + * @generated + */ + protected Image getLabelIcon() { + return null; + } + + /** + * @generated + */ + protected String getLabelText() { + String text = null; + EObject parserElement = getParserElement(); + if (parserElement != null && getParser() != null) { + text = getParser().getPrintString( + new EObjectAdapter(parserElement), + getParserOptions().intValue()); + } + if (text == null || text.length() == 0) { + text = defaultText; + } + return text; + } + + /** + * @generated + */ + @Override + public void setLabelText(String text) { + setLabelTextHelper(getFigure(), text); + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + @Override + public String getEditText() { + if (getParserElement() == null || getParser() == null) { + return ""; //$NON-NLS-1$ + } + return getParser().getEditString( + new EObjectAdapter(getParserElement()), + getParserOptions().intValue()); + } + + /** + * @generated + */ + protected boolean isEditable() { + return getParser() != null; + } + + /** + * @generated + */ + @Override + public ICellEditorValidator getEditTextValidator() { + return new ICellEditorValidator() { + + @Override + public String isValid(final Object value) { + if (value instanceof String) { + final EObject element = getParserElement(); + final IParser parser = getParser(); + try { + IParserEditStatus valid = + (IParserEditStatus) getEditingDomain().runExclusive( + new RunnableWithResult.Impl() { + + @Override + public void run() { + setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); + } + }); + return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); + } catch (InterruptedException ie) { + ie.printStackTrace(); + } + } + + // shouldn't get here + return null; + } + }; + } + + /** + * @generated + */ + @Override + public IContentAssistProcessor getCompletionProcessor() { + if (getParserElement() == null || getParser() == null) { + return null; + } + return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); + } + + /** + * @generated + */ + @Override + public ParserOptions getParserOptions() { + return ParserOptions.NONE; + } + + /** + * @generated + */ + @Override + public IParser getParser() { + if (parser == null) { + parser = UMLParserProvider.getParser(UMLElementTypes.InformationItemRepresented_4020, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.RepresentationTagLabelEditPart.VISUAL_ID)); + } + return parser; + } + + /** + * @generated + */ + protected DirectEditManager getManager() { + if (manager == null) { + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + } + return manager; + } + + /** + * @generated + */ + protected void setManager(DirectEditManager manager) { + this.manager = manager; + } + + /** + * @generated + */ + protected void performDirectEdit() { + BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { + + @Override + public void run() { + getManager().show(); + } + }); + } + + /** + * @generated + */ + protected void performDirectEdit(Point eventLocation) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); + } + } + + /** + * @generated + */ + private void performDirectEdit(char initialCharacter) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(initialCharacter); + } else { + performDirectEdit(); + } + } + + /** + * @generated + */ + @Override + protected void performDirectEditRequest(Request request) { + + final Request theRequest = request; + + if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { + directEditionMode = getDirectEditionType(); + } + switch (directEditionMode) { + case IDirectEdition.NO_DIRECT_EDITION: + // no direct edition mode => does nothing + return; + case IDirectEdition.EXTENDED_DIRECT_EDITOR: + updateExtendedEditorConfiguration(); + if (configuration == null || configuration.getLanguage() == null) { + // Create default edit manager + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + performDefaultDirectEditorEdit(theRequest); + } else { + configuration.preEditAction(resolveSemanticElement()); + Dialog dialog = null; + if (configuration instanceof ICustomDirectEditorConfiguration) { + setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); + initializeDirectEditManager(theRequest); + return; + } else if (configuration instanceof IPopupEditorConfiguration) { + IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); + helper.showEditor(); + return; + } + else if (configuration instanceof IAdvancedEditorConfiguration) { + dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); + } else if (configuration instanceof IDirectEditorConfiguration) { + dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), + configuration); + } else { + return; + } + final Dialog finalDialog = dialog; + + if (Window.OK == dialog.open()) { + TransactionalEditingDomain domain = getEditingDomain(); + RecordingCommand command = new RecordingCommand(domain, "Edit Label") { + + @Override + protected void doExecute() { + configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); + + } + }; + domain.getCommandStack().execute(command); + } + } + break; + case IDirectEdition.DEFAULT_DIRECT_EDITOR: + initializeDirectEditManager(theRequest); + break; + default: + break; + } + } + + /** + * @generated + */ + protected void initializeDirectEditManager(final Request request) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + @Override + public void run() { + if (isActive() && isEditable()) { + if (request.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } + else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void refreshVisuals() { + super.refreshVisuals(); + refreshLabel(); + refreshFont(); + refreshFontColor(); + refreshUnderline(); + refreshStrikeThrough(); + } + + /** + * @generated + */ + protected void refreshLabel() { + EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); + if (maskLabelPolicy == null) { + maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); + } + if (maskLabelPolicy == null) { + setLabelTextHelper(getFigure(), getLabelText()); + setLabelIconHelper(getFigure(), getLabelIcon()); + } + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + protected void refreshUnderline() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); + } + if (resolveSemanticElement() instanceof Feature) { + if (((Feature) resolveSemanticElement()).isStatic()) { + ((WrappingLabel) getFigure()).setTextUnderline(true); + } + else { + ((WrappingLabel) getFigure()).setTextUnderline(false); + } + } + } + + /** + * @generated + */ + protected void refreshStrikeThrough() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); + } + } + + /** + * @generated + */ + @Override + protected void refreshFont() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null) { + FontData fontData = new FontData( + style.getFontName(), style.getFontHeight(), + (style.isBold() ? SWT.BOLD : SWT.NORMAL) | + (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); + setFont(fontData); + } + } + + /** + * @generated + */ + @Override + protected void setFontColor(Color color) { + getFigure().setForegroundColor(color); + } + + /** + * @generated + */ + @Override + protected void addSemanticListeners() { + if (getParser() instanceof ISemanticParser) { + EObject element = resolveSemanticElement(); + parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); + for (int i = 0; i < parserElements.size(); i++) { + addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ + } + } else { + super.addSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected void removeSemanticListeners() { + if (parserElements != null) { + for (int i = 0; i < parserElements.size(); i++) { + removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ + } + } else { + super.removeSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected AccessibleEditPart getAccessibleEditPart() { + if (accessibleEP == null) { + accessibleEP = new AccessibleGraphicalEditPart() { + + @Override + public void getName(AccessibleEvent e) { + e.result = getLabelTextHelper(getFigure()); + } + }; + } + return accessibleEP; + } + + /** + * @generated + */ + private View getFontStyleOwnerView() { + return getPrimaryView(); + } + + /** + * Returns the kind of associated editor for direct edition. + * + * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition + * @generated + */ + public int getDirectEditionType() { + if (checkExtendedEditor()) { + initExtendedEditorConfiguration(); + return IDirectEdition.EXTENDED_DIRECT_EDITOR; + } + if (checkDefaultEdition()) { + return IDirectEdition.DEFAULT_DIRECT_EDITOR; + } + + // not a named element. no specific editor => do nothing + return IDirectEdition.NO_DIRECT_EDITION; + } + + /** + * Checks if an extended editor is present. + * + * @return true if an extended editor is present. + * @generated + */ + protected boolean checkExtendedEditor() { + if (resolveSemanticElement() != null) { + return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); + } + return false; + } + + /** + * Checks if a default direct edition is available + * + * @return true if a default direct edition is available + * @generated + */ + protected boolean checkDefaultEdition() { + return (getParser() != null); + } + + /** + * Initializes the extended editor configuration + * + * @generated + */ + protected void initExtendedEditorConfiguration() { + if (configuration == null) { + final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("")) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); + } else { + configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); + } + } + } + + /** + * Updates the preference configuration + * + * @generated + */ + protected void updateExtendedEditorConfiguration() { + String languagePreferred = Activator.getDefault().getPreferenceStore().getString( + IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() + .eClass().getInstanceClassName()); + } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { + configuration = null; + } + } + + /** + * Performs the direct edit usually used by GMF editors. + * + * @param theRequest + * the direct edit request that starts the direct edit system + * @generated + */ + protected void performDefaultDirectEditorEdit(final Request theRequest) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + + @Override + public void run() { + if (isActive() && isEditable()) { + if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) theRequest.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { + DirectEditRequest editRequest = (DirectEditRequest) theRequest; + performDirectEdit(editRequest.getLocation()); + } else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void handleNotificationEvent(Notification event) { + Object feature = event.getFeature(); + if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { + Integer c = (Integer) event.getNewValue(); + setFontColor(DiagramColorRegistry.getInstance().getColor(c)); + } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { + refreshUnderline(); + } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { + refreshStrikeThrough(); + } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { + refreshFont(); + } else { + if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { + refreshLabel(); + } + if (getParser() instanceof ISemanticParser) { + ISemanticParser modelParser = + (ISemanticParser) getParser(); + if (modelParser.areSemanticElementsAffected(null, event)) { + removeSemanticListeners(); + if (resolveSemanticElement() != null) { + addSemanticListeners(); + } + refreshLabel(); + } + } + } + + super.handleNotificationEvent(event); + } + + /** + * @generated + */ + @Override + protected IFigure createFigure() { + // Parent should assign one using setLabel() method + return null; + } +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/RoleBindingAppliedStereotypeEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/RoleBindingAppliedStereotypeEditPart.java index 77252a489c4..c35980a3775 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/RoleBindingAppliedStereotypeEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/RoleBindingAppliedStereotypeEditPart.java @@ -1,820 +1,815 @@ -/** - * 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.uml.diagram.composite.edit.parts; - -import java.util.Collections; -import java.util.List; - -import org.eclipse.draw2d.ConnectionLocator; -import org.eclipse.draw2d.IFigure; -import org.eclipse.draw2d.Label; -import org.eclipse.draw2d.geometry.Point; -import org.eclipse.emf.common.notify.Notification; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.transaction.RecordingCommand; -import org.eclipse.emf.transaction.RunnableWithResult; -import org.eclipse.emf.transaction.TransactionalEditingDomain; -import org.eclipse.gef.AccessibleEditPart; -import org.eclipse.gef.EditPolicy; -import org.eclipse.gef.Request; -import org.eclipse.gef.requests.DirectEditRequest; -import org.eclipse.gef.tools.DirectEditManager; -import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; -import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; -import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; -import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; -import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; -import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; -import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; -import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; -import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; -import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; -import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; -import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; -import org.eclipse.gmf.runtime.notation.FontStyle; -import org.eclipse.gmf.runtime.notation.NotationPackage; -import org.eclipse.gmf.runtime.notation.View; -import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.jface.text.contentassist.IContentAssistProcessor; -import org.eclipse.jface.viewers.ICellEditorValidator; -import org.eclipse.jface.window.Window; -import org.eclipse.papyrus.extensionpoints.editors.Activator; -import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; -import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; -import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; -import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; -import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; -import org.eclipse.papyrus.infra.gmfdiag.common.editpart.IControlParserForDirectEdit; -import org.eclipse.papyrus.infra.gmfdiag.common.editpart.PapyrusLabelEditPart; -import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; -import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; -import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.PapyrusLinkLabelDragPolicy; -import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; -import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; -import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; -import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; -import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; -import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; -import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; -import org.eclipse.swt.SWT; -import org.eclipse.swt.accessibility.AccessibleEvent; -import org.eclipse.swt.custom.BusyIndicator; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.FontData; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.widgets.Display; -import org.eclipse.ui.PlatformUI; -import org.eclipse.uml2.uml.Feature; - -/** - * @generated - */ -public class RoleBindingAppliedStereotypeEditPart extends PapyrusLabelEditPart implements ITextAwareEditPart, IControlParserForDirectEdit { - - /** - * @generated - */ - public static final int VISUAL_ID = 6028; - - /** - * @generated - */ - private DirectEditManager manager; - - /** - * @generated - */ - private IParser parser; - - /** - * @generated - */ - private List parserElements; - - /** - * @generated - */ - private String defaultText; - - /** - * direct edition mode (default, undefined, registered editor, etc.) - * - * @generated - */ - protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; - - /** - * configuration from a registered edit dialog - * - * @generated - */ - protected IDirectEditorConfiguration configuration; - /** - * @generated - */ - static { - registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.RoleBindingAppliedStereotypeEditPart.VISUAL_ID), new Point(0, 60)); - } - - /** - * @generated - */ - public RoleBindingAppliedStereotypeEditPart(View view) { - super(view); - } - - /** - * @generated - */ - @Override - protected void createDefaultEditPolicies() { - super.createDefaultEditPolicies(); - installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); - installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); - installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new PapyrusLinkLabelDragPolicy()); - } - - /** - * @generated - */ - @Override - public int getKeyPoint() { - return ConnectionLocator.MIDDLE; - } - - /** - * @generated - */ - protected String getLabelTextHelper(IFigure figure) { - if (figure instanceof WrappingLabel) { - return ((WrappingLabel) figure).getText(); - } else if (figure instanceof ILabelFigure) { - return ((ILabelFigure) figure).getText(); - } else { - return ((Label) figure).getText(); - } - } - - /** - * @generated - */ - protected void setLabelTextHelper(IFigure figure, String text) { - if (figure instanceof WrappingLabel) { - ((WrappingLabel) figure).setText(text); - } else if (figure instanceof ILabelFigure) { - ((ILabelFigure) figure).setText(text); - } else { - ((Label) figure).setText(text); - } - } - - /** - * @generated - */ - protected Image getLabelIconHelper(IFigure figure) { - if (figure instanceof WrappingLabel) { - return ((WrappingLabel) figure).getIcon(); - } else if (figure instanceof ILabelFigure) { - return ((ILabelFigure) figure).getIcon(); - } else { - return ((Label) figure).getIcon(); - } - } - - /** - * @generated - */ - protected void setLabelIconHelper(IFigure figure, Image icon) { - if (figure instanceof WrappingLabel) { - ((WrappingLabel) figure).setIcon(icon); - } else if (figure instanceof ILabelFigure) { - ((ILabelFigure) figure).setIcon(icon); - } else { - ((Label) figure).setIcon(icon); - } - } - - /** - * @generated - */ - public void setLabel(IFigure - figure) { - unregisterVisuals(); - setFigure(figure); - defaultText = getLabelTextHelper(figure); - registerVisuals(); - refreshVisuals(); - } - - /** - * @generated - */ - @Override - protected List getModelChildren() { - return Collections.EMPTY_LIST; - } - - /** - * @generated - */ - @Override - public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { - return null; - } - - /** - * @generated - */ - @Override - public void setParser(IParser parser) { - this.parser = parser; - } - - /** - * @generated - */ - protected EObject getParserElement() { - return resolveSemanticElement(); - } - - /** - * @generated - */ - protected Image getLabelIcon() { - return null; - } - - /** - * @generated - */ - protected String getLabelText() { - String text = null; - EObject parserElement = getParserElement(); - if (parserElement != null && getParser() != null) { - text = getParser().getPrintString( - new EObjectAdapter(parserElement), - getParserOptions().intValue()); - } - if (text == null || text.length() == 0) { - text = defaultText; - } - return text; - } - - /** - * @generated - */ - @Override - public void setLabelText(String text) { - setLabelTextHelper(getFigure(), text); - Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); - if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); - } - Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); - if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); - } - } - - /** - * @generated - */ - @Override - public String getEditText() { - if (getParserElement() == null || getParser() == null) { - return ""; //$NON-NLS-1$ - } - return getParser().getEditString( - new EObjectAdapter(getParserElement()), - getParserOptions().intValue()); - } - - /** - * @generated - */ - protected boolean isEditable() { - return false; - } - - /** - * @generated - */ - @Override - public ICellEditorValidator getEditTextValidator() { - return new ICellEditorValidator() { - - @Override - public String isValid(final Object value) { - if (value instanceof String) { - final EObject element = getParserElement(); - final IParser parser = getParser(); - try { - IParserEditStatus valid = - (IParserEditStatus) getEditingDomain().runExclusive( - new RunnableWithResult.Impl() { - - @Override - public void run() { - setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); - } - }); - return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); - } catch (InterruptedException ie) { - ie.printStackTrace(); - } - } - - // shouldn't get here - return null; - } - }; - } - - /** - * @generated - */ - @Override - public IContentAssistProcessor getCompletionProcessor() { - if (getParserElement() == null || getParser() == null) { - return null; - } - return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); - } - - /** - * @generated - */ - @Override - public ParserOptions getParserOptions() { - return ParserOptions.NONE; - } - - /** - * @generated - */ - @Override - public IParser getParser() { - if (parser == null) { - parser = UMLParserProvider.getParser(UMLElementTypes.Dependency_4017, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.RoleBindingAppliedStereotypeEditPart.VISUAL_ID)); - } - return parser; - } - - /** - * @generated - */ - protected DirectEditManager getManager() { - if (manager == null) { - setManager(new MultilineLabelDirectEditManager(this, - MultilineLabelDirectEditManager.getTextCellEditorClass(this), - UMLEditPartFactory.getTextCellEditorLocator(this))); - } - return manager; - } - - /** - * @generated - */ - protected void setManager(DirectEditManager manager) { - this.manager = manager; - } - - /** - * @generated - */ - protected void performDirectEdit() { - BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { - - @Override - public void run() { - getManager().show(); - } - }); - } - - /** - * @generated - */ - protected void performDirectEdit(Point eventLocation) { - if (getManager() instanceof TextDirectEditManager) { - ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); - } - } - - /** - * @generated - */ - private void performDirectEdit(char initialCharacter) { - if (getManager() instanceof TextDirectEditManager) { - ((TextDirectEditManager) getManager()).show(initialCharacter); - } else { - performDirectEdit(); - } - } - - /** - * @generated - */ - @Override - protected void performDirectEditRequest(Request request) { - - final Request theRequest = request; - - if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { - directEditionMode = getDirectEditionType(); - } - switch (directEditionMode) { - case IDirectEdition.NO_DIRECT_EDITION: - // no direct edition mode => does nothing - return; - case IDirectEdition.EXTENDED_DIRECT_EDITOR: - updateExtendedEditorConfiguration(); - if (configuration == null || configuration.getLanguage() == null) { - // Create default edit manager - setManager(new MultilineLabelDirectEditManager(this, - MultilineLabelDirectEditManager.getTextCellEditorClass(this), - UMLEditPartFactory.getTextCellEditorLocator(this))); - performDefaultDirectEditorEdit(theRequest); - } else { - configuration.preEditAction(resolveSemanticElement()); - Dialog dialog = null; - if (configuration instanceof ICustomDirectEditorConfiguration) { - setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); - initializeDirectEditManager(theRequest); - return; - } else if (configuration instanceof IPopupEditorConfiguration) { - IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); - helper.showEditor(); - return; - } - else if (configuration instanceof IAdvancedEditorConfiguration) { - dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); - } else if (configuration instanceof IDirectEditorConfiguration) { - dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), - configuration); - } else { - return; - } - final Dialog finalDialog = dialog; - - if (Window.OK == dialog.open()) { - TransactionalEditingDomain domain = getEditingDomain(); - RecordingCommand command = new RecordingCommand(domain, "Edit Label") { - - @Override - protected void doExecute() { - configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); - - } - }; - domain.getCommandStack().execute(command); - } - } - break; - case IDirectEdition.DEFAULT_DIRECT_EDITOR: - initializeDirectEditManager(theRequest); - break; - default: - break; - } - } - - /** - * @generated - */ - protected void initializeDirectEditManager(final Request request) { - // initialize the direct edit manager - try { - getEditingDomain().runExclusive(new Runnable() { - @Override - public void run() { - if (isActive() && isEditable()) { - if (request.getExtendedData().get( - RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { - Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); - performDirectEdit(initialChar.charValue()); - } - else { - performDirectEdit(); - } - } - } - }); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - - /** - * @generated - */ - @Override - protected void refreshVisuals() { - super.refreshVisuals(); - refreshLabel(); - refreshFont(); - refreshFontColor(); - refreshUnderline(); - refreshStrikeThrough(); - } - - /** - * @generated - */ - protected void refreshLabel() { - EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); - if (maskLabelPolicy == null) { - maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); - } - if (maskLabelPolicy == null) { - View view = (View) getModel(); - if (view.isVisible()) { - setLabelTextHelper(getFigure(), getLabelText()); - setLabelIconHelper(getFigure(), getLabelIcon()); - } - else { - setLabelTextHelper(getFigure(), ""); //$NON-NLS-1$ - setLabelIconHelper(getFigure(), null); - } - } - Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); - if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); - } - Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); - if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); - } - } - - /** - * @generated - */ - protected void refreshUnderline() { - FontStyle style = - (FontStyle) getFontStyleOwnerView().getStyle( - NotationPackage.eINSTANCE.getFontStyle()); - if (style != null && getFigure() instanceof WrappingLabel) { - ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); - } - if (resolveSemanticElement() instanceof Feature) { - if (((Feature) resolveSemanticElement()).isStatic()) { - ((WrappingLabel) getFigure()).setTextUnderline(true); - } - else { - ((WrappingLabel) getFigure()).setTextUnderline(false); - } - } - } - - /** - * @generated - */ - protected void refreshStrikeThrough() { - FontStyle style = - (FontStyle) getFontStyleOwnerView().getStyle( - NotationPackage.eINSTANCE.getFontStyle()); - if (style != null && getFigure() instanceof WrappingLabel) { - ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); - } - } - - /** - * @generated - */ - @Override - protected void refreshFont() { - FontStyle style = - (FontStyle) getFontStyleOwnerView().getStyle( - NotationPackage.eINSTANCE.getFontStyle()); - if (style != null) { - FontData fontData = new FontData( - style.getFontName(), style.getFontHeight(), - (style.isBold() ? SWT.BOLD : SWT.NORMAL) | - (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); - setFont(fontData); - } - } - - /** - * @generated - */ - @Override - protected void setFontColor(Color color) { - getFigure().setForegroundColor(color); - } - - /** - * @generated - */ - @Override - protected void addSemanticListeners() { - if (getParser() instanceof ISemanticParser) { - EObject element = resolveSemanticElement(); - parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); - for (int i = 0; i < parserElements.size(); i++) { - addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ - } - } else { - super.addSemanticListeners(); - } - } - - /** - * @generated - */ - @Override - protected void removeSemanticListeners() { - if (parserElements != null) { - for (int i = 0; i < parserElements.size(); i++) { - removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ - } - } else { - super.removeSemanticListeners(); - } - } - - /** - * @generated - */ - @Override - protected AccessibleEditPart getAccessibleEditPart() { - if (accessibleEP == null) { - accessibleEP = new AccessibleGraphicalEditPart() { - - @Override - public void getName(AccessibleEvent e) { - e.result = getLabelTextHelper(getFigure()); - } - }; - } - return accessibleEP; - } - - /** - * @generated - */ - private View getFontStyleOwnerView() { - return getPrimaryView(); - } - - /** - * Returns the kind of associated editor for direct edition. - * - * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition - * @generated - */ - public int getDirectEditionType() { - // The label is read-only (defined in GMFGen model) - return IDirectEdition.NO_DIRECT_EDITION; - } - - /** - * Checks if an extended editor is present. - * - * @return true if an extended editor is present. - * @generated - */ - protected boolean checkExtendedEditor() { - if (resolveSemanticElement() != null) { - return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); - } - return false; - } - - /** - * Checks if a default direct edition is available - * - * @return true if a default direct edition is available - * @generated - */ - protected boolean checkDefaultEdition() { - return (getParser() != null); - } - - /** - * Initializes the extended editor configuration - * - * @generated - */ - protected void initExtendedEditorConfiguration() { - if (configuration == null) { - final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); - if (languagePreferred != null && !languagePreferred.equals("")) { - configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); - } else { - configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); - } - } - } - - /** - * Updates the preference configuration - * - * @generated - */ - protected void updateExtendedEditorConfiguration() { - String languagePreferred = Activator.getDefault().getPreferenceStore().getString( - IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); - if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { - configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() - .eClass().getInstanceClassName()); - } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { - configuration = null; - } - } - - /** - * Performs the direct edit usually used by GMF editors. - * - * @param theRequest - * the direct edit request that starts the direct edit system - * @generated - */ - protected void performDefaultDirectEditorEdit(final Request theRequest) { - // initialize the direct edit manager - try { - getEditingDomain().runExclusive(new Runnable() { - - @Override - public void run() { - if (isActive() && isEditable()) { - if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { - Character initialChar = (Character) theRequest.getExtendedData().get( - RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); - performDirectEdit(initialChar.charValue()); - } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { - DirectEditRequest editRequest = (DirectEditRequest) theRequest; - performDirectEdit(editRequest.getLocation()); - } else { - performDirectEdit(); - } - } - } - }); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - - /** - * @generated - */ - @Override - protected void handleNotificationEvent(Notification event) { - Object feature = event.getFeature(); - if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { - Integer c = (Integer) event.getNewValue(); - setFontColor(DiagramColorRegistry.getInstance().getColor(c)); - } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { - refreshUnderline(); - } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { - refreshStrikeThrough(); - } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || - NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || - NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || - NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { - refreshFont(); - } else { - if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { - refreshLabel(); - } - if (getParser() instanceof ISemanticParser) { - ISemanticParser modelParser = - (ISemanticParser) getParser(); - if (modelParser.areSemanticElementsAffected(null, event)) { - removeSemanticListeners(); - if (resolveSemanticElement() != null) { - addSemanticListeners(); - } - refreshLabel(); - } - } - } - - super.handleNotificationEvent(event); - } - - /** - * @generated - */ - @Override - protected IFigure createFigure() { - // Parent should assign one using setLabel() method - return 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.uml.diagram.composite.edit.parts; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.draw2d.ConnectionLocator; +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.Label; +import org.eclipse.draw2d.geometry.Point; +import org.eclipse.emf.common.notify.Notification; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.RunnableWithResult; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gef.AccessibleEditPart; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.Request; +import org.eclipse.gef.requests.DirectEditRequest; +import org.eclipse.gef.tools.DirectEditManager; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; +import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; +import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; +import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; +import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; +import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; +import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; +import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; +import org.eclipse.gmf.runtime.notation.FontStyle; +import org.eclipse.gmf.runtime.notation.NotationPackage; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.gmf.tooling.runtime.edit.policies.DefaultLinkLabelDragPolicy; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.text.contentassist.IContentAssistProcessor; +import org.eclipse.jface.viewers.ICellEditorValidator; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.extensionpoints.editors.Activator; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; +import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; +import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; +import org.eclipse.papyrus.infra.gmfdiag.common.editpart.IControlParserForDirectEdit; +import org.eclipse.papyrus.infra.gmfdiag.common.editpart.PapyrusLabelEditPart; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.PapyrusLinkLabelDragPolicy; +import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; +import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; +import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; +import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; +import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.accessibility.AccessibleEvent; +import org.eclipse.swt.custom.BusyIndicator; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; +import org.eclipse.uml2.uml.Feature; + +/** + * @generated + */ +public class RoleBindingAppliedStereotypeEditPart extends PapyrusLabelEditPart implements ITextAwareEditPart, IControlParserForDirectEdit { + + /** + * @generated + */ + public static final int VISUAL_ID = 6028; + + /** + * @generated + */ + private DirectEditManager manager; + + /** + * @generated + */ + private IParser parser; + + /** + * @generated + */ + private List parserElements; + + /** + * @generated + */ + private String defaultText; + + /** + * direct edition mode (default, undefined, registered editor, etc.) + * + * @generated + */ + protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; + + /** + * configuration from a registered edit dialog + * + * @generated + */ + protected IDirectEditorConfiguration configuration; + /** + * @generated + */ + static { + registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.RoleBindingAppliedStereotypeEditPart.VISUAL_ID), new Point(0, 60)); + } + + /** + * @generated + */ + public RoleBindingAppliedStereotypeEditPart(View view) { + super(view); + } + + /** + * @generated + */ + @Override + protected void createDefaultEditPolicies() { + super.createDefaultEditPolicies(); + installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); + installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new DefaultLinkLabelDragPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new PapyrusLinkLabelDragPolicy()); + } + + /** + * @generated + */ + @Override + public int getKeyPoint() { + return ConnectionLocator.MIDDLE; + } + + /** + * @generated + */ + protected String getLabelTextHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getText(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getText(); + } else { + return ((Label) figure).getText(); + } + } + + /** + * @generated + */ + protected void setLabelTextHelper(IFigure figure, String text) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setText(text); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setText(text); + } else { + ((Label) figure).setText(text); + } + } + + /** + * @generated + */ + protected Image getLabelIconHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getIcon(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getIcon(); + } else { + return ((Label) figure).getIcon(); + } + } + + /** + * @generated + */ + protected void setLabelIconHelper(IFigure figure, Image icon) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setIcon(icon); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setIcon(icon); + } else { + ((Label) figure).setIcon(icon); + } + } + + /** + * @generated + */ + public void setLabel(IFigure + figure) { + unregisterVisuals(); + setFigure(figure); + defaultText = getLabelTextHelper(figure); + registerVisuals(); + refreshVisuals(); + } + + /** + * @generated + */ + @Override + protected List getModelChildren() { + return Collections.EMPTY_LIST; + } + + /** + * @generated + */ + @Override + public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { + return null; + } + + /** + * @generated + */ + @Override + public void setParser(IParser parser) { + this.parser = parser; + } + + /** + * @generated + */ + protected EObject getParserElement() { + return resolveSemanticElement(); + } + + /** + * @generated + */ + protected Image getLabelIcon() { + return null; + } + + /** + * @generated + */ + protected String getLabelText() { + String text = null; + EObject parserElement = getParserElement(); + if (parserElement != null && getParser() != null) { + text = getParser().getPrintString( + new EObjectAdapter(parserElement), + getParserOptions().intValue()); + } + if (text == null || text.length() == 0) { + text = defaultText; + } + return text; + } + + /** + * @generated + */ + @Override + public void setLabelText(String text) { + setLabelTextHelper(getFigure(), text); + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + @Override + public String getEditText() { + if (getParserElement() == null || getParser() == null) { + return ""; //$NON-NLS-1$ + } + return getParser().getEditString( + new EObjectAdapter(getParserElement()), + getParserOptions().intValue()); + } + + /** + * @generated + */ + protected boolean isEditable() { + return false; + } + + /** + * @generated + */ + @Override + public ICellEditorValidator getEditTextValidator() { + return new ICellEditorValidator() { + + @Override + public String isValid(final Object value) { + if (value instanceof String) { + final EObject element = getParserElement(); + final IParser parser = getParser(); + try { + IParserEditStatus valid = + (IParserEditStatus) getEditingDomain().runExclusive( + new RunnableWithResult.Impl() { + + @Override + public void run() { + setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); + } + }); + return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); + } catch (InterruptedException ie) { + ie.printStackTrace(); + } + } + + // shouldn't get here + return null; + } + }; + } + + /** + * @generated + */ + @Override + public IContentAssistProcessor getCompletionProcessor() { + if (getParserElement() == null || getParser() == null) { + return null; + } + return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); + } + + /** + * @generated + */ + @Override + public ParserOptions getParserOptions() { + return ParserOptions.NONE; + } + + /** + * @generated + */ + @Override + public IParser getParser() { + if (parser == null) { + parser = UMLParserProvider.getParser(UMLElementTypes.Dependency_4017, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.RoleBindingAppliedStereotypeEditPart.VISUAL_ID)); + } + return parser; + } + + /** + * @generated + */ + protected DirectEditManager getManager() { + if (manager == null) { + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + } + return manager; + } + + /** + * @generated + */ + protected void setManager(DirectEditManager manager) { + this.manager = manager; + } + + /** + * @generated + */ + protected void performDirectEdit() { + BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { + + @Override + public void run() { + getManager().show(); + } + }); + } + + /** + * @generated + */ + protected void performDirectEdit(Point eventLocation) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); + } + } + + /** + * @generated + */ + private void performDirectEdit(char initialCharacter) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(initialCharacter); + } else { + performDirectEdit(); + } + } + + /** + * @generated + */ + @Override + protected void performDirectEditRequest(Request request) { + + final Request theRequest = request; + + if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { + directEditionMode = getDirectEditionType(); + } + switch (directEditionMode) { + case IDirectEdition.NO_DIRECT_EDITION: + // no direct edition mode => does nothing + return; + case IDirectEdition.EXTENDED_DIRECT_EDITOR: + updateExtendedEditorConfiguration(); + if (configuration == null || configuration.getLanguage() == null) { + // Create default edit manager + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + performDefaultDirectEditorEdit(theRequest); + } else { + configuration.preEditAction(resolveSemanticElement()); + Dialog dialog = null; + if (configuration instanceof ICustomDirectEditorConfiguration) { + setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); + initializeDirectEditManager(theRequest); + return; + } else if (configuration instanceof IPopupEditorConfiguration) { + IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); + helper.showEditor(); + return; + } + else if (configuration instanceof IAdvancedEditorConfiguration) { + dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); + } else if (configuration instanceof IDirectEditorConfiguration) { + dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), + configuration); + } else { + return; + } + final Dialog finalDialog = dialog; + + if (Window.OK == dialog.open()) { + TransactionalEditingDomain domain = getEditingDomain(); + RecordingCommand command = new RecordingCommand(domain, "Edit Label") { + + @Override + protected void doExecute() { + configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); + + } + }; + domain.getCommandStack().execute(command); + } + } + break; + case IDirectEdition.DEFAULT_DIRECT_EDITOR: + initializeDirectEditManager(theRequest); + break; + default: + break; + } + } + + /** + * @generated + */ + protected void initializeDirectEditManager(final Request request) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + @Override + public void run() { + if (isActive() && isEditable()) { + if (request.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } + else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void refreshVisuals() { + super.refreshVisuals(); + refreshLabel(); + refreshFont(); + refreshFontColor(); + refreshUnderline(); + refreshStrikeThrough(); + } + + /** + * @generated + */ + protected void refreshLabel() { + EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); + if (maskLabelPolicy == null) { + maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); + } + if (maskLabelPolicy == null) { + setLabelTextHelper(getFigure(), getLabelText()); + setLabelIconHelper(getFigure(), getLabelIcon()); + } + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + protected void refreshUnderline() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); + } + if (resolveSemanticElement() instanceof Feature) { + if (((Feature) resolveSemanticElement()).isStatic()) { + ((WrappingLabel) getFigure()).setTextUnderline(true); + } + else { + ((WrappingLabel) getFigure()).setTextUnderline(false); + } + } + } + + /** + * @generated + */ + protected void refreshStrikeThrough() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); + } + } + + /** + * @generated + */ + @Override + protected void refreshFont() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null) { + FontData fontData = new FontData( + style.getFontName(), style.getFontHeight(), + (style.isBold() ? SWT.BOLD : SWT.NORMAL) | + (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); + setFont(fontData); + } + } + + /** + * @generated + */ + @Override + protected void setFontColor(Color color) { + getFigure().setForegroundColor(color); + } + + /** + * @generated + */ + @Override + protected void addSemanticListeners() { + if (getParser() instanceof ISemanticParser) { + EObject element = resolveSemanticElement(); + parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); + for (int i = 0; i < parserElements.size(); i++) { + addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ + } + } else { + super.addSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected void removeSemanticListeners() { + if (parserElements != null) { + for (int i = 0; i < parserElements.size(); i++) { + removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ + } + } else { + super.removeSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected AccessibleEditPart getAccessibleEditPart() { + if (accessibleEP == null) { + accessibleEP = new AccessibleGraphicalEditPart() { + + @Override + public void getName(AccessibleEvent e) { + e.result = getLabelTextHelper(getFigure()); + } + }; + } + return accessibleEP; + } + + /** + * @generated + */ + private View getFontStyleOwnerView() { + return getPrimaryView(); + } + + /** + * Returns the kind of associated editor for direct edition. + * + * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition + * @generated + */ + public int getDirectEditionType() { + // The label is read-only (defined in GMFGen model) + return IDirectEdition.NO_DIRECT_EDITION; + } + + /** + * Checks if an extended editor is present. + * + * @return true if an extended editor is present. + * @generated + */ + protected boolean checkExtendedEditor() { + if (resolveSemanticElement() != null) { + return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); + } + return false; + } + + /** + * Checks if a default direct edition is available + * + * @return true if a default direct edition is available + * @generated + */ + protected boolean checkDefaultEdition() { + return (getParser() != null); + } + + /** + * Initializes the extended editor configuration + * + * @generated + */ + protected void initExtendedEditorConfiguration() { + if (configuration == null) { + final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("")) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); + } else { + configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); + } + } + } + + /** + * Updates the preference configuration + * + * @generated + */ + protected void updateExtendedEditorConfiguration() { + String languagePreferred = Activator.getDefault().getPreferenceStore().getString( + IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() + .eClass().getInstanceClassName()); + } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { + configuration = null; + } + } + + /** + * Performs the direct edit usually used by GMF editors. + * + * @param theRequest + * the direct edit request that starts the direct edit system + * @generated + */ + protected void performDefaultDirectEditorEdit(final Request theRequest) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + + @Override + public void run() { + if (isActive() && isEditable()) { + if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) theRequest.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { + DirectEditRequest editRequest = (DirectEditRequest) theRequest; + performDirectEdit(editRequest.getLocation()); + } else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void handleNotificationEvent(Notification event) { + Object feature = event.getFeature(); + if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { + Integer c = (Integer) event.getNewValue(); + setFontColor(DiagramColorRegistry.getInstance().getColor(c)); + } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { + refreshUnderline(); + } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { + refreshStrikeThrough(); + } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { + refreshFont(); + } else { + if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { + refreshLabel(); + } + if (getParser() instanceof ISemanticParser) { + ISemanticParser modelParser = + (ISemanticParser) getParser(); + if (modelParser.areSemanticElementsAffected(null, event)) { + removeSemanticListeners(); + if (resolveSemanticElement() != null) { + addSemanticListeners(); + } + refreshLabel(); + } + } + } + + super.handleNotificationEvent(event); + } + + /** + * @generated + */ + @Override + protected IFigure createFigure() { + // Parent should assign one using setLabel() method + return null; + } +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/RoleBindingRoleNameEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/RoleBindingRoleNameEditPart.java index 7052ee92e3e..c8dd82e4d41 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/RoleBindingRoleNameEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/RoleBindingRoleNameEditPart.java @@ -1,820 +1,815 @@ -/** - * 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.uml.diagram.composite.edit.parts; - -import java.util.Collections; -import java.util.List; - -import org.eclipse.draw2d.ConnectionLocator; -import org.eclipse.draw2d.IFigure; -import org.eclipse.draw2d.Label; -import org.eclipse.draw2d.geometry.Point; -import org.eclipse.emf.common.notify.Notification; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.transaction.RecordingCommand; -import org.eclipse.emf.transaction.RunnableWithResult; -import org.eclipse.emf.transaction.TransactionalEditingDomain; -import org.eclipse.gef.AccessibleEditPart; -import org.eclipse.gef.EditPolicy; -import org.eclipse.gef.Request; -import org.eclipse.gef.requests.DirectEditRequest; -import org.eclipse.gef.tools.DirectEditManager; -import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; -import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; -import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; -import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; -import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; -import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; -import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; -import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; -import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; -import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; -import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; -import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; -import org.eclipse.gmf.runtime.notation.FontStyle; -import org.eclipse.gmf.runtime.notation.NotationPackage; -import org.eclipse.gmf.runtime.notation.View; -import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.jface.text.contentassist.IContentAssistProcessor; -import org.eclipse.jface.viewers.ICellEditorValidator; -import org.eclipse.jface.window.Window; -import org.eclipse.papyrus.extensionpoints.editors.Activator; -import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; -import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; -import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; -import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; -import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; -import org.eclipse.papyrus.infra.gmfdiag.common.editpart.IControlParserForDirectEdit; -import org.eclipse.papyrus.infra.gmfdiag.common.editpart.PapyrusLabelEditPart; -import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; -import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; -import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.PapyrusLinkLabelDragPolicy; -import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; -import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; -import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; -import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; -import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; -import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; -import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; -import org.eclipse.swt.SWT; -import org.eclipse.swt.accessibility.AccessibleEvent; -import org.eclipse.swt.custom.BusyIndicator; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.FontData; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.widgets.Display; -import org.eclipse.ui.PlatformUI; -import org.eclipse.uml2.uml.Feature; - -/** - * @generated - */ -public class RoleBindingRoleNameEditPart extends PapyrusLabelEditPart implements ITextAwareEditPart, IControlParserForDirectEdit { - - /** - * @generated - */ - public static final int VISUAL_ID = 6027; - - /** - * @generated - */ - private DirectEditManager manager; - - /** - * @generated - */ - private IParser parser; - - /** - * @generated - */ - private List parserElements; - - /** - * @generated - */ - private String defaultText; - - /** - * direct edition mode (default, undefined, registered editor, etc.) - * - * @generated - */ - protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; - - /** - * configuration from a registered edit dialog - * - * @generated - */ - protected IDirectEditorConfiguration configuration; - /** - * @generated - */ - static { - registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.RoleBindingRoleNameEditPart.VISUAL_ID), new Point(0, 20)); - } - - /** - * @generated - */ - public RoleBindingRoleNameEditPart(View view) { - super(view); - } - - /** - * @generated - */ - @Override - protected void createDefaultEditPolicies() { - super.createDefaultEditPolicies(); - installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); - installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); - installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new PapyrusLinkLabelDragPolicy()); - } - - /** - * @generated - */ - @Override - public int getKeyPoint() { - return ConnectionLocator.SOURCE; - } - - /** - * @generated - */ - protected String getLabelTextHelper(IFigure figure) { - if (figure instanceof WrappingLabel) { - return ((WrappingLabel) figure).getText(); - } else if (figure instanceof ILabelFigure) { - return ((ILabelFigure) figure).getText(); - } else { - return ((Label) figure).getText(); - } - } - - /** - * @generated - */ - protected void setLabelTextHelper(IFigure figure, String text) { - if (figure instanceof WrappingLabel) { - ((WrappingLabel) figure).setText(text); - } else if (figure instanceof ILabelFigure) { - ((ILabelFigure) figure).setText(text); - } else { - ((Label) figure).setText(text); - } - } - - /** - * @generated - */ - protected Image getLabelIconHelper(IFigure figure) { - if (figure instanceof WrappingLabel) { - return ((WrappingLabel) figure).getIcon(); - } else if (figure instanceof ILabelFigure) { - return ((ILabelFigure) figure).getIcon(); - } else { - return ((Label) figure).getIcon(); - } - } - - /** - * @generated - */ - protected void setLabelIconHelper(IFigure figure, Image icon) { - if (figure instanceof WrappingLabel) { - ((WrappingLabel) figure).setIcon(icon); - } else if (figure instanceof ILabelFigure) { - ((ILabelFigure) figure).setIcon(icon); - } else { - ((Label) figure).setIcon(icon); - } - } - - /** - * @generated - */ - public void setLabel(IFigure - figure) { - unregisterVisuals(); - setFigure(figure); - defaultText = getLabelTextHelper(figure); - registerVisuals(); - refreshVisuals(); - } - - /** - * @generated - */ - @Override - protected List getModelChildren() { - return Collections.EMPTY_LIST; - } - - /** - * @generated - */ - @Override - public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { - return null; - } - - /** - * @generated - */ - @Override - public void setParser(IParser parser) { - this.parser = parser; - } - - /** - * @generated - */ - protected EObject getParserElement() { - return resolveSemanticElement(); - } - - /** - * @generated - */ - protected Image getLabelIcon() { - return null; - } - - /** - * @generated - */ - protected String getLabelText() { - String text = null; - EObject parserElement = getParserElement(); - if (parserElement != null && getParser() != null) { - text = getParser().getPrintString( - new EObjectAdapter(parserElement), - getParserOptions().intValue()); - } - if (text == null || text.length() == 0) { - text = defaultText; - } - return text; - } - - /** - * @generated - */ - @Override - public void setLabelText(String text) { - setLabelTextHelper(getFigure(), text); - Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); - if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); - } - Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); - if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); - } - } - - /** - * @generated - */ - @Override - public String getEditText() { - if (getParserElement() == null || getParser() == null) { - return ""; //$NON-NLS-1$ - } - return getParser().getEditString( - new EObjectAdapter(getParserElement()), - getParserOptions().intValue()); - } - - /** - * @generated - */ - protected boolean isEditable() { - return false; - } - - /** - * @generated - */ - @Override - public ICellEditorValidator getEditTextValidator() { - return new ICellEditorValidator() { - - @Override - public String isValid(final Object value) { - if (value instanceof String) { - final EObject element = getParserElement(); - final IParser parser = getParser(); - try { - IParserEditStatus valid = - (IParserEditStatus) getEditingDomain().runExclusive( - new RunnableWithResult.Impl() { - - @Override - public void run() { - setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); - } - }); - return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); - } catch (InterruptedException ie) { - ie.printStackTrace(); - } - } - - // shouldn't get here - return null; - } - }; - } - - /** - * @generated - */ - @Override - public IContentAssistProcessor getCompletionProcessor() { - if (getParserElement() == null || getParser() == null) { - return null; - } - return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); - } - - /** - * @generated - */ - @Override - public ParserOptions getParserOptions() { - return ParserOptions.NONE; - } - - /** - * @generated - */ - @Override - public IParser getParser() { - if (parser == null) { - parser = UMLParserProvider.getParser(UMLElementTypes.Dependency_4017, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.RoleBindingRoleNameEditPart.VISUAL_ID)); - } - return parser; - } - - /** - * @generated - */ - protected DirectEditManager getManager() { - if (manager == null) { - setManager(new MultilineLabelDirectEditManager(this, - MultilineLabelDirectEditManager.getTextCellEditorClass(this), - UMLEditPartFactory.getTextCellEditorLocator(this))); - } - return manager; - } - - /** - * @generated - */ - protected void setManager(DirectEditManager manager) { - this.manager = manager; - } - - /** - * @generated - */ - protected void performDirectEdit() { - BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { - - @Override - public void run() { - getManager().show(); - } - }); - } - - /** - * @generated - */ - protected void performDirectEdit(Point eventLocation) { - if (getManager() instanceof TextDirectEditManager) { - ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); - } - } - - /** - * @generated - */ - private void performDirectEdit(char initialCharacter) { - if (getManager() instanceof TextDirectEditManager) { - ((TextDirectEditManager) getManager()).show(initialCharacter); - } else { - performDirectEdit(); - } - } - - /** - * @generated - */ - @Override - protected void performDirectEditRequest(Request request) { - - final Request theRequest = request; - - if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { - directEditionMode = getDirectEditionType(); - } - switch (directEditionMode) { - case IDirectEdition.NO_DIRECT_EDITION: - // no direct edition mode => does nothing - return; - case IDirectEdition.EXTENDED_DIRECT_EDITOR: - updateExtendedEditorConfiguration(); - if (configuration == null || configuration.getLanguage() == null) { - // Create default edit manager - setManager(new MultilineLabelDirectEditManager(this, - MultilineLabelDirectEditManager.getTextCellEditorClass(this), - UMLEditPartFactory.getTextCellEditorLocator(this))); - performDefaultDirectEditorEdit(theRequest); - } else { - configuration.preEditAction(resolveSemanticElement()); - Dialog dialog = null; - if (configuration instanceof ICustomDirectEditorConfiguration) { - setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); - initializeDirectEditManager(theRequest); - return; - } else if (configuration instanceof IPopupEditorConfiguration) { - IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); - helper.showEditor(); - return; - } - else if (configuration instanceof IAdvancedEditorConfiguration) { - dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); - } else if (configuration instanceof IDirectEditorConfiguration) { - dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), - configuration); - } else { - return; - } - final Dialog finalDialog = dialog; - - if (Window.OK == dialog.open()) { - TransactionalEditingDomain domain = getEditingDomain(); - RecordingCommand command = new RecordingCommand(domain, "Edit Label") { - - @Override - protected void doExecute() { - configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); - - } - }; - domain.getCommandStack().execute(command); - } - } - break; - case IDirectEdition.DEFAULT_DIRECT_EDITOR: - initializeDirectEditManager(theRequest); - break; - default: - break; - } - } - - /** - * @generated - */ - protected void initializeDirectEditManager(final Request request) { - // initialize the direct edit manager - try { - getEditingDomain().runExclusive(new Runnable() { - @Override - public void run() { - if (isActive() && isEditable()) { - if (request.getExtendedData().get( - RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { - Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); - performDirectEdit(initialChar.charValue()); - } - else { - performDirectEdit(); - } - } - } - }); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - - /** - * @generated - */ - @Override - protected void refreshVisuals() { - super.refreshVisuals(); - refreshLabel(); - refreshFont(); - refreshFontColor(); - refreshUnderline(); - refreshStrikeThrough(); - } - - /** - * @generated - */ - protected void refreshLabel() { - EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); - if (maskLabelPolicy == null) { - maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); - } - if (maskLabelPolicy == null) { - View view = (View) getModel(); - if (view.isVisible()) { - setLabelTextHelper(getFigure(), getLabelText()); - setLabelIconHelper(getFigure(), getLabelIcon()); - } - else { - setLabelTextHelper(getFigure(), ""); //$NON-NLS-1$ - setLabelIconHelper(getFigure(), null); - } - } - Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); - if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); - } - Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); - if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); - } - } - - /** - * @generated - */ - protected void refreshUnderline() { - FontStyle style = - (FontStyle) getFontStyleOwnerView().getStyle( - NotationPackage.eINSTANCE.getFontStyle()); - if (style != null && getFigure() instanceof WrappingLabel) { - ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); - } - if (resolveSemanticElement() instanceof Feature) { - if (((Feature) resolveSemanticElement()).isStatic()) { - ((WrappingLabel) getFigure()).setTextUnderline(true); - } - else { - ((WrappingLabel) getFigure()).setTextUnderline(false); - } - } - } - - /** - * @generated - */ - protected void refreshStrikeThrough() { - FontStyle style = - (FontStyle) getFontStyleOwnerView().getStyle( - NotationPackage.eINSTANCE.getFontStyle()); - if (style != null && getFigure() instanceof WrappingLabel) { - ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); - } - } - - /** - * @generated - */ - @Override - protected void refreshFont() { - FontStyle style = - (FontStyle) getFontStyleOwnerView().getStyle( - NotationPackage.eINSTANCE.getFontStyle()); - if (style != null) { - FontData fontData = new FontData( - style.getFontName(), style.getFontHeight(), - (style.isBold() ? SWT.BOLD : SWT.NORMAL) | - (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); - setFont(fontData); - } - } - - /** - * @generated - */ - @Override - protected void setFontColor(Color color) { - getFigure().setForegroundColor(color); - } - - /** - * @generated - */ - @Override - protected void addSemanticListeners() { - if (getParser() instanceof ISemanticParser) { - EObject element = resolveSemanticElement(); - parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); - for (int i = 0; i < parserElements.size(); i++) { - addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ - } - } else { - super.addSemanticListeners(); - } - } - - /** - * @generated - */ - @Override - protected void removeSemanticListeners() { - if (parserElements != null) { - for (int i = 0; i < parserElements.size(); i++) { - removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ - } - } else { - super.removeSemanticListeners(); - } - } - - /** - * @generated - */ - @Override - protected AccessibleEditPart getAccessibleEditPart() { - if (accessibleEP == null) { - accessibleEP = new AccessibleGraphicalEditPart() { - - @Override - public void getName(AccessibleEvent e) { - e.result = getLabelTextHelper(getFigure()); - } - }; - } - return accessibleEP; - } - - /** - * @generated - */ - private View getFontStyleOwnerView() { - return getPrimaryView(); - } - - /** - * Returns the kind of associated editor for direct edition. - * - * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition - * @generated - */ - public int getDirectEditionType() { - // The label is read-only (defined in GMFGen model) - return IDirectEdition.NO_DIRECT_EDITION; - } - - /** - * Checks if an extended editor is present. - * - * @return true if an extended editor is present. - * @generated - */ - protected boolean checkExtendedEditor() { - if (resolveSemanticElement() != null) { - return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); - } - return false; - } - - /** - * Checks if a default direct edition is available - * - * @return true if a default direct edition is available - * @generated - */ - protected boolean checkDefaultEdition() { - return (getParser() != null); - } - - /** - * Initializes the extended editor configuration - * - * @generated - */ - protected void initExtendedEditorConfiguration() { - if (configuration == null) { - final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); - if (languagePreferred != null && !languagePreferred.equals("")) { - configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); - } else { - configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); - } - } - } - - /** - * Updates the preference configuration - * - * @generated - */ - protected void updateExtendedEditorConfiguration() { - String languagePreferred = Activator.getDefault().getPreferenceStore().getString( - IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); - if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { - configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() - .eClass().getInstanceClassName()); - } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { - configuration = null; - } - } - - /** - * Performs the direct edit usually used by GMF editors. - * - * @param theRequest - * the direct edit request that starts the direct edit system - * @generated - */ - protected void performDefaultDirectEditorEdit(final Request theRequest) { - // initialize the direct edit manager - try { - getEditingDomain().runExclusive(new Runnable() { - - @Override - public void run() { - if (isActive() && isEditable()) { - if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { - Character initialChar = (Character) theRequest.getExtendedData().get( - RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); - performDirectEdit(initialChar.charValue()); - } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { - DirectEditRequest editRequest = (DirectEditRequest) theRequest; - performDirectEdit(editRequest.getLocation()); - } else { - performDirectEdit(); - } - } - } - }); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - - /** - * @generated - */ - @Override - protected void handleNotificationEvent(Notification event) { - Object feature = event.getFeature(); - if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { - Integer c = (Integer) event.getNewValue(); - setFontColor(DiagramColorRegistry.getInstance().getColor(c)); - } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { - refreshUnderline(); - } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { - refreshStrikeThrough(); - } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || - NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || - NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || - NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { - refreshFont(); - } else { - if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { - refreshLabel(); - } - if (getParser() instanceof ISemanticParser) { - ISemanticParser modelParser = - (ISemanticParser) getParser(); - if (modelParser.areSemanticElementsAffected(null, event)) { - removeSemanticListeners(); - if (resolveSemanticElement() != null) { - addSemanticListeners(); - } - refreshLabel(); - } - } - } - - super.handleNotificationEvent(event); - } - - /** - * @generated - */ - @Override - protected IFigure createFigure() { - // Parent should assign one using setLabel() method - return 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.uml.diagram.composite.edit.parts; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.draw2d.ConnectionLocator; +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.Label; +import org.eclipse.draw2d.geometry.Point; +import org.eclipse.emf.common.notify.Notification; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.RunnableWithResult; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gef.AccessibleEditPart; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.Request; +import org.eclipse.gef.requests.DirectEditRequest; +import org.eclipse.gef.tools.DirectEditManager; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; +import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; +import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; +import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; +import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; +import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; +import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; +import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; +import org.eclipse.gmf.runtime.notation.FontStyle; +import org.eclipse.gmf.runtime.notation.NotationPackage; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.gmf.tooling.runtime.edit.policies.DefaultLinkLabelDragPolicy; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.text.contentassist.IContentAssistProcessor; +import org.eclipse.jface.viewers.ICellEditorValidator; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.extensionpoints.editors.Activator; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; +import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; +import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; +import org.eclipse.papyrus.infra.gmfdiag.common.editpart.IControlParserForDirectEdit; +import org.eclipse.papyrus.infra.gmfdiag.common.editpart.PapyrusLabelEditPart; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.PapyrusLinkLabelDragPolicy; +import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; +import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; +import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; +import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; +import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.accessibility.AccessibleEvent; +import org.eclipse.swt.custom.BusyIndicator; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; +import org.eclipse.uml2.uml.Feature; + +/** + * @generated + */ +public class RoleBindingRoleNameEditPart extends PapyrusLabelEditPart implements ITextAwareEditPart, IControlParserForDirectEdit { + + /** + * @generated + */ + public static final int VISUAL_ID = 6027; + + /** + * @generated + */ + private DirectEditManager manager; + + /** + * @generated + */ + private IParser parser; + + /** + * @generated + */ + private List parserElements; + + /** + * @generated + */ + private String defaultText; + + /** + * direct edition mode (default, undefined, registered editor, etc.) + * + * @generated + */ + protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; + + /** + * configuration from a registered edit dialog + * + * @generated + */ + protected IDirectEditorConfiguration configuration; + /** + * @generated + */ + static { + registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.RoleBindingRoleNameEditPart.VISUAL_ID), new Point(0, 20)); + } + + /** + * @generated + */ + public RoleBindingRoleNameEditPart(View view) { + super(view); + } + + /** + * @generated + */ + @Override + protected void createDefaultEditPolicies() { + super.createDefaultEditPolicies(); + installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); + installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new DefaultLinkLabelDragPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new PapyrusLinkLabelDragPolicy()); + } + + /** + * @generated + */ + @Override + public int getKeyPoint() { + return ConnectionLocator.SOURCE; + } + + /** + * @generated + */ + protected String getLabelTextHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getText(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getText(); + } else { + return ((Label) figure).getText(); + } + } + + /** + * @generated + */ + protected void setLabelTextHelper(IFigure figure, String text) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setText(text); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setText(text); + } else { + ((Label) figure).setText(text); + } + } + + /** + * @generated + */ + protected Image getLabelIconHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getIcon(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getIcon(); + } else { + return ((Label) figure).getIcon(); + } + } + + /** + * @generated + */ + protected void setLabelIconHelper(IFigure figure, Image icon) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setIcon(icon); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setIcon(icon); + } else { + ((Label) figure).setIcon(icon); + } + } + + /** + * @generated + */ + public void setLabel(IFigure + figure) { + unregisterVisuals(); + setFigure(figure); + defaultText = getLabelTextHelper(figure); + registerVisuals(); + refreshVisuals(); + } + + /** + * @generated + */ + @Override + protected List getModelChildren() { + return Collections.EMPTY_LIST; + } + + /** + * @generated + */ + @Override + public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { + return null; + } + + /** + * @generated + */ + @Override + public void setParser(IParser parser) { + this.parser = parser; + } + + /** + * @generated + */ + protected EObject getParserElement() { + return resolveSemanticElement(); + } + + /** + * @generated + */ + protected Image getLabelIcon() { + return null; + } + + /** + * @generated + */ + protected String getLabelText() { + String text = null; + EObject parserElement = getParserElement(); + if (parserElement != null && getParser() != null) { + text = getParser().getPrintString( + new EObjectAdapter(parserElement), + getParserOptions().intValue()); + } + if (text == null || text.length() == 0) { + text = defaultText; + } + return text; + } + + /** + * @generated + */ + @Override + public void setLabelText(String text) { + setLabelTextHelper(getFigure(), text); + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + @Override + public String getEditText() { + if (getParserElement() == null || getParser() == null) { + return ""; //$NON-NLS-1$ + } + return getParser().getEditString( + new EObjectAdapter(getParserElement()), + getParserOptions().intValue()); + } + + /** + * @generated + */ + protected boolean isEditable() { + return false; + } + + /** + * @generated + */ + @Override + public ICellEditorValidator getEditTextValidator() { + return new ICellEditorValidator() { + + @Override + public String isValid(final Object value) { + if (value instanceof String) { + final EObject element = getParserElement(); + final IParser parser = getParser(); + try { + IParserEditStatus valid = + (IParserEditStatus) getEditingDomain().runExclusive( + new RunnableWithResult.Impl() { + + @Override + public void run() { + setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); + } + }); + return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); + } catch (InterruptedException ie) { + ie.printStackTrace(); + } + } + + // shouldn't get here + return null; + } + }; + } + + /** + * @generated + */ + @Override + public IContentAssistProcessor getCompletionProcessor() { + if (getParserElement() == null || getParser() == null) { + return null; + } + return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); + } + + /** + * @generated + */ + @Override + public ParserOptions getParserOptions() { + return ParserOptions.NONE; + } + + /** + * @generated + */ + @Override + public IParser getParser() { + if (parser == null) { + parser = UMLParserProvider.getParser(UMLElementTypes.Dependency_4017, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.RoleBindingRoleNameEditPart.VISUAL_ID)); + } + return parser; + } + + /** + * @generated + */ + protected DirectEditManager getManager() { + if (manager == null) { + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + } + return manager; + } + + /** + * @generated + */ + protected void setManager(DirectEditManager manager) { + this.manager = manager; + } + + /** + * @generated + */ + protected void performDirectEdit() { + BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { + + @Override + public void run() { + getManager().show(); + } + }); + } + + /** + * @generated + */ + protected void performDirectEdit(Point eventLocation) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); + } + } + + /** + * @generated + */ + private void performDirectEdit(char initialCharacter) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(initialCharacter); + } else { + performDirectEdit(); + } + } + + /** + * @generated + */ + @Override + protected void performDirectEditRequest(Request request) { + + final Request theRequest = request; + + if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { + directEditionMode = getDirectEditionType(); + } + switch (directEditionMode) { + case IDirectEdition.NO_DIRECT_EDITION: + // no direct edition mode => does nothing + return; + case IDirectEdition.EXTENDED_DIRECT_EDITOR: + updateExtendedEditorConfiguration(); + if (configuration == null || configuration.getLanguage() == null) { + // Create default edit manager + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + performDefaultDirectEditorEdit(theRequest); + } else { + configuration.preEditAction(resolveSemanticElement()); + Dialog dialog = null; + if (configuration instanceof ICustomDirectEditorConfiguration) { + setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); + initializeDirectEditManager(theRequest); + return; + } else if (configuration instanceof IPopupEditorConfiguration) { + IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); + helper.showEditor(); + return; + } + else if (configuration instanceof IAdvancedEditorConfiguration) { + dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); + } else if (configuration instanceof IDirectEditorConfiguration) { + dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), + configuration); + } else { + return; + } + final Dialog finalDialog = dialog; + + if (Window.OK == dialog.open()) { + TransactionalEditingDomain domain = getEditingDomain(); + RecordingCommand command = new RecordingCommand(domain, "Edit Label") { + + @Override + protected void doExecute() { + configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); + + } + }; + domain.getCommandStack().execute(command); + } + } + break; + case IDirectEdition.DEFAULT_DIRECT_EDITOR: + initializeDirectEditManager(theRequest); + break; + default: + break; + } + } + + /** + * @generated + */ + protected void initializeDirectEditManager(final Request request) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + @Override + public void run() { + if (isActive() && isEditable()) { + if (request.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } + else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void refreshVisuals() { + super.refreshVisuals(); + refreshLabel(); + refreshFont(); + refreshFontColor(); + refreshUnderline(); + refreshStrikeThrough(); + } + + /** + * @generated + */ + protected void refreshLabel() { + EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); + if (maskLabelPolicy == null) { + maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); + } + if (maskLabelPolicy == null) { + setLabelTextHelper(getFigure(), getLabelText()); + setLabelIconHelper(getFigure(), getLabelIcon()); + } + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + protected void refreshUnderline() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); + } + if (resolveSemanticElement() instanceof Feature) { + if (((Feature) resolveSemanticElement()).isStatic()) { + ((WrappingLabel) getFigure()).setTextUnderline(true); + } + else { + ((WrappingLabel) getFigure()).setTextUnderline(false); + } + } + } + + /** + * @generated + */ + protected void refreshStrikeThrough() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); + } + } + + /** + * @generated + */ + @Override + protected void refreshFont() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null) { + FontData fontData = new FontData( + style.getFontName(), style.getFontHeight(), + (style.isBold() ? SWT.BOLD : SWT.NORMAL) | + (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); + setFont(fontData); + } + } + + /** + * @generated + */ + @Override + protected void setFontColor(Color color) { + getFigure().setForegroundColor(color); + } + + /** + * @generated + */ + @Override + protected void addSemanticListeners() { + if (getParser() instanceof ISemanticParser) { + EObject element = resolveSemanticElement(); + parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); + for (int i = 0; i < parserElements.size(); i++) { + addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ + } + } else { + super.addSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected void removeSemanticListeners() { + if (parserElements != null) { + for (int i = 0; i < parserElements.size(); i++) { + removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ + } + } else { + super.removeSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected AccessibleEditPart getAccessibleEditPart() { + if (accessibleEP == null) { + accessibleEP = new AccessibleGraphicalEditPart() { + + @Override + public void getName(AccessibleEvent e) { + e.result = getLabelTextHelper(getFigure()); + } + }; + } + return accessibleEP; + } + + /** + * @generated + */ + private View getFontStyleOwnerView() { + return getPrimaryView(); + } + + /** + * Returns the kind of associated editor for direct edition. + * + * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition + * @generated + */ + public int getDirectEditionType() { + // The label is read-only (defined in GMFGen model) + return IDirectEdition.NO_DIRECT_EDITION; + } + + /** + * Checks if an extended editor is present. + * + * @return true if an extended editor is present. + * @generated + */ + protected boolean checkExtendedEditor() { + if (resolveSemanticElement() != null) { + return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); + } + return false; + } + + /** + * Checks if a default direct edition is available + * + * @return true if a default direct edition is available + * @generated + */ + protected boolean checkDefaultEdition() { + return (getParser() != null); + } + + /** + * Initializes the extended editor configuration + * + * @generated + */ + protected void initExtendedEditorConfiguration() { + if (configuration == null) { + final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("")) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); + } else { + configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); + } + } + } + + /** + * Updates the preference configuration + * + * @generated + */ + protected void updateExtendedEditorConfiguration() { + String languagePreferred = Activator.getDefault().getPreferenceStore().getString( + IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() + .eClass().getInstanceClassName()); + } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { + configuration = null; + } + } + + /** + * Performs the direct edit usually used by GMF editors. + * + * @param theRequest + * the direct edit request that starts the direct edit system + * @generated + */ + protected void performDefaultDirectEditorEdit(final Request theRequest) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + + @Override + public void run() { + if (isActive() && isEditable()) { + if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) theRequest.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { + DirectEditRequest editRequest = (DirectEditRequest) theRequest; + performDirectEdit(editRequest.getLocation()); + } else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void handleNotificationEvent(Notification event) { + Object feature = event.getFeature(); + if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { + Integer c = (Integer) event.getNewValue(); + setFontColor(DiagramColorRegistry.getInstance().getColor(c)); + } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { + refreshUnderline(); + } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { + refreshStrikeThrough(); + } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { + refreshFont(); + } else { + if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { + refreshLabel(); + } + if (getParser() instanceof ISemanticParser) { + ISemanticParser modelParser = + (ISemanticParser) getParser(); + if (modelParser.areSemanticElementsAffected(null, event)) { + removeSemanticListeners(); + if (resolveSemanticElement() != null) { + addSemanticListeners(); + } + refreshLabel(); + } + } + } + + super.handleNotificationEvent(event); + } + + /** + * @generated + */ + @Override + protected IFigure createFigure() { + // Parent should assign one using setLabel() method + return null; + } +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/SignalEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/SignalEditPart.java index 1411fb309a8..f2b050d3031 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/SignalEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/SignalEditPart.java @@ -11,28 +11,40 @@ */ package org.eclipse.papyrus.uml.diagram.composite.edit.parts; +import java.util.Collections; +import java.util.List; + import org.eclipse.draw2d.IFigure; import org.eclipse.emf.common.notify.Notification; import org.eclipse.gef.EditPart; import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.GraphicalEditPart; 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.handles.MoveHandle; import org.eclipse.gef.requests.CreateRequest; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.BorderItemSelectionEditPolicy; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles; +import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; -import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure; import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure; +import org.eclipse.gmf.runtime.notation.Edge; +import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.GetChildLayoutEditPolicy; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.IPapyrusNodeFigure; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.RoundedRectangleNodePlateFigure; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.SelectableBorderedNodeFigure; -import org.eclipse.papyrus.uml.diagram.common.editparts.NamedElementEditPart; +import org.eclipse.papyrus.uml.diagram.common.editparts.RoundedCompartmentEditPart; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeNodeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.QualifiedNameDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.figure.node.SignalFigure; +import org.eclipse.papyrus.uml.diagram.common.locator.RoundedRectangleLabelPositionLocator; import org.eclipse.papyrus.uml.diagram.composite.edit.policies.SignalItemSemanticEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; import org.eclipse.swt.graphics.Color; @@ -40,7 +52,7 @@ import org.eclipse.swt.graphics.Color; /** * @generated */ -public class SignalEditPart extends NamedElementEditPart { +public class SignalEditPart extends RoundedCompartmentEditPart { /** * @generated @@ -74,6 +86,7 @@ public class SignalEditPart extends NamedElementEditPart { installEditPolicy(EditPolicy.LAYOUT_ROLE, createLayoutEditPolicy()); installEditPolicy(QualifiedNameDisplayEditPolicy.QUALIFIED_NAME_POLICY, new QualifiedNameDisplayEditPolicy()); installEditPolicy(AppliedStereotypeLabelDisplayEditPolicy.STEREOTYPE_LABEL_POLICY, new AppliedStereotypeNodeLabelDisplayEditPolicy()); + installEditPolicy(EditPolicy.LAYOUT_ROLE, new GetChildLayoutEditPolicy()); // XXX need an SCR to runtime to have another abstract superclass that would let children add reasonable editpolicies // removeEditPolicy(org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles.CONNECTION_HANDLES_ROLE); } @@ -86,6 +99,20 @@ public class SignalEditPart extends NamedElementEditPart { @Override protected EditPolicy createChildEditPolicy(EditPart child) { + View childView = (View) child.getModel(); + switch (UMLVisualIDRegistry.getVisualID(childView)) { + case SignalFloatingLabelEditPart.VISUAL_ID: + return new BorderItemSelectionEditPolicy() { + + @Override + protected List createSelectionHandles() { + MoveHandle mh = new MoveHandle((GraphicalEditPart) getHost()); + mh.setBorder(null); + return Collections.singletonList(mh); + } + } + ; + } EditPolicy result = child.getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); if (result == null) { result = new NonResizableEditPolicy(); @@ -113,6 +140,19 @@ public class SignalEditPart extends NamedElementEditPart { **/ @Override protected void handleNotificationEvent(Notification event) { + /* + * when a node have external node labels, the methods refreshChildren() remove the EditPart corresponding to the Label from the EditPart + * Registry. After that, we can't reset the visibility to true (using the Show/Hide Label Action)! + */ + if (NotationPackage.eINSTANCE.getView_Visible().equals(event.getFeature())) { + Object notifier = event.getNotifier(); + List modelChildren = ((View) getModel()).getChildren(); + if (!(notifier instanceof Edge)) { + if (modelChildren.contains(event.getNotifier())) { + return; + } + } + } super.handleNotificationEvent(event); } @@ -185,15 +225,32 @@ public class SignalEditPart extends NamedElementEditPart { */ @Override protected IFigure getContentPaneFor(IGraphicalEditPart editPart) { + if (editPart instanceof IBorderItemEditPart) { + return getBorderedFigure().getBorderItemContainer(); + } return getContentPane(); } + /** + * @generated + */ + @Override + protected void addBorderItem(IFigure borderItemContainer, IBorderItemEditPart borderItemEditPart) { + if (borderItemEditPart instanceof SignalFloatingLabelEditPart) { + IBorderItemLocator locator = new RoundedRectangleLabelPositionLocator(getMainFigure()); + borderItemContainer.add(borderItemEditPart.getFigure(), locator); + } else + { + super.addBorderItem(borderItemContainer, borderItemEditPart); + } + } + /** * @generated */ @Override protected NodeFigure createNodePlate() { - DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(40, 40); + RoundedRectangleNodePlateFigure result = new RoundedRectangleNodePlateFigure(40, 40); return result; } @@ -206,7 +263,7 @@ public class SignalEditPart extends NamedElementEditPart { * @generated */ @Override - protected NodeFigure createNodeFigure() { + protected NodeFigure createMainFigure() { return new SelectableBorderedNodeFigure(createMainFigureWithSVG()); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/SignalEditPartCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/SignalEditPartCN.java index c105c82a805..03056c39a41 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/SignalEditPartCN.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/SignalEditPartCN.java @@ -11,28 +11,40 @@ */ package org.eclipse.papyrus.uml.diagram.composite.edit.parts; +import java.util.Collections; +import java.util.List; + import org.eclipse.draw2d.IFigure; import org.eclipse.emf.common.notify.Notification; import org.eclipse.gef.EditPart; import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.GraphicalEditPart; 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.handles.MoveHandle; import org.eclipse.gef.requests.CreateRequest; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.BorderItemSelectionEditPolicy; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles; +import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; -import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure; import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure; +import org.eclipse.gmf.runtime.notation.Edge; +import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.GetChildLayoutEditPolicy; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.IPapyrusNodeFigure; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.RoundedRectangleNodePlateFigure; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.SelectableBorderedNodeFigure; -import org.eclipse.papyrus.uml.diagram.common.editparts.NamedElementEditPart; +import org.eclipse.papyrus.uml.diagram.common.editparts.RoundedCompartmentEditPart; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeNodeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.QualifiedNameDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.figure.node.SignalFigure; +import org.eclipse.papyrus.uml.diagram.common.locator.RoundedRectangleLabelPositionLocator; import org.eclipse.papyrus.uml.diagram.composite.edit.policies.SignalItemSemanticEditPolicyCN; import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; import org.eclipse.swt.graphics.Color; @@ -40,7 +52,7 @@ import org.eclipse.swt.graphics.Color; /** * @generated */ -public class SignalEditPartCN extends NamedElementEditPart { +public class SignalEditPartCN extends RoundedCompartmentEditPart { /** * @generated @@ -74,6 +86,7 @@ public class SignalEditPartCN extends NamedElementEditPart { installEditPolicy(EditPolicy.LAYOUT_ROLE, createLayoutEditPolicy()); installEditPolicy(QualifiedNameDisplayEditPolicy.QUALIFIED_NAME_POLICY, new QualifiedNameDisplayEditPolicy()); installEditPolicy(AppliedStereotypeLabelDisplayEditPolicy.STEREOTYPE_LABEL_POLICY, new AppliedStereotypeNodeLabelDisplayEditPolicy()); + installEditPolicy(EditPolicy.LAYOUT_ROLE, new GetChildLayoutEditPolicy()); // XXX need an SCR to runtime to have another abstract superclass that would let children add reasonable editpolicies // removeEditPolicy(org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles.CONNECTION_HANDLES_ROLE); } @@ -86,6 +99,20 @@ public class SignalEditPartCN extends NamedElementEditPart { @Override protected EditPolicy createChildEditPolicy(EditPart child) { + View childView = (View) child.getModel(); + switch (UMLVisualIDRegistry.getVisualID(childView)) { + case SignalFloatingLabelEditPartCN.VISUAL_ID: + return new BorderItemSelectionEditPolicy() { + + @Override + protected List createSelectionHandles() { + MoveHandle mh = new MoveHandle((GraphicalEditPart) getHost()); + mh.setBorder(null); + return Collections.singletonList(mh); + } + } + ; + } EditPolicy result = child.getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); if (result == null) { result = new NonResizableEditPolicy(); @@ -113,6 +140,19 @@ public class SignalEditPartCN extends NamedElementEditPart { **/ @Override protected void handleNotificationEvent(Notification event) { + /* + * when a node have external node labels, the methods refreshChildren() remove the EditPart corresponding to the Label from the EditPart + * Registry. After that, we can't reset the visibility to true (using the Show/Hide Label Action)! + */ + if (NotationPackage.eINSTANCE.getView_Visible().equals(event.getFeature())) { + Object notifier = event.getNotifier(); + List modelChildren = ((View) getModel()).getChildren(); + if (!(notifier instanceof Edge)) { + if (modelChildren.contains(event.getNotifier())) { + return; + } + } + } super.handleNotificationEvent(event); } @@ -185,15 +225,32 @@ public class SignalEditPartCN extends NamedElementEditPart { */ @Override protected IFigure getContentPaneFor(IGraphicalEditPart editPart) { + if (editPart instanceof IBorderItemEditPart) { + return getBorderedFigure().getBorderItemContainer(); + } return getContentPane(); } + /** + * @generated + */ + @Override + protected void addBorderItem(IFigure borderItemContainer, IBorderItemEditPart borderItemEditPart) { + if (borderItemEditPart instanceof SignalFloatingLabelEditPartCN) { + IBorderItemLocator locator = new RoundedRectangleLabelPositionLocator(getMainFigure()); + borderItemContainer.add(borderItemEditPart.getFigure(), locator); + } else + { + super.addBorderItem(borderItemContainer, borderItemEditPart); + } + } + /** * @generated */ @Override protected NodeFigure createNodePlate() { - DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(40, 40); + RoundedRectangleNodePlateFigure result = new RoundedRectangleNodePlateFigure(40, 40); return result; } @@ -206,7 +263,7 @@ public class SignalEditPartCN extends NamedElementEditPart { * @generated */ @Override - protected NodeFigure createNodeFigure() { + protected NodeFigure createMainFigure() { return new SelectableBorderedNodeFigure(createMainFigureWithSVG()); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/SignalEventEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/SignalEventEditPart.java index 812808355c2..dc6e45ec246 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/SignalEventEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/SignalEventEditPart.java @@ -11,27 +11,40 @@ */ package org.eclipse.papyrus.uml.diagram.composite.edit.parts; +import java.util.Collections; +import java.util.List; + import org.eclipse.draw2d.IFigure; +import org.eclipse.emf.common.notify.Notification; import org.eclipse.gef.EditPart; import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.GraphicalEditPart; 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.handles.MoveHandle; import org.eclipse.gef.requests.CreateRequest; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.BorderItemSelectionEditPolicy; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles; +import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; -import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure; import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure; +import org.eclipse.gmf.runtime.notation.Edge; +import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.gmf.runtime.notation.View; -import org.eclipse.papyrus.infra.gmfdiag.common.editpart.NodeEditPart; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.GetChildLayoutEditPolicy; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.IPapyrusNodeFigure; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.RoundedRectangleNodePlateFigure; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.SelectableBorderedNodeFigure; +import org.eclipse.papyrus.uml.diagram.common.editparts.RoundedCompartmentEditPart; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeNodeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.QualifiedNameDisplayEditPolicy; -import org.eclipse.papyrus.uml.diagram.common.figure.node.NodeNamedElementFigure; +import org.eclipse.papyrus.uml.diagram.common.figure.node.RoundedCompartmentFigure; +import org.eclipse.papyrus.uml.diagram.common.locator.RoundedRectangleLabelPositionLocator; import org.eclipse.papyrus.uml.diagram.composite.edit.policies.SignalEventItemSemanticEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; import org.eclipse.swt.graphics.Color; @@ -39,7 +52,7 @@ import org.eclipse.swt.graphics.Color; /** * @generated */ -public class SignalEventEditPart extends NodeEditPart { +public class SignalEventEditPart extends RoundedCompartmentEditPart { /** * @generated @@ -73,6 +86,7 @@ public class SignalEventEditPart extends NodeEditPart { installEditPolicy(EditPolicy.LAYOUT_ROLE, createLayoutEditPolicy()); installEditPolicy(QualifiedNameDisplayEditPolicy.QUALIFIED_NAME_POLICY, new QualifiedNameDisplayEditPolicy()); installEditPolicy(AppliedStereotypeLabelDisplayEditPolicy.STEREOTYPE_LABEL_POLICY, new AppliedStereotypeNodeLabelDisplayEditPolicy()); + installEditPolicy(EditPolicy.LAYOUT_ROLE, new GetChildLayoutEditPolicy()); // XXX need an SCR to runtime to have another abstract superclass that would let children add reasonable editpolicies // removeEditPolicy(org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles.CONNECTION_HANDLES_ROLE); } @@ -85,6 +99,20 @@ public class SignalEventEditPart extends NodeEditPart { @Override protected EditPolicy createChildEditPolicy(EditPart child) { + View childView = (View) child.getModel(); + switch (UMLVisualIDRegistry.getVisualID(childView)) { + case SignalEventFloatingLabelEditPart.VISUAL_ID: + return new BorderItemSelectionEditPolicy() { + + @Override + protected List createSelectionHandles() { + MoveHandle mh = new MoveHandle((GraphicalEditPart) getHost()); + mh.setBorder(null); + return Collections.singletonList(mh); + } + } + ; + } EditPolicy result = child.getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); if (result == null) { result = new NonResizableEditPolicy(); @@ -105,12 +133,36 @@ public class SignalEventEditPart extends NodeEditPart { return lep; } + /** + * Papyrus codeGen + * + * @generated + **/ + @Override + protected void handleNotificationEvent(Notification event) { + /* + * when a node have external node labels, the methods refreshChildren() remove the EditPart corresponding to the Label from the EditPart + * Registry. After that, we can't reset the visibility to true (using the Show/Hide Label Action)! + */ + if (NotationPackage.eINSTANCE.getView_Visible().equals(event.getFeature())) { + Object notifier = event.getNotifier(); + List modelChildren = ((View) getModel()).getChildren(); + if (!(notifier instanceof Edge)) { + if (modelChildren.contains(event.getNotifier())) { + return; + } + } + } + super.handleNotificationEvent(event); + + } + /** * @generated */ @Override protected IFigure createNodeShape() { - return primaryShape = new NodeNamedElementFigure(); + return primaryShape = new RoundedCompartmentFigure(); } /** @@ -119,8 +171,8 @@ public class SignalEventEditPart extends NodeEditPart { * @generated */ @Override - public NodeNamedElementFigure getPrimaryShape() { - return (NodeNamedElementFigure) primaryShape; + public RoundedCompartmentFigure getPrimaryShape() { + return (RoundedCompartmentFigure) primaryShape; } /** @@ -173,15 +225,32 @@ public class SignalEventEditPart extends NodeEditPart { */ @Override protected IFigure getContentPaneFor(IGraphicalEditPart editPart) { + if (editPart instanceof IBorderItemEditPart) { + return getBorderedFigure().getBorderItemContainer(); + } return getContentPane(); } + /** + * @generated + */ + @Override + protected void addBorderItem(IFigure borderItemContainer, IBorderItemEditPart borderItemEditPart) { + if (borderItemEditPart instanceof SignalEventFloatingLabelEditPart) { + IBorderItemLocator locator = new RoundedRectangleLabelPositionLocator(getMainFigure()); + borderItemContainer.add(borderItemEditPart.getFigure(), locator); + } else + { + super.addBorderItem(borderItemContainer, borderItemEditPart); + } + } + /** * @generated */ @Override protected NodeFigure createNodePlate() { - DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(40, 40); + RoundedRectangleNodePlateFigure result = new RoundedRectangleNodePlateFigure(40, 40); return result; } @@ -194,7 +263,7 @@ public class SignalEventEditPart extends NodeEditPart { * @generated */ @Override - protected NodeFigure createNodeFigure() { + protected NodeFigure createMainFigure() { return new SelectableBorderedNodeFigure(createMainFigureWithSVG()); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/SignalEventFloatingLabelEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/SignalEventFloatingLabelEditPart.java new file mode 100644 index 00000000000..a862b3c2104 --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/SignalEventFloatingLabelEditPart.java @@ -0,0 +1,860 @@ +/** + * 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.uml.diagram.composite.edit.parts; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.Label; +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.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.RunnableWithResult; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gef.AccessibleEditPart; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.Request; +import org.eclipse.gef.requests.DirectEditRequest; +import org.eclipse.gef.tools.DirectEditManager; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; +import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; +import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; +import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; +import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; +import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; +import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; +import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; +import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; +import org.eclipse.gmf.runtime.notation.FontStyle; +import org.eclipse.gmf.runtime.notation.NotationPackage; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.text.contentassist.IContentAssistProcessor; +import org.eclipse.jface.viewers.ICellEditorValidator; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.extensionpoints.editors.Activator; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; +import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; +import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.ExternalLabelPrimaryDragRoleEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.PapyrusWrappingLabel; +import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; +import org.eclipse.papyrus.uml.diagram.common.editparts.FloatingLabelEditPart; +import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; +import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; +import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; +import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.accessibility.AccessibleEvent; +import org.eclipse.swt.custom.BusyIndicator; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; +import org.eclipse.uml2.uml.Feature; + +/** + * @generated + */ +public class SignalEventFloatingLabelEditPart extends FloatingLabelEditPart + implements ITextAwareEditPart, IBorderItemEditPart +{ + + /** + * @generated + */ + public static final int VISUAL_ID = 6101; + + /** + * @generated + */ + private DirectEditManager manager; + + /** + * @generated + */ + private IParser parser; + + /** + * @generated + */ + private List parserElements; + + /** + * @generated + */ + private String defaultText; + + /** + * direct edition mode (default, undefined, registered editor, etc.) + * + * @generated + */ + protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; + + /** + * configuration from a registered edit dialog + * + * @generated + */ + protected IDirectEditorConfiguration configuration; + + + /** + * @generated + */ + static { + registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.SignalEventFloatingLabelEditPart.VISUAL_ID), new Point(0, 0)); + } + + /** + * @generated + */ + public SignalEventFloatingLabelEditPart(View view) { + super(view); + } + + /** + * @generated + */ + @Override + protected void createDefaultEditPolicies() { + super.createDefaultEditPolicies(); + installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); + installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ExternalLabelPrimaryDragRoleEditPolicy()); + } + + /** + * @generated + */ + @Override + public IBorderItemLocator getBorderItemLocator() { + IFigure parentFigure = getFigure().getParent(); + if (parentFigure != null && parentFigure.getLayoutManager() != null) { + Object constraint = parentFigure.getLayoutManager().getConstraint(getFigure()); + return (IBorderItemLocator) constraint; + } + return null; + } + + /** + * @generated + */ + @Override + public void refreshBounds() { + int x = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_X())).intValue(); + int y = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_Y())).intValue(); + int width = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Width())).intValue(); + int height = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Height())).intValue(); + getBorderItemLocator().setConstraint(new Rectangle(x, y, width, height)); + } + + + /** + * @generated + */ + protected String getLabelTextHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getText(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getText(); + } else { + return ((Label) figure).getText(); + } + } + + /** + * @generated + */ + protected void setLabelTextHelper(IFigure figure, String text) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setText(text); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setText(text); + } else { + ((Label) figure).setText(text); + } + } + + /** + * @generated + */ + protected Image getLabelIconHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getIcon(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getIcon(); + } else { + return ((Label) figure).getIcon(); + } + } + + /** + * @generated + */ + protected void setLabelIconHelper(IFigure figure, Image icon) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setIcon(icon); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setIcon(icon); + } else { + ((Label) figure).setIcon(icon); + } + } + + /** + * @generated + */ + public void setLabel(IFigure + figure) { + unregisterVisuals(); + setFigure(figure); + defaultText = getLabelTextHelper(figure); + registerVisuals(); + refreshVisuals(); + } + + /** + * @generated + */ + @Override + protected List getModelChildren() { + return Collections.EMPTY_LIST; + } + + /** + * @generated + */ + @Override + public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { + return null; + } + + /** + * @generated + */ + public void setParser(IParser parser) { + this.parser = parser; + } + + /** + * @generated + */ + protected EObject getParserElement() { + return resolveSemanticElement(); + } + + /** + * @generated + */ + protected Image getLabelIcon() { + return null; + } + + /** + * @generated + */ + protected String getLabelText() { + String text = null; + EObject parserElement = getParserElement(); + if (parserElement != null && getParser() != null) { + text = getParser().getPrintString( + new EObjectAdapter(parserElement), + getParserOptions().intValue()); + } + if (text == null || text.length() == 0) { + text = defaultText; + } + return text; + } + + /** + * @generated + */ + @Override + public void setLabelText(String text) { + setLabelTextHelper(getFigure(), text); + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + @Override + public String getEditText() { + if (getParserElement() == null || getParser() == null) { + return ""; //$NON-NLS-1$ + } + return getParser().getEditString( + new EObjectAdapter(getParserElement()), + getParserOptions().intValue()); + } + + /** + * @generated + */ + protected boolean isEditable() { + return getParser() != null; + } + + /** + * @generated + */ + @Override + public ICellEditorValidator getEditTextValidator() { + return new ICellEditorValidator() { + + @Override + public String isValid(final Object value) { + if (value instanceof String) { + final EObject element = getParserElement(); + final IParser parser = getParser(); + try { + IParserEditStatus valid = + (IParserEditStatus) getEditingDomain().runExclusive( + new RunnableWithResult.Impl() { + + @Override + public void run() { + setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); + } + }); + return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); + } catch (InterruptedException ie) { + ie.printStackTrace(); + } + } + + // shouldn't get here + return null; + } + }; + } + + /** + * @generated + */ + @Override + public IContentAssistProcessor getCompletionProcessor() { + if (getParserElement() == null || getParser() == null) { + return null; + } + return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); + } + + /** + * @generated + */ + @Override + public ParserOptions getParserOptions() { + return ParserOptions.NONE; + } + + /** + * @generated + */ + @Override + public IParser getParser() { + if (parser == null) { + parser = UMLParserProvider.getParser(UMLElementTypes.SignalEvent_2083, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.SignalEventFloatingLabelEditPart.VISUAL_ID)); + } + return parser; + } + + /** + * @generated + */ + protected DirectEditManager getManager() { + if (manager == null) { + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + } + return manager; + } + + /** + * @generated + */ + protected void setManager(DirectEditManager manager) { + this.manager = manager; + } + + /** + * @generated + */ + protected void performDirectEdit() { + BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { + + @Override + public void run() { + getManager().show(); + } + }); + } + + /** + * @generated + */ + protected void performDirectEdit(Point eventLocation) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); + } + } + + /** + * @generated + */ + private void performDirectEdit(char initialCharacter) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(initialCharacter); + } else { + performDirectEdit(); + } + } + + /** + * @generated + */ + @Override + protected void performDirectEditRequest(Request request) { + + final Request theRequest = request; + + if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { + directEditionMode = getDirectEditionType(); + } + switch (directEditionMode) { + case IDirectEdition.NO_DIRECT_EDITION: + // no direct edition mode => does nothing + return; + case IDirectEdition.EXTENDED_DIRECT_EDITOR: + updateExtendedEditorConfiguration(); + if (configuration == null || configuration.getLanguage() == null) { + // Create default edit manager + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + performDefaultDirectEditorEdit(theRequest); + } else { + configuration.preEditAction(resolveSemanticElement()); + Dialog dialog = null; + if (configuration instanceof ICustomDirectEditorConfiguration) { + setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); + initializeDirectEditManager(theRequest); + return; + } else if (configuration instanceof IPopupEditorConfiguration) { + IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); + helper.showEditor(); + return; + } + else if (configuration instanceof IAdvancedEditorConfiguration) { + dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); + } else if (configuration instanceof IDirectEditorConfiguration) { + dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), + configuration); + } else { + return; + } + final Dialog finalDialog = dialog; + + if (Window.OK == dialog.open()) { + TransactionalEditingDomain domain = getEditingDomain(); + RecordingCommand command = new RecordingCommand(domain, "Edit Label") { + + @Override + protected void doExecute() { + configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); + + } + }; + domain.getCommandStack().execute(command); + } + } + break; + case IDirectEdition.DEFAULT_DIRECT_EDITOR: + initializeDirectEditManager(theRequest); + break; + default: + break; + } + } + + /** + * @generated + */ + protected void initializeDirectEditManager(final Request request) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + @Override + public void run() { + if (isActive() && isEditable()) { + if (request.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } + else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void refreshVisuals() { + super.refreshVisuals(); + refreshLabel(); + refreshFont(); + refreshFontColor(); + refreshUnderline(); + refreshStrikeThrough(); + } + + /** + * @generated + */ + protected void refreshLabel() { + EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); + if (maskLabelPolicy == null) { + maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); + } + if (maskLabelPolicy == null) { + View view = (View) getModel(); + if (view.isVisible()) { + setLabelTextHelper(getFigure(), getLabelText()); + setLabelIconHelper(getFigure(), getLabelIcon()); + } + else { + setLabelTextHelper(getFigure(), ""); //$NON-NLS-1$ + setLabelIconHelper(getFigure(), null); + } + } + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + protected void refreshUnderline() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); + } + if (resolveSemanticElement() instanceof Feature) { + if (((Feature) resolveSemanticElement()).isStatic()) { + ((WrappingLabel) getFigure()).setTextUnderline(true); + } + else { + ((WrappingLabel) getFigure()).setTextUnderline(false); + } + } + } + + /** + * @generated + */ + protected void refreshStrikeThrough() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); + } + } + + /** + * @generated + */ + @Override + protected void refreshFont() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null) { + FontData fontData = new FontData( + style.getFontName(), style.getFontHeight(), + (style.isBold() ? SWT.BOLD : SWT.NORMAL) | + (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); + setFont(fontData); + } + } + + /** + * @generated + */ + @Override + protected void setFontColor(Color color) { + getFigure().setForegroundColor(color); + } + + /** + * @generated + */ + @Override + protected void addSemanticListeners() { + if (getParser() instanceof ISemanticParser) { + EObject element = resolveSemanticElement(); + parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); + for (int i = 0; i < parserElements.size(); i++) { + addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ + } + } else { + super.addSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected void removeSemanticListeners() { + if (parserElements != null) { + for (int i = 0; i < parserElements.size(); i++) { + removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ + } + } else { + super.removeSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected AccessibleEditPart getAccessibleEditPart() { + if (accessibleEP == null) { + accessibleEP = new AccessibleGraphicalEditPart() { + + @Override + public void getName(AccessibleEvent e) { + e.result = getLabelTextHelper(getFigure()); + } + }; + } + return accessibleEP; + } + + /** + * @generated + */ + private View getFontStyleOwnerView() { + return getPrimaryView(); + } + + /** + * Returns the kind of associated editor for direct edition. + * + * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition + * @generated + */ + public int getDirectEditionType() { + if (checkExtendedEditor()) { + initExtendedEditorConfiguration(); + return IDirectEdition.EXTENDED_DIRECT_EDITOR; + } + if (checkDefaultEdition()) { + return IDirectEdition.DEFAULT_DIRECT_EDITOR; + } + + // not a named element. no specific editor => do nothing + return IDirectEdition.NO_DIRECT_EDITION; + } + + /** + * Checks if an extended editor is present. + * + * @return true if an extended editor is present. + * @generated + */ + protected boolean checkExtendedEditor() { + if (resolveSemanticElement() != null) { + return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); + } + return false; + } + + /** + * Checks if a default direct edition is available + * + * @return true if a default direct edition is available + * @generated + */ + protected boolean checkDefaultEdition() { + return (getParser() != null); + } + + /** + * Initializes the extended editor configuration + * + * @generated + */ + protected void initExtendedEditorConfiguration() { + if (configuration == null) { + final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("")) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); + } else { + configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); + } + } + } + + /** + * Updates the preference configuration + * + * @generated + */ + protected void updateExtendedEditorConfiguration() { + String languagePreferred = Activator.getDefault().getPreferenceStore().getString( + IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() + .eClass().getInstanceClassName()); + } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { + configuration = null; + } + } + + /** + * Performs the direct edit usually used by GMF editors. + * + * @param theRequest + * the direct edit request that starts the direct edit system + * @generated + */ + protected void performDefaultDirectEditorEdit(final Request theRequest) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + + @Override + public void run() { + if (isActive() && isEditable()) { + if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) theRequest.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { + DirectEditRequest editRequest = (DirectEditRequest) theRequest; + performDirectEdit(editRequest.getLocation()); + } else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + + /** + * @generated + */ + @Override + protected void handleNotificationEvent(Notification event) { + Object feature = event.getFeature(); + if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { + Integer c = (Integer) event.getNewValue(); + setFontColor(DiagramColorRegistry.getInstance().getColor(c)); + } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { + refreshUnderline(); + } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { + refreshStrikeThrough(); + } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { + refreshFont(); + } else { + if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { + refreshLabel(); + } + if (getParser() instanceof ISemanticParser) { + ISemanticParser modelParser = + (ISemanticParser) getParser(); + if (modelParser.areSemanticElementsAffected(null, event)) { + removeSemanticListeners(); + if (resolveSemanticElement() != null) { + addSemanticListeners(); + } + refreshLabel(); + } + } + } + super.handleNotificationEvent(event); + } + + /** + * @generated + */ + @Override + protected IFigure createFigure() { + IFigure label = createFigurePrim(); + defaultText = getLabelTextHelper(label); + return label; + } + + /** + * @generated + */ + protected IFigure createFigurePrim() { + return new PapyrusWrappingLabel(); + } + +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/SignalEventNameEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/SignalEventNameEditPart.java index 67f54a5c000..9d2d63830f9 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/SignalEventNameEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/SignalEventNameEditPart.java @@ -864,7 +864,7 @@ public class SignalEventNameEditPart extends PapyrusCompartmentEditPart implemen * @generated */ protected void addOwnerElementListeners() { - addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); + addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/SignalFloatingLabelEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/SignalFloatingLabelEditPart.java new file mode 100644 index 00000000000..4d6c11cc5c2 --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/SignalFloatingLabelEditPart.java @@ -0,0 +1,860 @@ +/** + * 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.uml.diagram.composite.edit.parts; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.Label; +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.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.RunnableWithResult; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gef.AccessibleEditPart; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.Request; +import org.eclipse.gef.requests.DirectEditRequest; +import org.eclipse.gef.tools.DirectEditManager; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; +import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; +import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; +import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; +import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; +import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; +import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; +import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; +import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; +import org.eclipse.gmf.runtime.notation.FontStyle; +import org.eclipse.gmf.runtime.notation.NotationPackage; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.text.contentassist.IContentAssistProcessor; +import org.eclipse.jface.viewers.ICellEditorValidator; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.extensionpoints.editors.Activator; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; +import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; +import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.ExternalLabelPrimaryDragRoleEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.PapyrusWrappingLabel; +import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; +import org.eclipse.papyrus.uml.diagram.common.editparts.FloatingLabelEditPart; +import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; +import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; +import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; +import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.accessibility.AccessibleEvent; +import org.eclipse.swt.custom.BusyIndicator; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; +import org.eclipse.uml2.uml.Feature; + +/** + * @generated + */ +public class SignalFloatingLabelEditPart extends FloatingLabelEditPart + implements ITextAwareEditPart, IBorderItemEditPart +{ + + /** + * @generated + */ + public static final int VISUAL_ID = 6099; + + /** + * @generated + */ + private DirectEditManager manager; + + /** + * @generated + */ + private IParser parser; + + /** + * @generated + */ + private List parserElements; + + /** + * @generated + */ + private String defaultText; + + /** + * direct edition mode (default, undefined, registered editor, etc.) + * + * @generated + */ + protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; + + /** + * configuration from a registered edit dialog + * + * @generated + */ + protected IDirectEditorConfiguration configuration; + + + /** + * @generated + */ + static { + registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.SignalFloatingLabelEditPart.VISUAL_ID), new Point(0, 0)); + } + + /** + * @generated + */ + public SignalFloatingLabelEditPart(View view) { + super(view); + } + + /** + * @generated + */ + @Override + protected void createDefaultEditPolicies() { + super.createDefaultEditPolicies(); + installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); + installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ExternalLabelPrimaryDragRoleEditPolicy()); + } + + /** + * @generated + */ + @Override + public IBorderItemLocator getBorderItemLocator() { + IFigure parentFigure = getFigure().getParent(); + if (parentFigure != null && parentFigure.getLayoutManager() != null) { + Object constraint = parentFigure.getLayoutManager().getConstraint(getFigure()); + return (IBorderItemLocator) constraint; + } + return null; + } + + /** + * @generated + */ + @Override + public void refreshBounds() { + int x = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_X())).intValue(); + int y = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_Y())).intValue(); + int width = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Width())).intValue(); + int height = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Height())).intValue(); + getBorderItemLocator().setConstraint(new Rectangle(x, y, width, height)); + } + + + /** + * @generated + */ + protected String getLabelTextHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getText(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getText(); + } else { + return ((Label) figure).getText(); + } + } + + /** + * @generated + */ + protected void setLabelTextHelper(IFigure figure, String text) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setText(text); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setText(text); + } else { + ((Label) figure).setText(text); + } + } + + /** + * @generated + */ + protected Image getLabelIconHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getIcon(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getIcon(); + } else { + return ((Label) figure).getIcon(); + } + } + + /** + * @generated + */ + protected void setLabelIconHelper(IFigure figure, Image icon) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setIcon(icon); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setIcon(icon); + } else { + ((Label) figure).setIcon(icon); + } + } + + /** + * @generated + */ + public void setLabel(IFigure + figure) { + unregisterVisuals(); + setFigure(figure); + defaultText = getLabelTextHelper(figure); + registerVisuals(); + refreshVisuals(); + } + + /** + * @generated + */ + @Override + protected List getModelChildren() { + return Collections.EMPTY_LIST; + } + + /** + * @generated + */ + @Override + public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { + return null; + } + + /** + * @generated + */ + public void setParser(IParser parser) { + this.parser = parser; + } + + /** + * @generated + */ + protected EObject getParserElement() { + return resolveSemanticElement(); + } + + /** + * @generated + */ + protected Image getLabelIcon() { + return null; + } + + /** + * @generated + */ + protected String getLabelText() { + String text = null; + EObject parserElement = getParserElement(); + if (parserElement != null && getParser() != null) { + text = getParser().getPrintString( + new EObjectAdapter(parserElement), + getParserOptions().intValue()); + } + if (text == null || text.length() == 0) { + text = defaultText; + } + return text; + } + + /** + * @generated + */ + @Override + public void setLabelText(String text) { + setLabelTextHelper(getFigure(), text); + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + @Override + public String getEditText() { + if (getParserElement() == null || getParser() == null) { + return ""; //$NON-NLS-1$ + } + return getParser().getEditString( + new EObjectAdapter(getParserElement()), + getParserOptions().intValue()); + } + + /** + * @generated + */ + protected boolean isEditable() { + return getParser() != null; + } + + /** + * @generated + */ + @Override + public ICellEditorValidator getEditTextValidator() { + return new ICellEditorValidator() { + + @Override + public String isValid(final Object value) { + if (value instanceof String) { + final EObject element = getParserElement(); + final IParser parser = getParser(); + try { + IParserEditStatus valid = + (IParserEditStatus) getEditingDomain().runExclusive( + new RunnableWithResult.Impl() { + + @Override + public void run() { + setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); + } + }); + return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); + } catch (InterruptedException ie) { + ie.printStackTrace(); + } + } + + // shouldn't get here + return null; + } + }; + } + + /** + * @generated + */ + @Override + public IContentAssistProcessor getCompletionProcessor() { + if (getParserElement() == null || getParser() == null) { + return null; + } + return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); + } + + /** + * @generated + */ + @Override + public ParserOptions getParserOptions() { + return ParserOptions.NONE; + } + + /** + * @generated + */ + @Override + public IParser getParser() { + if (parser == null) { + parser = UMLParserProvider.getParser(UMLElementTypes.Signal_2081, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.SignalFloatingLabelEditPart.VISUAL_ID)); + } + return parser; + } + + /** + * @generated + */ + protected DirectEditManager getManager() { + if (manager == null) { + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + } + return manager; + } + + /** + * @generated + */ + protected void setManager(DirectEditManager manager) { + this.manager = manager; + } + + /** + * @generated + */ + protected void performDirectEdit() { + BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { + + @Override + public void run() { + getManager().show(); + } + }); + } + + /** + * @generated + */ + protected void performDirectEdit(Point eventLocation) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); + } + } + + /** + * @generated + */ + private void performDirectEdit(char initialCharacter) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(initialCharacter); + } else { + performDirectEdit(); + } + } + + /** + * @generated + */ + @Override + protected void performDirectEditRequest(Request request) { + + final Request theRequest = request; + + if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { + directEditionMode = getDirectEditionType(); + } + switch (directEditionMode) { + case IDirectEdition.NO_DIRECT_EDITION: + // no direct edition mode => does nothing + return; + case IDirectEdition.EXTENDED_DIRECT_EDITOR: + updateExtendedEditorConfiguration(); + if (configuration == null || configuration.getLanguage() == null) { + // Create default edit manager + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + performDefaultDirectEditorEdit(theRequest); + } else { + configuration.preEditAction(resolveSemanticElement()); + Dialog dialog = null; + if (configuration instanceof ICustomDirectEditorConfiguration) { + setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); + initializeDirectEditManager(theRequest); + return; + } else if (configuration instanceof IPopupEditorConfiguration) { + IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); + helper.showEditor(); + return; + } + else if (configuration instanceof IAdvancedEditorConfiguration) { + dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); + } else if (configuration instanceof IDirectEditorConfiguration) { + dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), + configuration); + } else { + return; + } + final Dialog finalDialog = dialog; + + if (Window.OK == dialog.open()) { + TransactionalEditingDomain domain = getEditingDomain(); + RecordingCommand command = new RecordingCommand(domain, "Edit Label") { + + @Override + protected void doExecute() { + configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); + + } + }; + domain.getCommandStack().execute(command); + } + } + break; + case IDirectEdition.DEFAULT_DIRECT_EDITOR: + initializeDirectEditManager(theRequest); + break; + default: + break; + } + } + + /** + * @generated + */ + protected void initializeDirectEditManager(final Request request) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + @Override + public void run() { + if (isActive() && isEditable()) { + if (request.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } + else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void refreshVisuals() { + super.refreshVisuals(); + refreshLabel(); + refreshFont(); + refreshFontColor(); + refreshUnderline(); + refreshStrikeThrough(); + } + + /** + * @generated + */ + protected void refreshLabel() { + EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); + if (maskLabelPolicy == null) { + maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); + } + if (maskLabelPolicy == null) { + View view = (View) getModel(); + if (view.isVisible()) { + setLabelTextHelper(getFigure(), getLabelText()); + setLabelIconHelper(getFigure(), getLabelIcon()); + } + else { + setLabelTextHelper(getFigure(), ""); //$NON-NLS-1$ + setLabelIconHelper(getFigure(), null); + } + } + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + protected void refreshUnderline() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); + } + if (resolveSemanticElement() instanceof Feature) { + if (((Feature) resolveSemanticElement()).isStatic()) { + ((WrappingLabel) getFigure()).setTextUnderline(true); + } + else { + ((WrappingLabel) getFigure()).setTextUnderline(false); + } + } + } + + /** + * @generated + */ + protected void refreshStrikeThrough() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); + } + } + + /** + * @generated + */ + @Override + protected void refreshFont() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null) { + FontData fontData = new FontData( + style.getFontName(), style.getFontHeight(), + (style.isBold() ? SWT.BOLD : SWT.NORMAL) | + (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); + setFont(fontData); + } + } + + /** + * @generated + */ + @Override + protected void setFontColor(Color color) { + getFigure().setForegroundColor(color); + } + + /** + * @generated + */ + @Override + protected void addSemanticListeners() { + if (getParser() instanceof ISemanticParser) { + EObject element = resolveSemanticElement(); + parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); + for (int i = 0; i < parserElements.size(); i++) { + addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ + } + } else { + super.addSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected void removeSemanticListeners() { + if (parserElements != null) { + for (int i = 0; i < parserElements.size(); i++) { + removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ + } + } else { + super.removeSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected AccessibleEditPart getAccessibleEditPart() { + if (accessibleEP == null) { + accessibleEP = new AccessibleGraphicalEditPart() { + + @Override + public void getName(AccessibleEvent e) { + e.result = getLabelTextHelper(getFigure()); + } + }; + } + return accessibleEP; + } + + /** + * @generated + */ + private View getFontStyleOwnerView() { + return getPrimaryView(); + } + + /** + * Returns the kind of associated editor for direct edition. + * + * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition + * @generated + */ + public int getDirectEditionType() { + if (checkExtendedEditor()) { + initExtendedEditorConfiguration(); + return IDirectEdition.EXTENDED_DIRECT_EDITOR; + } + if (checkDefaultEdition()) { + return IDirectEdition.DEFAULT_DIRECT_EDITOR; + } + + // not a named element. no specific editor => do nothing + return IDirectEdition.NO_DIRECT_EDITION; + } + + /** + * Checks if an extended editor is present. + * + * @return true if an extended editor is present. + * @generated + */ + protected boolean checkExtendedEditor() { + if (resolveSemanticElement() != null) { + return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); + } + return false; + } + + /** + * Checks if a default direct edition is available + * + * @return true if a default direct edition is available + * @generated + */ + protected boolean checkDefaultEdition() { + return (getParser() != null); + } + + /** + * Initializes the extended editor configuration + * + * @generated + */ + protected void initExtendedEditorConfiguration() { + if (configuration == null) { + final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("")) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); + } else { + configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); + } + } + } + + /** + * Updates the preference configuration + * + * @generated + */ + protected void updateExtendedEditorConfiguration() { + String languagePreferred = Activator.getDefault().getPreferenceStore().getString( + IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() + .eClass().getInstanceClassName()); + } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { + configuration = null; + } + } + + /** + * Performs the direct edit usually used by GMF editors. + * + * @param theRequest + * the direct edit request that starts the direct edit system + * @generated + */ + protected void performDefaultDirectEditorEdit(final Request theRequest) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + + @Override + public void run() { + if (isActive() && isEditable()) { + if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) theRequest.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { + DirectEditRequest editRequest = (DirectEditRequest) theRequest; + performDirectEdit(editRequest.getLocation()); + } else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + + /** + * @generated + */ + @Override + protected void handleNotificationEvent(Notification event) { + Object feature = event.getFeature(); + if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { + Integer c = (Integer) event.getNewValue(); + setFontColor(DiagramColorRegistry.getInstance().getColor(c)); + } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { + refreshUnderline(); + } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { + refreshStrikeThrough(); + } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { + refreshFont(); + } else { + if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { + refreshLabel(); + } + if (getParser() instanceof ISemanticParser) { + ISemanticParser modelParser = + (ISemanticParser) getParser(); + if (modelParser.areSemanticElementsAffected(null, event)) { + removeSemanticListeners(); + if (resolveSemanticElement() != null) { + addSemanticListeners(); + } + refreshLabel(); + } + } + } + super.handleNotificationEvent(event); + } + + /** + * @generated + */ + @Override + protected IFigure createFigure() { + IFigure label = createFigurePrim(); + defaultText = getLabelTextHelper(label); + return label; + } + + /** + * @generated + */ + protected IFigure createFigurePrim() { + return new PapyrusWrappingLabel(); + } + +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/SignalFloatingLabelEditPartCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/SignalFloatingLabelEditPartCN.java new file mode 100644 index 00000000000..0152a035d2e --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/SignalFloatingLabelEditPartCN.java @@ -0,0 +1,860 @@ +/** + * 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.uml.diagram.composite.edit.parts; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.Label; +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.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.RunnableWithResult; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gef.AccessibleEditPart; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.Request; +import org.eclipse.gef.requests.DirectEditRequest; +import org.eclipse.gef.tools.DirectEditManager; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; +import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; +import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; +import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; +import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; +import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; +import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; +import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; +import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; +import org.eclipse.gmf.runtime.notation.FontStyle; +import org.eclipse.gmf.runtime.notation.NotationPackage; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.text.contentassist.IContentAssistProcessor; +import org.eclipse.jface.viewers.ICellEditorValidator; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.extensionpoints.editors.Activator; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; +import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; +import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.ExternalLabelPrimaryDragRoleEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.PapyrusWrappingLabel; +import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; +import org.eclipse.papyrus.uml.diagram.common.editparts.FloatingLabelEditPart; +import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; +import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; +import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; +import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.accessibility.AccessibleEvent; +import org.eclipse.swt.custom.BusyIndicator; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; +import org.eclipse.uml2.uml.Feature; + +/** + * @generated + */ +public class SignalFloatingLabelEditPartCN extends FloatingLabelEditPart + implements ITextAwareEditPart, IBorderItemEditPart +{ + + /** + * @generated + */ + public static final int VISUAL_ID = 6077; + + /** + * @generated + */ + private DirectEditManager manager; + + /** + * @generated + */ + private IParser parser; + + /** + * @generated + */ + private List parserElements; + + /** + * @generated + */ + private String defaultText; + + /** + * direct edition mode (default, undefined, registered editor, etc.) + * + * @generated + */ + protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; + + /** + * configuration from a registered edit dialog + * + * @generated + */ + protected IDirectEditorConfiguration configuration; + + + /** + * @generated + */ + static { + registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.SignalFloatingLabelEditPartCN.VISUAL_ID), new Point(0, 0)); + } + + /** + * @generated + */ + public SignalFloatingLabelEditPartCN(View view) { + super(view); + } + + /** + * @generated + */ + @Override + protected void createDefaultEditPolicies() { + super.createDefaultEditPolicies(); + installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); + installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ExternalLabelPrimaryDragRoleEditPolicy()); + } + + /** + * @generated + */ + @Override + public IBorderItemLocator getBorderItemLocator() { + IFigure parentFigure = getFigure().getParent(); + if (parentFigure != null && parentFigure.getLayoutManager() != null) { + Object constraint = parentFigure.getLayoutManager().getConstraint(getFigure()); + return (IBorderItemLocator) constraint; + } + return null; + } + + /** + * @generated + */ + @Override + public void refreshBounds() { + int x = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_X())).intValue(); + int y = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_Y())).intValue(); + int width = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Width())).intValue(); + int height = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Height())).intValue(); + getBorderItemLocator().setConstraint(new Rectangle(x, y, width, height)); + } + + + /** + * @generated + */ + protected String getLabelTextHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getText(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getText(); + } else { + return ((Label) figure).getText(); + } + } + + /** + * @generated + */ + protected void setLabelTextHelper(IFigure figure, String text) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setText(text); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setText(text); + } else { + ((Label) figure).setText(text); + } + } + + /** + * @generated + */ + protected Image getLabelIconHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getIcon(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getIcon(); + } else { + return ((Label) figure).getIcon(); + } + } + + /** + * @generated + */ + protected void setLabelIconHelper(IFigure figure, Image icon) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setIcon(icon); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setIcon(icon); + } else { + ((Label) figure).setIcon(icon); + } + } + + /** + * @generated + */ + public void setLabel(IFigure + figure) { + unregisterVisuals(); + setFigure(figure); + defaultText = getLabelTextHelper(figure); + registerVisuals(); + refreshVisuals(); + } + + /** + * @generated + */ + @Override + protected List getModelChildren() { + return Collections.EMPTY_LIST; + } + + /** + * @generated + */ + @Override + public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { + return null; + } + + /** + * @generated + */ + public void setParser(IParser parser) { + this.parser = parser; + } + + /** + * @generated + */ + protected EObject getParserElement() { + return resolveSemanticElement(); + } + + /** + * @generated + */ + protected Image getLabelIcon() { + return null; + } + + /** + * @generated + */ + protected String getLabelText() { + String text = null; + EObject parserElement = getParserElement(); + if (parserElement != null && getParser() != null) { + text = getParser().getPrintString( + new EObjectAdapter(parserElement), + getParserOptions().intValue()); + } + if (text == null || text.length() == 0) { + text = defaultText; + } + return text; + } + + /** + * @generated + */ + @Override + public void setLabelText(String text) { + setLabelTextHelper(getFigure(), text); + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + @Override + public String getEditText() { + if (getParserElement() == null || getParser() == null) { + return ""; //$NON-NLS-1$ + } + return getParser().getEditString( + new EObjectAdapter(getParserElement()), + getParserOptions().intValue()); + } + + /** + * @generated + */ + protected boolean isEditable() { + return getParser() != null; + } + + /** + * @generated + */ + @Override + public ICellEditorValidator getEditTextValidator() { + return new ICellEditorValidator() { + + @Override + public String isValid(final Object value) { + if (value instanceof String) { + final EObject element = getParserElement(); + final IParser parser = getParser(); + try { + IParserEditStatus valid = + (IParserEditStatus) getEditingDomain().runExclusive( + new RunnableWithResult.Impl() { + + @Override + public void run() { + setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); + } + }); + return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); + } catch (InterruptedException ie) { + ie.printStackTrace(); + } + } + + // shouldn't get here + return null; + } + }; + } + + /** + * @generated + */ + @Override + public IContentAssistProcessor getCompletionProcessor() { + if (getParserElement() == null || getParser() == null) { + return null; + } + return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); + } + + /** + * @generated + */ + @Override + public ParserOptions getParserOptions() { + return ParserOptions.NONE; + } + + /** + * @generated + */ + @Override + public IParser getParser() { + if (parser == null) { + parser = UMLParserProvider.getParser(UMLElementTypes.Signal_3095, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.SignalFloatingLabelEditPartCN.VISUAL_ID)); + } + return parser; + } + + /** + * @generated + */ + protected DirectEditManager getManager() { + if (manager == null) { + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + } + return manager; + } + + /** + * @generated + */ + protected void setManager(DirectEditManager manager) { + this.manager = manager; + } + + /** + * @generated + */ + protected void performDirectEdit() { + BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { + + @Override + public void run() { + getManager().show(); + } + }); + } + + /** + * @generated + */ + protected void performDirectEdit(Point eventLocation) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); + } + } + + /** + * @generated + */ + private void performDirectEdit(char initialCharacter) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(initialCharacter); + } else { + performDirectEdit(); + } + } + + /** + * @generated + */ + @Override + protected void performDirectEditRequest(Request request) { + + final Request theRequest = request; + + if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { + directEditionMode = getDirectEditionType(); + } + switch (directEditionMode) { + case IDirectEdition.NO_DIRECT_EDITION: + // no direct edition mode => does nothing + return; + case IDirectEdition.EXTENDED_DIRECT_EDITOR: + updateExtendedEditorConfiguration(); + if (configuration == null || configuration.getLanguage() == null) { + // Create default edit manager + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + performDefaultDirectEditorEdit(theRequest); + } else { + configuration.preEditAction(resolveSemanticElement()); + Dialog dialog = null; + if (configuration instanceof ICustomDirectEditorConfiguration) { + setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); + initializeDirectEditManager(theRequest); + return; + } else if (configuration instanceof IPopupEditorConfiguration) { + IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); + helper.showEditor(); + return; + } + else if (configuration instanceof IAdvancedEditorConfiguration) { + dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); + } else if (configuration instanceof IDirectEditorConfiguration) { + dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), + configuration); + } else { + return; + } + final Dialog finalDialog = dialog; + + if (Window.OK == dialog.open()) { + TransactionalEditingDomain domain = getEditingDomain(); + RecordingCommand command = new RecordingCommand(domain, "Edit Label") { + + @Override + protected void doExecute() { + configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); + + } + }; + domain.getCommandStack().execute(command); + } + } + break; + case IDirectEdition.DEFAULT_DIRECT_EDITOR: + initializeDirectEditManager(theRequest); + break; + default: + break; + } + } + + /** + * @generated + */ + protected void initializeDirectEditManager(final Request request) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + @Override + public void run() { + if (isActive() && isEditable()) { + if (request.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } + else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void refreshVisuals() { + super.refreshVisuals(); + refreshLabel(); + refreshFont(); + refreshFontColor(); + refreshUnderline(); + refreshStrikeThrough(); + } + + /** + * @generated + */ + protected void refreshLabel() { + EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); + if (maskLabelPolicy == null) { + maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); + } + if (maskLabelPolicy == null) { + View view = (View) getModel(); + if (view.isVisible()) { + setLabelTextHelper(getFigure(), getLabelText()); + setLabelIconHelper(getFigure(), getLabelIcon()); + } + else { + setLabelTextHelper(getFigure(), ""); //$NON-NLS-1$ + setLabelIconHelper(getFigure(), null); + } + } + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + protected void refreshUnderline() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); + } + if (resolveSemanticElement() instanceof Feature) { + if (((Feature) resolveSemanticElement()).isStatic()) { + ((WrappingLabel) getFigure()).setTextUnderline(true); + } + else { + ((WrappingLabel) getFigure()).setTextUnderline(false); + } + } + } + + /** + * @generated + */ + protected void refreshStrikeThrough() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); + } + } + + /** + * @generated + */ + @Override + protected void refreshFont() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null) { + FontData fontData = new FontData( + style.getFontName(), style.getFontHeight(), + (style.isBold() ? SWT.BOLD : SWT.NORMAL) | + (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); + setFont(fontData); + } + } + + /** + * @generated + */ + @Override + protected void setFontColor(Color color) { + getFigure().setForegroundColor(color); + } + + /** + * @generated + */ + @Override + protected void addSemanticListeners() { + if (getParser() instanceof ISemanticParser) { + EObject element = resolveSemanticElement(); + parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); + for (int i = 0; i < parserElements.size(); i++) { + addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ + } + } else { + super.addSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected void removeSemanticListeners() { + if (parserElements != null) { + for (int i = 0; i < parserElements.size(); i++) { + removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ + } + } else { + super.removeSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected AccessibleEditPart getAccessibleEditPart() { + if (accessibleEP == null) { + accessibleEP = new AccessibleGraphicalEditPart() { + + @Override + public void getName(AccessibleEvent e) { + e.result = getLabelTextHelper(getFigure()); + } + }; + } + return accessibleEP; + } + + /** + * @generated + */ + private View getFontStyleOwnerView() { + return getPrimaryView(); + } + + /** + * Returns the kind of associated editor for direct edition. + * + * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition + * @generated + */ + public int getDirectEditionType() { + if (checkExtendedEditor()) { + initExtendedEditorConfiguration(); + return IDirectEdition.EXTENDED_DIRECT_EDITOR; + } + if (checkDefaultEdition()) { + return IDirectEdition.DEFAULT_DIRECT_EDITOR; + } + + // not a named element. no specific editor => do nothing + return IDirectEdition.NO_DIRECT_EDITION; + } + + /** + * Checks if an extended editor is present. + * + * @return true if an extended editor is present. + * @generated + */ + protected boolean checkExtendedEditor() { + if (resolveSemanticElement() != null) { + return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); + } + return false; + } + + /** + * Checks if a default direct edition is available + * + * @return true if a default direct edition is available + * @generated + */ + protected boolean checkDefaultEdition() { + return (getParser() != null); + } + + /** + * Initializes the extended editor configuration + * + * @generated + */ + protected void initExtendedEditorConfiguration() { + if (configuration == null) { + final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("")) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); + } else { + configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); + } + } + } + + /** + * Updates the preference configuration + * + * @generated + */ + protected void updateExtendedEditorConfiguration() { + String languagePreferred = Activator.getDefault().getPreferenceStore().getString( + IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() + .eClass().getInstanceClassName()); + } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { + configuration = null; + } + } + + /** + * Performs the direct edit usually used by GMF editors. + * + * @param theRequest + * the direct edit request that starts the direct edit system + * @generated + */ + protected void performDefaultDirectEditorEdit(final Request theRequest) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + + @Override + public void run() { + if (isActive() && isEditable()) { + if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) theRequest.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { + DirectEditRequest editRequest = (DirectEditRequest) theRequest; + performDirectEdit(editRequest.getLocation()); + } else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + + /** + * @generated + */ + @Override + protected void handleNotificationEvent(Notification event) { + Object feature = event.getFeature(); + if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { + Integer c = (Integer) event.getNewValue(); + setFontColor(DiagramColorRegistry.getInstance().getColor(c)); + } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { + refreshUnderline(); + } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { + refreshStrikeThrough(); + } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { + refreshFont(); + } else { + if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { + refreshLabel(); + } + if (getParser() instanceof ISemanticParser) { + ISemanticParser modelParser = + (ISemanticParser) getParser(); + if (modelParser.areSemanticElementsAffected(null, event)) { + removeSemanticListeners(); + if (resolveSemanticElement() != null) { + addSemanticListeners(); + } + refreshLabel(); + } + } + } + super.handleNotificationEvent(event); + } + + /** + * @generated + */ + @Override + protected IFigure createFigure() { + IFigure label = createFigurePrim(); + defaultText = getLabelTextHelper(label); + return label; + } + + /** + * @generated + */ + protected IFigure createFigurePrim() { + return new PapyrusWrappingLabel(); + } + +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/SignalNameEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/SignalNameEditPart.java index 5906a978eca..e7a99e9b136 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/SignalNameEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/SignalNameEditPart.java @@ -864,7 +864,7 @@ public class SignalNameEditPart extends PapyrusCompartmentEditPart implements IT * @generated */ protected void addOwnerElementListeners() { - addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); + addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/SignalNameEditPartCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/SignalNameEditPartCN.java index d085b7bd23a..cbcce786eed 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/SignalNameEditPartCN.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/SignalNameEditPartCN.java @@ -864,7 +864,7 @@ public class SignalNameEditPartCN extends PapyrusCompartmentEditPart implements * @generated */ protected void addOwnerElementListeners() { - addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); + addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/StateMachineCompositeCompartmentEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/StateMachineCompositeCompartmentEditPart.java index 1b7e3967009..db5452ec901 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/StateMachineCompositeCompartmentEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/StateMachineCompositeCompartmentEditPart.java @@ -26,6 +26,7 @@ import org.eclipse.gmf.runtime.diagram.ui.editpolicies.ResizableCompartmentEditP import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.BorderDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.CustomContainerEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.DuplicatePasteEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.PapyrusCreationEditPolicy; @@ -75,6 +76,7 @@ public class StateMachineCompositeCompartmentEditPart extends ShapeCompartmentEd installEditPolicy(EditPolicy.GRAPHICAL_NODE_ROLE, new CustomContainerEditPolicy()); installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, new CustomDiagramDragDropEditPolicy()); installEditPolicy(EditPolicyRoles.CREATION_ROLE, new PortInCompartmentCreationEditPolicy()); + installEditPolicy(BorderDisplayEditPolicy.BORDER_DISPLAY_EDITPOLICY, new BorderDisplayEditPolicy()); } /** diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/StateMachineCompositeCompartmentEditPartCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/StateMachineCompositeCompartmentEditPartCN.java index 4e083df39be..3191d29c758 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/StateMachineCompositeCompartmentEditPartCN.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/StateMachineCompositeCompartmentEditPartCN.java @@ -26,6 +26,7 @@ import org.eclipse.gmf.runtime.diagram.ui.editpolicies.ResizableCompartmentEditP import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.BorderDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.CustomContainerEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.DuplicatePasteEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.PapyrusCreationEditPolicy; @@ -75,6 +76,7 @@ public class StateMachineCompositeCompartmentEditPartCN extends ShapeCompartment installEditPolicy(EditPolicy.GRAPHICAL_NODE_ROLE, new CustomContainerEditPolicy()); installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, new CustomDiagramDragDropEditPolicy()); installEditPolicy(EditPolicyRoles.CREATION_ROLE, new PortInCompartmentCreationEditPolicy()); + installEditPolicy(BorderDisplayEditPolicy.BORDER_DISPLAY_EDITPOLICY, new BorderDisplayEditPolicy()); } /** diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/StateMachineCompositeEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/StateMachineCompositeEditPart.java index 120a7181030..554a4659dad 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/StateMachineCompositeEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/StateMachineCompositeEditPart.java @@ -11,28 +11,37 @@ */ package org.eclipse.papyrus.uml.diagram.composite.edit.parts; +import java.util.Collections; +import java.util.List; + import org.eclipse.draw2d.IFigure; import org.eclipse.draw2d.PositionConstants; import org.eclipse.emf.common.notify.Notification; import org.eclipse.gef.EditPart; import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.GraphicalEditPart; 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.handles.MoveHandle; import org.eclipse.gef.requests.CreateRequest; import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.BorderItemSelectionEditPolicy; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.DragDropEditPolicy; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles; import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; -import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure; import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure; +import org.eclipse.gmf.runtime.notation.Edge; +import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.GetChildLayoutEditPolicy; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.IPapyrusNodeFigure; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.RoundedRectangleNodePlateFigure; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.SelectableBorderedNodeFigure; -import org.eclipse.papyrus.uml.diagram.common.editparts.NamedElementEditPart; +import org.eclipse.papyrus.uml.diagram.common.editparts.RoundedCompartmentEditPart; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AffixedNodeAlignmentEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeNodeLabelDisplayEditPolicy; @@ -41,11 +50,11 @@ import org.eclipse.papyrus.uml.diagram.common.editpolicies.PapyrusCreationEditPo import org.eclipse.papyrus.uml.diagram.common.editpolicies.QualifiedNameDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.ShowHideClassifierContentsEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.ShowHideCompartmentEditPolicy; +import org.eclipse.papyrus.uml.diagram.common.locator.RoundedRectangleLabelPositionLocator; import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.BehaviorLayoutEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.CustomDiagramDragDropEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.RemoveOrphanViewPolicy; import org.eclipse.papyrus.uml.diagram.composite.custom.figures.StateMachineCompositeFigure; -import org.eclipse.papyrus.uml.diagram.composite.custom.locators.PortPositionLocator; import org.eclipse.papyrus.uml.diagram.composite.edit.policies.StateMachineCompositeItemSemanticEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; import org.eclipse.swt.graphics.Color; @@ -53,7 +62,7 @@ import org.eclipse.swt.graphics.Color; /** * @generated */ -public class StateMachineCompositeEditPart extends NamedElementEditPart { +public class StateMachineCompositeEditPart extends RoundedCompartmentEditPart { /** * @generated @@ -95,6 +104,7 @@ public class StateMachineCompositeEditPart extends NamedElementEditPart { installEditPolicy(ShowHideCompartmentEditPolicy.SHOW_HIDE_COMPARTMENT_POLICY, new ShowHideCompartmentEditPolicy()); installEditPolicy(AffixedNodeAlignmentEditPolicy.AFFIXED_CHILD_ALIGNMENT_ROLE, new AffixedNodeAlignmentEditPolicy()); installEditPolicy("REMOVE_ORPHAN_VIEW", new RemoveOrphanViewPolicy()); //$NON-NLS-1$ + installEditPolicy(EditPolicy.LAYOUT_ROLE, new GetChildLayoutEditPolicy()); // XXX need an SCR to runtime to have another abstract superclass that would let children add reasonable editpolicies // removeEditPolicy(org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles.CONNECTION_HANDLES_ROLE); } @@ -109,6 +119,17 @@ public class StateMachineCompositeEditPart extends NamedElementEditPart { protected EditPolicy createChildEditPolicy(EditPart child) { View childView = (View) child.getModel(); switch (UMLVisualIDRegistry.getVisualID(childView)) { + case StateMachineCompositeFloatingLabelEditPart.VISUAL_ID: + return new BorderItemSelectionEditPolicy() { + + @Override + protected List createSelectionHandles() { + MoveHandle mh = new MoveHandle((GraphicalEditPart) getHost()); + mh.setBorder(null); + return Collections.singletonList(mh); + } + } + ; case PortEditPart.VISUAL_ID: case ParameterEditPart.VISUAL_ID: return new BorderItemResizableEditPolicy(); @@ -140,6 +161,19 @@ public class StateMachineCompositeEditPart extends NamedElementEditPart { **/ @Override protected void handleNotificationEvent(Notification event) { + /* + * when a node have external node labels, the methods refreshChildren() remove the EditPart corresponding to the Label from the EditPart + * Registry. After that, we can't reset the visibility to true (using the Show/Hide Label Action)! + */ + if (NotationPackage.eINSTANCE.getView_Visible().equals(event.getFeature())) { + Object notifier = event.getNotifier(); + List modelChildren = ((View) getModel()).getChildren(); + if (!(notifier instanceof Edge)) { + if (modelChildren.contains(event.getNotifier())) { + return; + } + } + } super.handleNotificationEvent(event); } @@ -181,9 +215,9 @@ public class StateMachineCompositeEditPart extends NamedElementEditPart { - //Papyrus Gencode :Affixed Port locator + // Papyrus Gencode :Affixed Port locator if (childEditPart instanceof PortEditPart) { - IBorderItemLocator locator = new PortPositionLocator(getMainFigure(), PositionConstants.NONE); + IBorderItemLocator locator = new org.eclipse.papyrus.uml.diagram.common.locator.PortPositionLocator(getMainFigure(), PositionConstants.NONE); getBorderedFigure().getBorderItemContainer().add(((PortEditPart) childEditPart).getFigure(), locator); return true; } @@ -191,9 +225,9 @@ public class StateMachineCompositeEditPart extends NamedElementEditPart { - //Papyrus Gencode :Affixed Port locator + // Papyrus Gencode :Affixed Port locator if (childEditPart instanceof ParameterEditPart) { - IBorderItemLocator locator = new PortPositionLocator(getMainFigure(), PositionConstants.NONE); + IBorderItemLocator locator = new org.eclipse.papyrus.uml.diagram.common.locator.PortPositionLocator(getMainFigure(), PositionConstants.NONE); getBorderedFigure().getBorderItemContainer().add(((ParameterEditPart) childEditPart).getFigure(), locator); return true; } @@ -261,12 +295,26 @@ public class StateMachineCompositeEditPart extends NamedElementEditPart { return getContentPane(); } + /** + * @generated + */ + @Override + protected void addBorderItem(IFigure borderItemContainer, IBorderItemEditPart borderItemEditPart) { + if (borderItemEditPart instanceof StateMachineCompositeFloatingLabelEditPart) { + IBorderItemLocator locator = new RoundedRectangleLabelPositionLocator(getMainFigure()); + borderItemContainer.add(borderItemEditPart.getFigure(), locator); + } else + { + super.addBorderItem(borderItemContainer, borderItemEditPart); + } + } + /** * @generated */ @Override protected NodeFigure createNodePlate() { - DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(40, 40); + RoundedRectangleNodePlateFigure result = new RoundedRectangleNodePlateFigure(40, 40); return result; } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/StateMachineCompositeEditPartCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/StateMachineCompositeEditPartCN.java index 94b60c0a2f2..89ea059cba5 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/StateMachineCompositeEditPartCN.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/StateMachineCompositeEditPartCN.java @@ -11,28 +11,37 @@ */ package org.eclipse.papyrus.uml.diagram.composite.edit.parts; +import java.util.Collections; +import java.util.List; + import org.eclipse.draw2d.IFigure; import org.eclipse.draw2d.PositionConstants; import org.eclipse.emf.common.notify.Notification; import org.eclipse.gef.EditPart; import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.GraphicalEditPart; 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.handles.MoveHandle; import org.eclipse.gef.requests.CreateRequest; import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.BorderItemSelectionEditPolicy; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.DragDropEditPolicy; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles; import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; -import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure; import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure; +import org.eclipse.gmf.runtime.notation.Edge; +import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.GetChildLayoutEditPolicy; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.IPapyrusNodeFigure; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.RoundedRectangleNodePlateFigure; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.SelectableBorderedNodeFigure; -import org.eclipse.papyrus.uml.diagram.common.editparts.NamedElementEditPart; +import org.eclipse.papyrus.uml.diagram.common.editparts.RoundedCompartmentEditPart; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AffixedNodeAlignmentEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeNodeLabelDisplayEditPolicy; @@ -41,11 +50,11 @@ import org.eclipse.papyrus.uml.diagram.common.editpolicies.PapyrusCreationEditPo import org.eclipse.papyrus.uml.diagram.common.editpolicies.QualifiedNameDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.ShowHideClassifierContentsEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.ShowHideCompartmentEditPolicy; +import org.eclipse.papyrus.uml.diagram.common.locator.RoundedRectangleLabelPositionLocator; import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.BehaviorLayoutEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.CustomDiagramDragDropEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.RemoveOrphanViewPolicy; import org.eclipse.papyrus.uml.diagram.composite.custom.figures.StateMachineCompositeFigure; -import org.eclipse.papyrus.uml.diagram.composite.custom.locators.PortPositionLocator; import org.eclipse.papyrus.uml.diagram.composite.edit.policies.StateMachineCompositeItemSemanticEditPolicyCN; import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; import org.eclipse.swt.graphics.Color; @@ -53,7 +62,7 @@ import org.eclipse.swt.graphics.Color; /** * @generated */ -public class StateMachineCompositeEditPartCN extends NamedElementEditPart { +public class StateMachineCompositeEditPartCN extends RoundedCompartmentEditPart { /** * @generated @@ -95,6 +104,7 @@ public class StateMachineCompositeEditPartCN extends NamedElementEditPart { installEditPolicy(ShowHideCompartmentEditPolicy.SHOW_HIDE_COMPARTMENT_POLICY, new ShowHideCompartmentEditPolicy()); installEditPolicy(AffixedNodeAlignmentEditPolicy.AFFIXED_CHILD_ALIGNMENT_ROLE, new AffixedNodeAlignmentEditPolicy()); installEditPolicy("REMOVE_ORPHAN_VIEW", new RemoveOrphanViewPolicy()); //$NON-NLS-1$ + installEditPolicy(EditPolicy.LAYOUT_ROLE, new GetChildLayoutEditPolicy()); // XXX need an SCR to runtime to have another abstract superclass that would let children add reasonable editpolicies // removeEditPolicy(org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles.CONNECTION_HANDLES_ROLE); } @@ -109,6 +119,17 @@ public class StateMachineCompositeEditPartCN extends NamedElementEditPart { protected EditPolicy createChildEditPolicy(EditPart child) { View childView = (View) child.getModel(); switch (UMLVisualIDRegistry.getVisualID(childView)) { + case StateMachineCompositeFloatingLabelEditPartCN.VISUAL_ID: + return new BorderItemSelectionEditPolicy() { + + @Override + protected List createSelectionHandles() { + MoveHandle mh = new MoveHandle((GraphicalEditPart) getHost()); + mh.setBorder(null); + return Collections.singletonList(mh); + } + } + ; case PortEditPart.VISUAL_ID: case ParameterEditPart.VISUAL_ID: return new BorderItemResizableEditPolicy(); @@ -140,6 +161,19 @@ public class StateMachineCompositeEditPartCN extends NamedElementEditPart { **/ @Override protected void handleNotificationEvent(Notification event) { + /* + * when a node have external node labels, the methods refreshChildren() remove the EditPart corresponding to the Label from the EditPart + * Registry. After that, we can't reset the visibility to true (using the Show/Hide Label Action)! + */ + if (NotationPackage.eINSTANCE.getView_Visible().equals(event.getFeature())) { + Object notifier = event.getNotifier(); + List modelChildren = ((View) getModel()).getChildren(); + if (!(notifier instanceof Edge)) { + if (modelChildren.contains(event.getNotifier())) { + return; + } + } + } super.handleNotificationEvent(event); } @@ -181,9 +215,9 @@ public class StateMachineCompositeEditPartCN extends NamedElementEditPart { - //Papyrus Gencode :Affixed Port locator + // Papyrus Gencode :Affixed Port locator if (childEditPart instanceof PortEditPart) { - IBorderItemLocator locator = new PortPositionLocator(getMainFigure(), PositionConstants.NONE); + IBorderItemLocator locator = new org.eclipse.papyrus.uml.diagram.common.locator.PortPositionLocator(getMainFigure(), PositionConstants.NONE); getBorderedFigure().getBorderItemContainer().add(((PortEditPart) childEditPart).getFigure(), locator); return true; } @@ -191,9 +225,9 @@ public class StateMachineCompositeEditPartCN extends NamedElementEditPart { - //Papyrus Gencode :Affixed Port locator + // Papyrus Gencode :Affixed Port locator if (childEditPart instanceof ParameterEditPart) { - IBorderItemLocator locator = new PortPositionLocator(getMainFigure(), PositionConstants.NONE); + IBorderItemLocator locator = new org.eclipse.papyrus.uml.diagram.common.locator.PortPositionLocator(getMainFigure(), PositionConstants.NONE); getBorderedFigure().getBorderItemContainer().add(((ParameterEditPart) childEditPart).getFigure(), locator); return true; } @@ -261,12 +295,26 @@ public class StateMachineCompositeEditPartCN extends NamedElementEditPart { return getContentPane(); } + /** + * @generated + */ + @Override + protected void addBorderItem(IFigure borderItemContainer, IBorderItemEditPart borderItemEditPart) { + if (borderItemEditPart instanceof StateMachineCompositeFloatingLabelEditPartCN) { + IBorderItemLocator locator = new RoundedRectangleLabelPositionLocator(getMainFigure()); + borderItemContainer.add(borderItemEditPart.getFigure(), locator); + } else + { + super.addBorderItem(borderItemContainer, borderItemEditPart); + } + } + /** * @generated */ @Override protected NodeFigure createNodePlate() { - DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(40, 40); + RoundedRectangleNodePlateFigure result = new RoundedRectangleNodePlateFigure(40, 40); return result; } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/StateMachineCompositeFloatingLabelEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/StateMachineCompositeFloatingLabelEditPart.java new file mode 100644 index 00000000000..3c05b845eb7 --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/StateMachineCompositeFloatingLabelEditPart.java @@ -0,0 +1,860 @@ +/** + * 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.uml.diagram.composite.edit.parts; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.Label; +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.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.RunnableWithResult; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gef.AccessibleEditPart; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.Request; +import org.eclipse.gef.requests.DirectEditRequest; +import org.eclipse.gef.tools.DirectEditManager; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; +import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; +import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; +import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; +import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; +import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; +import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; +import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; +import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; +import org.eclipse.gmf.runtime.notation.FontStyle; +import org.eclipse.gmf.runtime.notation.NotationPackage; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.text.contentassist.IContentAssistProcessor; +import org.eclipse.jface.viewers.ICellEditorValidator; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.extensionpoints.editors.Activator; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; +import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; +import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.ExternalLabelPrimaryDragRoleEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.PapyrusWrappingLabel; +import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; +import org.eclipse.papyrus.uml.diagram.common.editparts.FloatingLabelEditPart; +import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; +import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; +import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; +import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.accessibility.AccessibleEvent; +import org.eclipse.swt.custom.BusyIndicator; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; +import org.eclipse.uml2.uml.Feature; + +/** + * @generated + */ +public class StateMachineCompositeFloatingLabelEditPart extends FloatingLabelEditPart + implements ITextAwareEditPart, IBorderItemEditPart +{ + + /** + * @generated + */ + public static final int VISUAL_ID = 6082; + + /** + * @generated + */ + private DirectEditManager manager; + + /** + * @generated + */ + private IParser parser; + + /** + * @generated + */ + private List parserElements; + + /** + * @generated + */ + private String defaultText; + + /** + * direct edition mode (default, undefined, registered editor, etc.) + * + * @generated + */ + protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; + + /** + * configuration from a registered edit dialog + * + * @generated + */ + protected IDirectEditorConfiguration configuration; + + + /** + * @generated + */ + static { + registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.StateMachineCompositeFloatingLabelEditPart.VISUAL_ID), new Point(0, 0)); + } + + /** + * @generated + */ + public StateMachineCompositeFloatingLabelEditPart(View view) { + super(view); + } + + /** + * @generated + */ + @Override + protected void createDefaultEditPolicies() { + super.createDefaultEditPolicies(); + installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); + installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ExternalLabelPrimaryDragRoleEditPolicy()); + } + + /** + * @generated + */ + @Override + public IBorderItemLocator getBorderItemLocator() { + IFigure parentFigure = getFigure().getParent(); + if (parentFigure != null && parentFigure.getLayoutManager() != null) { + Object constraint = parentFigure.getLayoutManager().getConstraint(getFigure()); + return (IBorderItemLocator) constraint; + } + return null; + } + + /** + * @generated + */ + @Override + public void refreshBounds() { + int x = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_X())).intValue(); + int y = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_Y())).intValue(); + int width = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Width())).intValue(); + int height = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Height())).intValue(); + getBorderItemLocator().setConstraint(new Rectangle(x, y, width, height)); + } + + + /** + * @generated + */ + protected String getLabelTextHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getText(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getText(); + } else { + return ((Label) figure).getText(); + } + } + + /** + * @generated + */ + protected void setLabelTextHelper(IFigure figure, String text) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setText(text); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setText(text); + } else { + ((Label) figure).setText(text); + } + } + + /** + * @generated + */ + protected Image getLabelIconHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getIcon(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getIcon(); + } else { + return ((Label) figure).getIcon(); + } + } + + /** + * @generated + */ + protected void setLabelIconHelper(IFigure figure, Image icon) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setIcon(icon); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setIcon(icon); + } else { + ((Label) figure).setIcon(icon); + } + } + + /** + * @generated + */ + public void setLabel(IFigure + figure) { + unregisterVisuals(); + setFigure(figure); + defaultText = getLabelTextHelper(figure); + registerVisuals(); + refreshVisuals(); + } + + /** + * @generated + */ + @Override + protected List getModelChildren() { + return Collections.EMPTY_LIST; + } + + /** + * @generated + */ + @Override + public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { + return null; + } + + /** + * @generated + */ + public void setParser(IParser parser) { + this.parser = parser; + } + + /** + * @generated + */ + protected EObject getParserElement() { + return resolveSemanticElement(); + } + + /** + * @generated + */ + protected Image getLabelIcon() { + return null; + } + + /** + * @generated + */ + protected String getLabelText() { + String text = null; + EObject parserElement = getParserElement(); + if (parserElement != null && getParser() != null) { + text = getParser().getPrintString( + new EObjectAdapter(parserElement), + getParserOptions().intValue()); + } + if (text == null || text.length() == 0) { + text = defaultText; + } + return text; + } + + /** + * @generated + */ + @Override + public void setLabelText(String text) { + setLabelTextHelper(getFigure(), text); + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + @Override + public String getEditText() { + if (getParserElement() == null || getParser() == null) { + return ""; //$NON-NLS-1$ + } + return getParser().getEditString( + new EObjectAdapter(getParserElement()), + getParserOptions().intValue()); + } + + /** + * @generated + */ + protected boolean isEditable() { + return getParser() != null; + } + + /** + * @generated + */ + @Override + public ICellEditorValidator getEditTextValidator() { + return new ICellEditorValidator() { + + @Override + public String isValid(final Object value) { + if (value instanceof String) { + final EObject element = getParserElement(); + final IParser parser = getParser(); + try { + IParserEditStatus valid = + (IParserEditStatus) getEditingDomain().runExclusive( + new RunnableWithResult.Impl() { + + @Override + public void run() { + setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); + } + }); + return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); + } catch (InterruptedException ie) { + ie.printStackTrace(); + } + } + + // shouldn't get here + return null; + } + }; + } + + /** + * @generated + */ + @Override + public IContentAssistProcessor getCompletionProcessor() { + if (getParserElement() == null || getParser() == null) { + return null; + } + return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); + } + + /** + * @generated + */ + @Override + public ParserOptions getParserOptions() { + return ParserOptions.NONE; + } + + /** + * @generated + */ + @Override + public IParser getParser() { + if (parser == null) { + parser = UMLParserProvider.getParser(UMLElementTypes.StateMachine_2063, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.StateMachineCompositeFloatingLabelEditPart.VISUAL_ID)); + } + return parser; + } + + /** + * @generated + */ + protected DirectEditManager getManager() { + if (manager == null) { + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + } + return manager; + } + + /** + * @generated + */ + protected void setManager(DirectEditManager manager) { + this.manager = manager; + } + + /** + * @generated + */ + protected void performDirectEdit() { + BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { + + @Override + public void run() { + getManager().show(); + } + }); + } + + /** + * @generated + */ + protected void performDirectEdit(Point eventLocation) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); + } + } + + /** + * @generated + */ + private void performDirectEdit(char initialCharacter) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(initialCharacter); + } else { + performDirectEdit(); + } + } + + /** + * @generated + */ + @Override + protected void performDirectEditRequest(Request request) { + + final Request theRequest = request; + + if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { + directEditionMode = getDirectEditionType(); + } + switch (directEditionMode) { + case IDirectEdition.NO_DIRECT_EDITION: + // no direct edition mode => does nothing + return; + case IDirectEdition.EXTENDED_DIRECT_EDITOR: + updateExtendedEditorConfiguration(); + if (configuration == null || configuration.getLanguage() == null) { + // Create default edit manager + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + performDefaultDirectEditorEdit(theRequest); + } else { + configuration.preEditAction(resolveSemanticElement()); + Dialog dialog = null; + if (configuration instanceof ICustomDirectEditorConfiguration) { + setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); + initializeDirectEditManager(theRequest); + return; + } else if (configuration instanceof IPopupEditorConfiguration) { + IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); + helper.showEditor(); + return; + } + else if (configuration instanceof IAdvancedEditorConfiguration) { + dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); + } else if (configuration instanceof IDirectEditorConfiguration) { + dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), + configuration); + } else { + return; + } + final Dialog finalDialog = dialog; + + if (Window.OK == dialog.open()) { + TransactionalEditingDomain domain = getEditingDomain(); + RecordingCommand command = new RecordingCommand(domain, "Edit Label") { + + @Override + protected void doExecute() { + configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); + + } + }; + domain.getCommandStack().execute(command); + } + } + break; + case IDirectEdition.DEFAULT_DIRECT_EDITOR: + initializeDirectEditManager(theRequest); + break; + default: + break; + } + } + + /** + * @generated + */ + protected void initializeDirectEditManager(final Request request) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + @Override + public void run() { + if (isActive() && isEditable()) { + if (request.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } + else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void refreshVisuals() { + super.refreshVisuals(); + refreshLabel(); + refreshFont(); + refreshFontColor(); + refreshUnderline(); + refreshStrikeThrough(); + } + + /** + * @generated + */ + protected void refreshLabel() { + EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); + if (maskLabelPolicy == null) { + maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); + } + if (maskLabelPolicy == null) { + View view = (View) getModel(); + if (view.isVisible()) { + setLabelTextHelper(getFigure(), getLabelText()); + setLabelIconHelper(getFigure(), getLabelIcon()); + } + else { + setLabelTextHelper(getFigure(), ""); //$NON-NLS-1$ + setLabelIconHelper(getFigure(), null); + } + } + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + protected void refreshUnderline() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); + } + if (resolveSemanticElement() instanceof Feature) { + if (((Feature) resolveSemanticElement()).isStatic()) { + ((WrappingLabel) getFigure()).setTextUnderline(true); + } + else { + ((WrappingLabel) getFigure()).setTextUnderline(false); + } + } + } + + /** + * @generated + */ + protected void refreshStrikeThrough() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); + } + } + + /** + * @generated + */ + @Override + protected void refreshFont() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null) { + FontData fontData = new FontData( + style.getFontName(), style.getFontHeight(), + (style.isBold() ? SWT.BOLD : SWT.NORMAL) | + (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); + setFont(fontData); + } + } + + /** + * @generated + */ + @Override + protected void setFontColor(Color color) { + getFigure().setForegroundColor(color); + } + + /** + * @generated + */ + @Override + protected void addSemanticListeners() { + if (getParser() instanceof ISemanticParser) { + EObject element = resolveSemanticElement(); + parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); + for (int i = 0; i < parserElements.size(); i++) { + addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ + } + } else { + super.addSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected void removeSemanticListeners() { + if (parserElements != null) { + for (int i = 0; i < parserElements.size(); i++) { + removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ + } + } else { + super.removeSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected AccessibleEditPart getAccessibleEditPart() { + if (accessibleEP == null) { + accessibleEP = new AccessibleGraphicalEditPart() { + + @Override + public void getName(AccessibleEvent e) { + e.result = getLabelTextHelper(getFigure()); + } + }; + } + return accessibleEP; + } + + /** + * @generated + */ + private View getFontStyleOwnerView() { + return getPrimaryView(); + } + + /** + * Returns the kind of associated editor for direct edition. + * + * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition + * @generated + */ + public int getDirectEditionType() { + if (checkExtendedEditor()) { + initExtendedEditorConfiguration(); + return IDirectEdition.EXTENDED_DIRECT_EDITOR; + } + if (checkDefaultEdition()) { + return IDirectEdition.DEFAULT_DIRECT_EDITOR; + } + + // not a named element. no specific editor => do nothing + return IDirectEdition.NO_DIRECT_EDITION; + } + + /** + * Checks if an extended editor is present. + * + * @return true if an extended editor is present. + * @generated + */ + protected boolean checkExtendedEditor() { + if (resolveSemanticElement() != null) { + return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); + } + return false; + } + + /** + * Checks if a default direct edition is available + * + * @return true if a default direct edition is available + * @generated + */ + protected boolean checkDefaultEdition() { + return (getParser() != null); + } + + /** + * Initializes the extended editor configuration + * + * @generated + */ + protected void initExtendedEditorConfiguration() { + if (configuration == null) { + final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("")) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); + } else { + configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); + } + } + } + + /** + * Updates the preference configuration + * + * @generated + */ + protected void updateExtendedEditorConfiguration() { + String languagePreferred = Activator.getDefault().getPreferenceStore().getString( + IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() + .eClass().getInstanceClassName()); + } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { + configuration = null; + } + } + + /** + * Performs the direct edit usually used by GMF editors. + * + * @param theRequest + * the direct edit request that starts the direct edit system + * @generated + */ + protected void performDefaultDirectEditorEdit(final Request theRequest) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + + @Override + public void run() { + if (isActive() && isEditable()) { + if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) theRequest.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { + DirectEditRequest editRequest = (DirectEditRequest) theRequest; + performDirectEdit(editRequest.getLocation()); + } else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + + /** + * @generated + */ + @Override + protected void handleNotificationEvent(Notification event) { + Object feature = event.getFeature(); + if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { + Integer c = (Integer) event.getNewValue(); + setFontColor(DiagramColorRegistry.getInstance().getColor(c)); + } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { + refreshUnderline(); + } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { + refreshStrikeThrough(); + } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { + refreshFont(); + } else { + if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { + refreshLabel(); + } + if (getParser() instanceof ISemanticParser) { + ISemanticParser modelParser = + (ISemanticParser) getParser(); + if (modelParser.areSemanticElementsAffected(null, event)) { + removeSemanticListeners(); + if (resolveSemanticElement() != null) { + addSemanticListeners(); + } + refreshLabel(); + } + } + } + super.handleNotificationEvent(event); + } + + /** + * @generated + */ + @Override + protected IFigure createFigure() { + IFigure label = createFigurePrim(); + defaultText = getLabelTextHelper(label); + return label; + } + + /** + * @generated + */ + protected IFigure createFigurePrim() { + return new PapyrusWrappingLabel(); + } + +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/StateMachineCompositeFloatingLabelEditPartCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/StateMachineCompositeFloatingLabelEditPartCN.java new file mode 100644 index 00000000000..036d70b4eba --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/StateMachineCompositeFloatingLabelEditPartCN.java @@ -0,0 +1,860 @@ +/** + * 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.uml.diagram.composite.edit.parts; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.Label; +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.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.RunnableWithResult; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gef.AccessibleEditPart; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.Request; +import org.eclipse.gef.requests.DirectEditRequest; +import org.eclipse.gef.tools.DirectEditManager; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; +import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; +import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; +import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; +import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; +import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; +import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; +import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; +import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; +import org.eclipse.gmf.runtime.notation.FontStyle; +import org.eclipse.gmf.runtime.notation.NotationPackage; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.text.contentassist.IContentAssistProcessor; +import org.eclipse.jface.viewers.ICellEditorValidator; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.extensionpoints.editors.Activator; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; +import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; +import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.ExternalLabelPrimaryDragRoleEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.PapyrusWrappingLabel; +import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; +import org.eclipse.papyrus.uml.diagram.common.editparts.FloatingLabelEditPart; +import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; +import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; +import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; +import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.accessibility.AccessibleEvent; +import org.eclipse.swt.custom.BusyIndicator; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; +import org.eclipse.uml2.uml.Feature; + +/** + * @generated + */ +public class StateMachineCompositeFloatingLabelEditPartCN extends FloatingLabelEditPart + implements ITextAwareEditPart, IBorderItemEditPart +{ + + /** + * @generated + */ + public static final int VISUAL_ID = 6060; + + /** + * @generated + */ + private DirectEditManager manager; + + /** + * @generated + */ + private IParser parser; + + /** + * @generated + */ + private List parserElements; + + /** + * @generated + */ + private String defaultText; + + /** + * direct edition mode (default, undefined, registered editor, etc.) + * + * @generated + */ + protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; + + /** + * configuration from a registered edit dialog + * + * @generated + */ + protected IDirectEditorConfiguration configuration; + + + /** + * @generated + */ + static { + registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.StateMachineCompositeFloatingLabelEditPartCN.VISUAL_ID), new Point(0, 0)); + } + + /** + * @generated + */ + public StateMachineCompositeFloatingLabelEditPartCN(View view) { + super(view); + } + + /** + * @generated + */ + @Override + protected void createDefaultEditPolicies() { + super.createDefaultEditPolicies(); + installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); + installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ExternalLabelPrimaryDragRoleEditPolicy()); + } + + /** + * @generated + */ + @Override + public IBorderItemLocator getBorderItemLocator() { + IFigure parentFigure = getFigure().getParent(); + if (parentFigure != null && parentFigure.getLayoutManager() != null) { + Object constraint = parentFigure.getLayoutManager().getConstraint(getFigure()); + return (IBorderItemLocator) constraint; + } + return null; + } + + /** + * @generated + */ + @Override + public void refreshBounds() { + int x = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_X())).intValue(); + int y = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_Y())).intValue(); + int width = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Width())).intValue(); + int height = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Height())).intValue(); + getBorderItemLocator().setConstraint(new Rectangle(x, y, width, height)); + } + + + /** + * @generated + */ + protected String getLabelTextHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getText(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getText(); + } else { + return ((Label) figure).getText(); + } + } + + /** + * @generated + */ + protected void setLabelTextHelper(IFigure figure, String text) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setText(text); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setText(text); + } else { + ((Label) figure).setText(text); + } + } + + /** + * @generated + */ + protected Image getLabelIconHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getIcon(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getIcon(); + } else { + return ((Label) figure).getIcon(); + } + } + + /** + * @generated + */ + protected void setLabelIconHelper(IFigure figure, Image icon) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setIcon(icon); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setIcon(icon); + } else { + ((Label) figure).setIcon(icon); + } + } + + /** + * @generated + */ + public void setLabel(IFigure + figure) { + unregisterVisuals(); + setFigure(figure); + defaultText = getLabelTextHelper(figure); + registerVisuals(); + refreshVisuals(); + } + + /** + * @generated + */ + @Override + protected List getModelChildren() { + return Collections.EMPTY_LIST; + } + + /** + * @generated + */ + @Override + public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { + return null; + } + + /** + * @generated + */ + public void setParser(IParser parser) { + this.parser = parser; + } + + /** + * @generated + */ + protected EObject getParserElement() { + return resolveSemanticElement(); + } + + /** + * @generated + */ + protected Image getLabelIcon() { + return null; + } + + /** + * @generated + */ + protected String getLabelText() { + String text = null; + EObject parserElement = getParserElement(); + if (parserElement != null && getParser() != null) { + text = getParser().getPrintString( + new EObjectAdapter(parserElement), + getParserOptions().intValue()); + } + if (text == null || text.length() == 0) { + text = defaultText; + } + return text; + } + + /** + * @generated + */ + @Override + public void setLabelText(String text) { + setLabelTextHelper(getFigure(), text); + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + @Override + public String getEditText() { + if (getParserElement() == null || getParser() == null) { + return ""; //$NON-NLS-1$ + } + return getParser().getEditString( + new EObjectAdapter(getParserElement()), + getParserOptions().intValue()); + } + + /** + * @generated + */ + protected boolean isEditable() { + return getParser() != null; + } + + /** + * @generated + */ + @Override + public ICellEditorValidator getEditTextValidator() { + return new ICellEditorValidator() { + + @Override + public String isValid(final Object value) { + if (value instanceof String) { + final EObject element = getParserElement(); + final IParser parser = getParser(); + try { + IParserEditStatus valid = + (IParserEditStatus) getEditingDomain().runExclusive( + new RunnableWithResult.Impl() { + + @Override + public void run() { + setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); + } + }); + return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); + } catch (InterruptedException ie) { + ie.printStackTrace(); + } + } + + // shouldn't get here + return null; + } + }; + } + + /** + * @generated + */ + @Override + public IContentAssistProcessor getCompletionProcessor() { + if (getParserElement() == null || getParser() == null) { + return null; + } + return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); + } + + /** + * @generated + */ + @Override + public ParserOptions getParserOptions() { + return ParserOptions.NONE; + } + + /** + * @generated + */ + @Override + public IParser getParser() { + if (parser == null) { + parser = UMLParserProvider.getParser(UMLElementTypes.StateMachine_3075, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.StateMachineCompositeFloatingLabelEditPartCN.VISUAL_ID)); + } + return parser; + } + + /** + * @generated + */ + protected DirectEditManager getManager() { + if (manager == null) { + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + } + return manager; + } + + /** + * @generated + */ + protected void setManager(DirectEditManager manager) { + this.manager = manager; + } + + /** + * @generated + */ + protected void performDirectEdit() { + BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { + + @Override + public void run() { + getManager().show(); + } + }); + } + + /** + * @generated + */ + protected void performDirectEdit(Point eventLocation) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); + } + } + + /** + * @generated + */ + private void performDirectEdit(char initialCharacter) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(initialCharacter); + } else { + performDirectEdit(); + } + } + + /** + * @generated + */ + @Override + protected void performDirectEditRequest(Request request) { + + final Request theRequest = request; + + if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { + directEditionMode = getDirectEditionType(); + } + switch (directEditionMode) { + case IDirectEdition.NO_DIRECT_EDITION: + // no direct edition mode => does nothing + return; + case IDirectEdition.EXTENDED_DIRECT_EDITOR: + updateExtendedEditorConfiguration(); + if (configuration == null || configuration.getLanguage() == null) { + // Create default edit manager + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + performDefaultDirectEditorEdit(theRequest); + } else { + configuration.preEditAction(resolveSemanticElement()); + Dialog dialog = null; + if (configuration instanceof ICustomDirectEditorConfiguration) { + setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); + initializeDirectEditManager(theRequest); + return; + } else if (configuration instanceof IPopupEditorConfiguration) { + IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); + helper.showEditor(); + return; + } + else if (configuration instanceof IAdvancedEditorConfiguration) { + dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); + } else if (configuration instanceof IDirectEditorConfiguration) { + dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), + configuration); + } else { + return; + } + final Dialog finalDialog = dialog; + + if (Window.OK == dialog.open()) { + TransactionalEditingDomain domain = getEditingDomain(); + RecordingCommand command = new RecordingCommand(domain, "Edit Label") { + + @Override + protected void doExecute() { + configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); + + } + }; + domain.getCommandStack().execute(command); + } + } + break; + case IDirectEdition.DEFAULT_DIRECT_EDITOR: + initializeDirectEditManager(theRequest); + break; + default: + break; + } + } + + /** + * @generated + */ + protected void initializeDirectEditManager(final Request request) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + @Override + public void run() { + if (isActive() && isEditable()) { + if (request.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } + else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void refreshVisuals() { + super.refreshVisuals(); + refreshLabel(); + refreshFont(); + refreshFontColor(); + refreshUnderline(); + refreshStrikeThrough(); + } + + /** + * @generated + */ + protected void refreshLabel() { + EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); + if (maskLabelPolicy == null) { + maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); + } + if (maskLabelPolicy == null) { + View view = (View) getModel(); + if (view.isVisible()) { + setLabelTextHelper(getFigure(), getLabelText()); + setLabelIconHelper(getFigure(), getLabelIcon()); + } + else { + setLabelTextHelper(getFigure(), ""); //$NON-NLS-1$ + setLabelIconHelper(getFigure(), null); + } + } + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + protected void refreshUnderline() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); + } + if (resolveSemanticElement() instanceof Feature) { + if (((Feature) resolveSemanticElement()).isStatic()) { + ((WrappingLabel) getFigure()).setTextUnderline(true); + } + else { + ((WrappingLabel) getFigure()).setTextUnderline(false); + } + } + } + + /** + * @generated + */ + protected void refreshStrikeThrough() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); + } + } + + /** + * @generated + */ + @Override + protected void refreshFont() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null) { + FontData fontData = new FontData( + style.getFontName(), style.getFontHeight(), + (style.isBold() ? SWT.BOLD : SWT.NORMAL) | + (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); + setFont(fontData); + } + } + + /** + * @generated + */ + @Override + protected void setFontColor(Color color) { + getFigure().setForegroundColor(color); + } + + /** + * @generated + */ + @Override + protected void addSemanticListeners() { + if (getParser() instanceof ISemanticParser) { + EObject element = resolveSemanticElement(); + parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); + for (int i = 0; i < parserElements.size(); i++) { + addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ + } + } else { + super.addSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected void removeSemanticListeners() { + if (parserElements != null) { + for (int i = 0; i < parserElements.size(); i++) { + removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ + } + } else { + super.removeSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected AccessibleEditPart getAccessibleEditPart() { + if (accessibleEP == null) { + accessibleEP = new AccessibleGraphicalEditPart() { + + @Override + public void getName(AccessibleEvent e) { + e.result = getLabelTextHelper(getFigure()); + } + }; + } + return accessibleEP; + } + + /** + * @generated + */ + private View getFontStyleOwnerView() { + return getPrimaryView(); + } + + /** + * Returns the kind of associated editor for direct edition. + * + * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition + * @generated + */ + public int getDirectEditionType() { + if (checkExtendedEditor()) { + initExtendedEditorConfiguration(); + return IDirectEdition.EXTENDED_DIRECT_EDITOR; + } + if (checkDefaultEdition()) { + return IDirectEdition.DEFAULT_DIRECT_EDITOR; + } + + // not a named element. no specific editor => do nothing + return IDirectEdition.NO_DIRECT_EDITION; + } + + /** + * Checks if an extended editor is present. + * + * @return true if an extended editor is present. + * @generated + */ + protected boolean checkExtendedEditor() { + if (resolveSemanticElement() != null) { + return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); + } + return false; + } + + /** + * Checks if a default direct edition is available + * + * @return true if a default direct edition is available + * @generated + */ + protected boolean checkDefaultEdition() { + return (getParser() != null); + } + + /** + * Initializes the extended editor configuration + * + * @generated + */ + protected void initExtendedEditorConfiguration() { + if (configuration == null) { + final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("")) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); + } else { + configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); + } + } + } + + /** + * Updates the preference configuration + * + * @generated + */ + protected void updateExtendedEditorConfiguration() { + String languagePreferred = Activator.getDefault().getPreferenceStore().getString( + IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() + .eClass().getInstanceClassName()); + } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { + configuration = null; + } + } + + /** + * Performs the direct edit usually used by GMF editors. + * + * @param theRequest + * the direct edit request that starts the direct edit system + * @generated + */ + protected void performDefaultDirectEditorEdit(final Request theRequest) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + + @Override + public void run() { + if (isActive() && isEditable()) { + if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) theRequest.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { + DirectEditRequest editRequest = (DirectEditRequest) theRequest; + performDirectEdit(editRequest.getLocation()); + } else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + + /** + * @generated + */ + @Override + protected void handleNotificationEvent(Notification event) { + Object feature = event.getFeature(); + if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { + Integer c = (Integer) event.getNewValue(); + setFontColor(DiagramColorRegistry.getInstance().getColor(c)); + } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { + refreshUnderline(); + } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { + refreshStrikeThrough(); + } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { + refreshFont(); + } else { + if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { + refreshLabel(); + } + if (getParser() instanceof ISemanticParser) { + ISemanticParser modelParser = + (ISemanticParser) getParser(); + if (modelParser.areSemanticElementsAffected(null, event)) { + removeSemanticListeners(); + if (resolveSemanticElement() != null) { + addSemanticListeners(); + } + refreshLabel(); + } + } + } + super.handleNotificationEvent(event); + } + + /** + * @generated + */ + @Override + protected IFigure createFigure() { + IFigure label = createFigurePrim(); + defaultText = getLabelTextHelper(label); + return label; + } + + /** + * @generated + */ + protected IFigure createFigurePrim() { + return new PapyrusWrappingLabel(); + } + +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/StateMachineCompositeNameEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/StateMachineCompositeNameEditPart.java index 791865fd53b..0d33f03866a 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/StateMachineCompositeNameEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/StateMachineCompositeNameEditPart.java @@ -864,7 +864,7 @@ public class StateMachineCompositeNameEditPart extends PapyrusCompartmentEditPar * @generated */ protected void addOwnerElementListeners() { - addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); + addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/StateMachineCompositeNameEditPartCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/StateMachineCompositeNameEditPartCN.java index 0369c5e288a..2d570561832 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/StateMachineCompositeNameEditPartCN.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/StateMachineCompositeNameEditPartCN.java @@ -864,7 +864,7 @@ public class StateMachineCompositeNameEditPartCN extends PapyrusCompartmentEditP * @generated */ protected void addOwnerElementListeners() { - addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); + addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/StringExpressionEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/StringExpressionEditPart.java index 533006860ea..ce477d5ebae 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/StringExpressionEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/StringExpressionEditPart.java @@ -11,27 +11,40 @@ */ package org.eclipse.papyrus.uml.diagram.composite.edit.parts; +import java.util.Collections; +import java.util.List; + import org.eclipse.draw2d.IFigure; +import org.eclipse.emf.common.notify.Notification; import org.eclipse.gef.EditPart; import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.GraphicalEditPart; 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.handles.MoveHandle; import org.eclipse.gef.requests.CreateRequest; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.BorderItemSelectionEditPolicy; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles; +import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; -import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure; import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure; +import org.eclipse.gmf.runtime.notation.Edge; +import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.gmf.runtime.notation.View; -import org.eclipse.papyrus.infra.gmfdiag.common.editpart.NodeEditPart; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.GetChildLayoutEditPolicy; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.IPapyrusNodeFigure; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.RoundedRectangleNodePlateFigure; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.SelectableBorderedNodeFigure; +import org.eclipse.papyrus.uml.diagram.common.editparts.RoundedCompartmentEditPart; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeNodeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.QualifiedNameDisplayEditPolicy; -import org.eclipse.papyrus.uml.diagram.common.figure.node.NodeNamedElementFigure; +import org.eclipse.papyrus.uml.diagram.common.figure.node.RoundedCompartmentFigure; +import org.eclipse.papyrus.uml.diagram.common.locator.RoundedRectangleLabelPositionLocator; import org.eclipse.papyrus.uml.diagram.composite.edit.policies.StringExpressionItemSemanticEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; import org.eclipse.swt.graphics.Color; @@ -39,7 +52,7 @@ import org.eclipse.swt.graphics.Color; /** * @generated */ -public class StringExpressionEditPart extends NodeEditPart { +public class StringExpressionEditPart extends RoundedCompartmentEditPart { /** * @generated @@ -73,6 +86,7 @@ public class StringExpressionEditPart extends NodeEditPart { installEditPolicy(EditPolicy.LAYOUT_ROLE, createLayoutEditPolicy()); installEditPolicy(QualifiedNameDisplayEditPolicy.QUALIFIED_NAME_POLICY, new QualifiedNameDisplayEditPolicy()); installEditPolicy(AppliedStereotypeLabelDisplayEditPolicy.STEREOTYPE_LABEL_POLICY, new AppliedStereotypeNodeLabelDisplayEditPolicy()); + installEditPolicy(EditPolicy.LAYOUT_ROLE, new GetChildLayoutEditPolicy()); // XXX need an SCR to runtime to have another abstract superclass that would let children add reasonable editpolicies // removeEditPolicy(org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles.CONNECTION_HANDLES_ROLE); } @@ -85,6 +99,20 @@ public class StringExpressionEditPart extends NodeEditPart { @Override protected EditPolicy createChildEditPolicy(EditPart child) { + View childView = (View) child.getModel(); + switch (UMLVisualIDRegistry.getVisualID(childView)) { + case StringExpressionFloatingLabelEditPart.VISUAL_ID: + return new BorderItemSelectionEditPolicy() { + + @Override + protected List createSelectionHandles() { + MoveHandle mh = new MoveHandle((GraphicalEditPart) getHost()); + mh.setBorder(null); + return Collections.singletonList(mh); + } + } + ; + } EditPolicy result = child.getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); if (result == null) { result = new NonResizableEditPolicy(); @@ -105,12 +133,36 @@ public class StringExpressionEditPart extends NodeEditPart { return lep; } + /** + * Papyrus codeGen + * + * @generated + **/ + @Override + protected void handleNotificationEvent(Notification event) { + /* + * when a node have external node labels, the methods refreshChildren() remove the EditPart corresponding to the Label from the EditPart + * Registry. After that, we can't reset the visibility to true (using the Show/Hide Label Action)! + */ + if (NotationPackage.eINSTANCE.getView_Visible().equals(event.getFeature())) { + Object notifier = event.getNotifier(); + List modelChildren = ((View) getModel()).getChildren(); + if (!(notifier instanceof Edge)) { + if (modelChildren.contains(event.getNotifier())) { + return; + } + } + } + super.handleNotificationEvent(event); + + } + /** * @generated */ @Override protected IFigure createNodeShape() { - return primaryShape = new NodeNamedElementFigure(); + return primaryShape = new RoundedCompartmentFigure(); } /** @@ -119,8 +171,8 @@ public class StringExpressionEditPart extends NodeEditPart { * @generated */ @Override - public NodeNamedElementFigure getPrimaryShape() { - return (NodeNamedElementFigure) primaryShape; + public RoundedCompartmentFigure getPrimaryShape() { + return (RoundedCompartmentFigure) primaryShape; } /** @@ -173,15 +225,32 @@ public class StringExpressionEditPart extends NodeEditPart { */ @Override protected IFigure getContentPaneFor(IGraphicalEditPart editPart) { + if (editPart instanceof IBorderItemEditPart) { + return getBorderedFigure().getBorderItemContainer(); + } return getContentPane(); } + /** + * @generated + */ + @Override + protected void addBorderItem(IFigure borderItemContainer, IBorderItemEditPart borderItemEditPart) { + if (borderItemEditPart instanceof StringExpressionFloatingLabelEditPart) { + IBorderItemLocator locator = new RoundedRectangleLabelPositionLocator(getMainFigure()); + borderItemContainer.add(borderItemEditPart.getFigure(), locator); + } else + { + super.addBorderItem(borderItemContainer, borderItemEditPart); + } + } + /** * @generated */ @Override protected NodeFigure createNodePlate() { - DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(40, 40); + RoundedRectangleNodePlateFigure result = new RoundedRectangleNodePlateFigure(40, 40); return result; } @@ -194,7 +263,7 @@ public class StringExpressionEditPart extends NodeEditPart { * @generated */ @Override - protected NodeFigure createNodeFigure() { + protected NodeFigure createMainFigure() { return new SelectableBorderedNodeFigure(createMainFigureWithSVG()); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/StringExpressionFloatingLabelEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/StringExpressionFloatingLabelEditPart.java new file mode 100644 index 00000000000..aaaee6f2e1d --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/StringExpressionFloatingLabelEditPart.java @@ -0,0 +1,860 @@ +/** + * 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.uml.diagram.composite.edit.parts; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.Label; +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.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.RunnableWithResult; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gef.AccessibleEditPart; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.Request; +import org.eclipse.gef.requests.DirectEditRequest; +import org.eclipse.gef.tools.DirectEditManager; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; +import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; +import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; +import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; +import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; +import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; +import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; +import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; +import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; +import org.eclipse.gmf.runtime.notation.FontStyle; +import org.eclipse.gmf.runtime.notation.NotationPackage; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.text.contentassist.IContentAssistProcessor; +import org.eclipse.jface.viewers.ICellEditorValidator; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.extensionpoints.editors.Activator; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; +import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; +import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.ExternalLabelPrimaryDragRoleEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.PapyrusWrappingLabel; +import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; +import org.eclipse.papyrus.uml.diagram.common.editparts.FloatingLabelEditPart; +import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; +import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; +import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; +import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.accessibility.AccessibleEvent; +import org.eclipse.swt.custom.BusyIndicator; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; +import org.eclipse.uml2.uml.Feature; + +/** + * @generated + */ +public class StringExpressionFloatingLabelEditPart extends FloatingLabelEditPart + implements ITextAwareEditPart, IBorderItemEditPart +{ + + /** + * @generated + */ + public static final int VISUAL_ID = 6111; + + /** + * @generated + */ + private DirectEditManager manager; + + /** + * @generated + */ + private IParser parser; + + /** + * @generated + */ + private List parserElements; + + /** + * @generated + */ + private String defaultText; + + /** + * direct edition mode (default, undefined, registered editor, etc.) + * + * @generated + */ + protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; + + /** + * configuration from a registered edit dialog + * + * @generated + */ + protected IDirectEditorConfiguration configuration; + + + /** + * @generated + */ + static { + registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.StringExpressionFloatingLabelEditPart.VISUAL_ID), new Point(0, 0)); + } + + /** + * @generated + */ + public StringExpressionFloatingLabelEditPart(View view) { + super(view); + } + + /** + * @generated + */ + @Override + protected void createDefaultEditPolicies() { + super.createDefaultEditPolicies(); + installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); + installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ExternalLabelPrimaryDragRoleEditPolicy()); + } + + /** + * @generated + */ + @Override + public IBorderItemLocator getBorderItemLocator() { + IFigure parentFigure = getFigure().getParent(); + if (parentFigure != null && parentFigure.getLayoutManager() != null) { + Object constraint = parentFigure.getLayoutManager().getConstraint(getFigure()); + return (IBorderItemLocator) constraint; + } + return null; + } + + /** + * @generated + */ + @Override + public void refreshBounds() { + int x = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_X())).intValue(); + int y = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_Y())).intValue(); + int width = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Width())).intValue(); + int height = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Height())).intValue(); + getBorderItemLocator().setConstraint(new Rectangle(x, y, width, height)); + } + + + /** + * @generated + */ + protected String getLabelTextHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getText(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getText(); + } else { + return ((Label) figure).getText(); + } + } + + /** + * @generated + */ + protected void setLabelTextHelper(IFigure figure, String text) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setText(text); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setText(text); + } else { + ((Label) figure).setText(text); + } + } + + /** + * @generated + */ + protected Image getLabelIconHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getIcon(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getIcon(); + } else { + return ((Label) figure).getIcon(); + } + } + + /** + * @generated + */ + protected void setLabelIconHelper(IFigure figure, Image icon) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setIcon(icon); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setIcon(icon); + } else { + ((Label) figure).setIcon(icon); + } + } + + /** + * @generated + */ + public void setLabel(IFigure + figure) { + unregisterVisuals(); + setFigure(figure); + defaultText = getLabelTextHelper(figure); + registerVisuals(); + refreshVisuals(); + } + + /** + * @generated + */ + @Override + protected List getModelChildren() { + return Collections.EMPTY_LIST; + } + + /** + * @generated + */ + @Override + public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { + return null; + } + + /** + * @generated + */ + public void setParser(IParser parser) { + this.parser = parser; + } + + /** + * @generated + */ + protected EObject getParserElement() { + return resolveSemanticElement(); + } + + /** + * @generated + */ + protected Image getLabelIcon() { + return null; + } + + /** + * @generated + */ + protected String getLabelText() { + String text = null; + EObject parserElement = getParserElement(); + if (parserElement != null && getParser() != null) { + text = getParser().getPrintString( + new EObjectAdapter(parserElement), + getParserOptions().intValue()); + } + if (text == null || text.length() == 0) { + text = defaultText; + } + return text; + } + + /** + * @generated + */ + @Override + public void setLabelText(String text) { + setLabelTextHelper(getFigure(), text); + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + @Override + public String getEditText() { + if (getParserElement() == null || getParser() == null) { + return ""; //$NON-NLS-1$ + } + return getParser().getEditString( + new EObjectAdapter(getParserElement()), + getParserOptions().intValue()); + } + + /** + * @generated + */ + protected boolean isEditable() { + return getParser() != null; + } + + /** + * @generated + */ + @Override + public ICellEditorValidator getEditTextValidator() { + return new ICellEditorValidator() { + + @Override + public String isValid(final Object value) { + if (value instanceof String) { + final EObject element = getParserElement(); + final IParser parser = getParser(); + try { + IParserEditStatus valid = + (IParserEditStatus) getEditingDomain().runExclusive( + new RunnableWithResult.Impl() { + + @Override + public void run() { + setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); + } + }); + return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); + } catch (InterruptedException ie) { + ie.printStackTrace(); + } + } + + // shouldn't get here + return null; + } + }; + } + + /** + * @generated + */ + @Override + public IContentAssistProcessor getCompletionProcessor() { + if (getParserElement() == null || getParser() == null) { + return null; + } + return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); + } + + /** + * @generated + */ + @Override + public ParserOptions getParserOptions() { + return ParserOptions.NONE; + } + + /** + * @generated + */ + @Override + public IParser getParser() { + if (parser == null) { + parser = UMLParserProvider.getParser(UMLElementTypes.StringExpression_2100, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.StringExpressionFloatingLabelEditPart.VISUAL_ID)); + } + return parser; + } + + /** + * @generated + */ + protected DirectEditManager getManager() { + if (manager == null) { + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + } + return manager; + } + + /** + * @generated + */ + protected void setManager(DirectEditManager manager) { + this.manager = manager; + } + + /** + * @generated + */ + protected void performDirectEdit() { + BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { + + @Override + public void run() { + getManager().show(); + } + }); + } + + /** + * @generated + */ + protected void performDirectEdit(Point eventLocation) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); + } + } + + /** + * @generated + */ + private void performDirectEdit(char initialCharacter) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(initialCharacter); + } else { + performDirectEdit(); + } + } + + /** + * @generated + */ + @Override + protected void performDirectEditRequest(Request request) { + + final Request theRequest = request; + + if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { + directEditionMode = getDirectEditionType(); + } + switch (directEditionMode) { + case IDirectEdition.NO_DIRECT_EDITION: + // no direct edition mode => does nothing + return; + case IDirectEdition.EXTENDED_DIRECT_EDITOR: + updateExtendedEditorConfiguration(); + if (configuration == null || configuration.getLanguage() == null) { + // Create default edit manager + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + performDefaultDirectEditorEdit(theRequest); + } else { + configuration.preEditAction(resolveSemanticElement()); + Dialog dialog = null; + if (configuration instanceof ICustomDirectEditorConfiguration) { + setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); + initializeDirectEditManager(theRequest); + return; + } else if (configuration instanceof IPopupEditorConfiguration) { + IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); + helper.showEditor(); + return; + } + else if (configuration instanceof IAdvancedEditorConfiguration) { + dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); + } else if (configuration instanceof IDirectEditorConfiguration) { + dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), + configuration); + } else { + return; + } + final Dialog finalDialog = dialog; + + if (Window.OK == dialog.open()) { + TransactionalEditingDomain domain = getEditingDomain(); + RecordingCommand command = new RecordingCommand(domain, "Edit Label") { + + @Override + protected void doExecute() { + configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); + + } + }; + domain.getCommandStack().execute(command); + } + } + break; + case IDirectEdition.DEFAULT_DIRECT_EDITOR: + initializeDirectEditManager(theRequest); + break; + default: + break; + } + } + + /** + * @generated + */ + protected void initializeDirectEditManager(final Request request) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + @Override + public void run() { + if (isActive() && isEditable()) { + if (request.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } + else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void refreshVisuals() { + super.refreshVisuals(); + refreshLabel(); + refreshFont(); + refreshFontColor(); + refreshUnderline(); + refreshStrikeThrough(); + } + + /** + * @generated + */ + protected void refreshLabel() { + EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); + if (maskLabelPolicy == null) { + maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); + } + if (maskLabelPolicy == null) { + View view = (View) getModel(); + if (view.isVisible()) { + setLabelTextHelper(getFigure(), getLabelText()); + setLabelIconHelper(getFigure(), getLabelIcon()); + } + else { + setLabelTextHelper(getFigure(), ""); //$NON-NLS-1$ + setLabelIconHelper(getFigure(), null); + } + } + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + protected void refreshUnderline() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); + } + if (resolveSemanticElement() instanceof Feature) { + if (((Feature) resolveSemanticElement()).isStatic()) { + ((WrappingLabel) getFigure()).setTextUnderline(true); + } + else { + ((WrappingLabel) getFigure()).setTextUnderline(false); + } + } + } + + /** + * @generated + */ + protected void refreshStrikeThrough() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); + } + } + + /** + * @generated + */ + @Override + protected void refreshFont() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null) { + FontData fontData = new FontData( + style.getFontName(), style.getFontHeight(), + (style.isBold() ? SWT.BOLD : SWT.NORMAL) | + (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); + setFont(fontData); + } + } + + /** + * @generated + */ + @Override + protected void setFontColor(Color color) { + getFigure().setForegroundColor(color); + } + + /** + * @generated + */ + @Override + protected void addSemanticListeners() { + if (getParser() instanceof ISemanticParser) { + EObject element = resolveSemanticElement(); + parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); + for (int i = 0; i < parserElements.size(); i++) { + addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ + } + } else { + super.addSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected void removeSemanticListeners() { + if (parserElements != null) { + for (int i = 0; i < parserElements.size(); i++) { + removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ + } + } else { + super.removeSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected AccessibleEditPart getAccessibleEditPart() { + if (accessibleEP == null) { + accessibleEP = new AccessibleGraphicalEditPart() { + + @Override + public void getName(AccessibleEvent e) { + e.result = getLabelTextHelper(getFigure()); + } + }; + } + return accessibleEP; + } + + /** + * @generated + */ + private View getFontStyleOwnerView() { + return getPrimaryView(); + } + + /** + * Returns the kind of associated editor for direct edition. + * + * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition + * @generated + */ + public int getDirectEditionType() { + if (checkExtendedEditor()) { + initExtendedEditorConfiguration(); + return IDirectEdition.EXTENDED_DIRECT_EDITOR; + } + if (checkDefaultEdition()) { + return IDirectEdition.DEFAULT_DIRECT_EDITOR; + } + + // not a named element. no specific editor => do nothing + return IDirectEdition.NO_DIRECT_EDITION; + } + + /** + * Checks if an extended editor is present. + * + * @return true if an extended editor is present. + * @generated + */ + protected boolean checkExtendedEditor() { + if (resolveSemanticElement() != null) { + return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); + } + return false; + } + + /** + * Checks if a default direct edition is available + * + * @return true if a default direct edition is available + * @generated + */ + protected boolean checkDefaultEdition() { + return (getParser() != null); + } + + /** + * Initializes the extended editor configuration + * + * @generated + */ + protected void initExtendedEditorConfiguration() { + if (configuration == null) { + final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("")) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); + } else { + configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); + } + } + } + + /** + * Updates the preference configuration + * + * @generated + */ + protected void updateExtendedEditorConfiguration() { + String languagePreferred = Activator.getDefault().getPreferenceStore().getString( + IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() + .eClass().getInstanceClassName()); + } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { + configuration = null; + } + } + + /** + * Performs the direct edit usually used by GMF editors. + * + * @param theRequest + * the direct edit request that starts the direct edit system + * @generated + */ + protected void performDefaultDirectEditorEdit(final Request theRequest) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + + @Override + public void run() { + if (isActive() && isEditable()) { + if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) theRequest.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { + DirectEditRequest editRequest = (DirectEditRequest) theRequest; + performDirectEdit(editRequest.getLocation()); + } else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + + /** + * @generated + */ + @Override + protected void handleNotificationEvent(Notification event) { + Object feature = event.getFeature(); + if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { + Integer c = (Integer) event.getNewValue(); + setFontColor(DiagramColorRegistry.getInstance().getColor(c)); + } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { + refreshUnderline(); + } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { + refreshStrikeThrough(); + } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { + refreshFont(); + } else { + if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { + refreshLabel(); + } + if (getParser() instanceof ISemanticParser) { + ISemanticParser modelParser = + (ISemanticParser) getParser(); + if (modelParser.areSemanticElementsAffected(null, event)) { + removeSemanticListeners(); + if (resolveSemanticElement() != null) { + addSemanticListeners(); + } + refreshLabel(); + } + } + } + super.handleNotificationEvent(event); + } + + /** + * @generated + */ + @Override + protected IFigure createFigure() { + IFigure label = createFigurePrim(); + defaultText = getLabelTextHelper(label); + return label; + } + + /** + * @generated + */ + protected IFigure createFigurePrim() { + return new PapyrusWrappingLabel(); + } + +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/StringExpressionNameEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/StringExpressionNameEditPart.java index 16620132cee..f1c09b50bea 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/StringExpressionNameEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/StringExpressionNameEditPart.java @@ -864,7 +864,7 @@ public class StringExpressionNameEditPart extends PapyrusCompartmentEditPart imp * @generated */ protected void addOwnerElementListeners() { - addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); + addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/SubstitutionAppliedStereotypeEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/SubstitutionAppliedStereotypeEditPart.java index 64753af0281..85ff965bf5d 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/SubstitutionAppliedStereotypeEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/SubstitutionAppliedStereotypeEditPart.java @@ -1,820 +1,815 @@ -/** - * 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.uml.diagram.composite.edit.parts; - -import java.util.Collections; -import java.util.List; - -import org.eclipse.draw2d.ConnectionLocator; -import org.eclipse.draw2d.IFigure; -import org.eclipse.draw2d.Label; -import org.eclipse.draw2d.geometry.Point; -import org.eclipse.emf.common.notify.Notification; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.transaction.RecordingCommand; -import org.eclipse.emf.transaction.RunnableWithResult; -import org.eclipse.emf.transaction.TransactionalEditingDomain; -import org.eclipse.gef.AccessibleEditPart; -import org.eclipse.gef.EditPolicy; -import org.eclipse.gef.Request; -import org.eclipse.gef.requests.DirectEditRequest; -import org.eclipse.gef.tools.DirectEditManager; -import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; -import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; -import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; -import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; -import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; -import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; -import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; -import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; -import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; -import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; -import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; -import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; -import org.eclipse.gmf.runtime.notation.FontStyle; -import org.eclipse.gmf.runtime.notation.NotationPackage; -import org.eclipse.gmf.runtime.notation.View; -import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.jface.text.contentassist.IContentAssistProcessor; -import org.eclipse.jface.viewers.ICellEditorValidator; -import org.eclipse.jface.window.Window; -import org.eclipse.papyrus.extensionpoints.editors.Activator; -import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; -import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; -import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; -import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; -import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; -import org.eclipse.papyrus.infra.gmfdiag.common.editpart.IControlParserForDirectEdit; -import org.eclipse.papyrus.infra.gmfdiag.common.editpart.PapyrusLabelEditPart; -import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; -import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; -import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.PapyrusLinkLabelDragPolicy; -import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; -import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; -import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; -import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; -import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; -import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; -import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; -import org.eclipse.swt.SWT; -import org.eclipse.swt.accessibility.AccessibleEvent; -import org.eclipse.swt.custom.BusyIndicator; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.FontData; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.widgets.Display; -import org.eclipse.ui.PlatformUI; -import org.eclipse.uml2.uml.Feature; - -/** - * @generated - */ -public class SubstitutionAppliedStereotypeEditPart extends PapyrusLabelEditPart implements ITextAwareEditPart, IControlParserForDirectEdit { - - /** - * @generated - */ - public static final int VISUAL_ID = 6017; - - /** - * @generated - */ - private DirectEditManager manager; - - /** - * @generated - */ - private IParser parser; - - /** - * @generated - */ - private List parserElements; - - /** - * @generated - */ - private String defaultText; - - /** - * direct edition mode (default, undefined, registered editor, etc.) - * - * @generated - */ - protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; - - /** - * configuration from a registered edit dialog - * - * @generated - */ - protected IDirectEditorConfiguration configuration; - /** - * @generated - */ - static { - registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.SubstitutionAppliedStereotypeEditPart.VISUAL_ID), new Point(0, 30)); - } - - /** - * @generated - */ - public SubstitutionAppliedStereotypeEditPart(View view) { - super(view); - } - - /** - * @generated - */ - @Override - protected void createDefaultEditPolicies() { - super.createDefaultEditPolicies(); - installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); - installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); - installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new PapyrusLinkLabelDragPolicy()); - } - - /** - * @generated - */ - @Override - public int getKeyPoint() { - return ConnectionLocator.MIDDLE; - } - - /** - * @generated - */ - protected String getLabelTextHelper(IFigure figure) { - if (figure instanceof WrappingLabel) { - return ((WrappingLabel) figure).getText(); - } else if (figure instanceof ILabelFigure) { - return ((ILabelFigure) figure).getText(); - } else { - return ((Label) figure).getText(); - } - } - - /** - * @generated - */ - protected void setLabelTextHelper(IFigure figure, String text) { - if (figure instanceof WrappingLabel) { - ((WrappingLabel) figure).setText(text); - } else if (figure instanceof ILabelFigure) { - ((ILabelFigure) figure).setText(text); - } else { - ((Label) figure).setText(text); - } - } - - /** - * @generated - */ - protected Image getLabelIconHelper(IFigure figure) { - if (figure instanceof WrappingLabel) { - return ((WrappingLabel) figure).getIcon(); - } else if (figure instanceof ILabelFigure) { - return ((ILabelFigure) figure).getIcon(); - } else { - return ((Label) figure).getIcon(); - } - } - - /** - * @generated - */ - protected void setLabelIconHelper(IFigure figure, Image icon) { - if (figure instanceof WrappingLabel) { - ((WrappingLabel) figure).setIcon(icon); - } else if (figure instanceof ILabelFigure) { - ((ILabelFigure) figure).setIcon(icon); - } else { - ((Label) figure).setIcon(icon); - } - } - - /** - * @generated - */ - public void setLabel(IFigure - figure) { - unregisterVisuals(); - setFigure(figure); - defaultText = getLabelTextHelper(figure); - registerVisuals(); - refreshVisuals(); - } - - /** - * @generated - */ - @Override - protected List getModelChildren() { - return Collections.EMPTY_LIST; - } - - /** - * @generated - */ - @Override - public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { - return null; - } - - /** - * @generated - */ - @Override - public void setParser(IParser parser) { - this.parser = parser; - } - - /** - * @generated - */ - protected EObject getParserElement() { - return resolveSemanticElement(); - } - - /** - * @generated - */ - protected Image getLabelIcon() { - return null; - } - - /** - * @generated - */ - protected String getLabelText() { - String text = null; - EObject parserElement = getParserElement(); - if (parserElement != null && getParser() != null) { - text = getParser().getPrintString( - new EObjectAdapter(parserElement), - getParserOptions().intValue()); - } - if (text == null || text.length() == 0) { - text = defaultText; - } - return text; - } - - /** - * @generated - */ - @Override - public void setLabelText(String text) { - setLabelTextHelper(getFigure(), text); - Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); - if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); - } - Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); - if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); - } - } - - /** - * @generated - */ - @Override - public String getEditText() { - if (getParserElement() == null || getParser() == null) { - return ""; //$NON-NLS-1$ - } - return getParser().getEditString( - new EObjectAdapter(getParserElement()), - getParserOptions().intValue()); - } - - /** - * @generated - */ - protected boolean isEditable() { - return false; - } - - /** - * @generated - */ - @Override - public ICellEditorValidator getEditTextValidator() { - return new ICellEditorValidator() { - - @Override - public String isValid(final Object value) { - if (value instanceof String) { - final EObject element = getParserElement(); - final IParser parser = getParser(); - try { - IParserEditStatus valid = - (IParserEditStatus) getEditingDomain().runExclusive( - new RunnableWithResult.Impl() { - - @Override - public void run() { - setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); - } - }); - return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); - } catch (InterruptedException ie) { - ie.printStackTrace(); - } - } - - // shouldn't get here - return null; - } - }; - } - - /** - * @generated - */ - @Override - public IContentAssistProcessor getCompletionProcessor() { - if (getParserElement() == null || getParser() == null) { - return null; - } - return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); - } - - /** - * @generated - */ - @Override - public ParserOptions getParserOptions() { - return ParserOptions.NONE; - } - - /** - * @generated - */ - @Override - public IParser getParser() { - if (parser == null) { - parser = UMLParserProvider.getParser(UMLElementTypes.Substitution_4011, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.SubstitutionAppliedStereotypeEditPart.VISUAL_ID)); - } - return parser; - } - - /** - * @generated - */ - protected DirectEditManager getManager() { - if (manager == null) { - setManager(new MultilineLabelDirectEditManager(this, - MultilineLabelDirectEditManager.getTextCellEditorClass(this), - UMLEditPartFactory.getTextCellEditorLocator(this))); - } - return manager; - } - - /** - * @generated - */ - protected void setManager(DirectEditManager manager) { - this.manager = manager; - } - - /** - * @generated - */ - protected void performDirectEdit() { - BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { - - @Override - public void run() { - getManager().show(); - } - }); - } - - /** - * @generated - */ - protected void performDirectEdit(Point eventLocation) { - if (getManager() instanceof TextDirectEditManager) { - ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); - } - } - - /** - * @generated - */ - private void performDirectEdit(char initialCharacter) { - if (getManager() instanceof TextDirectEditManager) { - ((TextDirectEditManager) getManager()).show(initialCharacter); - } else { - performDirectEdit(); - } - } - - /** - * @generated - */ - @Override - protected void performDirectEditRequest(Request request) { - - final Request theRequest = request; - - if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { - directEditionMode = getDirectEditionType(); - } - switch (directEditionMode) { - case IDirectEdition.NO_DIRECT_EDITION: - // no direct edition mode => does nothing - return; - case IDirectEdition.EXTENDED_DIRECT_EDITOR: - updateExtendedEditorConfiguration(); - if (configuration == null || configuration.getLanguage() == null) { - // Create default edit manager - setManager(new MultilineLabelDirectEditManager(this, - MultilineLabelDirectEditManager.getTextCellEditorClass(this), - UMLEditPartFactory.getTextCellEditorLocator(this))); - performDefaultDirectEditorEdit(theRequest); - } else { - configuration.preEditAction(resolveSemanticElement()); - Dialog dialog = null; - if (configuration instanceof ICustomDirectEditorConfiguration) { - setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); - initializeDirectEditManager(theRequest); - return; - } else if (configuration instanceof IPopupEditorConfiguration) { - IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); - helper.showEditor(); - return; - } - else if (configuration instanceof IAdvancedEditorConfiguration) { - dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); - } else if (configuration instanceof IDirectEditorConfiguration) { - dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), - configuration); - } else { - return; - } - final Dialog finalDialog = dialog; - - if (Window.OK == dialog.open()) { - TransactionalEditingDomain domain = getEditingDomain(); - RecordingCommand command = new RecordingCommand(domain, "Edit Label") { - - @Override - protected void doExecute() { - configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); - - } - }; - domain.getCommandStack().execute(command); - } - } - break; - case IDirectEdition.DEFAULT_DIRECT_EDITOR: - initializeDirectEditManager(theRequest); - break; - default: - break; - } - } - - /** - * @generated - */ - protected void initializeDirectEditManager(final Request request) { - // initialize the direct edit manager - try { - getEditingDomain().runExclusive(new Runnable() { - @Override - public void run() { - if (isActive() && isEditable()) { - if (request.getExtendedData().get( - RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { - Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); - performDirectEdit(initialChar.charValue()); - } - else { - performDirectEdit(); - } - } - } - }); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - - /** - * @generated - */ - @Override - protected void refreshVisuals() { - super.refreshVisuals(); - refreshLabel(); - refreshFont(); - refreshFontColor(); - refreshUnderline(); - refreshStrikeThrough(); - } - - /** - * @generated - */ - protected void refreshLabel() { - EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); - if (maskLabelPolicy == null) { - maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); - } - if (maskLabelPolicy == null) { - View view = (View) getModel(); - if (view.isVisible()) { - setLabelTextHelper(getFigure(), getLabelText()); - setLabelIconHelper(getFigure(), getLabelIcon()); - } - else { - setLabelTextHelper(getFigure(), ""); //$NON-NLS-1$ - setLabelIconHelper(getFigure(), null); - } - } - Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); - if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); - } - Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); - if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); - } - } - - /** - * @generated - */ - protected void refreshUnderline() { - FontStyle style = - (FontStyle) getFontStyleOwnerView().getStyle( - NotationPackage.eINSTANCE.getFontStyle()); - if (style != null && getFigure() instanceof WrappingLabel) { - ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); - } - if (resolveSemanticElement() instanceof Feature) { - if (((Feature) resolveSemanticElement()).isStatic()) { - ((WrappingLabel) getFigure()).setTextUnderline(true); - } - else { - ((WrappingLabel) getFigure()).setTextUnderline(false); - } - } - } - - /** - * @generated - */ - protected void refreshStrikeThrough() { - FontStyle style = - (FontStyle) getFontStyleOwnerView().getStyle( - NotationPackage.eINSTANCE.getFontStyle()); - if (style != null && getFigure() instanceof WrappingLabel) { - ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); - } - } - - /** - * @generated - */ - @Override - protected void refreshFont() { - FontStyle style = - (FontStyle) getFontStyleOwnerView().getStyle( - NotationPackage.eINSTANCE.getFontStyle()); - if (style != null) { - FontData fontData = new FontData( - style.getFontName(), style.getFontHeight(), - (style.isBold() ? SWT.BOLD : SWT.NORMAL) | - (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); - setFont(fontData); - } - } - - /** - * @generated - */ - @Override - protected void setFontColor(Color color) { - getFigure().setForegroundColor(color); - } - - /** - * @generated - */ - @Override - protected void addSemanticListeners() { - if (getParser() instanceof ISemanticParser) { - EObject element = resolveSemanticElement(); - parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); - for (int i = 0; i < parserElements.size(); i++) { - addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ - } - } else { - super.addSemanticListeners(); - } - } - - /** - * @generated - */ - @Override - protected void removeSemanticListeners() { - if (parserElements != null) { - for (int i = 0; i < parserElements.size(); i++) { - removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ - } - } else { - super.removeSemanticListeners(); - } - } - - /** - * @generated - */ - @Override - protected AccessibleEditPart getAccessibleEditPart() { - if (accessibleEP == null) { - accessibleEP = new AccessibleGraphicalEditPart() { - - @Override - public void getName(AccessibleEvent e) { - e.result = getLabelTextHelper(getFigure()); - } - }; - } - return accessibleEP; - } - - /** - * @generated - */ - private View getFontStyleOwnerView() { - return getPrimaryView(); - } - - /** - * Returns the kind of associated editor for direct edition. - * - * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition - * @generated - */ - public int getDirectEditionType() { - // The label is read-only (defined in GMFGen model) - return IDirectEdition.NO_DIRECT_EDITION; - } - - /** - * Checks if an extended editor is present. - * - * @return true if an extended editor is present. - * @generated - */ - protected boolean checkExtendedEditor() { - if (resolveSemanticElement() != null) { - return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); - } - return false; - } - - /** - * Checks if a default direct edition is available - * - * @return true if a default direct edition is available - * @generated - */ - protected boolean checkDefaultEdition() { - return (getParser() != null); - } - - /** - * Initializes the extended editor configuration - * - * @generated - */ - protected void initExtendedEditorConfiguration() { - if (configuration == null) { - final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); - if (languagePreferred != null && !languagePreferred.equals("")) { - configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); - } else { - configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); - } - } - } - - /** - * Updates the preference configuration - * - * @generated - */ - protected void updateExtendedEditorConfiguration() { - String languagePreferred = Activator.getDefault().getPreferenceStore().getString( - IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); - if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { - configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() - .eClass().getInstanceClassName()); - } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { - configuration = null; - } - } - - /** - * Performs the direct edit usually used by GMF editors. - * - * @param theRequest - * the direct edit request that starts the direct edit system - * @generated - */ - protected void performDefaultDirectEditorEdit(final Request theRequest) { - // initialize the direct edit manager - try { - getEditingDomain().runExclusive(new Runnable() { - - @Override - public void run() { - if (isActive() && isEditable()) { - if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { - Character initialChar = (Character) theRequest.getExtendedData().get( - RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); - performDirectEdit(initialChar.charValue()); - } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { - DirectEditRequest editRequest = (DirectEditRequest) theRequest; - performDirectEdit(editRequest.getLocation()); - } else { - performDirectEdit(); - } - } - } - }); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - - /** - * @generated - */ - @Override - protected void handleNotificationEvent(Notification event) { - Object feature = event.getFeature(); - if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { - Integer c = (Integer) event.getNewValue(); - setFontColor(DiagramColorRegistry.getInstance().getColor(c)); - } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { - refreshUnderline(); - } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { - refreshStrikeThrough(); - } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || - NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || - NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || - NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { - refreshFont(); - } else { - if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { - refreshLabel(); - } - if (getParser() instanceof ISemanticParser) { - ISemanticParser modelParser = - (ISemanticParser) getParser(); - if (modelParser.areSemanticElementsAffected(null, event)) { - removeSemanticListeners(); - if (resolveSemanticElement() != null) { - addSemanticListeners(); - } - refreshLabel(); - } - } - } - - super.handleNotificationEvent(event); - } - - /** - * @generated - */ - @Override - protected IFigure createFigure() { - // Parent should assign one using setLabel() method - return 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.uml.diagram.composite.edit.parts; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.draw2d.ConnectionLocator; +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.Label; +import org.eclipse.draw2d.geometry.Point; +import org.eclipse.emf.common.notify.Notification; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.RunnableWithResult; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gef.AccessibleEditPart; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.Request; +import org.eclipse.gef.requests.DirectEditRequest; +import org.eclipse.gef.tools.DirectEditManager; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; +import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; +import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; +import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; +import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; +import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; +import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; +import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; +import org.eclipse.gmf.runtime.notation.FontStyle; +import org.eclipse.gmf.runtime.notation.NotationPackage; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.gmf.tooling.runtime.edit.policies.DefaultLinkLabelDragPolicy; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.text.contentassist.IContentAssistProcessor; +import org.eclipse.jface.viewers.ICellEditorValidator; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.extensionpoints.editors.Activator; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; +import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; +import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; +import org.eclipse.papyrus.infra.gmfdiag.common.editpart.IControlParserForDirectEdit; +import org.eclipse.papyrus.infra.gmfdiag.common.editpart.PapyrusLabelEditPart; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.PapyrusLinkLabelDragPolicy; +import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; +import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; +import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; +import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; +import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.accessibility.AccessibleEvent; +import org.eclipse.swt.custom.BusyIndicator; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; +import org.eclipse.uml2.uml.Feature; + +/** + * @generated + */ +public class SubstitutionAppliedStereotypeEditPart extends PapyrusLabelEditPart implements ITextAwareEditPart, IControlParserForDirectEdit { + + /** + * @generated + */ + public static final int VISUAL_ID = 6017; + + /** + * @generated + */ + private DirectEditManager manager; + + /** + * @generated + */ + private IParser parser; + + /** + * @generated + */ + private List parserElements; + + /** + * @generated + */ + private String defaultText; + + /** + * direct edition mode (default, undefined, registered editor, etc.) + * + * @generated + */ + protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; + + /** + * configuration from a registered edit dialog + * + * @generated + */ + protected IDirectEditorConfiguration configuration; + /** + * @generated + */ + static { + registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.SubstitutionAppliedStereotypeEditPart.VISUAL_ID), new Point(0, 30)); + } + + /** + * @generated + */ + public SubstitutionAppliedStereotypeEditPart(View view) { + super(view); + } + + /** + * @generated + */ + @Override + protected void createDefaultEditPolicies() { + super.createDefaultEditPolicies(); + installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); + installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new DefaultLinkLabelDragPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new PapyrusLinkLabelDragPolicy()); + } + + /** + * @generated + */ + @Override + public int getKeyPoint() { + return ConnectionLocator.MIDDLE; + } + + /** + * @generated + */ + protected String getLabelTextHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getText(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getText(); + } else { + return ((Label) figure).getText(); + } + } + + /** + * @generated + */ + protected void setLabelTextHelper(IFigure figure, String text) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setText(text); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setText(text); + } else { + ((Label) figure).setText(text); + } + } + + /** + * @generated + */ + protected Image getLabelIconHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getIcon(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getIcon(); + } else { + return ((Label) figure).getIcon(); + } + } + + /** + * @generated + */ + protected void setLabelIconHelper(IFigure figure, Image icon) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setIcon(icon); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setIcon(icon); + } else { + ((Label) figure).setIcon(icon); + } + } + + /** + * @generated + */ + public void setLabel(IFigure + figure) { + unregisterVisuals(); + setFigure(figure); + defaultText = getLabelTextHelper(figure); + registerVisuals(); + refreshVisuals(); + } + + /** + * @generated + */ + @Override + protected List getModelChildren() { + return Collections.EMPTY_LIST; + } + + /** + * @generated + */ + @Override + public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { + return null; + } + + /** + * @generated + */ + @Override + public void setParser(IParser parser) { + this.parser = parser; + } + + /** + * @generated + */ + protected EObject getParserElement() { + return resolveSemanticElement(); + } + + /** + * @generated + */ + protected Image getLabelIcon() { + return null; + } + + /** + * @generated + */ + protected String getLabelText() { + String text = null; + EObject parserElement = getParserElement(); + if (parserElement != null && getParser() != null) { + text = getParser().getPrintString( + new EObjectAdapter(parserElement), + getParserOptions().intValue()); + } + if (text == null || text.length() == 0) { + text = defaultText; + } + return text; + } + + /** + * @generated + */ + @Override + public void setLabelText(String text) { + setLabelTextHelper(getFigure(), text); + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + @Override + public String getEditText() { + if (getParserElement() == null || getParser() == null) { + return ""; //$NON-NLS-1$ + } + return getParser().getEditString( + new EObjectAdapter(getParserElement()), + getParserOptions().intValue()); + } + + /** + * @generated + */ + protected boolean isEditable() { + return false; + } + + /** + * @generated + */ + @Override + public ICellEditorValidator getEditTextValidator() { + return new ICellEditorValidator() { + + @Override + public String isValid(final Object value) { + if (value instanceof String) { + final EObject element = getParserElement(); + final IParser parser = getParser(); + try { + IParserEditStatus valid = + (IParserEditStatus) getEditingDomain().runExclusive( + new RunnableWithResult.Impl() { + + @Override + public void run() { + setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); + } + }); + return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); + } catch (InterruptedException ie) { + ie.printStackTrace(); + } + } + + // shouldn't get here + return null; + } + }; + } + + /** + * @generated + */ + @Override + public IContentAssistProcessor getCompletionProcessor() { + if (getParserElement() == null || getParser() == null) { + return null; + } + return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); + } + + /** + * @generated + */ + @Override + public ParserOptions getParserOptions() { + return ParserOptions.NONE; + } + + /** + * @generated + */ + @Override + public IParser getParser() { + if (parser == null) { + parser = UMLParserProvider.getParser(UMLElementTypes.Substitution_4011, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.SubstitutionAppliedStereotypeEditPart.VISUAL_ID)); + } + return parser; + } + + /** + * @generated + */ + protected DirectEditManager getManager() { + if (manager == null) { + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + } + return manager; + } + + /** + * @generated + */ + protected void setManager(DirectEditManager manager) { + this.manager = manager; + } + + /** + * @generated + */ + protected void performDirectEdit() { + BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { + + @Override + public void run() { + getManager().show(); + } + }); + } + + /** + * @generated + */ + protected void performDirectEdit(Point eventLocation) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); + } + } + + /** + * @generated + */ + private void performDirectEdit(char initialCharacter) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(initialCharacter); + } else { + performDirectEdit(); + } + } + + /** + * @generated + */ + @Override + protected void performDirectEditRequest(Request request) { + + final Request theRequest = request; + + if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { + directEditionMode = getDirectEditionType(); + } + switch (directEditionMode) { + case IDirectEdition.NO_DIRECT_EDITION: + // no direct edition mode => does nothing + return; + case IDirectEdition.EXTENDED_DIRECT_EDITOR: + updateExtendedEditorConfiguration(); + if (configuration == null || configuration.getLanguage() == null) { + // Create default edit manager + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + performDefaultDirectEditorEdit(theRequest); + } else { + configuration.preEditAction(resolveSemanticElement()); + Dialog dialog = null; + if (configuration instanceof ICustomDirectEditorConfiguration) { + setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); + initializeDirectEditManager(theRequest); + return; + } else if (configuration instanceof IPopupEditorConfiguration) { + IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); + helper.showEditor(); + return; + } + else if (configuration instanceof IAdvancedEditorConfiguration) { + dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); + } else if (configuration instanceof IDirectEditorConfiguration) { + dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), + configuration); + } else { + return; + } + final Dialog finalDialog = dialog; + + if (Window.OK == dialog.open()) { + TransactionalEditingDomain domain = getEditingDomain(); + RecordingCommand command = new RecordingCommand(domain, "Edit Label") { + + @Override + protected void doExecute() { + configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); + + } + }; + domain.getCommandStack().execute(command); + } + } + break; + case IDirectEdition.DEFAULT_DIRECT_EDITOR: + initializeDirectEditManager(theRequest); + break; + default: + break; + } + } + + /** + * @generated + */ + protected void initializeDirectEditManager(final Request request) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + @Override + public void run() { + if (isActive() && isEditable()) { + if (request.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } + else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void refreshVisuals() { + super.refreshVisuals(); + refreshLabel(); + refreshFont(); + refreshFontColor(); + refreshUnderline(); + refreshStrikeThrough(); + } + + /** + * @generated + */ + protected void refreshLabel() { + EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); + if (maskLabelPolicy == null) { + maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); + } + if (maskLabelPolicy == null) { + setLabelTextHelper(getFigure(), getLabelText()); + setLabelIconHelper(getFigure(), getLabelIcon()); + } + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + protected void refreshUnderline() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); + } + if (resolveSemanticElement() instanceof Feature) { + if (((Feature) resolveSemanticElement()).isStatic()) { + ((WrappingLabel) getFigure()).setTextUnderline(true); + } + else { + ((WrappingLabel) getFigure()).setTextUnderline(false); + } + } + } + + /** + * @generated + */ + protected void refreshStrikeThrough() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); + } + } + + /** + * @generated + */ + @Override + protected void refreshFont() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null) { + FontData fontData = new FontData( + style.getFontName(), style.getFontHeight(), + (style.isBold() ? SWT.BOLD : SWT.NORMAL) | + (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); + setFont(fontData); + } + } + + /** + * @generated + */ + @Override + protected void setFontColor(Color color) { + getFigure().setForegroundColor(color); + } + + /** + * @generated + */ + @Override + protected void addSemanticListeners() { + if (getParser() instanceof ISemanticParser) { + EObject element = resolveSemanticElement(); + parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); + for (int i = 0; i < parserElements.size(); i++) { + addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ + } + } else { + super.addSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected void removeSemanticListeners() { + if (parserElements != null) { + for (int i = 0; i < parserElements.size(); i++) { + removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ + } + } else { + super.removeSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected AccessibleEditPart getAccessibleEditPart() { + if (accessibleEP == null) { + accessibleEP = new AccessibleGraphicalEditPart() { + + @Override + public void getName(AccessibleEvent e) { + e.result = getLabelTextHelper(getFigure()); + } + }; + } + return accessibleEP; + } + + /** + * @generated + */ + private View getFontStyleOwnerView() { + return getPrimaryView(); + } + + /** + * Returns the kind of associated editor for direct edition. + * + * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition + * @generated + */ + public int getDirectEditionType() { + // The label is read-only (defined in GMFGen model) + return IDirectEdition.NO_DIRECT_EDITION; + } + + /** + * Checks if an extended editor is present. + * + * @return true if an extended editor is present. + * @generated + */ + protected boolean checkExtendedEditor() { + if (resolveSemanticElement() != null) { + return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); + } + return false; + } + + /** + * Checks if a default direct edition is available + * + * @return true if a default direct edition is available + * @generated + */ + protected boolean checkDefaultEdition() { + return (getParser() != null); + } + + /** + * Initializes the extended editor configuration + * + * @generated + */ + protected void initExtendedEditorConfiguration() { + if (configuration == null) { + final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("")) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); + } else { + configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); + } + } + } + + /** + * Updates the preference configuration + * + * @generated + */ + protected void updateExtendedEditorConfiguration() { + String languagePreferred = Activator.getDefault().getPreferenceStore().getString( + IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() + .eClass().getInstanceClassName()); + } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { + configuration = null; + } + } + + /** + * Performs the direct edit usually used by GMF editors. + * + * @param theRequest + * the direct edit request that starts the direct edit system + * @generated + */ + protected void performDefaultDirectEditorEdit(final Request theRequest) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + + @Override + public void run() { + if (isActive() && isEditable()) { + if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) theRequest.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { + DirectEditRequest editRequest = (DirectEditRequest) theRequest; + performDirectEdit(editRequest.getLocation()); + } else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void handleNotificationEvent(Notification event) { + Object feature = event.getFeature(); + if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { + Integer c = (Integer) event.getNewValue(); + setFontColor(DiagramColorRegistry.getInstance().getColor(c)); + } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { + refreshUnderline(); + } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { + refreshStrikeThrough(); + } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { + refreshFont(); + } else { + if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { + refreshLabel(); + } + if (getParser() instanceof ISemanticParser) { + ISemanticParser modelParser = + (ISemanticParser) getParser(); + if (modelParser.areSemanticElementsAffected(null, event)) { + removeSemanticListeners(); + if (resolveSemanticElement() != null) { + addSemanticListeners(); + } + refreshLabel(); + } + } + } + + super.handleNotificationEvent(event); + } + + /** + * @generated + */ + @Override + protected IFigure createFigure() { + // Parent should assign one using setLabel() method + return null; + } +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/SubstitutionNameEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/SubstitutionNameEditPart.java index 2f6a291f336..da4f5ca1020 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/SubstitutionNameEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/SubstitutionNameEditPart.java @@ -1,828 +1,823 @@ -/** - * 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.uml.diagram.composite.edit.parts; - -import java.util.Collections; -import java.util.List; - -import org.eclipse.draw2d.ConnectionLocator; -import org.eclipse.draw2d.IFigure; -import org.eclipse.draw2d.Label; -import org.eclipse.draw2d.geometry.Point; -import org.eclipse.emf.common.notify.Notification; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.transaction.RecordingCommand; -import org.eclipse.emf.transaction.RunnableWithResult; -import org.eclipse.emf.transaction.TransactionalEditingDomain; -import org.eclipse.gef.AccessibleEditPart; -import org.eclipse.gef.EditPolicy; -import org.eclipse.gef.Request; -import org.eclipse.gef.requests.DirectEditRequest; -import org.eclipse.gef.tools.DirectEditManager; -import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; -import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; -import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; -import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; -import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; -import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; -import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; -import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; -import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; -import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; -import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; -import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; -import org.eclipse.gmf.runtime.notation.FontStyle; -import org.eclipse.gmf.runtime.notation.NotationPackage; -import org.eclipse.gmf.runtime.notation.View; -import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.jface.text.contentassist.IContentAssistProcessor; -import org.eclipse.jface.viewers.ICellEditorValidator; -import org.eclipse.jface.window.Window; -import org.eclipse.papyrus.extensionpoints.editors.Activator; -import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; -import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; -import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; -import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; -import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; -import org.eclipse.papyrus.infra.gmfdiag.common.editpart.IControlParserForDirectEdit; -import org.eclipse.papyrus.infra.gmfdiag.common.editpart.PapyrusLabelEditPart; -import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; -import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; -import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.PapyrusLinkLabelDragPolicy; -import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; -import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; -import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; -import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; -import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; -import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; -import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; -import org.eclipse.swt.SWT; -import org.eclipse.swt.accessibility.AccessibleEvent; -import org.eclipse.swt.custom.BusyIndicator; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.FontData; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.widgets.Display; -import org.eclipse.ui.PlatformUI; -import org.eclipse.uml2.uml.Feature; - -/** - * @generated - */ -public class SubstitutionNameEditPart extends PapyrusLabelEditPart implements ITextAwareEditPart, IControlParserForDirectEdit { - - /** - * @generated - */ - public static final int VISUAL_ID = 6003; - - /** - * @generated - */ - private DirectEditManager manager; - - /** - * @generated - */ - private IParser parser; - - /** - * @generated - */ - private List parserElements; - - /** - * @generated - */ - private String defaultText; - - /** - * direct edition mode (default, undefined, registered editor, etc.) - * - * @generated - */ - protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; - - /** - * configuration from a registered edit dialog - * - * @generated - */ - protected IDirectEditorConfiguration configuration; - /** - * @generated - */ - static { - registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.SubstitutionNameEditPart.VISUAL_ID), new Point(0, 60)); - } - - /** - * @generated - */ - public SubstitutionNameEditPart(View view) { - super(view); - } - - /** - * @generated - */ - @Override - protected void createDefaultEditPolicies() { - super.createDefaultEditPolicies(); - installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); - installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); - installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new PapyrusLinkLabelDragPolicy()); - } - - /** - * @generated - */ - @Override - public int getKeyPoint() { - return ConnectionLocator.MIDDLE; - } - - /** - * @generated - */ - protected String getLabelTextHelper(IFigure figure) { - if (figure instanceof WrappingLabel) { - return ((WrappingLabel) figure).getText(); - } else if (figure instanceof ILabelFigure) { - return ((ILabelFigure) figure).getText(); - } else { - return ((Label) figure).getText(); - } - } - - /** - * @generated - */ - protected void setLabelTextHelper(IFigure figure, String text) { - if (figure instanceof WrappingLabel) { - ((WrappingLabel) figure).setText(text); - } else if (figure instanceof ILabelFigure) { - ((ILabelFigure) figure).setText(text); - } else { - ((Label) figure).setText(text); - } - } - - /** - * @generated - */ - protected Image getLabelIconHelper(IFigure figure) { - if (figure instanceof WrappingLabel) { - return ((WrappingLabel) figure).getIcon(); - } else if (figure instanceof ILabelFigure) { - return ((ILabelFigure) figure).getIcon(); - } else { - return ((Label) figure).getIcon(); - } - } - - /** - * @generated - */ - protected void setLabelIconHelper(IFigure figure, Image icon) { - if (figure instanceof WrappingLabel) { - ((WrappingLabel) figure).setIcon(icon); - } else if (figure instanceof ILabelFigure) { - ((ILabelFigure) figure).setIcon(icon); - } else { - ((Label) figure).setIcon(icon); - } - } - - /** - * @generated - */ - public void setLabel(IFigure - figure) { - unregisterVisuals(); - setFigure(figure); - defaultText = getLabelTextHelper(figure); - registerVisuals(); - refreshVisuals(); - } - - /** - * @generated - */ - @Override - protected List getModelChildren() { - return Collections.EMPTY_LIST; - } - - /** - * @generated - */ - @Override - public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { - return null; - } - - /** - * @generated - */ - @Override - public void setParser(IParser parser) { - this.parser = parser; - } - - /** - * @generated - */ - protected EObject getParserElement() { - return resolveSemanticElement(); - } - - /** - * @generated - */ - protected Image getLabelIcon() { - return null; - } - - /** - * @generated - */ - protected String getLabelText() { - String text = null; - EObject parserElement = getParserElement(); - if (parserElement != null && getParser() != null) { - text = getParser().getPrintString( - new EObjectAdapter(parserElement), - getParserOptions().intValue()); - } - if (text == null || text.length() == 0) { - text = defaultText; - } - return text; - } - - /** - * @generated - */ - @Override - public void setLabelText(String text) { - setLabelTextHelper(getFigure(), text); - Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); - if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); - } - Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); - if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); - } - } - - /** - * @generated - */ - @Override - public String getEditText() { - if (getParserElement() == null || getParser() == null) { - return ""; //$NON-NLS-1$ - } - return getParser().getEditString( - new EObjectAdapter(getParserElement()), - getParserOptions().intValue()); - } - - /** - * @generated - */ - protected boolean isEditable() { - return getParser() != null; - } - - /** - * @generated - */ - @Override - public ICellEditorValidator getEditTextValidator() { - return new ICellEditorValidator() { - - @Override - public String isValid(final Object value) { - if (value instanceof String) { - final EObject element = getParserElement(); - final IParser parser = getParser(); - try { - IParserEditStatus valid = - (IParserEditStatus) getEditingDomain().runExclusive( - new RunnableWithResult.Impl() { - - @Override - public void run() { - setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); - } - }); - return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); - } catch (InterruptedException ie) { - ie.printStackTrace(); - } - } - - // shouldn't get here - return null; - } - }; - } - - /** - * @generated - */ - @Override - public IContentAssistProcessor getCompletionProcessor() { - if (getParserElement() == null || getParser() == null) { - return null; - } - return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); - } - - /** - * @generated - */ - @Override - public ParserOptions getParserOptions() { - return ParserOptions.NONE; - } - - /** - * @generated - */ - @Override - public IParser getParser() { - if (parser == null) { - parser = UMLParserProvider.getParser(UMLElementTypes.Substitution_4011, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.SubstitutionNameEditPart.VISUAL_ID)); - } - return parser; - } - - /** - * @generated - */ - protected DirectEditManager getManager() { - if (manager == null) { - setManager(new MultilineLabelDirectEditManager(this, - MultilineLabelDirectEditManager.getTextCellEditorClass(this), - UMLEditPartFactory.getTextCellEditorLocator(this))); - } - return manager; - } - - /** - * @generated - */ - protected void setManager(DirectEditManager manager) { - this.manager = manager; - } - - /** - * @generated - */ - protected void performDirectEdit() { - BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { - - @Override - public void run() { - getManager().show(); - } - }); - } - - /** - * @generated - */ - protected void performDirectEdit(Point eventLocation) { - if (getManager() instanceof TextDirectEditManager) { - ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); - } - } - - /** - * @generated - */ - private void performDirectEdit(char initialCharacter) { - if (getManager() instanceof TextDirectEditManager) { - ((TextDirectEditManager) getManager()).show(initialCharacter); - } else { - performDirectEdit(); - } - } - - /** - * @generated - */ - @Override - protected void performDirectEditRequest(Request request) { - - final Request theRequest = request; - - if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { - directEditionMode = getDirectEditionType(); - } - switch (directEditionMode) { - case IDirectEdition.NO_DIRECT_EDITION: - // no direct edition mode => does nothing - return; - case IDirectEdition.EXTENDED_DIRECT_EDITOR: - updateExtendedEditorConfiguration(); - if (configuration == null || configuration.getLanguage() == null) { - // Create default edit manager - setManager(new MultilineLabelDirectEditManager(this, - MultilineLabelDirectEditManager.getTextCellEditorClass(this), - UMLEditPartFactory.getTextCellEditorLocator(this))); - performDefaultDirectEditorEdit(theRequest); - } else { - configuration.preEditAction(resolveSemanticElement()); - Dialog dialog = null; - if (configuration instanceof ICustomDirectEditorConfiguration) { - setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); - initializeDirectEditManager(theRequest); - return; - } else if (configuration instanceof IPopupEditorConfiguration) { - IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); - helper.showEditor(); - return; - } - else if (configuration instanceof IAdvancedEditorConfiguration) { - dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); - } else if (configuration instanceof IDirectEditorConfiguration) { - dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), - configuration); - } else { - return; - } - final Dialog finalDialog = dialog; - - if (Window.OK == dialog.open()) { - TransactionalEditingDomain domain = getEditingDomain(); - RecordingCommand command = new RecordingCommand(domain, "Edit Label") { - - @Override - protected void doExecute() { - configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); - - } - }; - domain.getCommandStack().execute(command); - } - } - break; - case IDirectEdition.DEFAULT_DIRECT_EDITOR: - initializeDirectEditManager(theRequest); - break; - default: - break; - } - } - - /** - * @generated - */ - protected void initializeDirectEditManager(final Request request) { - // initialize the direct edit manager - try { - getEditingDomain().runExclusive(new Runnable() { - @Override - public void run() { - if (isActive() && isEditable()) { - if (request.getExtendedData().get( - RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { - Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); - performDirectEdit(initialChar.charValue()); - } - else { - performDirectEdit(); - } - } - } - }); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - - /** - * @generated - */ - @Override - protected void refreshVisuals() { - super.refreshVisuals(); - refreshLabel(); - refreshFont(); - refreshFontColor(); - refreshUnderline(); - refreshStrikeThrough(); - } - - /** - * @generated - */ - protected void refreshLabel() { - EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); - if (maskLabelPolicy == null) { - maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); - } - if (maskLabelPolicy == null) { - View view = (View) getModel(); - if (view.isVisible()) { - setLabelTextHelper(getFigure(), getLabelText()); - setLabelIconHelper(getFigure(), getLabelIcon()); - } - else { - setLabelTextHelper(getFigure(), ""); //$NON-NLS-1$ - setLabelIconHelper(getFigure(), null); - } - } - Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); - if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); - } - Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); - if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); - } - } - - /** - * @generated - */ - protected void refreshUnderline() { - FontStyle style = - (FontStyle) getFontStyleOwnerView().getStyle( - NotationPackage.eINSTANCE.getFontStyle()); - if (style != null && getFigure() instanceof WrappingLabel) { - ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); - } - if (resolveSemanticElement() instanceof Feature) { - if (((Feature) resolveSemanticElement()).isStatic()) { - ((WrappingLabel) getFigure()).setTextUnderline(true); - } - else { - ((WrappingLabel) getFigure()).setTextUnderline(false); - } - } - } - - /** - * @generated - */ - protected void refreshStrikeThrough() { - FontStyle style = - (FontStyle) getFontStyleOwnerView().getStyle( - NotationPackage.eINSTANCE.getFontStyle()); - if (style != null && getFigure() instanceof WrappingLabel) { - ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); - } - } - - /** - * @generated - */ - @Override - protected void refreshFont() { - FontStyle style = - (FontStyle) getFontStyleOwnerView().getStyle( - NotationPackage.eINSTANCE.getFontStyle()); - if (style != null) { - FontData fontData = new FontData( - style.getFontName(), style.getFontHeight(), - (style.isBold() ? SWT.BOLD : SWT.NORMAL) | - (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); - setFont(fontData); - } - } - - /** - * @generated - */ - @Override - protected void setFontColor(Color color) { - getFigure().setForegroundColor(color); - } - - /** - * @generated - */ - @Override - protected void addSemanticListeners() { - if (getParser() instanceof ISemanticParser) { - EObject element = resolveSemanticElement(); - parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); - for (int i = 0; i < parserElements.size(); i++) { - addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ - } - } else { - super.addSemanticListeners(); - } - } - - /** - * @generated - */ - @Override - protected void removeSemanticListeners() { - if (parserElements != null) { - for (int i = 0; i < parserElements.size(); i++) { - removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ - } - } else { - super.removeSemanticListeners(); - } - } - - /** - * @generated - */ - @Override - protected AccessibleEditPart getAccessibleEditPart() { - if (accessibleEP == null) { - accessibleEP = new AccessibleGraphicalEditPart() { - - @Override - public void getName(AccessibleEvent e) { - e.result = getLabelTextHelper(getFigure()); - } - }; - } - return accessibleEP; - } - - /** - * @generated - */ - private View getFontStyleOwnerView() { - return getPrimaryView(); - } - - /** - * Returns the kind of associated editor for direct edition. - * - * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition - * @generated - */ - public int getDirectEditionType() { - if (checkExtendedEditor()) { - initExtendedEditorConfiguration(); - return IDirectEdition.EXTENDED_DIRECT_EDITOR; - } - if (checkDefaultEdition()) { - return IDirectEdition.DEFAULT_DIRECT_EDITOR; - } - - // not a named element. no specific editor => do nothing - return IDirectEdition.NO_DIRECT_EDITION; - } - - /** - * Checks if an extended editor is present. - * - * @return true if an extended editor is present. - * @generated - */ - protected boolean checkExtendedEditor() { - if (resolveSemanticElement() != null) { - return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); - } - return false; - } - - /** - * Checks if a default direct edition is available - * - * @return true if a default direct edition is available - * @generated - */ - protected boolean checkDefaultEdition() { - return (getParser() != null); - } - - /** - * Initializes the extended editor configuration - * - * @generated - */ - protected void initExtendedEditorConfiguration() { - if (configuration == null) { - final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); - if (languagePreferred != null && !languagePreferred.equals("")) { - configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); - } else { - configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); - } - } - } - - /** - * Updates the preference configuration - * - * @generated - */ - protected void updateExtendedEditorConfiguration() { - String languagePreferred = Activator.getDefault().getPreferenceStore().getString( - IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); - if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { - configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() - .eClass().getInstanceClassName()); - } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { - configuration = null; - } - } - - /** - * Performs the direct edit usually used by GMF editors. - * - * @param theRequest - * the direct edit request that starts the direct edit system - * @generated - */ - protected void performDefaultDirectEditorEdit(final Request theRequest) { - // initialize the direct edit manager - try { - getEditingDomain().runExclusive(new Runnable() { - - @Override - public void run() { - if (isActive() && isEditable()) { - if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { - Character initialChar = (Character) theRequest.getExtendedData().get( - RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); - performDirectEdit(initialChar.charValue()); - } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { - DirectEditRequest editRequest = (DirectEditRequest) theRequest; - performDirectEdit(editRequest.getLocation()); - } else { - performDirectEdit(); - } - } - } - }); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - - /** - * @generated - */ - @Override - protected void handleNotificationEvent(Notification event) { - Object feature = event.getFeature(); - if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { - Integer c = (Integer) event.getNewValue(); - setFontColor(DiagramColorRegistry.getInstance().getColor(c)); - } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { - refreshUnderline(); - } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { - refreshStrikeThrough(); - } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || - NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || - NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || - NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { - refreshFont(); - } else { - if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { - refreshLabel(); - } - if (getParser() instanceof ISemanticParser) { - ISemanticParser modelParser = - (ISemanticParser) getParser(); - if (modelParser.areSemanticElementsAffected(null, event)) { - removeSemanticListeners(); - if (resolveSemanticElement() != null) { - addSemanticListeners(); - } - refreshLabel(); - } - } - } - - super.handleNotificationEvent(event); - } - - /** - * @generated - */ - @Override - protected IFigure createFigure() { - // Parent should assign one using setLabel() method - return 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.uml.diagram.composite.edit.parts; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.draw2d.ConnectionLocator; +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.Label; +import org.eclipse.draw2d.geometry.Point; +import org.eclipse.emf.common.notify.Notification; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.RunnableWithResult; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gef.AccessibleEditPart; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.Request; +import org.eclipse.gef.requests.DirectEditRequest; +import org.eclipse.gef.tools.DirectEditManager; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; +import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; +import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; +import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; +import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; +import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; +import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; +import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; +import org.eclipse.gmf.runtime.notation.FontStyle; +import org.eclipse.gmf.runtime.notation.NotationPackage; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.gmf.tooling.runtime.edit.policies.DefaultLinkLabelDragPolicy; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.text.contentassist.IContentAssistProcessor; +import org.eclipse.jface.viewers.ICellEditorValidator; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.extensionpoints.editors.Activator; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; +import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; +import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; +import org.eclipse.papyrus.infra.gmfdiag.common.editpart.IControlParserForDirectEdit; +import org.eclipse.papyrus.infra.gmfdiag.common.editpart.PapyrusLabelEditPart; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.PapyrusLinkLabelDragPolicy; +import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; +import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; +import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; +import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; +import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.accessibility.AccessibleEvent; +import org.eclipse.swt.custom.BusyIndicator; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; +import org.eclipse.uml2.uml.Feature; + +/** + * @generated + */ +public class SubstitutionNameEditPart extends PapyrusLabelEditPart implements ITextAwareEditPart, IControlParserForDirectEdit { + + /** + * @generated + */ + public static final int VISUAL_ID = 6003; + + /** + * @generated + */ + private DirectEditManager manager; + + /** + * @generated + */ + private IParser parser; + + /** + * @generated + */ + private List parserElements; + + /** + * @generated + */ + private String defaultText; + + /** + * direct edition mode (default, undefined, registered editor, etc.) + * + * @generated + */ + protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; + + /** + * configuration from a registered edit dialog + * + * @generated + */ + protected IDirectEditorConfiguration configuration; + /** + * @generated + */ + static { + registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.SubstitutionNameEditPart.VISUAL_ID), new Point(0, 60)); + } + + /** + * @generated + */ + public SubstitutionNameEditPart(View view) { + super(view); + } + + /** + * @generated + */ + @Override + protected void createDefaultEditPolicies() { + super.createDefaultEditPolicies(); + installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); + installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new DefaultLinkLabelDragPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new PapyrusLinkLabelDragPolicy()); + } + + /** + * @generated + */ + @Override + public int getKeyPoint() { + return ConnectionLocator.MIDDLE; + } + + /** + * @generated + */ + protected String getLabelTextHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getText(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getText(); + } else { + return ((Label) figure).getText(); + } + } + + /** + * @generated + */ + protected void setLabelTextHelper(IFigure figure, String text) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setText(text); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setText(text); + } else { + ((Label) figure).setText(text); + } + } + + /** + * @generated + */ + protected Image getLabelIconHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getIcon(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getIcon(); + } else { + return ((Label) figure).getIcon(); + } + } + + /** + * @generated + */ + protected void setLabelIconHelper(IFigure figure, Image icon) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setIcon(icon); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setIcon(icon); + } else { + ((Label) figure).setIcon(icon); + } + } + + /** + * @generated + */ + public void setLabel(IFigure + figure) { + unregisterVisuals(); + setFigure(figure); + defaultText = getLabelTextHelper(figure); + registerVisuals(); + refreshVisuals(); + } + + /** + * @generated + */ + @Override + protected List getModelChildren() { + return Collections.EMPTY_LIST; + } + + /** + * @generated + */ + @Override + public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { + return null; + } + + /** + * @generated + */ + @Override + public void setParser(IParser parser) { + this.parser = parser; + } + + /** + * @generated + */ + protected EObject getParserElement() { + return resolveSemanticElement(); + } + + /** + * @generated + */ + protected Image getLabelIcon() { + return null; + } + + /** + * @generated + */ + protected String getLabelText() { + String text = null; + EObject parserElement = getParserElement(); + if (parserElement != null && getParser() != null) { + text = getParser().getPrintString( + new EObjectAdapter(parserElement), + getParserOptions().intValue()); + } + if (text == null || text.length() == 0) { + text = defaultText; + } + return text; + } + + /** + * @generated + */ + @Override + public void setLabelText(String text) { + setLabelTextHelper(getFigure(), text); + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + @Override + public String getEditText() { + if (getParserElement() == null || getParser() == null) { + return ""; //$NON-NLS-1$ + } + return getParser().getEditString( + new EObjectAdapter(getParserElement()), + getParserOptions().intValue()); + } + + /** + * @generated + */ + protected boolean isEditable() { + return getParser() != null; + } + + /** + * @generated + */ + @Override + public ICellEditorValidator getEditTextValidator() { + return new ICellEditorValidator() { + + @Override + public String isValid(final Object value) { + if (value instanceof String) { + final EObject element = getParserElement(); + final IParser parser = getParser(); + try { + IParserEditStatus valid = + (IParserEditStatus) getEditingDomain().runExclusive( + new RunnableWithResult.Impl() { + + @Override + public void run() { + setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); + } + }); + return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); + } catch (InterruptedException ie) { + ie.printStackTrace(); + } + } + + // shouldn't get here + return null; + } + }; + } + + /** + * @generated + */ + @Override + public IContentAssistProcessor getCompletionProcessor() { + if (getParserElement() == null || getParser() == null) { + return null; + } + return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); + } + + /** + * @generated + */ + @Override + public ParserOptions getParserOptions() { + return ParserOptions.NONE; + } + + /** + * @generated + */ + @Override + public IParser getParser() { + if (parser == null) { + parser = UMLParserProvider.getParser(UMLElementTypes.Substitution_4011, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.SubstitutionNameEditPart.VISUAL_ID)); + } + return parser; + } + + /** + * @generated + */ + protected DirectEditManager getManager() { + if (manager == null) { + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + } + return manager; + } + + /** + * @generated + */ + protected void setManager(DirectEditManager manager) { + this.manager = manager; + } + + /** + * @generated + */ + protected void performDirectEdit() { + BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { + + @Override + public void run() { + getManager().show(); + } + }); + } + + /** + * @generated + */ + protected void performDirectEdit(Point eventLocation) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); + } + } + + /** + * @generated + */ + private void performDirectEdit(char initialCharacter) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(initialCharacter); + } else { + performDirectEdit(); + } + } + + /** + * @generated + */ + @Override + protected void performDirectEditRequest(Request request) { + + final Request theRequest = request; + + if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { + directEditionMode = getDirectEditionType(); + } + switch (directEditionMode) { + case IDirectEdition.NO_DIRECT_EDITION: + // no direct edition mode => does nothing + return; + case IDirectEdition.EXTENDED_DIRECT_EDITOR: + updateExtendedEditorConfiguration(); + if (configuration == null || configuration.getLanguage() == null) { + // Create default edit manager + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + performDefaultDirectEditorEdit(theRequest); + } else { + configuration.preEditAction(resolveSemanticElement()); + Dialog dialog = null; + if (configuration instanceof ICustomDirectEditorConfiguration) { + setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); + initializeDirectEditManager(theRequest); + return; + } else if (configuration instanceof IPopupEditorConfiguration) { + IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); + helper.showEditor(); + return; + } + else if (configuration instanceof IAdvancedEditorConfiguration) { + dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); + } else if (configuration instanceof IDirectEditorConfiguration) { + dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), + configuration); + } else { + return; + } + final Dialog finalDialog = dialog; + + if (Window.OK == dialog.open()) { + TransactionalEditingDomain domain = getEditingDomain(); + RecordingCommand command = new RecordingCommand(domain, "Edit Label") { + + @Override + protected void doExecute() { + configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); + + } + }; + domain.getCommandStack().execute(command); + } + } + break; + case IDirectEdition.DEFAULT_DIRECT_EDITOR: + initializeDirectEditManager(theRequest); + break; + default: + break; + } + } + + /** + * @generated + */ + protected void initializeDirectEditManager(final Request request) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + @Override + public void run() { + if (isActive() && isEditable()) { + if (request.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } + else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void refreshVisuals() { + super.refreshVisuals(); + refreshLabel(); + refreshFont(); + refreshFontColor(); + refreshUnderline(); + refreshStrikeThrough(); + } + + /** + * @generated + */ + protected void refreshLabel() { + EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); + if (maskLabelPolicy == null) { + maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); + } + if (maskLabelPolicy == null) { + setLabelTextHelper(getFigure(), getLabelText()); + setLabelIconHelper(getFigure(), getLabelIcon()); + } + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + protected void refreshUnderline() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); + } + if (resolveSemanticElement() instanceof Feature) { + if (((Feature) resolveSemanticElement()).isStatic()) { + ((WrappingLabel) getFigure()).setTextUnderline(true); + } + else { + ((WrappingLabel) getFigure()).setTextUnderline(false); + } + } + } + + /** + * @generated + */ + protected void refreshStrikeThrough() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); + } + } + + /** + * @generated + */ + @Override + protected void refreshFont() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null) { + FontData fontData = new FontData( + style.getFontName(), style.getFontHeight(), + (style.isBold() ? SWT.BOLD : SWT.NORMAL) | + (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); + setFont(fontData); + } + } + + /** + * @generated + */ + @Override + protected void setFontColor(Color color) { + getFigure().setForegroundColor(color); + } + + /** + * @generated + */ + @Override + protected void addSemanticListeners() { + if (getParser() instanceof ISemanticParser) { + EObject element = resolveSemanticElement(); + parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); + for (int i = 0; i < parserElements.size(); i++) { + addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ + } + } else { + super.addSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected void removeSemanticListeners() { + if (parserElements != null) { + for (int i = 0; i < parserElements.size(); i++) { + removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ + } + } else { + super.removeSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected AccessibleEditPart getAccessibleEditPart() { + if (accessibleEP == null) { + accessibleEP = new AccessibleGraphicalEditPart() { + + @Override + public void getName(AccessibleEvent e) { + e.result = getLabelTextHelper(getFigure()); + } + }; + } + return accessibleEP; + } + + /** + * @generated + */ + private View getFontStyleOwnerView() { + return getPrimaryView(); + } + + /** + * Returns the kind of associated editor for direct edition. + * + * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition + * @generated + */ + public int getDirectEditionType() { + if (checkExtendedEditor()) { + initExtendedEditorConfiguration(); + return IDirectEdition.EXTENDED_DIRECT_EDITOR; + } + if (checkDefaultEdition()) { + return IDirectEdition.DEFAULT_DIRECT_EDITOR; + } + + // not a named element. no specific editor => do nothing + return IDirectEdition.NO_DIRECT_EDITION; + } + + /** + * Checks if an extended editor is present. + * + * @return true if an extended editor is present. + * @generated + */ + protected boolean checkExtendedEditor() { + if (resolveSemanticElement() != null) { + return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); + } + return false; + } + + /** + * Checks if a default direct edition is available + * + * @return true if a default direct edition is available + * @generated + */ + protected boolean checkDefaultEdition() { + return (getParser() != null); + } + + /** + * Initializes the extended editor configuration + * + * @generated + */ + protected void initExtendedEditorConfiguration() { + if (configuration == null) { + final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("")) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); + } else { + configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); + } + } + } + + /** + * Updates the preference configuration + * + * @generated + */ + protected void updateExtendedEditorConfiguration() { + String languagePreferred = Activator.getDefault().getPreferenceStore().getString( + IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() + .eClass().getInstanceClassName()); + } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { + configuration = null; + } + } + + /** + * Performs the direct edit usually used by GMF editors. + * + * @param theRequest + * the direct edit request that starts the direct edit system + * @generated + */ + protected void performDefaultDirectEditorEdit(final Request theRequest) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + + @Override + public void run() { + if (isActive() && isEditable()) { + if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) theRequest.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { + DirectEditRequest editRequest = (DirectEditRequest) theRequest; + performDirectEdit(editRequest.getLocation()); + } else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void handleNotificationEvent(Notification event) { + Object feature = event.getFeature(); + if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { + Integer c = (Integer) event.getNewValue(); + setFontColor(DiagramColorRegistry.getInstance().getColor(c)); + } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { + refreshUnderline(); + } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { + refreshStrikeThrough(); + } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { + refreshFont(); + } else { + if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { + refreshLabel(); + } + if (getParser() instanceof ISemanticParser) { + ISemanticParser modelParser = + (ISemanticParser) getParser(); + if (modelParser.areSemanticElementsAffected(null, event)) { + removeSemanticListeners(); + if (resolveSemanticElement() != null) { + addSemanticListeners(); + } + refreshLabel(); + } + } + } + + super.handleNotificationEvent(event); + } + + /** + * @generated + */ + @Override + protected IFigure createFigure() { + // Parent should assign one using setLabel() method + return null; + } +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/TimeConstraintEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/TimeConstraintEditPart.java index f9b3ebc24a8..dfa568b1e7c 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/TimeConstraintEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/TimeConstraintEditPart.java @@ -23,10 +23,10 @@ import org.eclipse.gef.requests.CreateRequest; import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles; import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; -import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure; import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure; import org.eclipse.gmf.runtime.notation.View; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.IPapyrusNodeFigure; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.RoundedRectangleNodePlateFigure; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.SelectableBorderedNodeFigure; import org.eclipse.papyrus.uml.diagram.common.editparts.AbstractConstraintEditPart; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeLabelDisplayEditPolicy; @@ -198,7 +198,7 @@ public class TimeConstraintEditPart extends AbstractConstraintEditPart { */ @Override protected NodeFigure createNodePlate() { - DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(40, 40); + RoundedRectangleNodePlateFigure result = new RoundedRectangleNodePlateFigure(40, 40); return result; } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/TimeConstraintEditPartCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/TimeConstraintEditPartCN.java index 3c518c8b340..2c919eafdfc 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/TimeConstraintEditPartCN.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/TimeConstraintEditPartCN.java @@ -23,10 +23,10 @@ import org.eclipse.gef.requests.CreateRequest; import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles; import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; -import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure; import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure; import org.eclipse.gmf.runtime.notation.View; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.IPapyrusNodeFigure; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.RoundedRectangleNodePlateFigure; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.SelectableBorderedNodeFigure; import org.eclipse.papyrus.uml.diagram.common.editparts.AbstractConstraintEditPart; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeLabelDisplayEditPolicy; @@ -198,7 +198,7 @@ public class TimeConstraintEditPartCN extends AbstractConstraintEditPart { */ @Override protected NodeFigure createNodePlate() { - DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(40, 40); + RoundedRectangleNodePlateFigure result = new RoundedRectangleNodePlateFigure(40, 40); return result; } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/TimeConstraintNameEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/TimeConstraintNameEditPart.java index ece93d5a1a6..264548c5210 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/TimeConstraintNameEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/TimeConstraintNameEditPart.java @@ -864,7 +864,7 @@ public class TimeConstraintNameEditPart extends PapyrusCompartmentEditPart imple * @generated */ protected void addOwnerElementListeners() { - addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); + addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/TimeConstraintNameEditPartCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/TimeConstraintNameEditPartCN.java index 75c20cea497..ac128a3ec2a 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/TimeConstraintNameEditPartCN.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/TimeConstraintNameEditPartCN.java @@ -864,7 +864,7 @@ public class TimeConstraintNameEditPartCN extends PapyrusCompartmentEditPart imp * @generated */ protected void addOwnerElementListeners() { - addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); + addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/TimeConstraintSpecificationEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/TimeConstraintSpecificationEditPart.java index ccaa6d1455a..cce51cdba5d 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/TimeConstraintSpecificationEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/TimeConstraintSpecificationEditPart.java @@ -847,7 +847,7 @@ public class TimeConstraintSpecificationEditPart extends PapyrusCompartmentEditP * @generated */ protected void addOwnerElementListeners() { - addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); + addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/TimeConstraintSpecificationEditPartCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/TimeConstraintSpecificationEditPartCN.java index 26ebfd674b3..48e396e5bb1 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/TimeConstraintSpecificationEditPartCN.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/TimeConstraintSpecificationEditPartCN.java @@ -847,7 +847,7 @@ public class TimeConstraintSpecificationEditPartCN extends PapyrusCompartmentEdi * @generated */ protected void addOwnerElementListeners() { - addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); + addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/TimeEventEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/TimeEventEditPart.java index e93ff5ba470..c3bfde2be82 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/TimeEventEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/TimeEventEditPart.java @@ -11,27 +11,40 @@ */ package org.eclipse.papyrus.uml.diagram.composite.edit.parts; +import java.util.Collections; +import java.util.List; + import org.eclipse.draw2d.IFigure; +import org.eclipse.emf.common.notify.Notification; import org.eclipse.gef.EditPart; import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.GraphicalEditPart; 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.handles.MoveHandle; import org.eclipse.gef.requests.CreateRequest; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.BorderItemSelectionEditPolicy; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles; +import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; -import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure; import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure; +import org.eclipse.gmf.runtime.notation.Edge; +import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.gmf.runtime.notation.View; -import org.eclipse.papyrus.infra.gmfdiag.common.editpart.NodeEditPart; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.GetChildLayoutEditPolicy; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.IPapyrusNodeFigure; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.RoundedRectangleNodePlateFigure; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.SelectableBorderedNodeFigure; +import org.eclipse.papyrus.uml.diagram.common.editparts.RoundedCompartmentEditPart; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeNodeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.QualifiedNameDisplayEditPolicy; -import org.eclipse.papyrus.uml.diagram.common.figure.node.NodeNamedElementFigure; +import org.eclipse.papyrus.uml.diagram.common.figure.node.RoundedCompartmentFigure; +import org.eclipse.papyrus.uml.diagram.common.locator.RoundedRectangleLabelPositionLocator; import org.eclipse.papyrus.uml.diagram.composite.edit.policies.TimeEventItemSemanticEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; import org.eclipse.swt.graphics.Color; @@ -39,7 +52,7 @@ import org.eclipse.swt.graphics.Color; /** * @generated */ -public class TimeEventEditPart extends NodeEditPart { +public class TimeEventEditPart extends RoundedCompartmentEditPart { /** * @generated @@ -73,6 +86,7 @@ public class TimeEventEditPart extends NodeEditPart { installEditPolicy(EditPolicy.LAYOUT_ROLE, createLayoutEditPolicy()); installEditPolicy(QualifiedNameDisplayEditPolicy.QUALIFIED_NAME_POLICY, new QualifiedNameDisplayEditPolicy()); installEditPolicy(AppliedStereotypeLabelDisplayEditPolicy.STEREOTYPE_LABEL_POLICY, new AppliedStereotypeNodeLabelDisplayEditPolicy()); + installEditPolicy(EditPolicy.LAYOUT_ROLE, new GetChildLayoutEditPolicy()); // XXX need an SCR to runtime to have another abstract superclass that would let children add reasonable editpolicies // removeEditPolicy(org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles.CONNECTION_HANDLES_ROLE); } @@ -85,6 +99,20 @@ public class TimeEventEditPart extends NodeEditPart { @Override protected EditPolicy createChildEditPolicy(EditPart child) { + View childView = (View) child.getModel(); + switch (UMLVisualIDRegistry.getVisualID(childView)) { + case TimeEventFloatingLabelEditPart.VISUAL_ID: + return new BorderItemSelectionEditPolicy() { + + @Override + protected List createSelectionHandles() { + MoveHandle mh = new MoveHandle((GraphicalEditPart) getHost()); + mh.setBorder(null); + return Collections.singletonList(mh); + } + } + ; + } EditPolicy result = child.getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); if (result == null) { result = new NonResizableEditPolicy(); @@ -105,12 +133,36 @@ public class TimeEventEditPart extends NodeEditPart { return lep; } + /** + * Papyrus codeGen + * + * @generated + **/ + @Override + protected void handleNotificationEvent(Notification event) { + /* + * when a node have external node labels, the methods refreshChildren() remove the EditPart corresponding to the Label from the EditPart + * Registry. After that, we can't reset the visibility to true (using the Show/Hide Label Action)! + */ + if (NotationPackage.eINSTANCE.getView_Visible().equals(event.getFeature())) { + Object notifier = event.getNotifier(); + List modelChildren = ((View) getModel()).getChildren(); + if (!(notifier instanceof Edge)) { + if (modelChildren.contains(event.getNotifier())) { + return; + } + } + } + super.handleNotificationEvent(event); + + } + /** * @generated */ @Override protected IFigure createNodeShape() { - return primaryShape = new NodeNamedElementFigure(); + return primaryShape = new RoundedCompartmentFigure(); } /** @@ -119,8 +171,8 @@ public class TimeEventEditPart extends NodeEditPart { * @generated */ @Override - public NodeNamedElementFigure getPrimaryShape() { - return (NodeNamedElementFigure) primaryShape; + public RoundedCompartmentFigure getPrimaryShape() { + return (RoundedCompartmentFigure) primaryShape; } /** @@ -173,15 +225,32 @@ public class TimeEventEditPart extends NodeEditPart { */ @Override protected IFigure getContentPaneFor(IGraphicalEditPart editPart) { + if (editPart instanceof IBorderItemEditPart) { + return getBorderedFigure().getBorderItemContainer(); + } return getContentPane(); } + /** + * @generated + */ + @Override + protected void addBorderItem(IFigure borderItemContainer, IBorderItemEditPart borderItemEditPart) { + if (borderItemEditPart instanceof TimeEventFloatingLabelEditPart) { + IBorderItemLocator locator = new RoundedRectangleLabelPositionLocator(getMainFigure()); + borderItemContainer.add(borderItemEditPart.getFigure(), locator); + } else + { + super.addBorderItem(borderItemContainer, borderItemEditPart); + } + } + /** * @generated */ @Override protected NodeFigure createNodePlate() { - DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(40, 40); + RoundedRectangleNodePlateFigure result = new RoundedRectangleNodePlateFigure(40, 40); return result; } @@ -194,7 +263,7 @@ public class TimeEventEditPart extends NodeEditPart { * @generated */ @Override - protected NodeFigure createNodeFigure() { + protected NodeFigure createMainFigure() { return new SelectableBorderedNodeFigure(createMainFigureWithSVG()); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/TimeEventFloatingLabelEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/TimeEventFloatingLabelEditPart.java new file mode 100644 index 00000000000..5ce60b15a6a --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/TimeEventFloatingLabelEditPart.java @@ -0,0 +1,860 @@ +/** + * 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.uml.diagram.composite.edit.parts; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.Label; +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.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.RunnableWithResult; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gef.AccessibleEditPart; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.Request; +import org.eclipse.gef.requests.DirectEditRequest; +import org.eclipse.gef.tools.DirectEditManager; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; +import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; +import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; +import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; +import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; +import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; +import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; +import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; +import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; +import org.eclipse.gmf.runtime.notation.FontStyle; +import org.eclipse.gmf.runtime.notation.NotationPackage; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.text.contentassist.IContentAssistProcessor; +import org.eclipse.jface.viewers.ICellEditorValidator; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.extensionpoints.editors.Activator; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; +import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; +import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.ExternalLabelPrimaryDragRoleEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.PapyrusWrappingLabel; +import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; +import org.eclipse.papyrus.uml.diagram.common.editparts.FloatingLabelEditPart; +import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; +import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; +import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; +import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.accessibility.AccessibleEvent; +import org.eclipse.swt.custom.BusyIndicator; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; +import org.eclipse.uml2.uml.Feature; + +/** + * @generated + */ +public class TimeEventFloatingLabelEditPart extends FloatingLabelEditPart + implements ITextAwareEditPart, IBorderItemEditPart +{ + + /** + * @generated + */ + public static final int VISUAL_ID = 6105; + + /** + * @generated + */ + private DirectEditManager manager; + + /** + * @generated + */ + private IParser parser; + + /** + * @generated + */ + private List parserElements; + + /** + * @generated + */ + private String defaultText; + + /** + * direct edition mode (default, undefined, registered editor, etc.) + * + * @generated + */ + protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; + + /** + * configuration from a registered edit dialog + * + * @generated + */ + protected IDirectEditorConfiguration configuration; + + + /** + * @generated + */ + static { + registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.TimeEventFloatingLabelEditPart.VISUAL_ID), new Point(0, 0)); + } + + /** + * @generated + */ + public TimeEventFloatingLabelEditPart(View view) { + super(view); + } + + /** + * @generated + */ + @Override + protected void createDefaultEditPolicies() { + super.createDefaultEditPolicies(); + installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); + installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ExternalLabelPrimaryDragRoleEditPolicy()); + } + + /** + * @generated + */ + @Override + public IBorderItemLocator getBorderItemLocator() { + IFigure parentFigure = getFigure().getParent(); + if (parentFigure != null && parentFigure.getLayoutManager() != null) { + Object constraint = parentFigure.getLayoutManager().getConstraint(getFigure()); + return (IBorderItemLocator) constraint; + } + return null; + } + + /** + * @generated + */ + @Override + public void refreshBounds() { + int x = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_X())).intValue(); + int y = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_Y())).intValue(); + int width = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Width())).intValue(); + int height = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Height())).intValue(); + getBorderItemLocator().setConstraint(new Rectangle(x, y, width, height)); + } + + + /** + * @generated + */ + protected String getLabelTextHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getText(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getText(); + } else { + return ((Label) figure).getText(); + } + } + + /** + * @generated + */ + protected void setLabelTextHelper(IFigure figure, String text) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setText(text); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setText(text); + } else { + ((Label) figure).setText(text); + } + } + + /** + * @generated + */ + protected Image getLabelIconHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getIcon(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getIcon(); + } else { + return ((Label) figure).getIcon(); + } + } + + /** + * @generated + */ + protected void setLabelIconHelper(IFigure figure, Image icon) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setIcon(icon); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setIcon(icon); + } else { + ((Label) figure).setIcon(icon); + } + } + + /** + * @generated + */ + public void setLabel(IFigure + figure) { + unregisterVisuals(); + setFigure(figure); + defaultText = getLabelTextHelper(figure); + registerVisuals(); + refreshVisuals(); + } + + /** + * @generated + */ + @Override + protected List getModelChildren() { + return Collections.EMPTY_LIST; + } + + /** + * @generated + */ + @Override + public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { + return null; + } + + /** + * @generated + */ + public void setParser(IParser parser) { + this.parser = parser; + } + + /** + * @generated + */ + protected EObject getParserElement() { + return resolveSemanticElement(); + } + + /** + * @generated + */ + protected Image getLabelIcon() { + return null; + } + + /** + * @generated + */ + protected String getLabelText() { + String text = null; + EObject parserElement = getParserElement(); + if (parserElement != null && getParser() != null) { + text = getParser().getPrintString( + new EObjectAdapter(parserElement), + getParserOptions().intValue()); + } + if (text == null || text.length() == 0) { + text = defaultText; + } + return text; + } + + /** + * @generated + */ + @Override + public void setLabelText(String text) { + setLabelTextHelper(getFigure(), text); + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + @Override + public String getEditText() { + if (getParserElement() == null || getParser() == null) { + return ""; //$NON-NLS-1$ + } + return getParser().getEditString( + new EObjectAdapter(getParserElement()), + getParserOptions().intValue()); + } + + /** + * @generated + */ + protected boolean isEditable() { + return getParser() != null; + } + + /** + * @generated + */ + @Override + public ICellEditorValidator getEditTextValidator() { + return new ICellEditorValidator() { + + @Override + public String isValid(final Object value) { + if (value instanceof String) { + final EObject element = getParserElement(); + final IParser parser = getParser(); + try { + IParserEditStatus valid = + (IParserEditStatus) getEditingDomain().runExclusive( + new RunnableWithResult.Impl() { + + @Override + public void run() { + setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); + } + }); + return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); + } catch (InterruptedException ie) { + ie.printStackTrace(); + } + } + + // shouldn't get here + return null; + } + }; + } + + /** + * @generated + */ + @Override + public IContentAssistProcessor getCompletionProcessor() { + if (getParserElement() == null || getParser() == null) { + return null; + } + return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); + } + + /** + * @generated + */ + @Override + public ParserOptions getParserOptions() { + return ParserOptions.NONE; + } + + /** + * @generated + */ + @Override + public IParser getParser() { + if (parser == null) { + parser = UMLParserProvider.getParser(UMLElementTypes.TimeEvent_2089, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.TimeEventFloatingLabelEditPart.VISUAL_ID)); + } + return parser; + } + + /** + * @generated + */ + protected DirectEditManager getManager() { + if (manager == null) { + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + } + return manager; + } + + /** + * @generated + */ + protected void setManager(DirectEditManager manager) { + this.manager = manager; + } + + /** + * @generated + */ + protected void performDirectEdit() { + BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { + + @Override + public void run() { + getManager().show(); + } + }); + } + + /** + * @generated + */ + protected void performDirectEdit(Point eventLocation) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); + } + } + + /** + * @generated + */ + private void performDirectEdit(char initialCharacter) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(initialCharacter); + } else { + performDirectEdit(); + } + } + + /** + * @generated + */ + @Override + protected void performDirectEditRequest(Request request) { + + final Request theRequest = request; + + if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { + directEditionMode = getDirectEditionType(); + } + switch (directEditionMode) { + case IDirectEdition.NO_DIRECT_EDITION: + // no direct edition mode => does nothing + return; + case IDirectEdition.EXTENDED_DIRECT_EDITOR: + updateExtendedEditorConfiguration(); + if (configuration == null || configuration.getLanguage() == null) { + // Create default edit manager + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + performDefaultDirectEditorEdit(theRequest); + } else { + configuration.preEditAction(resolveSemanticElement()); + Dialog dialog = null; + if (configuration instanceof ICustomDirectEditorConfiguration) { + setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); + initializeDirectEditManager(theRequest); + return; + } else if (configuration instanceof IPopupEditorConfiguration) { + IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); + helper.showEditor(); + return; + } + else if (configuration instanceof IAdvancedEditorConfiguration) { + dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); + } else if (configuration instanceof IDirectEditorConfiguration) { + dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), + configuration); + } else { + return; + } + final Dialog finalDialog = dialog; + + if (Window.OK == dialog.open()) { + TransactionalEditingDomain domain = getEditingDomain(); + RecordingCommand command = new RecordingCommand(domain, "Edit Label") { + + @Override + protected void doExecute() { + configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); + + } + }; + domain.getCommandStack().execute(command); + } + } + break; + case IDirectEdition.DEFAULT_DIRECT_EDITOR: + initializeDirectEditManager(theRequest); + break; + default: + break; + } + } + + /** + * @generated + */ + protected void initializeDirectEditManager(final Request request) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + @Override + public void run() { + if (isActive() && isEditable()) { + if (request.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } + else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void refreshVisuals() { + super.refreshVisuals(); + refreshLabel(); + refreshFont(); + refreshFontColor(); + refreshUnderline(); + refreshStrikeThrough(); + } + + /** + * @generated + */ + protected void refreshLabel() { + EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); + if (maskLabelPolicy == null) { + maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); + } + if (maskLabelPolicy == null) { + View view = (View) getModel(); + if (view.isVisible()) { + setLabelTextHelper(getFigure(), getLabelText()); + setLabelIconHelper(getFigure(), getLabelIcon()); + } + else { + setLabelTextHelper(getFigure(), ""); //$NON-NLS-1$ + setLabelIconHelper(getFigure(), null); + } + } + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + protected void refreshUnderline() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); + } + if (resolveSemanticElement() instanceof Feature) { + if (((Feature) resolveSemanticElement()).isStatic()) { + ((WrappingLabel) getFigure()).setTextUnderline(true); + } + else { + ((WrappingLabel) getFigure()).setTextUnderline(false); + } + } + } + + /** + * @generated + */ + protected void refreshStrikeThrough() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); + } + } + + /** + * @generated + */ + @Override + protected void refreshFont() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null) { + FontData fontData = new FontData( + style.getFontName(), style.getFontHeight(), + (style.isBold() ? SWT.BOLD : SWT.NORMAL) | + (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); + setFont(fontData); + } + } + + /** + * @generated + */ + @Override + protected void setFontColor(Color color) { + getFigure().setForegroundColor(color); + } + + /** + * @generated + */ + @Override + protected void addSemanticListeners() { + if (getParser() instanceof ISemanticParser) { + EObject element = resolveSemanticElement(); + parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); + for (int i = 0; i < parserElements.size(); i++) { + addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ + } + } else { + super.addSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected void removeSemanticListeners() { + if (parserElements != null) { + for (int i = 0; i < parserElements.size(); i++) { + removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ + } + } else { + super.removeSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected AccessibleEditPart getAccessibleEditPart() { + if (accessibleEP == null) { + accessibleEP = new AccessibleGraphicalEditPart() { + + @Override + public void getName(AccessibleEvent e) { + e.result = getLabelTextHelper(getFigure()); + } + }; + } + return accessibleEP; + } + + /** + * @generated + */ + private View getFontStyleOwnerView() { + return getPrimaryView(); + } + + /** + * Returns the kind of associated editor for direct edition. + * + * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition + * @generated + */ + public int getDirectEditionType() { + if (checkExtendedEditor()) { + initExtendedEditorConfiguration(); + return IDirectEdition.EXTENDED_DIRECT_EDITOR; + } + if (checkDefaultEdition()) { + return IDirectEdition.DEFAULT_DIRECT_EDITOR; + } + + // not a named element. no specific editor => do nothing + return IDirectEdition.NO_DIRECT_EDITION; + } + + /** + * Checks if an extended editor is present. + * + * @return true if an extended editor is present. + * @generated + */ + protected boolean checkExtendedEditor() { + if (resolveSemanticElement() != null) { + return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); + } + return false; + } + + /** + * Checks if a default direct edition is available + * + * @return true if a default direct edition is available + * @generated + */ + protected boolean checkDefaultEdition() { + return (getParser() != null); + } + + /** + * Initializes the extended editor configuration + * + * @generated + */ + protected void initExtendedEditorConfiguration() { + if (configuration == null) { + final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("")) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); + } else { + configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); + } + } + } + + /** + * Updates the preference configuration + * + * @generated + */ + protected void updateExtendedEditorConfiguration() { + String languagePreferred = Activator.getDefault().getPreferenceStore().getString( + IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() + .eClass().getInstanceClassName()); + } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { + configuration = null; + } + } + + /** + * Performs the direct edit usually used by GMF editors. + * + * @param theRequest + * the direct edit request that starts the direct edit system + * @generated + */ + protected void performDefaultDirectEditorEdit(final Request theRequest) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + + @Override + public void run() { + if (isActive() && isEditable()) { + if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) theRequest.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { + DirectEditRequest editRequest = (DirectEditRequest) theRequest; + performDirectEdit(editRequest.getLocation()); + } else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + + /** + * @generated + */ + @Override + protected void handleNotificationEvent(Notification event) { + Object feature = event.getFeature(); + if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { + Integer c = (Integer) event.getNewValue(); + setFontColor(DiagramColorRegistry.getInstance().getColor(c)); + } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { + refreshUnderline(); + } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { + refreshStrikeThrough(); + } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { + refreshFont(); + } else { + if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { + refreshLabel(); + } + if (getParser() instanceof ISemanticParser) { + ISemanticParser modelParser = + (ISemanticParser) getParser(); + if (modelParser.areSemanticElementsAffected(null, event)) { + removeSemanticListeners(); + if (resolveSemanticElement() != null) { + addSemanticListeners(); + } + refreshLabel(); + } + } + } + super.handleNotificationEvent(event); + } + + /** + * @generated + */ + @Override + protected IFigure createFigure() { + IFigure label = createFigurePrim(); + defaultText = getLabelTextHelper(label); + return label; + } + + /** + * @generated + */ + protected IFigure createFigurePrim() { + return new PapyrusWrappingLabel(); + } + +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/TimeEventNameEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/TimeEventNameEditPart.java index 85c4ac3761c..f293f9b45e3 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/TimeEventNameEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/TimeEventNameEditPart.java @@ -864,7 +864,7 @@ public class TimeEventNameEditPart extends PapyrusCompartmentEditPart implements * @generated */ protected void addOwnerElementListeners() { - addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); + addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/TimeExpressionEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/TimeExpressionEditPart.java index 03d8a0a3424..cd18bcf1d7b 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/TimeExpressionEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/TimeExpressionEditPart.java @@ -11,27 +11,40 @@ */ package org.eclipse.papyrus.uml.diagram.composite.edit.parts; +import java.util.Collections; +import java.util.List; + import org.eclipse.draw2d.IFigure; +import org.eclipse.emf.common.notify.Notification; import org.eclipse.gef.EditPart; import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.GraphicalEditPart; 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.handles.MoveHandle; import org.eclipse.gef.requests.CreateRequest; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.BorderItemSelectionEditPolicy; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles; +import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; -import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure; import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure; +import org.eclipse.gmf.runtime.notation.Edge; +import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.gmf.runtime.notation.View; -import org.eclipse.papyrus.infra.gmfdiag.common.editpart.NodeEditPart; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.GetChildLayoutEditPolicy; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.IPapyrusNodeFigure; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.RoundedRectangleNodePlateFigure; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.SelectableBorderedNodeFigure; +import org.eclipse.papyrus.uml.diagram.common.editparts.RoundedCompartmentEditPart; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeNodeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.QualifiedNameDisplayEditPolicy; -import org.eclipse.papyrus.uml.diagram.common.figure.node.NodeNamedElementFigure; +import org.eclipse.papyrus.uml.diagram.common.figure.node.RoundedCompartmentFigure; +import org.eclipse.papyrus.uml.diagram.common.locator.RoundedRectangleLabelPositionLocator; import org.eclipse.papyrus.uml.diagram.composite.edit.policies.TimeExpressionItemSemanticEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; import org.eclipse.swt.graphics.Color; @@ -39,7 +52,7 @@ import org.eclipse.swt.graphics.Color; /** * @generated */ -public class TimeExpressionEditPart extends NodeEditPart { +public class TimeExpressionEditPart extends RoundedCompartmentEditPart { /** * @generated @@ -73,6 +86,7 @@ public class TimeExpressionEditPart extends NodeEditPart { installEditPolicy(EditPolicy.LAYOUT_ROLE, createLayoutEditPolicy()); installEditPolicy(QualifiedNameDisplayEditPolicy.QUALIFIED_NAME_POLICY, new QualifiedNameDisplayEditPolicy()); installEditPolicy(AppliedStereotypeLabelDisplayEditPolicy.STEREOTYPE_LABEL_POLICY, new AppliedStereotypeNodeLabelDisplayEditPolicy()); + installEditPolicy(EditPolicy.LAYOUT_ROLE, new GetChildLayoutEditPolicy()); // XXX need an SCR to runtime to have another abstract superclass that would let children add reasonable editpolicies // removeEditPolicy(org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles.CONNECTION_HANDLES_ROLE); } @@ -85,6 +99,20 @@ public class TimeExpressionEditPart extends NodeEditPart { @Override protected EditPolicy createChildEditPolicy(EditPart child) { + View childView = (View) child.getModel(); + switch (UMLVisualIDRegistry.getVisualID(childView)) { + case TimeExpressionFloatingLabelEditPart.VISUAL_ID: + return new BorderItemSelectionEditPolicy() { + + @Override + protected List createSelectionHandles() { + MoveHandle mh = new MoveHandle((GraphicalEditPart) getHost()); + mh.setBorder(null); + return Collections.singletonList(mh); + } + } + ; + } EditPolicy result = child.getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); if (result == null) { result = new NonResizableEditPolicy(); @@ -105,12 +133,36 @@ public class TimeExpressionEditPart extends NodeEditPart { return lep; } + /** + * Papyrus codeGen + * + * @generated + **/ + @Override + protected void handleNotificationEvent(Notification event) { + /* + * when a node have external node labels, the methods refreshChildren() remove the EditPart corresponding to the Label from the EditPart + * Registry. After that, we can't reset the visibility to true (using the Show/Hide Label Action)! + */ + if (NotationPackage.eINSTANCE.getView_Visible().equals(event.getFeature())) { + Object notifier = event.getNotifier(); + List modelChildren = ((View) getModel()).getChildren(); + if (!(notifier instanceof Edge)) { + if (modelChildren.contains(event.getNotifier())) { + return; + } + } + } + super.handleNotificationEvent(event); + + } + /** * @generated */ @Override protected IFigure createNodeShape() { - return primaryShape = new NodeNamedElementFigure(); + return primaryShape = new RoundedCompartmentFigure(); } /** @@ -119,8 +171,8 @@ public class TimeExpressionEditPart extends NodeEditPart { * @generated */ @Override - public NodeNamedElementFigure getPrimaryShape() { - return (NodeNamedElementFigure) primaryShape; + public RoundedCompartmentFigure getPrimaryShape() { + return (RoundedCompartmentFigure) primaryShape; } /** @@ -173,15 +225,32 @@ public class TimeExpressionEditPart extends NodeEditPart { */ @Override protected IFigure getContentPaneFor(IGraphicalEditPart editPart) { + if (editPart instanceof IBorderItemEditPart) { + return getBorderedFigure().getBorderItemContainer(); + } return getContentPane(); } + /** + * @generated + */ + @Override + protected void addBorderItem(IFigure borderItemContainer, IBorderItemEditPart borderItemEditPart) { + if (borderItemEditPart instanceof TimeExpressionFloatingLabelEditPart) { + IBorderItemLocator locator = new RoundedRectangleLabelPositionLocator(getMainFigure()); + borderItemContainer.add(borderItemEditPart.getFigure(), locator); + } else + { + super.addBorderItem(borderItemContainer, borderItemEditPart); + } + } + /** * @generated */ @Override protected NodeFigure createNodePlate() { - DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(40, 40); + RoundedRectangleNodePlateFigure result = new RoundedRectangleNodePlateFigure(40, 40); return result; } @@ -194,7 +263,7 @@ public class TimeExpressionEditPart extends NodeEditPart { * @generated */ @Override - protected NodeFigure createNodeFigure() { + protected NodeFigure createMainFigure() { return new SelectableBorderedNodeFigure(createMainFigureWithSVG()); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/TimeExpressionFloatingLabelEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/TimeExpressionFloatingLabelEditPart.java new file mode 100644 index 00000000000..798b00e68c3 --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/TimeExpressionFloatingLabelEditPart.java @@ -0,0 +1,860 @@ +/** + * 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.uml.diagram.composite.edit.parts; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.Label; +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.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.RunnableWithResult; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gef.AccessibleEditPart; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.Request; +import org.eclipse.gef.requests.DirectEditRequest; +import org.eclipse.gef.tools.DirectEditManager; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; +import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; +import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; +import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; +import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; +import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; +import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; +import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; +import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; +import org.eclipse.gmf.runtime.notation.FontStyle; +import org.eclipse.gmf.runtime.notation.NotationPackage; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.text.contentassist.IContentAssistProcessor; +import org.eclipse.jface.viewers.ICellEditorValidator; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.extensionpoints.editors.Activator; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; +import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; +import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.ExternalLabelPrimaryDragRoleEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.PapyrusWrappingLabel; +import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; +import org.eclipse.papyrus.uml.diagram.common.editparts.FloatingLabelEditPart; +import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; +import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; +import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; +import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.accessibility.AccessibleEvent; +import org.eclipse.swt.custom.BusyIndicator; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; +import org.eclipse.uml2.uml.Feature; + +/** + * @generated + */ +public class TimeExpressionFloatingLabelEditPart extends FloatingLabelEditPart + implements ITextAwareEditPart, IBorderItemEditPart +{ + + /** + * @generated + */ + public static final int VISUAL_ID = 6113; + + /** + * @generated + */ + private DirectEditManager manager; + + /** + * @generated + */ + private IParser parser; + + /** + * @generated + */ + private List parserElements; + + /** + * @generated + */ + private String defaultText; + + /** + * direct edition mode (default, undefined, registered editor, etc.) + * + * @generated + */ + protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; + + /** + * configuration from a registered edit dialog + * + * @generated + */ + protected IDirectEditorConfiguration configuration; + + + /** + * @generated + */ + static { + registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.TimeExpressionFloatingLabelEditPart.VISUAL_ID), new Point(0, 0)); + } + + /** + * @generated + */ + public TimeExpressionFloatingLabelEditPart(View view) { + super(view); + } + + /** + * @generated + */ + @Override + protected void createDefaultEditPolicies() { + super.createDefaultEditPolicies(); + installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); + installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ExternalLabelPrimaryDragRoleEditPolicy()); + } + + /** + * @generated + */ + @Override + public IBorderItemLocator getBorderItemLocator() { + IFigure parentFigure = getFigure().getParent(); + if (parentFigure != null && parentFigure.getLayoutManager() != null) { + Object constraint = parentFigure.getLayoutManager().getConstraint(getFigure()); + return (IBorderItemLocator) constraint; + } + return null; + } + + /** + * @generated + */ + @Override + public void refreshBounds() { + int x = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_X())).intValue(); + int y = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_Y())).intValue(); + int width = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Width())).intValue(); + int height = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Height())).intValue(); + getBorderItemLocator().setConstraint(new Rectangle(x, y, width, height)); + } + + + /** + * @generated + */ + protected String getLabelTextHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getText(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getText(); + } else { + return ((Label) figure).getText(); + } + } + + /** + * @generated + */ + protected void setLabelTextHelper(IFigure figure, String text) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setText(text); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setText(text); + } else { + ((Label) figure).setText(text); + } + } + + /** + * @generated + */ + protected Image getLabelIconHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getIcon(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getIcon(); + } else { + return ((Label) figure).getIcon(); + } + } + + /** + * @generated + */ + protected void setLabelIconHelper(IFigure figure, Image icon) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setIcon(icon); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setIcon(icon); + } else { + ((Label) figure).setIcon(icon); + } + } + + /** + * @generated + */ + public void setLabel(IFigure + figure) { + unregisterVisuals(); + setFigure(figure); + defaultText = getLabelTextHelper(figure); + registerVisuals(); + refreshVisuals(); + } + + /** + * @generated + */ + @Override + protected List getModelChildren() { + return Collections.EMPTY_LIST; + } + + /** + * @generated + */ + @Override + public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { + return null; + } + + /** + * @generated + */ + public void setParser(IParser parser) { + this.parser = parser; + } + + /** + * @generated + */ + protected EObject getParserElement() { + return resolveSemanticElement(); + } + + /** + * @generated + */ + protected Image getLabelIcon() { + return null; + } + + /** + * @generated + */ + protected String getLabelText() { + String text = null; + EObject parserElement = getParserElement(); + if (parserElement != null && getParser() != null) { + text = getParser().getPrintString( + new EObjectAdapter(parserElement), + getParserOptions().intValue()); + } + if (text == null || text.length() == 0) { + text = defaultText; + } + return text; + } + + /** + * @generated + */ + @Override + public void setLabelText(String text) { + setLabelTextHelper(getFigure(), text); + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + @Override + public String getEditText() { + if (getParserElement() == null || getParser() == null) { + return ""; //$NON-NLS-1$ + } + return getParser().getEditString( + new EObjectAdapter(getParserElement()), + getParserOptions().intValue()); + } + + /** + * @generated + */ + protected boolean isEditable() { + return getParser() != null; + } + + /** + * @generated + */ + @Override + public ICellEditorValidator getEditTextValidator() { + return new ICellEditorValidator() { + + @Override + public String isValid(final Object value) { + if (value instanceof String) { + final EObject element = getParserElement(); + final IParser parser = getParser(); + try { + IParserEditStatus valid = + (IParserEditStatus) getEditingDomain().runExclusive( + new RunnableWithResult.Impl() { + + @Override + public void run() { + setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); + } + }); + return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); + } catch (InterruptedException ie) { + ie.printStackTrace(); + } + } + + // shouldn't get here + return null; + } + }; + } + + /** + * @generated + */ + @Override + public IContentAssistProcessor getCompletionProcessor() { + if (getParserElement() == null || getParser() == null) { + return null; + } + return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); + } + + /** + * @generated + */ + @Override + public ParserOptions getParserOptions() { + return ParserOptions.NONE; + } + + /** + * @generated + */ + @Override + public IParser getParser() { + if (parser == null) { + parser = UMLParserProvider.getParser(UMLElementTypes.TimeExpression_2102, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.TimeExpressionFloatingLabelEditPart.VISUAL_ID)); + } + return parser; + } + + /** + * @generated + */ + protected DirectEditManager getManager() { + if (manager == null) { + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + } + return manager; + } + + /** + * @generated + */ + protected void setManager(DirectEditManager manager) { + this.manager = manager; + } + + /** + * @generated + */ + protected void performDirectEdit() { + BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { + + @Override + public void run() { + getManager().show(); + } + }); + } + + /** + * @generated + */ + protected void performDirectEdit(Point eventLocation) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); + } + } + + /** + * @generated + */ + private void performDirectEdit(char initialCharacter) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(initialCharacter); + } else { + performDirectEdit(); + } + } + + /** + * @generated + */ + @Override + protected void performDirectEditRequest(Request request) { + + final Request theRequest = request; + + if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { + directEditionMode = getDirectEditionType(); + } + switch (directEditionMode) { + case IDirectEdition.NO_DIRECT_EDITION: + // no direct edition mode => does nothing + return; + case IDirectEdition.EXTENDED_DIRECT_EDITOR: + updateExtendedEditorConfiguration(); + if (configuration == null || configuration.getLanguage() == null) { + // Create default edit manager + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + performDefaultDirectEditorEdit(theRequest); + } else { + configuration.preEditAction(resolveSemanticElement()); + Dialog dialog = null; + if (configuration instanceof ICustomDirectEditorConfiguration) { + setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); + initializeDirectEditManager(theRequest); + return; + } else if (configuration instanceof IPopupEditorConfiguration) { + IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); + helper.showEditor(); + return; + } + else if (configuration instanceof IAdvancedEditorConfiguration) { + dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); + } else if (configuration instanceof IDirectEditorConfiguration) { + dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), + configuration); + } else { + return; + } + final Dialog finalDialog = dialog; + + if (Window.OK == dialog.open()) { + TransactionalEditingDomain domain = getEditingDomain(); + RecordingCommand command = new RecordingCommand(domain, "Edit Label") { + + @Override + protected void doExecute() { + configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); + + } + }; + domain.getCommandStack().execute(command); + } + } + break; + case IDirectEdition.DEFAULT_DIRECT_EDITOR: + initializeDirectEditManager(theRequest); + break; + default: + break; + } + } + + /** + * @generated + */ + protected void initializeDirectEditManager(final Request request) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + @Override + public void run() { + if (isActive() && isEditable()) { + if (request.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } + else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void refreshVisuals() { + super.refreshVisuals(); + refreshLabel(); + refreshFont(); + refreshFontColor(); + refreshUnderline(); + refreshStrikeThrough(); + } + + /** + * @generated + */ + protected void refreshLabel() { + EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); + if (maskLabelPolicy == null) { + maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); + } + if (maskLabelPolicy == null) { + View view = (View) getModel(); + if (view.isVisible()) { + setLabelTextHelper(getFigure(), getLabelText()); + setLabelIconHelper(getFigure(), getLabelIcon()); + } + else { + setLabelTextHelper(getFigure(), ""); //$NON-NLS-1$ + setLabelIconHelper(getFigure(), null); + } + } + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + protected void refreshUnderline() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); + } + if (resolveSemanticElement() instanceof Feature) { + if (((Feature) resolveSemanticElement()).isStatic()) { + ((WrappingLabel) getFigure()).setTextUnderline(true); + } + else { + ((WrappingLabel) getFigure()).setTextUnderline(false); + } + } + } + + /** + * @generated + */ + protected void refreshStrikeThrough() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); + } + } + + /** + * @generated + */ + @Override + protected void refreshFont() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null) { + FontData fontData = new FontData( + style.getFontName(), style.getFontHeight(), + (style.isBold() ? SWT.BOLD : SWT.NORMAL) | + (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); + setFont(fontData); + } + } + + /** + * @generated + */ + @Override + protected void setFontColor(Color color) { + getFigure().setForegroundColor(color); + } + + /** + * @generated + */ + @Override + protected void addSemanticListeners() { + if (getParser() instanceof ISemanticParser) { + EObject element = resolveSemanticElement(); + parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); + for (int i = 0; i < parserElements.size(); i++) { + addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ + } + } else { + super.addSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected void removeSemanticListeners() { + if (parserElements != null) { + for (int i = 0; i < parserElements.size(); i++) { + removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ + } + } else { + super.removeSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected AccessibleEditPart getAccessibleEditPart() { + if (accessibleEP == null) { + accessibleEP = new AccessibleGraphicalEditPart() { + + @Override + public void getName(AccessibleEvent e) { + e.result = getLabelTextHelper(getFigure()); + } + }; + } + return accessibleEP; + } + + /** + * @generated + */ + private View getFontStyleOwnerView() { + return getPrimaryView(); + } + + /** + * Returns the kind of associated editor for direct edition. + * + * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition + * @generated + */ + public int getDirectEditionType() { + if (checkExtendedEditor()) { + initExtendedEditorConfiguration(); + return IDirectEdition.EXTENDED_DIRECT_EDITOR; + } + if (checkDefaultEdition()) { + return IDirectEdition.DEFAULT_DIRECT_EDITOR; + } + + // not a named element. no specific editor => do nothing + return IDirectEdition.NO_DIRECT_EDITION; + } + + /** + * Checks if an extended editor is present. + * + * @return true if an extended editor is present. + * @generated + */ + protected boolean checkExtendedEditor() { + if (resolveSemanticElement() != null) { + return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); + } + return false; + } + + /** + * Checks if a default direct edition is available + * + * @return true if a default direct edition is available + * @generated + */ + protected boolean checkDefaultEdition() { + return (getParser() != null); + } + + /** + * Initializes the extended editor configuration + * + * @generated + */ + protected void initExtendedEditorConfiguration() { + if (configuration == null) { + final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("")) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); + } else { + configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); + } + } + } + + /** + * Updates the preference configuration + * + * @generated + */ + protected void updateExtendedEditorConfiguration() { + String languagePreferred = Activator.getDefault().getPreferenceStore().getString( + IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() + .eClass().getInstanceClassName()); + } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { + configuration = null; + } + } + + /** + * Performs the direct edit usually used by GMF editors. + * + * @param theRequest + * the direct edit request that starts the direct edit system + * @generated + */ + protected void performDefaultDirectEditorEdit(final Request theRequest) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + + @Override + public void run() { + if (isActive() && isEditable()) { + if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) theRequest.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { + DirectEditRequest editRequest = (DirectEditRequest) theRequest; + performDirectEdit(editRequest.getLocation()); + } else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + + /** + * @generated + */ + @Override + protected void handleNotificationEvent(Notification event) { + Object feature = event.getFeature(); + if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { + Integer c = (Integer) event.getNewValue(); + setFontColor(DiagramColorRegistry.getInstance().getColor(c)); + } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { + refreshUnderline(); + } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { + refreshStrikeThrough(); + } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { + refreshFont(); + } else { + if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { + refreshLabel(); + } + if (getParser() instanceof ISemanticParser) { + ISemanticParser modelParser = + (ISemanticParser) getParser(); + if (modelParser.areSemanticElementsAffected(null, event)) { + removeSemanticListeners(); + if (resolveSemanticElement() != null) { + addSemanticListeners(); + } + refreshLabel(); + } + } + } + super.handleNotificationEvent(event); + } + + /** + * @generated + */ + @Override + protected IFigure createFigure() { + IFigure label = createFigurePrim(); + defaultText = getLabelTextHelper(label); + return label; + } + + /** + * @generated + */ + protected IFigure createFigurePrim() { + return new PapyrusWrappingLabel(); + } + +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/TimeExpressionNameEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/TimeExpressionNameEditPart.java index 9bfb2391885..e9a0e9ab0dc 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/TimeExpressionNameEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/TimeExpressionNameEditPart.java @@ -864,7 +864,7 @@ public class TimeExpressionNameEditPart extends PapyrusCompartmentEditPart imple * @generated */ protected void addOwnerElementListeners() { - addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); + addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/TimeIntervalEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/TimeIntervalEditPart.java index eb1db699e2a..36d0bf00cb5 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/TimeIntervalEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/TimeIntervalEditPart.java @@ -11,27 +11,40 @@ */ package org.eclipse.papyrus.uml.diagram.composite.edit.parts; +import java.util.Collections; +import java.util.List; + import org.eclipse.draw2d.IFigure; +import org.eclipse.emf.common.notify.Notification; import org.eclipse.gef.EditPart; import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.GraphicalEditPart; 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.handles.MoveHandle; import org.eclipse.gef.requests.CreateRequest; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.BorderItemSelectionEditPolicy; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles; +import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; -import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure; import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure; +import org.eclipse.gmf.runtime.notation.Edge; +import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.gmf.runtime.notation.View; -import org.eclipse.papyrus.infra.gmfdiag.common.editpart.NodeEditPart; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.GetChildLayoutEditPolicy; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.IPapyrusNodeFigure; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.RoundedRectangleNodePlateFigure; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.SelectableBorderedNodeFigure; +import org.eclipse.papyrus.uml.diagram.common.editparts.RoundedCompartmentEditPart; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeNodeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.QualifiedNameDisplayEditPolicy; -import org.eclipse.papyrus.uml.diagram.common.figure.node.NodeNamedElementFigure; +import org.eclipse.papyrus.uml.diagram.common.figure.node.RoundedCompartmentFigure; +import org.eclipse.papyrus.uml.diagram.common.locator.RoundedRectangleLabelPositionLocator; import org.eclipse.papyrus.uml.diagram.composite.edit.policies.TimeIntervalItemSemanticEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; import org.eclipse.swt.graphics.Color; @@ -39,7 +52,7 @@ import org.eclipse.swt.graphics.Color; /** * @generated */ -public class TimeIntervalEditPart extends NodeEditPart { +public class TimeIntervalEditPart extends RoundedCompartmentEditPart { /** * @generated @@ -73,6 +86,7 @@ public class TimeIntervalEditPart extends NodeEditPart { installEditPolicy(EditPolicy.LAYOUT_ROLE, createLayoutEditPolicy()); installEditPolicy(QualifiedNameDisplayEditPolicy.QUALIFIED_NAME_POLICY, new QualifiedNameDisplayEditPolicy()); installEditPolicy(AppliedStereotypeLabelDisplayEditPolicy.STEREOTYPE_LABEL_POLICY, new AppliedStereotypeNodeLabelDisplayEditPolicy()); + installEditPolicy(EditPolicy.LAYOUT_ROLE, new GetChildLayoutEditPolicy()); // XXX need an SCR to runtime to have another abstract superclass that would let children add reasonable editpolicies // removeEditPolicy(org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles.CONNECTION_HANDLES_ROLE); } @@ -85,6 +99,20 @@ public class TimeIntervalEditPart extends NodeEditPart { @Override protected EditPolicy createChildEditPolicy(EditPart child) { + View childView = (View) child.getModel(); + switch (UMLVisualIDRegistry.getVisualID(childView)) { + case TimeIntervalFloatingLabelEditPart.VISUAL_ID: + return new BorderItemSelectionEditPolicy() { + + @Override + protected List createSelectionHandles() { + MoveHandle mh = new MoveHandle((GraphicalEditPart) getHost()); + mh.setBorder(null); + return Collections.singletonList(mh); + } + } + ; + } EditPolicy result = child.getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); if (result == null) { result = new NonResizableEditPolicy(); @@ -105,12 +133,36 @@ public class TimeIntervalEditPart extends NodeEditPart { return lep; } + /** + * Papyrus codeGen + * + * @generated + **/ + @Override + protected void handleNotificationEvent(Notification event) { + /* + * when a node have external node labels, the methods refreshChildren() remove the EditPart corresponding to the Label from the EditPart + * Registry. After that, we can't reset the visibility to true (using the Show/Hide Label Action)! + */ + if (NotationPackage.eINSTANCE.getView_Visible().equals(event.getFeature())) { + Object notifier = event.getNotifier(); + List modelChildren = ((View) getModel()).getChildren(); + if (!(notifier instanceof Edge)) { + if (modelChildren.contains(event.getNotifier())) { + return; + } + } + } + super.handleNotificationEvent(event); + + } + /** * @generated */ @Override protected IFigure createNodeShape() { - return primaryShape = new NodeNamedElementFigure(); + return primaryShape = new RoundedCompartmentFigure(); } /** @@ -119,8 +171,8 @@ public class TimeIntervalEditPart extends NodeEditPart { * @generated */ @Override - public NodeNamedElementFigure getPrimaryShape() { - return (NodeNamedElementFigure) primaryShape; + public RoundedCompartmentFigure getPrimaryShape() { + return (RoundedCompartmentFigure) primaryShape; } /** @@ -173,15 +225,32 @@ public class TimeIntervalEditPart extends NodeEditPart { */ @Override protected IFigure getContentPaneFor(IGraphicalEditPart editPart) { + if (editPart instanceof IBorderItemEditPart) { + return getBorderedFigure().getBorderItemContainer(); + } return getContentPane(); } + /** + * @generated + */ + @Override + protected void addBorderItem(IFigure borderItemContainer, IBorderItemEditPart borderItemEditPart) { + if (borderItemEditPart instanceof TimeIntervalFloatingLabelEditPart) { + IBorderItemLocator locator = new RoundedRectangleLabelPositionLocator(getMainFigure()); + borderItemContainer.add(borderItemEditPart.getFigure(), locator); + } else + { + super.addBorderItem(borderItemContainer, borderItemEditPart); + } + } + /** * @generated */ @Override protected NodeFigure createNodePlate() { - DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(40, 40); + RoundedRectangleNodePlateFigure result = new RoundedRectangleNodePlateFigure(40, 40); return result; } @@ -194,7 +263,7 @@ public class TimeIntervalEditPart extends NodeEditPart { * @generated */ @Override - protected NodeFigure createNodeFigure() { + protected NodeFigure createMainFigure() { return new SelectableBorderedNodeFigure(createMainFigureWithSVG()); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/TimeIntervalFloatingLabelEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/TimeIntervalFloatingLabelEditPart.java new file mode 100644 index 00000000000..75f22d22ace --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/TimeIntervalFloatingLabelEditPart.java @@ -0,0 +1,860 @@ +/** + * 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.uml.diagram.composite.edit.parts; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.Label; +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.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.RunnableWithResult; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gef.AccessibleEditPart; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.Request; +import org.eclipse.gef.requests.DirectEditRequest; +import org.eclipse.gef.tools.DirectEditManager; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; +import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; +import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; +import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; +import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; +import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; +import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; +import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; +import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; +import org.eclipse.gmf.runtime.notation.FontStyle; +import org.eclipse.gmf.runtime.notation.NotationPackage; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.text.contentassist.IContentAssistProcessor; +import org.eclipse.jface.viewers.ICellEditorValidator; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.extensionpoints.editors.Activator; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; +import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; +import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.ExternalLabelPrimaryDragRoleEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.PapyrusWrappingLabel; +import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; +import org.eclipse.papyrus.uml.diagram.common.editparts.FloatingLabelEditPart; +import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; +import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; +import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; +import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.accessibility.AccessibleEvent; +import org.eclipse.swt.custom.BusyIndicator; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; +import org.eclipse.uml2.uml.Feature; + +/** + * @generated + */ +public class TimeIntervalFloatingLabelEditPart extends FloatingLabelEditPart + implements ITextAwareEditPart, IBorderItemEditPart +{ + + /** + * @generated + */ + public static final int VISUAL_ID = 6116; + + /** + * @generated + */ + private DirectEditManager manager; + + /** + * @generated + */ + private IParser parser; + + /** + * @generated + */ + private List parserElements; + + /** + * @generated + */ + private String defaultText; + + /** + * direct edition mode (default, undefined, registered editor, etc.) + * + * @generated + */ + protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; + + /** + * configuration from a registered edit dialog + * + * @generated + */ + protected IDirectEditorConfiguration configuration; + + + /** + * @generated + */ + static { + registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.TimeIntervalFloatingLabelEditPart.VISUAL_ID), new Point(0, 0)); + } + + /** + * @generated + */ + public TimeIntervalFloatingLabelEditPart(View view) { + super(view); + } + + /** + * @generated + */ + @Override + protected void createDefaultEditPolicies() { + super.createDefaultEditPolicies(); + installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); + installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ExternalLabelPrimaryDragRoleEditPolicy()); + } + + /** + * @generated + */ + @Override + public IBorderItemLocator getBorderItemLocator() { + IFigure parentFigure = getFigure().getParent(); + if (parentFigure != null && parentFigure.getLayoutManager() != null) { + Object constraint = parentFigure.getLayoutManager().getConstraint(getFigure()); + return (IBorderItemLocator) constraint; + } + return null; + } + + /** + * @generated + */ + @Override + public void refreshBounds() { + int x = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_X())).intValue(); + int y = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_Y())).intValue(); + int width = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Width())).intValue(); + int height = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Height())).intValue(); + getBorderItemLocator().setConstraint(new Rectangle(x, y, width, height)); + } + + + /** + * @generated + */ + protected String getLabelTextHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getText(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getText(); + } else { + return ((Label) figure).getText(); + } + } + + /** + * @generated + */ + protected void setLabelTextHelper(IFigure figure, String text) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setText(text); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setText(text); + } else { + ((Label) figure).setText(text); + } + } + + /** + * @generated + */ + protected Image getLabelIconHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getIcon(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getIcon(); + } else { + return ((Label) figure).getIcon(); + } + } + + /** + * @generated + */ + protected void setLabelIconHelper(IFigure figure, Image icon) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setIcon(icon); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setIcon(icon); + } else { + ((Label) figure).setIcon(icon); + } + } + + /** + * @generated + */ + public void setLabel(IFigure + figure) { + unregisterVisuals(); + setFigure(figure); + defaultText = getLabelTextHelper(figure); + registerVisuals(); + refreshVisuals(); + } + + /** + * @generated + */ + @Override + protected List getModelChildren() { + return Collections.EMPTY_LIST; + } + + /** + * @generated + */ + @Override + public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { + return null; + } + + /** + * @generated + */ + public void setParser(IParser parser) { + this.parser = parser; + } + + /** + * @generated + */ + protected EObject getParserElement() { + return resolveSemanticElement(); + } + + /** + * @generated + */ + protected Image getLabelIcon() { + return null; + } + + /** + * @generated + */ + protected String getLabelText() { + String text = null; + EObject parserElement = getParserElement(); + if (parserElement != null && getParser() != null) { + text = getParser().getPrintString( + new EObjectAdapter(parserElement), + getParserOptions().intValue()); + } + if (text == null || text.length() == 0) { + text = defaultText; + } + return text; + } + + /** + * @generated + */ + @Override + public void setLabelText(String text) { + setLabelTextHelper(getFigure(), text); + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + @Override + public String getEditText() { + if (getParserElement() == null || getParser() == null) { + return ""; //$NON-NLS-1$ + } + return getParser().getEditString( + new EObjectAdapter(getParserElement()), + getParserOptions().intValue()); + } + + /** + * @generated + */ + protected boolean isEditable() { + return getParser() != null; + } + + /** + * @generated + */ + @Override + public ICellEditorValidator getEditTextValidator() { + return new ICellEditorValidator() { + + @Override + public String isValid(final Object value) { + if (value instanceof String) { + final EObject element = getParserElement(); + final IParser parser = getParser(); + try { + IParserEditStatus valid = + (IParserEditStatus) getEditingDomain().runExclusive( + new RunnableWithResult.Impl() { + + @Override + public void run() { + setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); + } + }); + return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); + } catch (InterruptedException ie) { + ie.printStackTrace(); + } + } + + // shouldn't get here + return null; + } + }; + } + + /** + * @generated + */ + @Override + public IContentAssistProcessor getCompletionProcessor() { + if (getParserElement() == null || getParser() == null) { + return null; + } + return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); + } + + /** + * @generated + */ + @Override + public ParserOptions getParserOptions() { + return ParserOptions.NONE; + } + + /** + * @generated + */ + @Override + public IParser getParser() { + if (parser == null) { + parser = UMLParserProvider.getParser(UMLElementTypes.TimeInterval_2105, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.TimeIntervalFloatingLabelEditPart.VISUAL_ID)); + } + return parser; + } + + /** + * @generated + */ + protected DirectEditManager getManager() { + if (manager == null) { + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + } + return manager; + } + + /** + * @generated + */ + protected void setManager(DirectEditManager manager) { + this.manager = manager; + } + + /** + * @generated + */ + protected void performDirectEdit() { + BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { + + @Override + public void run() { + getManager().show(); + } + }); + } + + /** + * @generated + */ + protected void performDirectEdit(Point eventLocation) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); + } + } + + /** + * @generated + */ + private void performDirectEdit(char initialCharacter) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(initialCharacter); + } else { + performDirectEdit(); + } + } + + /** + * @generated + */ + @Override + protected void performDirectEditRequest(Request request) { + + final Request theRequest = request; + + if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { + directEditionMode = getDirectEditionType(); + } + switch (directEditionMode) { + case IDirectEdition.NO_DIRECT_EDITION: + // no direct edition mode => does nothing + return; + case IDirectEdition.EXTENDED_DIRECT_EDITOR: + updateExtendedEditorConfiguration(); + if (configuration == null || configuration.getLanguage() == null) { + // Create default edit manager + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + performDefaultDirectEditorEdit(theRequest); + } else { + configuration.preEditAction(resolveSemanticElement()); + Dialog dialog = null; + if (configuration instanceof ICustomDirectEditorConfiguration) { + setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); + initializeDirectEditManager(theRequest); + return; + } else if (configuration instanceof IPopupEditorConfiguration) { + IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); + helper.showEditor(); + return; + } + else if (configuration instanceof IAdvancedEditorConfiguration) { + dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); + } else if (configuration instanceof IDirectEditorConfiguration) { + dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), + configuration); + } else { + return; + } + final Dialog finalDialog = dialog; + + if (Window.OK == dialog.open()) { + TransactionalEditingDomain domain = getEditingDomain(); + RecordingCommand command = new RecordingCommand(domain, "Edit Label") { + + @Override + protected void doExecute() { + configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); + + } + }; + domain.getCommandStack().execute(command); + } + } + break; + case IDirectEdition.DEFAULT_DIRECT_EDITOR: + initializeDirectEditManager(theRequest); + break; + default: + break; + } + } + + /** + * @generated + */ + protected void initializeDirectEditManager(final Request request) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + @Override + public void run() { + if (isActive() && isEditable()) { + if (request.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } + else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void refreshVisuals() { + super.refreshVisuals(); + refreshLabel(); + refreshFont(); + refreshFontColor(); + refreshUnderline(); + refreshStrikeThrough(); + } + + /** + * @generated + */ + protected void refreshLabel() { + EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); + if (maskLabelPolicy == null) { + maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); + } + if (maskLabelPolicy == null) { + View view = (View) getModel(); + if (view.isVisible()) { + setLabelTextHelper(getFigure(), getLabelText()); + setLabelIconHelper(getFigure(), getLabelIcon()); + } + else { + setLabelTextHelper(getFigure(), ""); //$NON-NLS-1$ + setLabelIconHelper(getFigure(), null); + } + } + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + protected void refreshUnderline() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); + } + if (resolveSemanticElement() instanceof Feature) { + if (((Feature) resolveSemanticElement()).isStatic()) { + ((WrappingLabel) getFigure()).setTextUnderline(true); + } + else { + ((WrappingLabel) getFigure()).setTextUnderline(false); + } + } + } + + /** + * @generated + */ + protected void refreshStrikeThrough() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); + } + } + + /** + * @generated + */ + @Override + protected void refreshFont() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null) { + FontData fontData = new FontData( + style.getFontName(), style.getFontHeight(), + (style.isBold() ? SWT.BOLD : SWT.NORMAL) | + (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); + setFont(fontData); + } + } + + /** + * @generated + */ + @Override + protected void setFontColor(Color color) { + getFigure().setForegroundColor(color); + } + + /** + * @generated + */ + @Override + protected void addSemanticListeners() { + if (getParser() instanceof ISemanticParser) { + EObject element = resolveSemanticElement(); + parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); + for (int i = 0; i < parserElements.size(); i++) { + addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ + } + } else { + super.addSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected void removeSemanticListeners() { + if (parserElements != null) { + for (int i = 0; i < parserElements.size(); i++) { + removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ + } + } else { + super.removeSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected AccessibleEditPart getAccessibleEditPart() { + if (accessibleEP == null) { + accessibleEP = new AccessibleGraphicalEditPart() { + + @Override + public void getName(AccessibleEvent e) { + e.result = getLabelTextHelper(getFigure()); + } + }; + } + return accessibleEP; + } + + /** + * @generated + */ + private View getFontStyleOwnerView() { + return getPrimaryView(); + } + + /** + * Returns the kind of associated editor for direct edition. + * + * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition + * @generated + */ + public int getDirectEditionType() { + if (checkExtendedEditor()) { + initExtendedEditorConfiguration(); + return IDirectEdition.EXTENDED_DIRECT_EDITOR; + } + if (checkDefaultEdition()) { + return IDirectEdition.DEFAULT_DIRECT_EDITOR; + } + + // not a named element. no specific editor => do nothing + return IDirectEdition.NO_DIRECT_EDITION; + } + + /** + * Checks if an extended editor is present. + * + * @return true if an extended editor is present. + * @generated + */ + protected boolean checkExtendedEditor() { + if (resolveSemanticElement() != null) { + return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); + } + return false; + } + + /** + * Checks if a default direct edition is available + * + * @return true if a default direct edition is available + * @generated + */ + protected boolean checkDefaultEdition() { + return (getParser() != null); + } + + /** + * Initializes the extended editor configuration + * + * @generated + */ + protected void initExtendedEditorConfiguration() { + if (configuration == null) { + final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("")) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); + } else { + configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); + } + } + } + + /** + * Updates the preference configuration + * + * @generated + */ + protected void updateExtendedEditorConfiguration() { + String languagePreferred = Activator.getDefault().getPreferenceStore().getString( + IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() + .eClass().getInstanceClassName()); + } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { + configuration = null; + } + } + + /** + * Performs the direct edit usually used by GMF editors. + * + * @param theRequest + * the direct edit request that starts the direct edit system + * @generated + */ + protected void performDefaultDirectEditorEdit(final Request theRequest) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + + @Override + public void run() { + if (isActive() && isEditable()) { + if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) theRequest.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { + DirectEditRequest editRequest = (DirectEditRequest) theRequest; + performDirectEdit(editRequest.getLocation()); + } else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + + /** + * @generated + */ + @Override + protected void handleNotificationEvent(Notification event) { + Object feature = event.getFeature(); + if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { + Integer c = (Integer) event.getNewValue(); + setFontColor(DiagramColorRegistry.getInstance().getColor(c)); + } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { + refreshUnderline(); + } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { + refreshStrikeThrough(); + } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { + refreshFont(); + } else { + if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { + refreshLabel(); + } + if (getParser() instanceof ISemanticParser) { + ISemanticParser modelParser = + (ISemanticParser) getParser(); + if (modelParser.areSemanticElementsAffected(null, event)) { + removeSemanticListeners(); + if (resolveSemanticElement() != null) { + addSemanticListeners(); + } + refreshLabel(); + } + } + } + super.handleNotificationEvent(event); + } + + /** + * @generated + */ + @Override + protected IFigure createFigure() { + IFigure label = createFigurePrim(); + defaultText = getLabelTextHelper(label); + return label; + } + + /** + * @generated + */ + protected IFigure createFigurePrim() { + return new PapyrusWrappingLabel(); + } + +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/TimeIntervalNameEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/TimeIntervalNameEditPart.java index cd48acea371..1ce2c5d2092 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/TimeIntervalNameEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/TimeIntervalNameEditPart.java @@ -864,7 +864,7 @@ public class TimeIntervalNameEditPart extends PapyrusCompartmentEditPart impleme * @generated */ protected void addOwnerElementListeners() { - addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); + addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/TimeObservationEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/TimeObservationEditPart.java index 28edd2aabd0..804b2f65e0d 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/TimeObservationEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/TimeObservationEditPart.java @@ -29,22 +29,23 @@ import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.BorderItemSelectionEditPolicy; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles; import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; -import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure; import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure; import org.eclipse.gmf.runtime.notation.Edge; import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.gmf.runtime.notation.View; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.IPapyrusNodeFigure; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.RoundedRectangleNodePlateFigure; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.SelectableBorderedNodeFigure; +import org.eclipse.papyrus.uml.diagram.common.editparts.RoundedCompartmentEditPart; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeIconlDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.QualifiedNameDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.ShowHideLabelEditPolicy; +import org.eclipse.papyrus.uml.diagram.common.figure.node.RoundedCompartmentFigure; import org.eclipse.papyrus.uml.diagram.common.locator.ExternalLabelPositionLocator; -import org.eclipse.papyrus.uml.diagram.composite.custom.edit.parts.AbstractObservationEditPart; +import org.eclipse.papyrus.uml.diagram.common.locator.RoundedRectangleLabelPositionLocator; import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.CustomDiagramDragDropEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.ObservationLayoutEditPolicy; -import org.eclipse.papyrus.uml.diagram.composite.custom.figures.TimeObservationNodeFigure; import org.eclipse.papyrus.uml.diagram.composite.edit.policies.TimeObservationItemSemanticEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; import org.eclipse.swt.graphics.Color; @@ -52,7 +53,7 @@ import org.eclipse.swt.graphics.Color; /** * @generated */ -public class TimeObservationEditPart extends AbstractObservationEditPart { +public class TimeObservationEditPart extends RoundedCompartmentEditPart { /** * @generated @@ -165,7 +166,7 @@ public class TimeObservationEditPart extends AbstractObservationEditPart { */ @Override protected IFigure createNodeShape() { - return primaryShape = new TimeObservationNodeFigure(); + return primaryShape = new RoundedCompartmentFigure(); } /** @@ -174,8 +175,8 @@ public class TimeObservationEditPart extends AbstractObservationEditPart { * @generated */ @Override - public TimeObservationNodeFigure getPrimaryShape() { - return (TimeObservationNodeFigure) primaryShape; + public RoundedCompartmentFigure getPrimaryShape() { + return (RoundedCompartmentFigure) primaryShape; } /** @@ -184,7 +185,7 @@ public class TimeObservationEditPart extends AbstractObservationEditPart { @Override protected void addBorderItem(IFigure borderItemContainer, IBorderItemEditPart borderItemEditPart) { if (borderItemEditPart instanceof TimeObservationNameEditPart) { - IBorderItemLocator locator = new ExternalLabelPositionLocator(getMainFigure()); + IBorderItemLocator locator = new RoundedRectangleLabelPositionLocator(getMainFigure()); borderItemContainer.add(borderItemEditPart.getFigure(), locator); } else if (borderItemEditPart instanceof TimeObservationStereotypeLabelEditPart) { IBorderItemLocator locator = new ExternalLabelPositionLocator(getMainFigure()); @@ -200,7 +201,7 @@ public class TimeObservationEditPart extends AbstractObservationEditPart { */ @Override protected NodeFigure createNodePlate() { - DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(40, 40); + RoundedRectangleNodePlateFigure result = new RoundedRectangleNodePlateFigure(20, 20); return result; } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/TimeObservationNameEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/TimeObservationNameEditPart.java index 71d063b8e08..bb5b7c802e6 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/TimeObservationNameEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/TimeObservationNameEditPart.java @@ -59,11 +59,12 @@ import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; -import org.eclipse.papyrus.infra.gmfdiag.common.editpart.PapyrusLabelEditPart; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.ExternalLabelPrimaryDragRoleEditPolicy; import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.PapyrusWrappingLabel; import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; +import org.eclipse.papyrus.uml.diagram.common.editparts.FloatingLabelEditPart; import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; @@ -83,7 +84,7 @@ import org.eclipse.uml2.uml.Feature; /** * @generated */ -public class TimeObservationNameEditPart extends PapyrusLabelEditPart implements ITextAwareEditPart, IBorderItemEditPart { +public class TimeObservationNameEditPart extends FloatingLabelEditPart implements ITextAwareEditPart, IBorderItemEditPart { /** * @generated @@ -145,6 +146,7 @@ public class TimeObservationNameEditPart extends PapyrusLabelEditPart implements super.createDefaultEditPolicies(); installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ExternalLabelPrimaryDragRoleEditPolicy()); } /** diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/TimeObservationStereotypeLabelEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/TimeObservationStereotypeLabelEditPart.java index a747c32de21..4aad0b96e44 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/TimeObservationStereotypeLabelEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/TimeObservationStereotypeLabelEditPart.java @@ -59,6 +59,7 @@ import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.ExternalLabelPrimaryDragRoleEditPolicy; import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; @@ -148,6 +149,7 @@ public class TimeObservationStereotypeLabelEditPart extends AbstractLabelEditPar installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); installEditPolicy(AppliedStereotypeLabelDisplayEditPolicy.STEREOTYPE_LABEL_POLICY, new AppliedStereotypeExternalNodeEditPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ExternalLabelPrimaryDragRoleEditPolicy()); } /** diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/UMLEditPartFactory.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/UMLEditPartFactory.java index d43495b8e2b..9304cb8c28e 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/UMLEditPartFactory.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/UMLEditPartFactory.java @@ -48,162 +48,243 @@ public class UMLEditPartFactory implements EditPartFactory { case ActivityCompositeNameEditPart.VISUAL_ID: return new ActivityCompositeNameEditPart(view); + case ActivityCompositeFloatingLabelEditPart.VISUAL_ID: + return new ActivityCompositeFloatingLabelEditPart(view); + case InteractionCompositeEditPart.VISUAL_ID: return new InteractionCompositeEditPart(view); case InteractionCompositeNameEditPart.VISUAL_ID: return new InteractionCompositeNameEditPart(view); + case InteractionCompositeFloatingLabelEditPart.VISUAL_ID: + return new InteractionCompositeFloatingLabelEditPart(view); + case ProtocolStateMachineCompositeEditPart.VISUAL_ID: return new ProtocolStateMachineCompositeEditPart(view); case ProtocolStateMachineCompositeNameEditPart.VISUAL_ID: return new ProtocolStateMachineCompositeNameEditPart(view); + case ProtocolStateMachineCompositeFloatingLabelEditPart.VISUAL_ID: + return new ProtocolStateMachineCompositeFloatingLabelEditPart(view); + case StateMachineCompositeEditPart.VISUAL_ID: return new StateMachineCompositeEditPart(view); case StateMachineCompositeNameEditPart.VISUAL_ID: return new StateMachineCompositeNameEditPart(view); + case StateMachineCompositeFloatingLabelEditPart.VISUAL_ID: + return new StateMachineCompositeFloatingLabelEditPart(view); + case FunctionBehaviorCompositeEditPart.VISUAL_ID: return new FunctionBehaviorCompositeEditPart(view); case FunctionBehaviorCompositeNameEditPart.VISUAL_ID: return new FunctionBehaviorCompositeNameEditPart(view); + case FunctionBehaviorCompositeFloatingLabelEditPart.VISUAL_ID: + return new FunctionBehaviorCompositeFloatingLabelEditPart(view); + case OpaqueBehaviorCompositeEditPart.VISUAL_ID: return new OpaqueBehaviorCompositeEditPart(view); case OpaqueBehaviorCompositeNameEditPart.VISUAL_ID: return new OpaqueBehaviorCompositeNameEditPart(view); + case OpaqueBehaviorCompositeFloatingLabelEditPart.VISUAL_ID: + return new OpaqueBehaviorCompositeFloatingLabelEditPart(view); + case ComponentCompositeEditPart.VISUAL_ID: return new ComponentCompositeEditPart(view); case ComponentCompositeNameEditPart.VISUAL_ID: return new ComponentCompositeNameEditPart(view); + case ComponentCompositeFloatingLabelEditPart.VISUAL_ID: + return new ComponentCompositeFloatingLabelEditPart(view); + case DeviceCompositeEditPart.VISUAL_ID: return new DeviceCompositeEditPart(view); case DeviceCompositeNameEditPart.VISUAL_ID: return new DeviceCompositeNameEditPart(view); + case DeviceCompositeFloatingLabelEditPart.VISUAL_ID: + return new DeviceCompositeFloatingLabelEditPart(view); + case ExecutionEnvironmentCompositeEditPart.VISUAL_ID: return new ExecutionEnvironmentCompositeEditPart(view); case ExecutionEnvironmentCompositeNameEditPart.VISUAL_ID: return new ExecutionEnvironmentCompositeNameEditPart(view); + case ExecutionEnvironmentCompositeFloatingLabelEditPart.VISUAL_ID: + return new ExecutionEnvironmentCompositeFloatingLabelEditPart(view); + case NodeCompositeEditPart.VISUAL_ID: return new NodeCompositeEditPart(view); case NodeCompositeNameEditPart.VISUAL_ID: return new NodeCompositeNameEditPart(view); + case NodeCompositeFloatingLabelEditPart.VISUAL_ID: + return new NodeCompositeFloatingLabelEditPart(view); + case ClassCompositeEditPart.VISUAL_ID: return new ClassCompositeEditPart(view); case ClassCompositeNameEditPart.VISUAL_ID: return new ClassCompositeNameEditPart(view); + case ClassCompositeFloatingLabelEditPart.VISUAL_ID: + return new ClassCompositeFloatingLabelEditPart(view); + case CollaborationCompositeEditPart.VISUAL_ID: return new CollaborationCompositeEditPart(view); case CollaborationCompositeNameEditPart.VISUAL_ID: return new CollaborationCompositeNameEditPart(view); + case CollaborationCompositeFloatingLabelEditPart.VISUAL_ID: + return new CollaborationCompositeFloatingLabelEditPart(view); + case InterfaceEditPart.VISUAL_ID: return new InterfaceEditPart(view); case InterfaceNameEditPart.VISUAL_ID: return new InterfaceNameEditPart(view); + case InterfaceFloatingLabelEditPart.VISUAL_ID: + return new InterfaceFloatingLabelEditPart(view); + case PrimitiveTypeEditPart.VISUAL_ID: return new PrimitiveTypeEditPart(view); case PrimitiveTypeNameEditPart.VISUAL_ID: return new PrimitiveTypeNameEditPart(view); + case PrimitiveTypeFloatingLabelEditPart.VISUAL_ID: + return new PrimitiveTypeFloatingLabelEditPart(view); + case EnumerationEditPart.VISUAL_ID: return new EnumerationEditPart(view); case EnumerationNameEditPart.VISUAL_ID: return new EnumerationNameEditPart(view); + case EnumerationFloatingLabelEditPart.VISUAL_ID: + return new EnumerationFloatingLabelEditPart(view); + case DataTypeEditPart.VISUAL_ID: return new DataTypeEditPart(view); case DataTypeNameEditPart.VISUAL_ID: return new DataTypeNameEditPart(view); + case DataTypeFloatingLabelEditPart.VISUAL_ID: + return new DataTypeFloatingLabelEditPart(view); + case ActorEditPart.VISUAL_ID: return new ActorEditPart(view); case ActorNameEditPart.VISUAL_ID: return new ActorNameEditPart(view); + case ActorFloatingLabelEditPart.VISUAL_ID: + return new ActorFloatingLabelEditPart(view); + case DeploymentSpecificationEditPart.VISUAL_ID: return new DeploymentSpecificationEditPart(view); case DeploymentSpecificationNameEditPart.VISUAL_ID: return new DeploymentSpecificationNameEditPart(view); + case DeploymentSpecificationFloatingLabelEditPart.VISUAL_ID: + return new DeploymentSpecificationFloatingLabelEditPart(view); + case ArtifactEditPart.VISUAL_ID: return new ArtifactEditPart(view); case ArtifactNameEditPart.VISUAL_ID: return new ArtifactNameEditPart(view); + case ArtifactFloatingLabelEditPart.VISUAL_ID: + return new ArtifactFloatingLabelEditPart(view); + case InformationItemEditPart.VISUAL_ID: return new InformationItemEditPart(view); case InformationItemNameEditPart.VISUAL_ID: return new InformationItemNameEditPart(view); + case InformationItemFloatingLabelEditPart.VISUAL_ID: + return new InformationItemFloatingLabelEditPart(view); + case SignalEditPart.VISUAL_ID: return new SignalEditPart(view); case SignalNameEditPart.VISUAL_ID: return new SignalNameEditPart(view); + case SignalFloatingLabelEditPart.VISUAL_ID: + return new SignalFloatingLabelEditPart(view); + case UseCaseEditPart.VISUAL_ID: return new UseCaseEditPart(view); case UseCaseNameEditPart.VISUAL_ID: return new UseCaseNameEditPart(view); + case UseCaseFloatingLabelEditPart.VISUAL_ID: + return new UseCaseFloatingLabelEditPart(view); + case SignalEventEditPart.VISUAL_ID: return new SignalEventEditPart(view); case SignalEventNameEditPart.VISUAL_ID: return new SignalEventNameEditPart(view); + case SignalEventFloatingLabelEditPart.VISUAL_ID: + return new SignalEventFloatingLabelEditPart(view); + case CallEventEditPart.VISUAL_ID: return new CallEventEditPart(view); case CallEventNameEditPart.VISUAL_ID: return new CallEventNameEditPart(view); + case CallEventFloatingLabelEditPart.VISUAL_ID: + return new CallEventFloatingLabelEditPart(view); + case AnyReceiveEventEditPart.VISUAL_ID: return new AnyReceiveEventEditPart(view); case AnyReceiveEventNameEditPart.VISUAL_ID: return new AnyReceiveEventNameEditPart(view); + case AnyReceiveEventFloatingLabelEditPart.VISUAL_ID: + return new AnyReceiveEventFloatingLabelEditPart(view); + case ChangeEventEditPart.VISUAL_ID: return new ChangeEventEditPart(view); case ChangeEventNameEditPart.VISUAL_ID: return new ChangeEventNameEditPart(view); + case ChangeEventFloatingLabelEditPart.VISUAL_ID: + return new ChangeEventFloatingLabelEditPart(view); + case TimeEventEditPart.VISUAL_ID: return new TimeEventEditPart(view); case TimeEventNameEditPart.VISUAL_ID: return new TimeEventNameEditPart(view); + case TimeEventFloatingLabelEditPart.VISUAL_ID: + return new TimeEventFloatingLabelEditPart(view); + case DurationObservationEditPart.VISUAL_ID: return new DurationObservationEditPart(view); @@ -228,84 +309,126 @@ public class UMLEditPartFactory implements EditPartFactory { case LiteralBooleanNameEditPart.VISUAL_ID: return new LiteralBooleanNameEditPart(view); + case LiteralBooleanFloatingLabelEditPart.VISUAL_ID: + return new LiteralBooleanFloatingLabelEditPart(view); + case LiteralIntegerEditPart.VISUAL_ID: return new LiteralIntegerEditPart(view); case LiteralIntegerNameEditPart.VISUAL_ID: return new LiteralIntegerNameEditPart(view); + case LiteralIntegerFloatingLabelEditPart.VISUAL_ID: + return new LiteralIntegerFloatingLabelEditPart(view); + case LiteralNullEditPart.VISUAL_ID: return new LiteralNullEditPart(view); case LiteralNullNameEditPart.VISUAL_ID: return new LiteralNullNameEditPart(view); + case LiteralNullFloatingLabelEditPart.VISUAL_ID: + return new LiteralNullFloatingLabelEditPart(view); + case LiteralStringEditPart.VISUAL_ID: return new LiteralStringEditPart(view); case LiteralStringNameEditPart.VISUAL_ID: return new LiteralStringNameEditPart(view); + case LiteralStringFloatingLabelEditPart.VISUAL_ID: + return new LiteralStringFloatingLabelEditPart(view); + case LiteralUnlimitedNaturalEditPart.VISUAL_ID: return new LiteralUnlimitedNaturalEditPart(view); case LiteralUnlimitedNaturalNameEditPart.VISUAL_ID: return new LiteralUnlimitedNaturalNameEditPart(view); + case LiteralUnlimitedNaturalFloatingLabelEditPart.VISUAL_ID: + return new LiteralUnlimitedNaturalFloatingLabelEditPart(view); + case StringExpressionEditPart.VISUAL_ID: return new StringExpressionEditPart(view); case StringExpressionNameEditPart.VISUAL_ID: return new StringExpressionNameEditPart(view); + case StringExpressionFloatingLabelEditPart.VISUAL_ID: + return new StringExpressionFloatingLabelEditPart(view); + case OpaqueExpressionEditPart.VISUAL_ID: return new OpaqueExpressionEditPart(view); case OpaqueExpressionNameEditPart.VISUAL_ID: return new OpaqueExpressionNameEditPart(view); + case OpaqueExpressionFloatingLabelEditPart.VISUAL_ID: + return new OpaqueExpressionFloatingLabelEditPart(view); + case TimeExpressionEditPart.VISUAL_ID: return new TimeExpressionEditPart(view); case TimeExpressionNameEditPart.VISUAL_ID: return new TimeExpressionNameEditPart(view); + case TimeExpressionFloatingLabelEditPart.VISUAL_ID: + return new TimeExpressionFloatingLabelEditPart(view); + case ExpressionEditPart.VISUAL_ID: return new ExpressionEditPart(view); case ExpressionNameEditPart.VISUAL_ID: return new ExpressionNameEditPart(view); + case ExpressionFloatingLabelEditPart.VISUAL_ID: + return new ExpressionFloatingLabelEditPart(view); + case DurationEditPart.VISUAL_ID: return new DurationEditPart(view); case DurationNameEditPart.VISUAL_ID: return new DurationNameEditPart(view); + case DurationFloatingLabelEditPart.VISUAL_ID: + return new DurationFloatingLabelEditPart(view); + case TimeIntervalEditPart.VISUAL_ID: return new TimeIntervalEditPart(view); case TimeIntervalNameEditPart.VISUAL_ID: return new TimeIntervalNameEditPart(view); + case TimeIntervalFloatingLabelEditPart.VISUAL_ID: + return new TimeIntervalFloatingLabelEditPart(view); + case DurationIntervalEditPart.VISUAL_ID: return new DurationIntervalEditPart(view); case DurationIntervalNameEditPart.VISUAL_ID: return new DurationIntervalNameEditPart(view); + case DurationIntervalFloatingLabelEditPart.VISUAL_ID: + return new DurationIntervalFloatingLabelEditPart(view); + case IntervalEditPart.VISUAL_ID: return new IntervalEditPart(view); case IntervalNameEditPart.VISUAL_ID: return new IntervalNameEditPart(view); + case IntervalFloatingLabelEditPart.VISUAL_ID: + return new IntervalFloatingLabelEditPart(view); + case InstanceValueEditPart.VISUAL_ID: return new InstanceValueEditPart(view); case InstanceValueNameEditPart.VISUAL_ID: return new InstanceValueNameEditPart(view); + case InstanceValueFloatingLabelEditPart.VISUAL_ID: + return new InstanceValueFloatingLabelEditPart(view); + case CommentEditPart.VISUAL_ID: return new CommentEditPart(view); @@ -360,6 +483,9 @@ public class UMLEditPartFactory implements EditPartFactory { case BehaviorPortEditPart.VISUAL_ID: return new BehaviorPortEditPart(view); + case BehaviorPortFloatingLabelEditPart.VISUAL_ID: + return new BehaviorPortFloatingLabelEditPart(view); + case PortEditPart.VISUAL_ID: return new PortEditPart(view); @@ -384,150 +510,225 @@ public class UMLEditPartFactory implements EditPartFactory { case PropertyPartNameEditPartCN.VISUAL_ID: return new PropertyPartNameEditPartCN(view); + case PropertyPartFloatingLabelEditPartCN.VISUAL_ID: + return new PropertyPartFloatingLabelEditPartCN(view); + case CollaborationRoleEditPartCN.VISUAL_ID: return new CollaborationRoleEditPartCN(view); case CollaborationRoleNameEditPartCN.VISUAL_ID: return new CollaborationRoleNameEditPartCN(view); + case CollaborationRoleFloatingLabelEditPartCN.VISUAL_ID: + return new CollaborationRoleFloatingLabelEditPartCN(view); + case CollaborationUseEditPartCN.VISUAL_ID: return new CollaborationUseEditPartCN(view); case CollaborationUseNameEditPart.VISUAL_ID: return new CollaborationUseNameEditPart(view); + case CollaborationUseFloatingLabelEditPartCN.VISUAL_ID: + return new CollaborationUseFloatingLabelEditPartCN(view); + case ActivityCompositeEditPartCN.VISUAL_ID: return new ActivityCompositeEditPartCN(view); case ActivityCompositeNameEditPartCN.VISUAL_ID: return new ActivityCompositeNameEditPartCN(view); + case ActivityCompositeFloatingLabelEditPartCN.VISUAL_ID: + return new ActivityCompositeFloatingLabelEditPartCN(view); + case InteractionCompositeEditPartCN.VISUAL_ID: return new InteractionCompositeEditPartCN(view); case InteractionCompositeNameEditPartCN.VISUAL_ID: return new InteractionCompositeNameEditPartCN(view); + case InteractionCompositeFloatingLabelEditPartCN.VISUAL_ID: + return new InteractionCompositeFloatingLabelEditPartCN(view); + case ProtocolStateMachineCompositeEditPartCN.VISUAL_ID: return new ProtocolStateMachineCompositeEditPartCN(view); case ProtocolStateMachineCompositeNameEditPartCN.VISUAL_ID: return new ProtocolStateMachineCompositeNameEditPartCN(view); + case ProtocolStateMachineCompositeFloatingLabelEditPartCN.VISUAL_ID: + return new ProtocolStateMachineCompositeFloatingLabelEditPartCN(view); + case StateMachineCompositeEditPartCN.VISUAL_ID: return new StateMachineCompositeEditPartCN(view); case StateMachineCompositeNameEditPartCN.VISUAL_ID: return new StateMachineCompositeNameEditPartCN(view); + case StateMachineCompositeFloatingLabelEditPartCN.VISUAL_ID: + return new StateMachineCompositeFloatingLabelEditPartCN(view); + case FunctionBehaviorCompositeEditPartCN.VISUAL_ID: return new FunctionBehaviorCompositeEditPartCN(view); case FunctionBehaviorCompositeNameEditPartCN.VISUAL_ID: return new FunctionBehaviorCompositeNameEditPartCN(view); + case FunctionBehaviorCompositeFloatingLabelEditPartCN.VISUAL_ID: + return new FunctionBehaviorCompositeFloatingLabelEditPartCN(view); + case OpaqueBehaviorCompositeEditPartCN.VISUAL_ID: return new OpaqueBehaviorCompositeEditPartCN(view); case OpaqueBehaviorCompositeNameEditPartCN.VISUAL_ID: return new OpaqueBehaviorCompositeNameEditPartCN(view); + case OpaqueBehaviorCompositeFloatingLabelEditPartCN.VISUAL_ID: + return new OpaqueBehaviorCompositeFloatingLabelEditPartCN(view); + case ComponentCompositeEditPartCN.VISUAL_ID: return new ComponentCompositeEditPartCN(view); case ComponentCompositeNameEditPartCN.VISUAL_ID: return new ComponentCompositeNameEditPartCN(view); + case ComponentCompositeFloatingLabelEditPartCN.VISUAL_ID: + return new ComponentCompositeFloatingLabelEditPartCN(view); + case DeviceCompositeEditPartCN.VISUAL_ID: return new DeviceCompositeEditPartCN(view); case DeviceCompositeNameEditPartCN.VISUAL_ID: return new DeviceCompositeNameEditPartCN(view); + case DeviceCompositeFloatingLabelEditPartCN.VISUAL_ID: + return new DeviceCompositeFloatingLabelEditPartCN(view); + case ExecutionEnvironmentCompositeEditPartCN.VISUAL_ID: return new ExecutionEnvironmentCompositeEditPartCN(view); case ExecutionEnvironmentCompositeNameEditPartCN.VISUAL_ID: return new ExecutionEnvironmentCompositeNameEditPartCN(view); + case ExecutionEnvironmentCompositeFloatingLabelEditPartCN.VISUAL_ID: + return new ExecutionEnvironmentCompositeFloatingLabelEditPartCN(view); + case NodeCompositeEditPartCN.VISUAL_ID: return new NodeCompositeEditPartCN(view); case NodeCompositeNameEditPartCN.VISUAL_ID: return new NodeCompositeNameEditPartCN(view); + case NodeCompositeFloatingLabelEditPartCN.VISUAL_ID: + return new NodeCompositeFloatingLabelEditPartCN(view); + case ClassCompositeEditPartCN.VISUAL_ID: return new ClassCompositeEditPartCN(view); case ClassCompositeNameEditPartCN.VISUAL_ID: return new ClassCompositeNameEditPartCN(view); + case ClassCompositeFloatingLabelEditPartCN.VISUAL_ID: + return new ClassCompositeFloatingLabelEditPartCN(view); + case CollaborationCompositeEditPartCN.VISUAL_ID: return new CollaborationCompositeEditPartCN(view); case CollaborationCompositeNameEditPartCN.VISUAL_ID: return new CollaborationCompositeNameEditPartCN(view); + case CollaborationCompositeFloatingLabelEditPartCN.VISUAL_ID: + return new CollaborationCompositeFloatingLabelEditPartCN(view); + case InterfaceEditPartCN.VISUAL_ID: return new InterfaceEditPartCN(view); case InterfaceNameEditPartCN.VISUAL_ID: return new InterfaceNameEditPartCN(view); + case InterfaceFloatingLabelEditPartCN.VISUAL_ID: + return new InterfaceFloatingLabelEditPartCN(view); + case PrimitiveTypeEditPartCN.VISUAL_ID: return new PrimitiveTypeEditPartCN(view); case PrimitiveTypeNameEditPartCN.VISUAL_ID: return new PrimitiveTypeNameEditPartCN(view); + case PrimitiveTypeFloatingLabelEditPartCN.VISUAL_ID: + return new PrimitiveTypeFloatingLabelEditPartCN(view); + case EnumerationEditPartCN.VISUAL_ID: return new EnumerationEditPartCN(view); case EnumerationNameEditPartCN.VISUAL_ID: return new EnumerationNameEditPartCN(view); + case EnumerationFloatingLabelEditPartCN.VISUAL_ID: + return new EnumerationFloatingLabelEditPartCN(view); + case DataTypeEditPartCN.VISUAL_ID: return new DataTypeEditPartCN(view); case DataTypeNameEditPartCN.VISUAL_ID: return new DataTypeNameEditPartCN(view); + case DataTypeFloatingLabelEditPartCN.VISUAL_ID: + return new DataTypeFloatingLabelEditPartCN(view); + case ActorEditPartCN.VISUAL_ID: return new ActorEditPartCN(view); case ActorNameEditPartCN.VISUAL_ID: return new ActorNameEditPartCN(view); + case ActorFloatingLabelEditPartCN.VISUAL_ID: + return new ActorFloatingLabelEditPartCN(view); + case DeploymentSpecificationEditPartCN.VISUAL_ID: return new DeploymentSpecificationEditPartCN(view); case DeploymentSpecificationNameEditPartCN.VISUAL_ID: return new DeploymentSpecificationNameEditPartCN(view); + case DeploymentSpecificationFloatingLabelEditPartCN.VISUAL_ID: + return new DeploymentSpecificationFloatingLabelEditPartCN(view); + case ArtifactEditPartCN.VISUAL_ID: return new ArtifactEditPartCN(view); case ArtifactNameEditPartCN.VISUAL_ID: return new ArtifactNameEditPartCN(view); + case ArtifactFloatingLabelEditPartCN.VISUAL_ID: + return new ArtifactFloatingLabelEditPartCN(view); + case InformationItemEditPartCN.VISUAL_ID: return new InformationItemEditPartCN(view); case InformationItemNameEditPartCN.VISUAL_ID: return new InformationItemNameEditPartCN(view); + case InformationItemFloatingLabelEditPartCN.VISUAL_ID: + return new InformationItemFloatingLabelEditPartCN(view); + case SignalEditPartCN.VISUAL_ID: return new SignalEditPartCN(view); case SignalNameEditPartCN.VISUAL_ID: return new SignalNameEditPartCN(view); + case SignalFloatingLabelEditPartCN.VISUAL_ID: + return new SignalFloatingLabelEditPartCN(view); + case UseCaseEditPartCN.VISUAL_ID: return new UseCaseEditPartCN(view); case UseCaseNameEditPartCN.VISUAL_ID: return new UseCaseNameEditPartCN(view); + case UseCaseFloatingLabelEditPartCN.VISUAL_ID: + return new UseCaseFloatingLabelEditPartCN(view); + case CommentEditPartCN.VISUAL_ID: return new CommentEditPartCN(view); diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/UsageAppliedStereotypeEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/UsageAppliedStereotypeEditPart.java index c6dd39a992a..c38a5337596 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/UsageAppliedStereotypeEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/UsageAppliedStereotypeEditPart.java @@ -1,820 +1,815 @@ -/** - * 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.uml.diagram.composite.edit.parts; - -import java.util.Collections; -import java.util.List; - -import org.eclipse.draw2d.ConnectionLocator; -import org.eclipse.draw2d.IFigure; -import org.eclipse.draw2d.Label; -import org.eclipse.draw2d.geometry.Point; -import org.eclipse.emf.common.notify.Notification; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.transaction.RecordingCommand; -import org.eclipse.emf.transaction.RunnableWithResult; -import org.eclipse.emf.transaction.TransactionalEditingDomain; -import org.eclipse.gef.AccessibleEditPart; -import org.eclipse.gef.EditPolicy; -import org.eclipse.gef.Request; -import org.eclipse.gef.requests.DirectEditRequest; -import org.eclipse.gef.tools.DirectEditManager; -import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; -import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; -import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; -import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; -import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; -import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; -import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; -import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; -import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; -import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; -import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; -import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; -import org.eclipse.gmf.runtime.notation.FontStyle; -import org.eclipse.gmf.runtime.notation.NotationPackage; -import org.eclipse.gmf.runtime.notation.View; -import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.jface.text.contentassist.IContentAssistProcessor; -import org.eclipse.jface.viewers.ICellEditorValidator; -import org.eclipse.jface.window.Window; -import org.eclipse.papyrus.extensionpoints.editors.Activator; -import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; -import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; -import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; -import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; -import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; -import org.eclipse.papyrus.infra.gmfdiag.common.editpart.IControlParserForDirectEdit; -import org.eclipse.papyrus.infra.gmfdiag.common.editpart.PapyrusLabelEditPart; -import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; -import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; -import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.PapyrusLinkLabelDragPolicy; -import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; -import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; -import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; -import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; -import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; -import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; -import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; -import org.eclipse.swt.SWT; -import org.eclipse.swt.accessibility.AccessibleEvent; -import org.eclipse.swt.custom.BusyIndicator; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.FontData; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.widgets.Display; -import org.eclipse.ui.PlatformUI; -import org.eclipse.uml2.uml.Feature; - -/** - * @generated - */ -public class UsageAppliedStereotypeEditPart extends PapyrusLabelEditPart implements ITextAwareEditPart, IControlParserForDirectEdit { - - /** - * @generated - */ - public static final int VISUAL_ID = 6021; - - /** - * @generated - */ - private DirectEditManager manager; - - /** - * @generated - */ - private IParser parser; - - /** - * @generated - */ - private List parserElements; - - /** - * @generated - */ - private String defaultText; - - /** - * direct edition mode (default, undefined, registered editor, etc.) - * - * @generated - */ - protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; - - /** - * configuration from a registered edit dialog - * - * @generated - */ - protected IDirectEditorConfiguration configuration; - /** - * @generated - */ - static { - registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.UsageAppliedStereotypeEditPart.VISUAL_ID), new Point(0, 30)); - } - - /** - * @generated - */ - public UsageAppliedStereotypeEditPart(View view) { - super(view); - } - - /** - * @generated - */ - @Override - protected void createDefaultEditPolicies() { - super.createDefaultEditPolicies(); - installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); - installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); - installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new PapyrusLinkLabelDragPolicy()); - } - - /** - * @generated - */ - @Override - public int getKeyPoint() { - return ConnectionLocator.MIDDLE; - } - - /** - * @generated - */ - protected String getLabelTextHelper(IFigure figure) { - if (figure instanceof WrappingLabel) { - return ((WrappingLabel) figure).getText(); - } else if (figure instanceof ILabelFigure) { - return ((ILabelFigure) figure).getText(); - } else { - return ((Label) figure).getText(); - } - } - - /** - * @generated - */ - protected void setLabelTextHelper(IFigure figure, String text) { - if (figure instanceof WrappingLabel) { - ((WrappingLabel) figure).setText(text); - } else if (figure instanceof ILabelFigure) { - ((ILabelFigure) figure).setText(text); - } else { - ((Label) figure).setText(text); - } - } - - /** - * @generated - */ - protected Image getLabelIconHelper(IFigure figure) { - if (figure instanceof WrappingLabel) { - return ((WrappingLabel) figure).getIcon(); - } else if (figure instanceof ILabelFigure) { - return ((ILabelFigure) figure).getIcon(); - } else { - return ((Label) figure).getIcon(); - } - } - - /** - * @generated - */ - protected void setLabelIconHelper(IFigure figure, Image icon) { - if (figure instanceof WrappingLabel) { - ((WrappingLabel) figure).setIcon(icon); - } else if (figure instanceof ILabelFigure) { - ((ILabelFigure) figure).setIcon(icon); - } else { - ((Label) figure).setIcon(icon); - } - } - - /** - * @generated - */ - public void setLabel(IFigure - figure) { - unregisterVisuals(); - setFigure(figure); - defaultText = getLabelTextHelper(figure); - registerVisuals(); - refreshVisuals(); - } - - /** - * @generated - */ - @Override - protected List getModelChildren() { - return Collections.EMPTY_LIST; - } - - /** - * @generated - */ - @Override - public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { - return null; - } - - /** - * @generated - */ - @Override - public void setParser(IParser parser) { - this.parser = parser; - } - - /** - * @generated - */ - protected EObject getParserElement() { - return resolveSemanticElement(); - } - - /** - * @generated - */ - protected Image getLabelIcon() { - return null; - } - - /** - * @generated - */ - protected String getLabelText() { - String text = null; - EObject parserElement = getParserElement(); - if (parserElement != null && getParser() != null) { - text = getParser().getPrintString( - new EObjectAdapter(parserElement), - getParserOptions().intValue()); - } - if (text == null || text.length() == 0) { - text = defaultText; - } - return text; - } - - /** - * @generated - */ - @Override - public void setLabelText(String text) { - setLabelTextHelper(getFigure(), text); - Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); - if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); - } - Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); - if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); - } - } - - /** - * @generated - */ - @Override - public String getEditText() { - if (getParserElement() == null || getParser() == null) { - return ""; //$NON-NLS-1$ - } - return getParser().getEditString( - new EObjectAdapter(getParserElement()), - getParserOptions().intValue()); - } - - /** - * @generated - */ - protected boolean isEditable() { - return false; - } - - /** - * @generated - */ - @Override - public ICellEditorValidator getEditTextValidator() { - return new ICellEditorValidator() { - - @Override - public String isValid(final Object value) { - if (value instanceof String) { - final EObject element = getParserElement(); - final IParser parser = getParser(); - try { - IParserEditStatus valid = - (IParserEditStatus) getEditingDomain().runExclusive( - new RunnableWithResult.Impl() { - - @Override - public void run() { - setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); - } - }); - return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); - } catch (InterruptedException ie) { - ie.printStackTrace(); - } - } - - // shouldn't get here - return null; - } - }; - } - - /** - * @generated - */ - @Override - public IContentAssistProcessor getCompletionProcessor() { - if (getParserElement() == null || getParser() == null) { - return null; - } - return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); - } - - /** - * @generated - */ - @Override - public ParserOptions getParserOptions() { - return ParserOptions.NONE; - } - - /** - * @generated - */ - @Override - public IParser getParser() { - if (parser == null) { - parser = UMLParserProvider.getParser(UMLElementTypes.Usage_4008, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.UsageAppliedStereotypeEditPart.VISUAL_ID)); - } - return parser; - } - - /** - * @generated - */ - protected DirectEditManager getManager() { - if (manager == null) { - setManager(new MultilineLabelDirectEditManager(this, - MultilineLabelDirectEditManager.getTextCellEditorClass(this), - UMLEditPartFactory.getTextCellEditorLocator(this))); - } - return manager; - } - - /** - * @generated - */ - protected void setManager(DirectEditManager manager) { - this.manager = manager; - } - - /** - * @generated - */ - protected void performDirectEdit() { - BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { - - @Override - public void run() { - getManager().show(); - } - }); - } - - /** - * @generated - */ - protected void performDirectEdit(Point eventLocation) { - if (getManager() instanceof TextDirectEditManager) { - ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); - } - } - - /** - * @generated - */ - private void performDirectEdit(char initialCharacter) { - if (getManager() instanceof TextDirectEditManager) { - ((TextDirectEditManager) getManager()).show(initialCharacter); - } else { - performDirectEdit(); - } - } - - /** - * @generated - */ - @Override - protected void performDirectEditRequest(Request request) { - - final Request theRequest = request; - - if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { - directEditionMode = getDirectEditionType(); - } - switch (directEditionMode) { - case IDirectEdition.NO_DIRECT_EDITION: - // no direct edition mode => does nothing - return; - case IDirectEdition.EXTENDED_DIRECT_EDITOR: - updateExtendedEditorConfiguration(); - if (configuration == null || configuration.getLanguage() == null) { - // Create default edit manager - setManager(new MultilineLabelDirectEditManager(this, - MultilineLabelDirectEditManager.getTextCellEditorClass(this), - UMLEditPartFactory.getTextCellEditorLocator(this))); - performDefaultDirectEditorEdit(theRequest); - } else { - configuration.preEditAction(resolveSemanticElement()); - Dialog dialog = null; - if (configuration instanceof ICustomDirectEditorConfiguration) { - setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); - initializeDirectEditManager(theRequest); - return; - } else if (configuration instanceof IPopupEditorConfiguration) { - IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); - helper.showEditor(); - return; - } - else if (configuration instanceof IAdvancedEditorConfiguration) { - dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); - } else if (configuration instanceof IDirectEditorConfiguration) { - dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), - configuration); - } else { - return; - } - final Dialog finalDialog = dialog; - - if (Window.OK == dialog.open()) { - TransactionalEditingDomain domain = getEditingDomain(); - RecordingCommand command = new RecordingCommand(domain, "Edit Label") { - - @Override - protected void doExecute() { - configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); - - } - }; - domain.getCommandStack().execute(command); - } - } - break; - case IDirectEdition.DEFAULT_DIRECT_EDITOR: - initializeDirectEditManager(theRequest); - break; - default: - break; - } - } - - /** - * @generated - */ - protected void initializeDirectEditManager(final Request request) { - // initialize the direct edit manager - try { - getEditingDomain().runExclusive(new Runnable() { - @Override - public void run() { - if (isActive() && isEditable()) { - if (request.getExtendedData().get( - RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { - Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); - performDirectEdit(initialChar.charValue()); - } - else { - performDirectEdit(); - } - } - } - }); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - - /** - * @generated - */ - @Override - protected void refreshVisuals() { - super.refreshVisuals(); - refreshLabel(); - refreshFont(); - refreshFontColor(); - refreshUnderline(); - refreshStrikeThrough(); - } - - /** - * @generated - */ - protected void refreshLabel() { - EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); - if (maskLabelPolicy == null) { - maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); - } - if (maskLabelPolicy == null) { - View view = (View) getModel(); - if (view.isVisible()) { - setLabelTextHelper(getFigure(), getLabelText()); - setLabelIconHelper(getFigure(), getLabelIcon()); - } - else { - setLabelTextHelper(getFigure(), ""); //$NON-NLS-1$ - setLabelIconHelper(getFigure(), null); - } - } - Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); - if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); - } - Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); - if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); - } - } - - /** - * @generated - */ - protected void refreshUnderline() { - FontStyle style = - (FontStyle) getFontStyleOwnerView().getStyle( - NotationPackage.eINSTANCE.getFontStyle()); - if (style != null && getFigure() instanceof WrappingLabel) { - ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); - } - if (resolveSemanticElement() instanceof Feature) { - if (((Feature) resolveSemanticElement()).isStatic()) { - ((WrappingLabel) getFigure()).setTextUnderline(true); - } - else { - ((WrappingLabel) getFigure()).setTextUnderline(false); - } - } - } - - /** - * @generated - */ - protected void refreshStrikeThrough() { - FontStyle style = - (FontStyle) getFontStyleOwnerView().getStyle( - NotationPackage.eINSTANCE.getFontStyle()); - if (style != null && getFigure() instanceof WrappingLabel) { - ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); - } - } - - /** - * @generated - */ - @Override - protected void refreshFont() { - FontStyle style = - (FontStyle) getFontStyleOwnerView().getStyle( - NotationPackage.eINSTANCE.getFontStyle()); - if (style != null) { - FontData fontData = new FontData( - style.getFontName(), style.getFontHeight(), - (style.isBold() ? SWT.BOLD : SWT.NORMAL) | - (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); - setFont(fontData); - } - } - - /** - * @generated - */ - @Override - protected void setFontColor(Color color) { - getFigure().setForegroundColor(color); - } - - /** - * @generated - */ - @Override - protected void addSemanticListeners() { - if (getParser() instanceof ISemanticParser) { - EObject element = resolveSemanticElement(); - parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); - for (int i = 0; i < parserElements.size(); i++) { - addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ - } - } else { - super.addSemanticListeners(); - } - } - - /** - * @generated - */ - @Override - protected void removeSemanticListeners() { - if (parserElements != null) { - for (int i = 0; i < parserElements.size(); i++) { - removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ - } - } else { - super.removeSemanticListeners(); - } - } - - /** - * @generated - */ - @Override - protected AccessibleEditPart getAccessibleEditPart() { - if (accessibleEP == null) { - accessibleEP = new AccessibleGraphicalEditPart() { - - @Override - public void getName(AccessibleEvent e) { - e.result = getLabelTextHelper(getFigure()); - } - }; - } - return accessibleEP; - } - - /** - * @generated - */ - private View getFontStyleOwnerView() { - return getPrimaryView(); - } - - /** - * Returns the kind of associated editor for direct edition. - * - * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition - * @generated - */ - public int getDirectEditionType() { - // The label is read-only (defined in GMFGen model) - return IDirectEdition.NO_DIRECT_EDITION; - } - - /** - * Checks if an extended editor is present. - * - * @return true if an extended editor is present. - * @generated - */ - protected boolean checkExtendedEditor() { - if (resolveSemanticElement() != null) { - return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); - } - return false; - } - - /** - * Checks if a default direct edition is available - * - * @return true if a default direct edition is available - * @generated - */ - protected boolean checkDefaultEdition() { - return (getParser() != null); - } - - /** - * Initializes the extended editor configuration - * - * @generated - */ - protected void initExtendedEditorConfiguration() { - if (configuration == null) { - final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); - if (languagePreferred != null && !languagePreferred.equals("")) { - configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); - } else { - configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); - } - } - } - - /** - * Updates the preference configuration - * - * @generated - */ - protected void updateExtendedEditorConfiguration() { - String languagePreferred = Activator.getDefault().getPreferenceStore().getString( - IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); - if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { - configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() - .eClass().getInstanceClassName()); - } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { - configuration = null; - } - } - - /** - * Performs the direct edit usually used by GMF editors. - * - * @param theRequest - * the direct edit request that starts the direct edit system - * @generated - */ - protected void performDefaultDirectEditorEdit(final Request theRequest) { - // initialize the direct edit manager - try { - getEditingDomain().runExclusive(new Runnable() { - - @Override - public void run() { - if (isActive() && isEditable()) { - if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { - Character initialChar = (Character) theRequest.getExtendedData().get( - RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); - performDirectEdit(initialChar.charValue()); - } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { - DirectEditRequest editRequest = (DirectEditRequest) theRequest; - performDirectEdit(editRequest.getLocation()); - } else { - performDirectEdit(); - } - } - } - }); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - - /** - * @generated - */ - @Override - protected void handleNotificationEvent(Notification event) { - Object feature = event.getFeature(); - if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { - Integer c = (Integer) event.getNewValue(); - setFontColor(DiagramColorRegistry.getInstance().getColor(c)); - } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { - refreshUnderline(); - } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { - refreshStrikeThrough(); - } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || - NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || - NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || - NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { - refreshFont(); - } else { - if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { - refreshLabel(); - } - if (getParser() instanceof ISemanticParser) { - ISemanticParser modelParser = - (ISemanticParser) getParser(); - if (modelParser.areSemanticElementsAffected(null, event)) { - removeSemanticListeners(); - if (resolveSemanticElement() != null) { - addSemanticListeners(); - } - refreshLabel(); - } - } - } - - super.handleNotificationEvent(event); - } - - /** - * @generated - */ - @Override - protected IFigure createFigure() { - // Parent should assign one using setLabel() method - return 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.uml.diagram.composite.edit.parts; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.draw2d.ConnectionLocator; +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.Label; +import org.eclipse.draw2d.geometry.Point; +import org.eclipse.emf.common.notify.Notification; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.RunnableWithResult; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gef.AccessibleEditPart; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.Request; +import org.eclipse.gef.requests.DirectEditRequest; +import org.eclipse.gef.tools.DirectEditManager; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; +import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; +import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; +import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; +import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; +import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; +import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; +import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; +import org.eclipse.gmf.runtime.notation.FontStyle; +import org.eclipse.gmf.runtime.notation.NotationPackage; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.gmf.tooling.runtime.edit.policies.DefaultLinkLabelDragPolicy; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.text.contentassist.IContentAssistProcessor; +import org.eclipse.jface.viewers.ICellEditorValidator; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.extensionpoints.editors.Activator; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; +import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; +import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; +import org.eclipse.papyrus.infra.gmfdiag.common.editpart.IControlParserForDirectEdit; +import org.eclipse.papyrus.infra.gmfdiag.common.editpart.PapyrusLabelEditPart; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.PapyrusLinkLabelDragPolicy; +import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; +import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; +import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; +import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; +import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.accessibility.AccessibleEvent; +import org.eclipse.swt.custom.BusyIndicator; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; +import org.eclipse.uml2.uml.Feature; + +/** + * @generated + */ +public class UsageAppliedStereotypeEditPart extends PapyrusLabelEditPart implements ITextAwareEditPart, IControlParserForDirectEdit { + + /** + * @generated + */ + public static final int VISUAL_ID = 6021; + + /** + * @generated + */ + private DirectEditManager manager; + + /** + * @generated + */ + private IParser parser; + + /** + * @generated + */ + private List parserElements; + + /** + * @generated + */ + private String defaultText; + + /** + * direct edition mode (default, undefined, registered editor, etc.) + * + * @generated + */ + protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; + + /** + * configuration from a registered edit dialog + * + * @generated + */ + protected IDirectEditorConfiguration configuration; + /** + * @generated + */ + static { + registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.UsageAppliedStereotypeEditPart.VISUAL_ID), new Point(0, 30)); + } + + /** + * @generated + */ + public UsageAppliedStereotypeEditPart(View view) { + super(view); + } + + /** + * @generated + */ + @Override + protected void createDefaultEditPolicies() { + super.createDefaultEditPolicies(); + installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); + installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new DefaultLinkLabelDragPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new PapyrusLinkLabelDragPolicy()); + } + + /** + * @generated + */ + @Override + public int getKeyPoint() { + return ConnectionLocator.MIDDLE; + } + + /** + * @generated + */ + protected String getLabelTextHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getText(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getText(); + } else { + return ((Label) figure).getText(); + } + } + + /** + * @generated + */ + protected void setLabelTextHelper(IFigure figure, String text) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setText(text); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setText(text); + } else { + ((Label) figure).setText(text); + } + } + + /** + * @generated + */ + protected Image getLabelIconHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getIcon(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getIcon(); + } else { + return ((Label) figure).getIcon(); + } + } + + /** + * @generated + */ + protected void setLabelIconHelper(IFigure figure, Image icon) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setIcon(icon); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setIcon(icon); + } else { + ((Label) figure).setIcon(icon); + } + } + + /** + * @generated + */ + public void setLabel(IFigure + figure) { + unregisterVisuals(); + setFigure(figure); + defaultText = getLabelTextHelper(figure); + registerVisuals(); + refreshVisuals(); + } + + /** + * @generated + */ + @Override + protected List getModelChildren() { + return Collections.EMPTY_LIST; + } + + /** + * @generated + */ + @Override + public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { + return null; + } + + /** + * @generated + */ + @Override + public void setParser(IParser parser) { + this.parser = parser; + } + + /** + * @generated + */ + protected EObject getParserElement() { + return resolveSemanticElement(); + } + + /** + * @generated + */ + protected Image getLabelIcon() { + return null; + } + + /** + * @generated + */ + protected String getLabelText() { + String text = null; + EObject parserElement = getParserElement(); + if (parserElement != null && getParser() != null) { + text = getParser().getPrintString( + new EObjectAdapter(parserElement), + getParserOptions().intValue()); + } + if (text == null || text.length() == 0) { + text = defaultText; + } + return text; + } + + /** + * @generated + */ + @Override + public void setLabelText(String text) { + setLabelTextHelper(getFigure(), text); + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + @Override + public String getEditText() { + if (getParserElement() == null || getParser() == null) { + return ""; //$NON-NLS-1$ + } + return getParser().getEditString( + new EObjectAdapter(getParserElement()), + getParserOptions().intValue()); + } + + /** + * @generated + */ + protected boolean isEditable() { + return false; + } + + /** + * @generated + */ + @Override + public ICellEditorValidator getEditTextValidator() { + return new ICellEditorValidator() { + + @Override + public String isValid(final Object value) { + if (value instanceof String) { + final EObject element = getParserElement(); + final IParser parser = getParser(); + try { + IParserEditStatus valid = + (IParserEditStatus) getEditingDomain().runExclusive( + new RunnableWithResult.Impl() { + + @Override + public void run() { + setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); + } + }); + return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); + } catch (InterruptedException ie) { + ie.printStackTrace(); + } + } + + // shouldn't get here + return null; + } + }; + } + + /** + * @generated + */ + @Override + public IContentAssistProcessor getCompletionProcessor() { + if (getParserElement() == null || getParser() == null) { + return null; + } + return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); + } + + /** + * @generated + */ + @Override + public ParserOptions getParserOptions() { + return ParserOptions.NONE; + } + + /** + * @generated + */ + @Override + public IParser getParser() { + if (parser == null) { + parser = UMLParserProvider.getParser(UMLElementTypes.Usage_4008, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.UsageAppliedStereotypeEditPart.VISUAL_ID)); + } + return parser; + } + + /** + * @generated + */ + protected DirectEditManager getManager() { + if (manager == null) { + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + } + return manager; + } + + /** + * @generated + */ + protected void setManager(DirectEditManager manager) { + this.manager = manager; + } + + /** + * @generated + */ + protected void performDirectEdit() { + BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { + + @Override + public void run() { + getManager().show(); + } + }); + } + + /** + * @generated + */ + protected void performDirectEdit(Point eventLocation) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); + } + } + + /** + * @generated + */ + private void performDirectEdit(char initialCharacter) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(initialCharacter); + } else { + performDirectEdit(); + } + } + + /** + * @generated + */ + @Override + protected void performDirectEditRequest(Request request) { + + final Request theRequest = request; + + if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { + directEditionMode = getDirectEditionType(); + } + switch (directEditionMode) { + case IDirectEdition.NO_DIRECT_EDITION: + // no direct edition mode => does nothing + return; + case IDirectEdition.EXTENDED_DIRECT_EDITOR: + updateExtendedEditorConfiguration(); + if (configuration == null || configuration.getLanguage() == null) { + // Create default edit manager + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + performDefaultDirectEditorEdit(theRequest); + } else { + configuration.preEditAction(resolveSemanticElement()); + Dialog dialog = null; + if (configuration instanceof ICustomDirectEditorConfiguration) { + setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); + initializeDirectEditManager(theRequest); + return; + } else if (configuration instanceof IPopupEditorConfiguration) { + IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); + helper.showEditor(); + return; + } + else if (configuration instanceof IAdvancedEditorConfiguration) { + dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); + } else if (configuration instanceof IDirectEditorConfiguration) { + dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), + configuration); + } else { + return; + } + final Dialog finalDialog = dialog; + + if (Window.OK == dialog.open()) { + TransactionalEditingDomain domain = getEditingDomain(); + RecordingCommand command = new RecordingCommand(domain, "Edit Label") { + + @Override + protected void doExecute() { + configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); + + } + }; + domain.getCommandStack().execute(command); + } + } + break; + case IDirectEdition.DEFAULT_DIRECT_EDITOR: + initializeDirectEditManager(theRequest); + break; + default: + break; + } + } + + /** + * @generated + */ + protected void initializeDirectEditManager(final Request request) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + @Override + public void run() { + if (isActive() && isEditable()) { + if (request.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } + else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void refreshVisuals() { + super.refreshVisuals(); + refreshLabel(); + refreshFont(); + refreshFontColor(); + refreshUnderline(); + refreshStrikeThrough(); + } + + /** + * @generated + */ + protected void refreshLabel() { + EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); + if (maskLabelPolicy == null) { + maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); + } + if (maskLabelPolicy == null) { + setLabelTextHelper(getFigure(), getLabelText()); + setLabelIconHelper(getFigure(), getLabelIcon()); + } + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + protected void refreshUnderline() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); + } + if (resolveSemanticElement() instanceof Feature) { + if (((Feature) resolveSemanticElement()).isStatic()) { + ((WrappingLabel) getFigure()).setTextUnderline(true); + } + else { + ((WrappingLabel) getFigure()).setTextUnderline(false); + } + } + } + + /** + * @generated + */ + protected void refreshStrikeThrough() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); + } + } + + /** + * @generated + */ + @Override + protected void refreshFont() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null) { + FontData fontData = new FontData( + style.getFontName(), style.getFontHeight(), + (style.isBold() ? SWT.BOLD : SWT.NORMAL) | + (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); + setFont(fontData); + } + } + + /** + * @generated + */ + @Override + protected void setFontColor(Color color) { + getFigure().setForegroundColor(color); + } + + /** + * @generated + */ + @Override + protected void addSemanticListeners() { + if (getParser() instanceof ISemanticParser) { + EObject element = resolveSemanticElement(); + parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); + for (int i = 0; i < parserElements.size(); i++) { + addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ + } + } else { + super.addSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected void removeSemanticListeners() { + if (parserElements != null) { + for (int i = 0; i < parserElements.size(); i++) { + removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ + } + } else { + super.removeSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected AccessibleEditPart getAccessibleEditPart() { + if (accessibleEP == null) { + accessibleEP = new AccessibleGraphicalEditPart() { + + @Override + public void getName(AccessibleEvent e) { + e.result = getLabelTextHelper(getFigure()); + } + }; + } + return accessibleEP; + } + + /** + * @generated + */ + private View getFontStyleOwnerView() { + return getPrimaryView(); + } + + /** + * Returns the kind of associated editor for direct edition. + * + * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition + * @generated + */ + public int getDirectEditionType() { + // The label is read-only (defined in GMFGen model) + return IDirectEdition.NO_DIRECT_EDITION; + } + + /** + * Checks if an extended editor is present. + * + * @return true if an extended editor is present. + * @generated + */ + protected boolean checkExtendedEditor() { + if (resolveSemanticElement() != null) { + return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); + } + return false; + } + + /** + * Checks if a default direct edition is available + * + * @return true if a default direct edition is available + * @generated + */ + protected boolean checkDefaultEdition() { + return (getParser() != null); + } + + /** + * Initializes the extended editor configuration + * + * @generated + */ + protected void initExtendedEditorConfiguration() { + if (configuration == null) { + final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("")) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); + } else { + configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); + } + } + } + + /** + * Updates the preference configuration + * + * @generated + */ + protected void updateExtendedEditorConfiguration() { + String languagePreferred = Activator.getDefault().getPreferenceStore().getString( + IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() + .eClass().getInstanceClassName()); + } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { + configuration = null; + } + } + + /** + * Performs the direct edit usually used by GMF editors. + * + * @param theRequest + * the direct edit request that starts the direct edit system + * @generated + */ + protected void performDefaultDirectEditorEdit(final Request theRequest) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + + @Override + public void run() { + if (isActive() && isEditable()) { + if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) theRequest.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { + DirectEditRequest editRequest = (DirectEditRequest) theRequest; + performDirectEdit(editRequest.getLocation()); + } else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void handleNotificationEvent(Notification event) { + Object feature = event.getFeature(); + if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { + Integer c = (Integer) event.getNewValue(); + setFontColor(DiagramColorRegistry.getInstance().getColor(c)); + } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { + refreshUnderline(); + } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { + refreshStrikeThrough(); + } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { + refreshFont(); + } else { + if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { + refreshLabel(); + } + if (getParser() instanceof ISemanticParser) { + ISemanticParser modelParser = + (ISemanticParser) getParser(); + if (modelParser.areSemanticElementsAffected(null, event)) { + removeSemanticListeners(); + if (resolveSemanticElement() != null) { + addSemanticListeners(); + } + refreshLabel(); + } + } + } + + super.handleNotificationEvent(event); + } + + /** + * @generated + */ + @Override + protected IFigure createFigure() { + // Parent should assign one using setLabel() method + return null; + } +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/UsageNameEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/UsageNameEditPart.java index aaa81295957..ccf42044f8c 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/UsageNameEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/UsageNameEditPart.java @@ -1,828 +1,823 @@ -/** - * 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.uml.diagram.composite.edit.parts; - -import java.util.Collections; -import java.util.List; - -import org.eclipse.draw2d.ConnectionLocator; -import org.eclipse.draw2d.IFigure; -import org.eclipse.draw2d.Label; -import org.eclipse.draw2d.geometry.Point; -import org.eclipse.emf.common.notify.Notification; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.transaction.RecordingCommand; -import org.eclipse.emf.transaction.RunnableWithResult; -import org.eclipse.emf.transaction.TransactionalEditingDomain; -import org.eclipse.gef.AccessibleEditPart; -import org.eclipse.gef.EditPolicy; -import org.eclipse.gef.Request; -import org.eclipse.gef.requests.DirectEditRequest; -import org.eclipse.gef.tools.DirectEditManager; -import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; -import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; -import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; -import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; -import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; -import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; -import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; -import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; -import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; -import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; -import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; -import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; -import org.eclipse.gmf.runtime.notation.FontStyle; -import org.eclipse.gmf.runtime.notation.NotationPackage; -import org.eclipse.gmf.runtime.notation.View; -import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.jface.text.contentassist.IContentAssistProcessor; -import org.eclipse.jface.viewers.ICellEditorValidator; -import org.eclipse.jface.window.Window; -import org.eclipse.papyrus.extensionpoints.editors.Activator; -import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; -import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; -import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; -import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; -import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; -import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; -import org.eclipse.papyrus.infra.gmfdiag.common.editpart.IControlParserForDirectEdit; -import org.eclipse.papyrus.infra.gmfdiag.common.editpart.PapyrusLabelEditPart; -import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; -import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; -import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.PapyrusLinkLabelDragPolicy; -import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; -import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; -import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; -import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; -import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; -import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; -import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; -import org.eclipse.swt.SWT; -import org.eclipse.swt.accessibility.AccessibleEvent; -import org.eclipse.swt.custom.BusyIndicator; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.FontData; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.widgets.Display; -import org.eclipse.ui.PlatformUI; -import org.eclipse.uml2.uml.Feature; - -/** - * @generated - */ -public class UsageNameEditPart extends PapyrusLabelEditPart implements ITextAwareEditPart, IControlParserForDirectEdit { - - /** - * @generated - */ - public static final int VISUAL_ID = 6007; - - /** - * @generated - */ - private DirectEditManager manager; - - /** - * @generated - */ - private IParser parser; - - /** - * @generated - */ - private List parserElements; - - /** - * @generated - */ - private String defaultText; - - /** - * direct edition mode (default, undefined, registered editor, etc.) - * - * @generated - */ - protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; - - /** - * configuration from a registered edit dialog - * - * @generated - */ - protected IDirectEditorConfiguration configuration; - /** - * @generated - */ - static { - registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.UsageNameEditPart.VISUAL_ID), new Point(0, 60)); - } - - /** - * @generated - */ - public UsageNameEditPart(View view) { - super(view); - } - - /** - * @generated - */ - @Override - protected void createDefaultEditPolicies() { - super.createDefaultEditPolicies(); - installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); - installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); - installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new PapyrusLinkLabelDragPolicy()); - } - - /** - * @generated - */ - @Override - public int getKeyPoint() { - return ConnectionLocator.MIDDLE; - } - - /** - * @generated - */ - protected String getLabelTextHelper(IFigure figure) { - if (figure instanceof WrappingLabel) { - return ((WrappingLabel) figure).getText(); - } else if (figure instanceof ILabelFigure) { - return ((ILabelFigure) figure).getText(); - } else { - return ((Label) figure).getText(); - } - } - - /** - * @generated - */ - protected void setLabelTextHelper(IFigure figure, String text) { - if (figure instanceof WrappingLabel) { - ((WrappingLabel) figure).setText(text); - } else if (figure instanceof ILabelFigure) { - ((ILabelFigure) figure).setText(text); - } else { - ((Label) figure).setText(text); - } - } - - /** - * @generated - */ - protected Image getLabelIconHelper(IFigure figure) { - if (figure instanceof WrappingLabel) { - return ((WrappingLabel) figure).getIcon(); - } else if (figure instanceof ILabelFigure) { - return ((ILabelFigure) figure).getIcon(); - } else { - return ((Label) figure).getIcon(); - } - } - - /** - * @generated - */ - protected void setLabelIconHelper(IFigure figure, Image icon) { - if (figure instanceof WrappingLabel) { - ((WrappingLabel) figure).setIcon(icon); - } else if (figure instanceof ILabelFigure) { - ((ILabelFigure) figure).setIcon(icon); - } else { - ((Label) figure).setIcon(icon); - } - } - - /** - * @generated - */ - public void setLabel(IFigure - figure) { - unregisterVisuals(); - setFigure(figure); - defaultText = getLabelTextHelper(figure); - registerVisuals(); - refreshVisuals(); - } - - /** - * @generated - */ - @Override - protected List getModelChildren() { - return Collections.EMPTY_LIST; - } - - /** - * @generated - */ - @Override - public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { - return null; - } - - /** - * @generated - */ - @Override - public void setParser(IParser parser) { - this.parser = parser; - } - - /** - * @generated - */ - protected EObject getParserElement() { - return resolveSemanticElement(); - } - - /** - * @generated - */ - protected Image getLabelIcon() { - return null; - } - - /** - * @generated - */ - protected String getLabelText() { - String text = null; - EObject parserElement = getParserElement(); - if (parserElement != null && getParser() != null) { - text = getParser().getPrintString( - new EObjectAdapter(parserElement), - getParserOptions().intValue()); - } - if (text == null || text.length() == 0) { - text = defaultText; - } - return text; - } - - /** - * @generated - */ - @Override - public void setLabelText(String text) { - setLabelTextHelper(getFigure(), text); - Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); - if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); - } - Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); - if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); - } - } - - /** - * @generated - */ - @Override - public String getEditText() { - if (getParserElement() == null || getParser() == null) { - return ""; //$NON-NLS-1$ - } - return getParser().getEditString( - new EObjectAdapter(getParserElement()), - getParserOptions().intValue()); - } - - /** - * @generated - */ - protected boolean isEditable() { - return getParser() != null; - } - - /** - * @generated - */ - @Override - public ICellEditorValidator getEditTextValidator() { - return new ICellEditorValidator() { - - @Override - public String isValid(final Object value) { - if (value instanceof String) { - final EObject element = getParserElement(); - final IParser parser = getParser(); - try { - IParserEditStatus valid = - (IParserEditStatus) getEditingDomain().runExclusive( - new RunnableWithResult.Impl() { - - @Override - public void run() { - setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); - } - }); - return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); - } catch (InterruptedException ie) { - ie.printStackTrace(); - } - } - - // shouldn't get here - return null; - } - }; - } - - /** - * @generated - */ - @Override - public IContentAssistProcessor getCompletionProcessor() { - if (getParserElement() == null || getParser() == null) { - return null; - } - return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); - } - - /** - * @generated - */ - @Override - public ParserOptions getParserOptions() { - return ParserOptions.NONE; - } - - /** - * @generated - */ - @Override - public IParser getParser() { - if (parser == null) { - parser = UMLParserProvider.getParser(UMLElementTypes.Usage_4008, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.UsageNameEditPart.VISUAL_ID)); - } - return parser; - } - - /** - * @generated - */ - protected DirectEditManager getManager() { - if (manager == null) { - setManager(new MultilineLabelDirectEditManager(this, - MultilineLabelDirectEditManager.getTextCellEditorClass(this), - UMLEditPartFactory.getTextCellEditorLocator(this))); - } - return manager; - } - - /** - * @generated - */ - protected void setManager(DirectEditManager manager) { - this.manager = manager; - } - - /** - * @generated - */ - protected void performDirectEdit() { - BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { - - @Override - public void run() { - getManager().show(); - } - }); - } - - /** - * @generated - */ - protected void performDirectEdit(Point eventLocation) { - if (getManager() instanceof TextDirectEditManager) { - ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); - } - } - - /** - * @generated - */ - private void performDirectEdit(char initialCharacter) { - if (getManager() instanceof TextDirectEditManager) { - ((TextDirectEditManager) getManager()).show(initialCharacter); - } else { - performDirectEdit(); - } - } - - /** - * @generated - */ - @Override - protected void performDirectEditRequest(Request request) { - - final Request theRequest = request; - - if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { - directEditionMode = getDirectEditionType(); - } - switch (directEditionMode) { - case IDirectEdition.NO_DIRECT_EDITION: - // no direct edition mode => does nothing - return; - case IDirectEdition.EXTENDED_DIRECT_EDITOR: - updateExtendedEditorConfiguration(); - if (configuration == null || configuration.getLanguage() == null) { - // Create default edit manager - setManager(new MultilineLabelDirectEditManager(this, - MultilineLabelDirectEditManager.getTextCellEditorClass(this), - UMLEditPartFactory.getTextCellEditorLocator(this))); - performDefaultDirectEditorEdit(theRequest); - } else { - configuration.preEditAction(resolveSemanticElement()); - Dialog dialog = null; - if (configuration instanceof ICustomDirectEditorConfiguration) { - setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); - initializeDirectEditManager(theRequest); - return; - } else if (configuration instanceof IPopupEditorConfiguration) { - IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); - helper.showEditor(); - return; - } - else if (configuration instanceof IAdvancedEditorConfiguration) { - dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); - } else if (configuration instanceof IDirectEditorConfiguration) { - dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), - configuration); - } else { - return; - } - final Dialog finalDialog = dialog; - - if (Window.OK == dialog.open()) { - TransactionalEditingDomain domain = getEditingDomain(); - RecordingCommand command = new RecordingCommand(domain, "Edit Label") { - - @Override - protected void doExecute() { - configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); - - } - }; - domain.getCommandStack().execute(command); - } - } - break; - case IDirectEdition.DEFAULT_DIRECT_EDITOR: - initializeDirectEditManager(theRequest); - break; - default: - break; - } - } - - /** - * @generated - */ - protected void initializeDirectEditManager(final Request request) { - // initialize the direct edit manager - try { - getEditingDomain().runExclusive(new Runnable() { - @Override - public void run() { - if (isActive() && isEditable()) { - if (request.getExtendedData().get( - RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { - Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); - performDirectEdit(initialChar.charValue()); - } - else { - performDirectEdit(); - } - } - } - }); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - - /** - * @generated - */ - @Override - protected void refreshVisuals() { - super.refreshVisuals(); - refreshLabel(); - refreshFont(); - refreshFontColor(); - refreshUnderline(); - refreshStrikeThrough(); - } - - /** - * @generated - */ - protected void refreshLabel() { - EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); - if (maskLabelPolicy == null) { - maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); - } - if (maskLabelPolicy == null) { - View view = (View) getModel(); - if (view.isVisible()) { - setLabelTextHelper(getFigure(), getLabelText()); - setLabelIconHelper(getFigure(), getLabelIcon()); - } - else { - setLabelTextHelper(getFigure(), ""); //$NON-NLS-1$ - setLabelIconHelper(getFigure(), null); - } - } - Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); - if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); - } - Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); - if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { - ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); - } - } - - /** - * @generated - */ - protected void refreshUnderline() { - FontStyle style = - (FontStyle) getFontStyleOwnerView().getStyle( - NotationPackage.eINSTANCE.getFontStyle()); - if (style != null && getFigure() instanceof WrappingLabel) { - ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); - } - if (resolveSemanticElement() instanceof Feature) { - if (((Feature) resolveSemanticElement()).isStatic()) { - ((WrappingLabel) getFigure()).setTextUnderline(true); - } - else { - ((WrappingLabel) getFigure()).setTextUnderline(false); - } - } - } - - /** - * @generated - */ - protected void refreshStrikeThrough() { - FontStyle style = - (FontStyle) getFontStyleOwnerView().getStyle( - NotationPackage.eINSTANCE.getFontStyle()); - if (style != null && getFigure() instanceof WrappingLabel) { - ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); - } - } - - /** - * @generated - */ - @Override - protected void refreshFont() { - FontStyle style = - (FontStyle) getFontStyleOwnerView().getStyle( - NotationPackage.eINSTANCE.getFontStyle()); - if (style != null) { - FontData fontData = new FontData( - style.getFontName(), style.getFontHeight(), - (style.isBold() ? SWT.BOLD : SWT.NORMAL) | - (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); - setFont(fontData); - } - } - - /** - * @generated - */ - @Override - protected void setFontColor(Color color) { - getFigure().setForegroundColor(color); - } - - /** - * @generated - */ - @Override - protected void addSemanticListeners() { - if (getParser() instanceof ISemanticParser) { - EObject element = resolveSemanticElement(); - parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); - for (int i = 0; i < parserElements.size(); i++) { - addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ - } - } else { - super.addSemanticListeners(); - } - } - - /** - * @generated - */ - @Override - protected void removeSemanticListeners() { - if (parserElements != null) { - for (int i = 0; i < parserElements.size(); i++) { - removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ - } - } else { - super.removeSemanticListeners(); - } - } - - /** - * @generated - */ - @Override - protected AccessibleEditPart getAccessibleEditPart() { - if (accessibleEP == null) { - accessibleEP = new AccessibleGraphicalEditPart() { - - @Override - public void getName(AccessibleEvent e) { - e.result = getLabelTextHelper(getFigure()); - } - }; - } - return accessibleEP; - } - - /** - * @generated - */ - private View getFontStyleOwnerView() { - return getPrimaryView(); - } - - /** - * Returns the kind of associated editor for direct edition. - * - * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition - * @generated - */ - public int getDirectEditionType() { - if (checkExtendedEditor()) { - initExtendedEditorConfiguration(); - return IDirectEdition.EXTENDED_DIRECT_EDITOR; - } - if (checkDefaultEdition()) { - return IDirectEdition.DEFAULT_DIRECT_EDITOR; - } - - // not a named element. no specific editor => do nothing - return IDirectEdition.NO_DIRECT_EDITION; - } - - /** - * Checks if an extended editor is present. - * - * @return true if an extended editor is present. - * @generated - */ - protected boolean checkExtendedEditor() { - if (resolveSemanticElement() != null) { - return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); - } - return false; - } - - /** - * Checks if a default direct edition is available - * - * @return true if a default direct edition is available - * @generated - */ - protected boolean checkDefaultEdition() { - return (getParser() != null); - } - - /** - * Initializes the extended editor configuration - * - * @generated - */ - protected void initExtendedEditorConfiguration() { - if (configuration == null) { - final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); - if (languagePreferred != null && !languagePreferred.equals("")) { - configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); - } else { - configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); - } - } - } - - /** - * Updates the preference configuration - * - * @generated - */ - protected void updateExtendedEditorConfiguration() { - String languagePreferred = Activator.getDefault().getPreferenceStore().getString( - IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); - if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { - configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() - .eClass().getInstanceClassName()); - } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { - configuration = null; - } - } - - /** - * Performs the direct edit usually used by GMF editors. - * - * @param theRequest - * the direct edit request that starts the direct edit system - * @generated - */ - protected void performDefaultDirectEditorEdit(final Request theRequest) { - // initialize the direct edit manager - try { - getEditingDomain().runExclusive(new Runnable() { - - @Override - public void run() { - if (isActive() && isEditable()) { - if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { - Character initialChar = (Character) theRequest.getExtendedData().get( - RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); - performDirectEdit(initialChar.charValue()); - } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { - DirectEditRequest editRequest = (DirectEditRequest) theRequest; - performDirectEdit(editRequest.getLocation()); - } else { - performDirectEdit(); - } - } - } - }); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - - /** - * @generated - */ - @Override - protected void handleNotificationEvent(Notification event) { - Object feature = event.getFeature(); - if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { - Integer c = (Integer) event.getNewValue(); - setFontColor(DiagramColorRegistry.getInstance().getColor(c)); - } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { - refreshUnderline(); - } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { - refreshStrikeThrough(); - } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || - NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || - NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || - NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { - refreshFont(); - } else { - if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { - refreshLabel(); - } - if (getParser() instanceof ISemanticParser) { - ISemanticParser modelParser = - (ISemanticParser) getParser(); - if (modelParser.areSemanticElementsAffected(null, event)) { - removeSemanticListeners(); - if (resolveSemanticElement() != null) { - addSemanticListeners(); - } - refreshLabel(); - } - } - } - - super.handleNotificationEvent(event); - } - - /** - * @generated - */ - @Override - protected IFigure createFigure() { - // Parent should assign one using setLabel() method - return 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.uml.diagram.composite.edit.parts; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.draw2d.ConnectionLocator; +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.Label; +import org.eclipse.draw2d.geometry.Point; +import org.eclipse.emf.common.notify.Notification; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.RunnableWithResult; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gef.AccessibleEditPart; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.Request; +import org.eclipse.gef.requests.DirectEditRequest; +import org.eclipse.gef.tools.DirectEditManager; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; +import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; +import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; +import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; +import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; +import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; +import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; +import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; +import org.eclipse.gmf.runtime.notation.FontStyle; +import org.eclipse.gmf.runtime.notation.NotationPackage; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.gmf.tooling.runtime.edit.policies.DefaultLinkLabelDragPolicy; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.text.contentassist.IContentAssistProcessor; +import org.eclipse.jface.viewers.ICellEditorValidator; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.extensionpoints.editors.Activator; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; +import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; +import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; +import org.eclipse.papyrus.infra.gmfdiag.common.editpart.IControlParserForDirectEdit; +import org.eclipse.papyrus.infra.gmfdiag.common.editpart.PapyrusLabelEditPart; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.PapyrusLinkLabelDragPolicy; +import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; +import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; +import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; +import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; +import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.accessibility.AccessibleEvent; +import org.eclipse.swt.custom.BusyIndicator; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; +import org.eclipse.uml2.uml.Feature; + +/** + * @generated + */ +public class UsageNameEditPart extends PapyrusLabelEditPart implements ITextAwareEditPart, IControlParserForDirectEdit { + + /** + * @generated + */ + public static final int VISUAL_ID = 6007; + + /** + * @generated + */ + private DirectEditManager manager; + + /** + * @generated + */ + private IParser parser; + + /** + * @generated + */ + private List parserElements; + + /** + * @generated + */ + private String defaultText; + + /** + * direct edition mode (default, undefined, registered editor, etc.) + * + * @generated + */ + protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; + + /** + * configuration from a registered edit dialog + * + * @generated + */ + protected IDirectEditorConfiguration configuration; + /** + * @generated + */ + static { + registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.UsageNameEditPart.VISUAL_ID), new Point(0, 60)); + } + + /** + * @generated + */ + public UsageNameEditPart(View view) { + super(view); + } + + /** + * @generated + */ + @Override + protected void createDefaultEditPolicies() { + super.createDefaultEditPolicies(); + installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); + installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new DefaultLinkLabelDragPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new PapyrusLinkLabelDragPolicy()); + } + + /** + * @generated + */ + @Override + public int getKeyPoint() { + return ConnectionLocator.MIDDLE; + } + + /** + * @generated + */ + protected String getLabelTextHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getText(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getText(); + } else { + return ((Label) figure).getText(); + } + } + + /** + * @generated + */ + protected void setLabelTextHelper(IFigure figure, String text) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setText(text); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setText(text); + } else { + ((Label) figure).setText(text); + } + } + + /** + * @generated + */ + protected Image getLabelIconHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getIcon(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getIcon(); + } else { + return ((Label) figure).getIcon(); + } + } + + /** + * @generated + */ + protected void setLabelIconHelper(IFigure figure, Image icon) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setIcon(icon); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setIcon(icon); + } else { + ((Label) figure).setIcon(icon); + } + } + + /** + * @generated + */ + public void setLabel(IFigure + figure) { + unregisterVisuals(); + setFigure(figure); + defaultText = getLabelTextHelper(figure); + registerVisuals(); + refreshVisuals(); + } + + /** + * @generated + */ + @Override + protected List getModelChildren() { + return Collections.EMPTY_LIST; + } + + /** + * @generated + */ + @Override + public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { + return null; + } + + /** + * @generated + */ + @Override + public void setParser(IParser parser) { + this.parser = parser; + } + + /** + * @generated + */ + protected EObject getParserElement() { + return resolveSemanticElement(); + } + + /** + * @generated + */ + protected Image getLabelIcon() { + return null; + } + + /** + * @generated + */ + protected String getLabelText() { + String text = null; + EObject parserElement = getParserElement(); + if (parserElement != null && getParser() != null) { + text = getParser().getPrintString( + new EObjectAdapter(parserElement), + getParserOptions().intValue()); + } + if (text == null || text.length() == 0) { + text = defaultText; + } + return text; + } + + /** + * @generated + */ + @Override + public void setLabelText(String text) { + setLabelTextHelper(getFigure(), text); + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + @Override + public String getEditText() { + if (getParserElement() == null || getParser() == null) { + return ""; //$NON-NLS-1$ + } + return getParser().getEditString( + new EObjectAdapter(getParserElement()), + getParserOptions().intValue()); + } + + /** + * @generated + */ + protected boolean isEditable() { + return getParser() != null; + } + + /** + * @generated + */ + @Override + public ICellEditorValidator getEditTextValidator() { + return new ICellEditorValidator() { + + @Override + public String isValid(final Object value) { + if (value instanceof String) { + final EObject element = getParserElement(); + final IParser parser = getParser(); + try { + IParserEditStatus valid = + (IParserEditStatus) getEditingDomain().runExclusive( + new RunnableWithResult.Impl() { + + @Override + public void run() { + setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); + } + }); + return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); + } catch (InterruptedException ie) { + ie.printStackTrace(); + } + } + + // shouldn't get here + return null; + } + }; + } + + /** + * @generated + */ + @Override + public IContentAssistProcessor getCompletionProcessor() { + if (getParserElement() == null || getParser() == null) { + return null; + } + return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); + } + + /** + * @generated + */ + @Override + public ParserOptions getParserOptions() { + return ParserOptions.NONE; + } + + /** + * @generated + */ + @Override + public IParser getParser() { + if (parser == null) { + parser = UMLParserProvider.getParser(UMLElementTypes.Usage_4008, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.UsageNameEditPart.VISUAL_ID)); + } + return parser; + } + + /** + * @generated + */ + protected DirectEditManager getManager() { + if (manager == null) { + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + } + return manager; + } + + /** + * @generated + */ + protected void setManager(DirectEditManager manager) { + this.manager = manager; + } + + /** + * @generated + */ + protected void performDirectEdit() { + BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { + + @Override + public void run() { + getManager().show(); + } + }); + } + + /** + * @generated + */ + protected void performDirectEdit(Point eventLocation) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); + } + } + + /** + * @generated + */ + private void performDirectEdit(char initialCharacter) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(initialCharacter); + } else { + performDirectEdit(); + } + } + + /** + * @generated + */ + @Override + protected void performDirectEditRequest(Request request) { + + final Request theRequest = request; + + if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { + directEditionMode = getDirectEditionType(); + } + switch (directEditionMode) { + case IDirectEdition.NO_DIRECT_EDITION: + // no direct edition mode => does nothing + return; + case IDirectEdition.EXTENDED_DIRECT_EDITOR: + updateExtendedEditorConfiguration(); + if (configuration == null || configuration.getLanguage() == null) { + // Create default edit manager + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + performDefaultDirectEditorEdit(theRequest); + } else { + configuration.preEditAction(resolveSemanticElement()); + Dialog dialog = null; + if (configuration instanceof ICustomDirectEditorConfiguration) { + setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); + initializeDirectEditManager(theRequest); + return; + } else if (configuration instanceof IPopupEditorConfiguration) { + IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); + helper.showEditor(); + return; + } + else if (configuration instanceof IAdvancedEditorConfiguration) { + dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); + } else if (configuration instanceof IDirectEditorConfiguration) { + dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), + configuration); + } else { + return; + } + final Dialog finalDialog = dialog; + + if (Window.OK == dialog.open()) { + TransactionalEditingDomain domain = getEditingDomain(); + RecordingCommand command = new RecordingCommand(domain, "Edit Label") { + + @Override + protected void doExecute() { + configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); + + } + }; + domain.getCommandStack().execute(command); + } + } + break; + case IDirectEdition.DEFAULT_DIRECT_EDITOR: + initializeDirectEditManager(theRequest); + break; + default: + break; + } + } + + /** + * @generated + */ + protected void initializeDirectEditManager(final Request request) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + @Override + public void run() { + if (isActive() && isEditable()) { + if (request.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } + else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void refreshVisuals() { + super.refreshVisuals(); + refreshLabel(); + refreshFont(); + refreshFontColor(); + refreshUnderline(); + refreshStrikeThrough(); + } + + /** + * @generated + */ + protected void refreshLabel() { + EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); + if (maskLabelPolicy == null) { + maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); + } + if (maskLabelPolicy == null) { + setLabelTextHelper(getFigure(), getLabelText()); + setLabelIconHelper(getFigure(), getLabelIcon()); + } + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + protected void refreshUnderline() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); + } + if (resolveSemanticElement() instanceof Feature) { + if (((Feature) resolveSemanticElement()).isStatic()) { + ((WrappingLabel) getFigure()).setTextUnderline(true); + } + else { + ((WrappingLabel) getFigure()).setTextUnderline(false); + } + } + } + + /** + * @generated + */ + protected void refreshStrikeThrough() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); + } + } + + /** + * @generated + */ + @Override + protected void refreshFont() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null) { + FontData fontData = new FontData( + style.getFontName(), style.getFontHeight(), + (style.isBold() ? SWT.BOLD : SWT.NORMAL) | + (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); + setFont(fontData); + } + } + + /** + * @generated + */ + @Override + protected void setFontColor(Color color) { + getFigure().setForegroundColor(color); + } + + /** + * @generated + */ + @Override + protected void addSemanticListeners() { + if (getParser() instanceof ISemanticParser) { + EObject element = resolveSemanticElement(); + parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); + for (int i = 0; i < parserElements.size(); i++) { + addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ + } + } else { + super.addSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected void removeSemanticListeners() { + if (parserElements != null) { + for (int i = 0; i < parserElements.size(); i++) { + removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ + } + } else { + super.removeSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected AccessibleEditPart getAccessibleEditPart() { + if (accessibleEP == null) { + accessibleEP = new AccessibleGraphicalEditPart() { + + @Override + public void getName(AccessibleEvent e) { + e.result = getLabelTextHelper(getFigure()); + } + }; + } + return accessibleEP; + } + + /** + * @generated + */ + private View getFontStyleOwnerView() { + return getPrimaryView(); + } + + /** + * Returns the kind of associated editor for direct edition. + * + * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition + * @generated + */ + public int getDirectEditionType() { + if (checkExtendedEditor()) { + initExtendedEditorConfiguration(); + return IDirectEdition.EXTENDED_DIRECT_EDITOR; + } + if (checkDefaultEdition()) { + return IDirectEdition.DEFAULT_DIRECT_EDITOR; + } + + // not a named element. no specific editor => do nothing + return IDirectEdition.NO_DIRECT_EDITION; + } + + /** + * Checks if an extended editor is present. + * + * @return true if an extended editor is present. + * @generated + */ + protected boolean checkExtendedEditor() { + if (resolveSemanticElement() != null) { + return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); + } + return false; + } + + /** + * Checks if a default direct edition is available + * + * @return true if a default direct edition is available + * @generated + */ + protected boolean checkDefaultEdition() { + return (getParser() != null); + } + + /** + * Initializes the extended editor configuration + * + * @generated + */ + protected void initExtendedEditorConfiguration() { + if (configuration == null) { + final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("")) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); + } else { + configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); + } + } + } + + /** + * Updates the preference configuration + * + * @generated + */ + protected void updateExtendedEditorConfiguration() { + String languagePreferred = Activator.getDefault().getPreferenceStore().getString( + IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() + .eClass().getInstanceClassName()); + } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { + configuration = null; + } + } + + /** + * Performs the direct edit usually used by GMF editors. + * + * @param theRequest + * the direct edit request that starts the direct edit system + * @generated + */ + protected void performDefaultDirectEditorEdit(final Request theRequest) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + + @Override + public void run() { + if (isActive() && isEditable()) { + if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) theRequest.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { + DirectEditRequest editRequest = (DirectEditRequest) theRequest; + performDirectEdit(editRequest.getLocation()); + } else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void handleNotificationEvent(Notification event) { + Object feature = event.getFeature(); + if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { + Integer c = (Integer) event.getNewValue(); + setFontColor(DiagramColorRegistry.getInstance().getColor(c)); + } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { + refreshUnderline(); + } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { + refreshStrikeThrough(); + } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { + refreshFont(); + } else { + if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { + refreshLabel(); + } + if (getParser() instanceof ISemanticParser) { + ISemanticParser modelParser = + (ISemanticParser) getParser(); + if (modelParser.areSemanticElementsAffected(null, event)) { + removeSemanticListeners(); + if (resolveSemanticElement() != null) { + addSemanticListeners(); + } + refreshLabel(); + } + } + } + + super.handleNotificationEvent(event); + } + + /** + * @generated + */ + @Override + protected IFigure createFigure() { + // Parent should assign one using setLabel() method + return null; + } +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/UseCaseEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/UseCaseEditPart.java index 3c1ac4121c7..de2f15ab8a8 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/UseCaseEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/UseCaseEditPart.java @@ -11,27 +11,40 @@ */ package org.eclipse.papyrus.uml.diagram.composite.edit.parts; +import java.util.Collections; +import java.util.List; + import org.eclipse.draw2d.IFigure; +import org.eclipse.emf.common.notify.Notification; import org.eclipse.gef.EditPart; import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.GraphicalEditPart; 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.handles.MoveHandle; import org.eclipse.gef.requests.CreateRequest; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.BorderItemSelectionEditPolicy; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles; +import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; -import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure; import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure; +import org.eclipse.gmf.runtime.notation.Edge; +import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.gmf.runtime.notation.View; -import org.eclipse.papyrus.infra.gmfdiag.common.editpart.NodeEditPart; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.GetChildLayoutEditPolicy; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.IPapyrusNodeFigure; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.RoundedRectangleNodePlateFigure; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.SelectableBorderedNodeFigure; +import org.eclipse.papyrus.uml.diagram.common.editparts.RoundedCompartmentEditPart; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeNodeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.QualifiedNameDisplayEditPolicy; -import org.eclipse.papyrus.uml.diagram.common.figure.node.NodeNamedElementFigure; +import org.eclipse.papyrus.uml.diagram.common.figure.node.RoundedCompartmentFigure; +import org.eclipse.papyrus.uml.diagram.common.locator.RoundedRectangleLabelPositionLocator; import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.CustomGraphicalNodeEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UseCaseItemSemanticEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; @@ -40,7 +53,7 @@ import org.eclipse.swt.graphics.Color; /** * @generated */ -public class UseCaseEditPart extends NodeEditPart { +public class UseCaseEditPart extends RoundedCompartmentEditPart { /** * @generated @@ -75,6 +88,7 @@ public class UseCaseEditPart extends NodeEditPart { installEditPolicy(QualifiedNameDisplayEditPolicy.QUALIFIED_NAME_POLICY, new QualifiedNameDisplayEditPolicy()); installEditPolicy(AppliedStereotypeLabelDisplayEditPolicy.STEREOTYPE_LABEL_POLICY, new AppliedStereotypeNodeLabelDisplayEditPolicy()); installEditPolicy(EditPolicy.GRAPHICAL_NODE_ROLE, new CustomGraphicalNodeEditPolicy()); + installEditPolicy(EditPolicy.LAYOUT_ROLE, new GetChildLayoutEditPolicy()); // XXX need an SCR to runtime to have another abstract superclass that would let children add reasonable editpolicies // removeEditPolicy(org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles.CONNECTION_HANDLES_ROLE); } @@ -87,6 +101,20 @@ public class UseCaseEditPart extends NodeEditPart { @Override protected EditPolicy createChildEditPolicy(EditPart child) { + View childView = (View) child.getModel(); + switch (UMLVisualIDRegistry.getVisualID(childView)) { + case UseCaseFloatingLabelEditPart.VISUAL_ID: + return new BorderItemSelectionEditPolicy() { + + @Override + protected List createSelectionHandles() { + MoveHandle mh = new MoveHandle((GraphicalEditPart) getHost()); + mh.setBorder(null); + return Collections.singletonList(mh); + } + } + ; + } EditPolicy result = child.getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); if (result == null) { result = new NonResizableEditPolicy(); @@ -107,12 +135,36 @@ public class UseCaseEditPart extends NodeEditPart { return lep; } + /** + * Papyrus codeGen + * + * @generated + **/ + @Override + protected void handleNotificationEvent(Notification event) { + /* + * when a node have external node labels, the methods refreshChildren() remove the EditPart corresponding to the Label from the EditPart + * Registry. After that, we can't reset the visibility to true (using the Show/Hide Label Action)! + */ + if (NotationPackage.eINSTANCE.getView_Visible().equals(event.getFeature())) { + Object notifier = event.getNotifier(); + List modelChildren = ((View) getModel()).getChildren(); + if (!(notifier instanceof Edge)) { + if (modelChildren.contains(event.getNotifier())) { + return; + } + } + } + super.handleNotificationEvent(event); + + } + /** * @generated */ @Override protected IFigure createNodeShape() { - return primaryShape = new NodeNamedElementFigure(); + return primaryShape = new RoundedCompartmentFigure(); } /** @@ -121,8 +173,8 @@ public class UseCaseEditPart extends NodeEditPart { * @generated */ @Override - public NodeNamedElementFigure getPrimaryShape() { - return (NodeNamedElementFigure) primaryShape; + public RoundedCompartmentFigure getPrimaryShape() { + return (RoundedCompartmentFigure) primaryShape; } /** @@ -175,15 +227,32 @@ public class UseCaseEditPart extends NodeEditPart { */ @Override protected IFigure getContentPaneFor(IGraphicalEditPart editPart) { + if (editPart instanceof IBorderItemEditPart) { + return getBorderedFigure().getBorderItemContainer(); + } return getContentPane(); } + /** + * @generated + */ + @Override + protected void addBorderItem(IFigure borderItemContainer, IBorderItemEditPart borderItemEditPart) { + if (borderItemEditPart instanceof UseCaseFloatingLabelEditPart) { + IBorderItemLocator locator = new RoundedRectangleLabelPositionLocator(getMainFigure()); + borderItemContainer.add(borderItemEditPart.getFigure(), locator); + } else + { + super.addBorderItem(borderItemContainer, borderItemEditPart); + } + } + /** * @generated */ @Override protected NodeFigure createNodePlate() { - DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(40, 40); + RoundedRectangleNodePlateFigure result = new RoundedRectangleNodePlateFigure(40, 40); return result; } @@ -196,7 +265,7 @@ public class UseCaseEditPart extends NodeEditPart { * @generated */ @Override - protected NodeFigure createNodeFigure() { + protected NodeFigure createMainFigure() { return new SelectableBorderedNodeFigure(createMainFigureWithSVG()); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/UseCaseEditPartCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/UseCaseEditPartCN.java index a34ea6f8c48..c4f62f22a87 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/UseCaseEditPartCN.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/UseCaseEditPartCN.java @@ -11,27 +11,40 @@ */ package org.eclipse.papyrus.uml.diagram.composite.edit.parts; +import java.util.Collections; +import java.util.List; + import org.eclipse.draw2d.IFigure; +import org.eclipse.emf.common.notify.Notification; import org.eclipse.gef.EditPart; import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.GraphicalEditPart; 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.handles.MoveHandle; import org.eclipse.gef.requests.CreateRequest; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.BorderItemSelectionEditPolicy; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles; +import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; -import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure; import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure; +import org.eclipse.gmf.runtime.notation.Edge; +import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.gmf.runtime.notation.View; -import org.eclipse.papyrus.infra.gmfdiag.common.editpart.NodeEditPart; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.GetChildLayoutEditPolicy; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.IPapyrusNodeFigure; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.RoundedRectangleNodePlateFigure; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.SelectableBorderedNodeFigure; +import org.eclipse.papyrus.uml.diagram.common.editparts.RoundedCompartmentEditPart; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeNodeLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.QualifiedNameDisplayEditPolicy; -import org.eclipse.papyrus.uml.diagram.common.figure.node.NodeNamedElementFigure; +import org.eclipse.papyrus.uml.diagram.common.figure.node.RoundedCompartmentFigure; +import org.eclipse.papyrus.uml.diagram.common.locator.RoundedRectangleLabelPositionLocator; import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.CustomGraphicalNodeEditPolicy; import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UseCaseItemSemanticEditPolicyCN; import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; @@ -40,7 +53,7 @@ import org.eclipse.swt.graphics.Color; /** * @generated */ -public class UseCaseEditPartCN extends NodeEditPart { +public class UseCaseEditPartCN extends RoundedCompartmentEditPart { /** * @generated @@ -75,6 +88,7 @@ public class UseCaseEditPartCN extends NodeEditPart { installEditPolicy(QualifiedNameDisplayEditPolicy.QUALIFIED_NAME_POLICY, new QualifiedNameDisplayEditPolicy()); installEditPolicy(AppliedStereotypeLabelDisplayEditPolicy.STEREOTYPE_LABEL_POLICY, new AppliedStereotypeNodeLabelDisplayEditPolicy()); installEditPolicy(EditPolicy.GRAPHICAL_NODE_ROLE, new CustomGraphicalNodeEditPolicy()); + installEditPolicy(EditPolicy.LAYOUT_ROLE, new GetChildLayoutEditPolicy()); // XXX need an SCR to runtime to have another abstract superclass that would let children add reasonable editpolicies // removeEditPolicy(org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles.CONNECTION_HANDLES_ROLE); } @@ -87,6 +101,20 @@ public class UseCaseEditPartCN extends NodeEditPart { @Override protected EditPolicy createChildEditPolicy(EditPart child) { + View childView = (View) child.getModel(); + switch (UMLVisualIDRegistry.getVisualID(childView)) { + case UseCaseFloatingLabelEditPartCN.VISUAL_ID: + return new BorderItemSelectionEditPolicy() { + + @Override + protected List createSelectionHandles() { + MoveHandle mh = new MoveHandle((GraphicalEditPart) getHost()); + mh.setBorder(null); + return Collections.singletonList(mh); + } + } + ; + } EditPolicy result = child.getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); if (result == null) { result = new NonResizableEditPolicy(); @@ -107,12 +135,36 @@ public class UseCaseEditPartCN extends NodeEditPart { return lep; } + /** + * Papyrus codeGen + * + * @generated + **/ + @Override + protected void handleNotificationEvent(Notification event) { + /* + * when a node have external node labels, the methods refreshChildren() remove the EditPart corresponding to the Label from the EditPart + * Registry. After that, we can't reset the visibility to true (using the Show/Hide Label Action)! + */ + if (NotationPackage.eINSTANCE.getView_Visible().equals(event.getFeature())) { + Object notifier = event.getNotifier(); + List modelChildren = ((View) getModel()).getChildren(); + if (!(notifier instanceof Edge)) { + if (modelChildren.contains(event.getNotifier())) { + return; + } + } + } + super.handleNotificationEvent(event); + + } + /** * @generated */ @Override protected IFigure createNodeShape() { - return primaryShape = new NodeNamedElementFigure(); + return primaryShape = new RoundedCompartmentFigure(); } /** @@ -121,8 +173,8 @@ public class UseCaseEditPartCN extends NodeEditPart { * @generated */ @Override - public NodeNamedElementFigure getPrimaryShape() { - return (NodeNamedElementFigure) primaryShape; + public RoundedCompartmentFigure getPrimaryShape() { + return (RoundedCompartmentFigure) primaryShape; } /** @@ -175,15 +227,32 @@ public class UseCaseEditPartCN extends NodeEditPart { */ @Override protected IFigure getContentPaneFor(IGraphicalEditPart editPart) { + if (editPart instanceof IBorderItemEditPart) { + return getBorderedFigure().getBorderItemContainer(); + } return getContentPane(); } + /** + * @generated + */ + @Override + protected void addBorderItem(IFigure borderItemContainer, IBorderItemEditPart borderItemEditPart) { + if (borderItemEditPart instanceof UseCaseFloatingLabelEditPartCN) { + IBorderItemLocator locator = new RoundedRectangleLabelPositionLocator(getMainFigure()); + borderItemContainer.add(borderItemEditPart.getFigure(), locator); + } else + { + super.addBorderItem(borderItemContainer, borderItemEditPart); + } + } + /** * @generated */ @Override protected NodeFigure createNodePlate() { - DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(40, 40); + RoundedRectangleNodePlateFigure result = new RoundedRectangleNodePlateFigure(40, 40); return result; } @@ -196,7 +265,7 @@ public class UseCaseEditPartCN extends NodeEditPart { * @generated */ @Override - protected NodeFigure createNodeFigure() { + protected NodeFigure createMainFigure() { return new SelectableBorderedNodeFigure(createMainFigureWithSVG()); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/UseCaseFloatingLabelEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/UseCaseFloatingLabelEditPart.java new file mode 100644 index 00000000000..9bf2d31f84b --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/UseCaseFloatingLabelEditPart.java @@ -0,0 +1,860 @@ +/** + * 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.uml.diagram.composite.edit.parts; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.Label; +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.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.RunnableWithResult; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gef.AccessibleEditPart; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.Request; +import org.eclipse.gef.requests.DirectEditRequest; +import org.eclipse.gef.tools.DirectEditManager; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; +import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; +import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; +import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; +import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; +import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; +import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; +import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; +import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; +import org.eclipse.gmf.runtime.notation.FontStyle; +import org.eclipse.gmf.runtime.notation.NotationPackage; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.text.contentassist.IContentAssistProcessor; +import org.eclipse.jface.viewers.ICellEditorValidator; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.extensionpoints.editors.Activator; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; +import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; +import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.ExternalLabelPrimaryDragRoleEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.PapyrusWrappingLabel; +import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; +import org.eclipse.papyrus.uml.diagram.common.editparts.FloatingLabelEditPart; +import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; +import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; +import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; +import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.accessibility.AccessibleEvent; +import org.eclipse.swt.custom.BusyIndicator; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; +import org.eclipse.uml2.uml.Feature; + +/** + * @generated + */ +public class UseCaseFloatingLabelEditPart extends FloatingLabelEditPart + implements ITextAwareEditPart, IBorderItemEditPart +{ + + /** + * @generated + */ + public static final int VISUAL_ID = 6100; + + /** + * @generated + */ + private DirectEditManager manager; + + /** + * @generated + */ + private IParser parser; + + /** + * @generated + */ + private List parserElements; + + /** + * @generated + */ + private String defaultText; + + /** + * direct edition mode (default, undefined, registered editor, etc.) + * + * @generated + */ + protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; + + /** + * configuration from a registered edit dialog + * + * @generated + */ + protected IDirectEditorConfiguration configuration; + + + /** + * @generated + */ + static { + registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.UseCaseFloatingLabelEditPart.VISUAL_ID), new Point(0, 0)); + } + + /** + * @generated + */ + public UseCaseFloatingLabelEditPart(View view) { + super(view); + } + + /** + * @generated + */ + @Override + protected void createDefaultEditPolicies() { + super.createDefaultEditPolicies(); + installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); + installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ExternalLabelPrimaryDragRoleEditPolicy()); + } + + /** + * @generated + */ + @Override + public IBorderItemLocator getBorderItemLocator() { + IFigure parentFigure = getFigure().getParent(); + if (parentFigure != null && parentFigure.getLayoutManager() != null) { + Object constraint = parentFigure.getLayoutManager().getConstraint(getFigure()); + return (IBorderItemLocator) constraint; + } + return null; + } + + /** + * @generated + */ + @Override + public void refreshBounds() { + int x = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_X())).intValue(); + int y = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_Y())).intValue(); + int width = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Width())).intValue(); + int height = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Height())).intValue(); + getBorderItemLocator().setConstraint(new Rectangle(x, y, width, height)); + } + + + /** + * @generated + */ + protected String getLabelTextHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getText(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getText(); + } else { + return ((Label) figure).getText(); + } + } + + /** + * @generated + */ + protected void setLabelTextHelper(IFigure figure, String text) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setText(text); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setText(text); + } else { + ((Label) figure).setText(text); + } + } + + /** + * @generated + */ + protected Image getLabelIconHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getIcon(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getIcon(); + } else { + return ((Label) figure).getIcon(); + } + } + + /** + * @generated + */ + protected void setLabelIconHelper(IFigure figure, Image icon) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setIcon(icon); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setIcon(icon); + } else { + ((Label) figure).setIcon(icon); + } + } + + /** + * @generated + */ + public void setLabel(IFigure + figure) { + unregisterVisuals(); + setFigure(figure); + defaultText = getLabelTextHelper(figure); + registerVisuals(); + refreshVisuals(); + } + + /** + * @generated + */ + @Override + protected List getModelChildren() { + return Collections.EMPTY_LIST; + } + + /** + * @generated + */ + @Override + public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { + return null; + } + + /** + * @generated + */ + public void setParser(IParser parser) { + this.parser = parser; + } + + /** + * @generated + */ + protected EObject getParserElement() { + return resolveSemanticElement(); + } + + /** + * @generated + */ + protected Image getLabelIcon() { + return null; + } + + /** + * @generated + */ + protected String getLabelText() { + String text = null; + EObject parserElement = getParserElement(); + if (parserElement != null && getParser() != null) { + text = getParser().getPrintString( + new EObjectAdapter(parserElement), + getParserOptions().intValue()); + } + if (text == null || text.length() == 0) { + text = defaultText; + } + return text; + } + + /** + * @generated + */ + @Override + public void setLabelText(String text) { + setLabelTextHelper(getFigure(), text); + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + @Override + public String getEditText() { + if (getParserElement() == null || getParser() == null) { + return ""; //$NON-NLS-1$ + } + return getParser().getEditString( + new EObjectAdapter(getParserElement()), + getParserOptions().intValue()); + } + + /** + * @generated + */ + protected boolean isEditable() { + return getParser() != null; + } + + /** + * @generated + */ + @Override + public ICellEditorValidator getEditTextValidator() { + return new ICellEditorValidator() { + + @Override + public String isValid(final Object value) { + if (value instanceof String) { + final EObject element = getParserElement(); + final IParser parser = getParser(); + try { + IParserEditStatus valid = + (IParserEditStatus) getEditingDomain().runExclusive( + new RunnableWithResult.Impl() { + + @Override + public void run() { + setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); + } + }); + return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); + } catch (InterruptedException ie) { + ie.printStackTrace(); + } + } + + // shouldn't get here + return null; + } + }; + } + + /** + * @generated + */ + @Override + public IContentAssistProcessor getCompletionProcessor() { + if (getParserElement() == null || getParser() == null) { + return null; + } + return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); + } + + /** + * @generated + */ + @Override + public ParserOptions getParserOptions() { + return ParserOptions.NONE; + } + + /** + * @generated + */ + @Override + public IParser getParser() { + if (parser == null) { + parser = UMLParserProvider.getParser(UMLElementTypes.UseCase_2082, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.UseCaseFloatingLabelEditPart.VISUAL_ID)); + } + return parser; + } + + /** + * @generated + */ + protected DirectEditManager getManager() { + if (manager == null) { + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + } + return manager; + } + + /** + * @generated + */ + protected void setManager(DirectEditManager manager) { + this.manager = manager; + } + + /** + * @generated + */ + protected void performDirectEdit() { + BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { + + @Override + public void run() { + getManager().show(); + } + }); + } + + /** + * @generated + */ + protected void performDirectEdit(Point eventLocation) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); + } + } + + /** + * @generated + */ + private void performDirectEdit(char initialCharacter) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(initialCharacter); + } else { + performDirectEdit(); + } + } + + /** + * @generated + */ + @Override + protected void performDirectEditRequest(Request request) { + + final Request theRequest = request; + + if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { + directEditionMode = getDirectEditionType(); + } + switch (directEditionMode) { + case IDirectEdition.NO_DIRECT_EDITION: + // no direct edition mode => does nothing + return; + case IDirectEdition.EXTENDED_DIRECT_EDITOR: + updateExtendedEditorConfiguration(); + if (configuration == null || configuration.getLanguage() == null) { + // Create default edit manager + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + performDefaultDirectEditorEdit(theRequest); + } else { + configuration.preEditAction(resolveSemanticElement()); + Dialog dialog = null; + if (configuration instanceof ICustomDirectEditorConfiguration) { + setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); + initializeDirectEditManager(theRequest); + return; + } else if (configuration instanceof IPopupEditorConfiguration) { + IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); + helper.showEditor(); + return; + } + else if (configuration instanceof IAdvancedEditorConfiguration) { + dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); + } else if (configuration instanceof IDirectEditorConfiguration) { + dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), + configuration); + } else { + return; + } + final Dialog finalDialog = dialog; + + if (Window.OK == dialog.open()) { + TransactionalEditingDomain domain = getEditingDomain(); + RecordingCommand command = new RecordingCommand(domain, "Edit Label") { + + @Override + protected void doExecute() { + configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); + + } + }; + domain.getCommandStack().execute(command); + } + } + break; + case IDirectEdition.DEFAULT_DIRECT_EDITOR: + initializeDirectEditManager(theRequest); + break; + default: + break; + } + } + + /** + * @generated + */ + protected void initializeDirectEditManager(final Request request) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + @Override + public void run() { + if (isActive() && isEditable()) { + if (request.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } + else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void refreshVisuals() { + super.refreshVisuals(); + refreshLabel(); + refreshFont(); + refreshFontColor(); + refreshUnderline(); + refreshStrikeThrough(); + } + + /** + * @generated + */ + protected void refreshLabel() { + EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); + if (maskLabelPolicy == null) { + maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); + } + if (maskLabelPolicy == null) { + View view = (View) getModel(); + if (view.isVisible()) { + setLabelTextHelper(getFigure(), getLabelText()); + setLabelIconHelper(getFigure(), getLabelIcon()); + } + else { + setLabelTextHelper(getFigure(), ""); //$NON-NLS-1$ + setLabelIconHelper(getFigure(), null); + } + } + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + protected void refreshUnderline() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); + } + if (resolveSemanticElement() instanceof Feature) { + if (((Feature) resolveSemanticElement()).isStatic()) { + ((WrappingLabel) getFigure()).setTextUnderline(true); + } + else { + ((WrappingLabel) getFigure()).setTextUnderline(false); + } + } + } + + /** + * @generated + */ + protected void refreshStrikeThrough() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); + } + } + + /** + * @generated + */ + @Override + protected void refreshFont() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null) { + FontData fontData = new FontData( + style.getFontName(), style.getFontHeight(), + (style.isBold() ? SWT.BOLD : SWT.NORMAL) | + (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); + setFont(fontData); + } + } + + /** + * @generated + */ + @Override + protected void setFontColor(Color color) { + getFigure().setForegroundColor(color); + } + + /** + * @generated + */ + @Override + protected void addSemanticListeners() { + if (getParser() instanceof ISemanticParser) { + EObject element = resolveSemanticElement(); + parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); + for (int i = 0; i < parserElements.size(); i++) { + addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ + } + } else { + super.addSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected void removeSemanticListeners() { + if (parserElements != null) { + for (int i = 0; i < parserElements.size(); i++) { + removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ + } + } else { + super.removeSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected AccessibleEditPart getAccessibleEditPart() { + if (accessibleEP == null) { + accessibleEP = new AccessibleGraphicalEditPart() { + + @Override + public void getName(AccessibleEvent e) { + e.result = getLabelTextHelper(getFigure()); + } + }; + } + return accessibleEP; + } + + /** + * @generated + */ + private View getFontStyleOwnerView() { + return getPrimaryView(); + } + + /** + * Returns the kind of associated editor for direct edition. + * + * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition + * @generated + */ + public int getDirectEditionType() { + if (checkExtendedEditor()) { + initExtendedEditorConfiguration(); + return IDirectEdition.EXTENDED_DIRECT_EDITOR; + } + if (checkDefaultEdition()) { + return IDirectEdition.DEFAULT_DIRECT_EDITOR; + } + + // not a named element. no specific editor => do nothing + return IDirectEdition.NO_DIRECT_EDITION; + } + + /** + * Checks if an extended editor is present. + * + * @return true if an extended editor is present. + * @generated + */ + protected boolean checkExtendedEditor() { + if (resolveSemanticElement() != null) { + return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); + } + return false; + } + + /** + * Checks if a default direct edition is available + * + * @return true if a default direct edition is available + * @generated + */ + protected boolean checkDefaultEdition() { + return (getParser() != null); + } + + /** + * Initializes the extended editor configuration + * + * @generated + */ + protected void initExtendedEditorConfiguration() { + if (configuration == null) { + final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("")) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); + } else { + configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); + } + } + } + + /** + * Updates the preference configuration + * + * @generated + */ + protected void updateExtendedEditorConfiguration() { + String languagePreferred = Activator.getDefault().getPreferenceStore().getString( + IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() + .eClass().getInstanceClassName()); + } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { + configuration = null; + } + } + + /** + * Performs the direct edit usually used by GMF editors. + * + * @param theRequest + * the direct edit request that starts the direct edit system + * @generated + */ + protected void performDefaultDirectEditorEdit(final Request theRequest) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + + @Override + public void run() { + if (isActive() && isEditable()) { + if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) theRequest.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { + DirectEditRequest editRequest = (DirectEditRequest) theRequest; + performDirectEdit(editRequest.getLocation()); + } else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + + /** + * @generated + */ + @Override + protected void handleNotificationEvent(Notification event) { + Object feature = event.getFeature(); + if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { + Integer c = (Integer) event.getNewValue(); + setFontColor(DiagramColorRegistry.getInstance().getColor(c)); + } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { + refreshUnderline(); + } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { + refreshStrikeThrough(); + } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { + refreshFont(); + } else { + if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { + refreshLabel(); + } + if (getParser() instanceof ISemanticParser) { + ISemanticParser modelParser = + (ISemanticParser) getParser(); + if (modelParser.areSemanticElementsAffected(null, event)) { + removeSemanticListeners(); + if (resolveSemanticElement() != null) { + addSemanticListeners(); + } + refreshLabel(); + } + } + } + super.handleNotificationEvent(event); + } + + /** + * @generated + */ + @Override + protected IFigure createFigure() { + IFigure label = createFigurePrim(); + defaultText = getLabelTextHelper(label); + return label; + } + + /** + * @generated + */ + protected IFigure createFigurePrim() { + return new PapyrusWrappingLabel(); + } + +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/UseCaseFloatingLabelEditPartCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/UseCaseFloatingLabelEditPartCN.java new file mode 100644 index 00000000000..001ee6978ba --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/UseCaseFloatingLabelEditPartCN.java @@ -0,0 +1,860 @@ +/** + * 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.uml.diagram.composite.edit.parts; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.Label; +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.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.RunnableWithResult; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gef.AccessibleEditPart; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.Request; +import org.eclipse.gef.requests.DirectEditRequest; +import org.eclipse.gef.tools.DirectEditManager; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; +import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; +import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy; +import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator; +import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry; +import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; +import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager; +import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; +import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; +import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; +import org.eclipse.gmf.runtime.notation.FontStyle; +import org.eclipse.gmf.runtime.notation.NotationPackage; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.text.contentassist.IContentAssistProcessor; +import org.eclipse.jface.viewers.ICellEditorValidator; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.extensionpoints.editors.Activator; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration; +import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog; +import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper; +import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil; +import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.ExternalLabelPrimaryDragRoleEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.PapyrusWrappingLabel; +import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager; +import org.eclipse.papyrus.uml.diagram.common.editparts.FloatingLabelEditPart; +import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition; +import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure; +import org.eclipse.papyrus.uml.diagram.composite.edit.policies.UMLTextSelectionEditPolicy; +import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; +import org.eclipse.papyrus.uml.diagram.composite.providers.UMLParserProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.accessibility.AccessibleEvent; +import org.eclipse.swt.custom.BusyIndicator; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; +import org.eclipse.uml2.uml.Feature; + +/** + * @generated + */ +public class UseCaseFloatingLabelEditPartCN extends FloatingLabelEditPart + implements ITextAwareEditPart, IBorderItemEditPart +{ + + /** + * @generated + */ + public static final int VISUAL_ID = 6078; + + /** + * @generated + */ + private DirectEditManager manager; + + /** + * @generated + */ + private IParser parser; + + /** + * @generated + */ + private List parserElements; + + /** + * @generated + */ + private String defaultText; + + /** + * direct edition mode (default, undefined, registered editor, etc.) + * + * @generated + */ + protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR; + + /** + * configuration from a registered edit dialog + * + * @generated + */ + protected IDirectEditorConfiguration configuration; + + + /** + * @generated + */ + static { + registerSnapBackPosition(UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.UseCaseFloatingLabelEditPartCN.VISUAL_ID), new Point(0, 0)); + } + + /** + * @generated + */ + public UseCaseFloatingLabelEditPartCN(View view) { + super(view); + } + + /** + * @generated + */ + @Override + protected void createDefaultEditPolicies() { + super.createDefaultEditPolicies(); + installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); + installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy()); + installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ExternalLabelPrimaryDragRoleEditPolicy()); + } + + /** + * @generated + */ + @Override + public IBorderItemLocator getBorderItemLocator() { + IFigure parentFigure = getFigure().getParent(); + if (parentFigure != null && parentFigure.getLayoutManager() != null) { + Object constraint = parentFigure.getLayoutManager().getConstraint(getFigure()); + return (IBorderItemLocator) constraint; + } + return null; + } + + /** + * @generated + */ + @Override + public void refreshBounds() { + int x = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_X())).intValue(); + int y = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_Y())).intValue(); + int width = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Width())).intValue(); + int height = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Height())).intValue(); + getBorderItemLocator().setConstraint(new Rectangle(x, y, width, height)); + } + + + /** + * @generated + */ + protected String getLabelTextHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getText(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getText(); + } else { + return ((Label) figure).getText(); + } + } + + /** + * @generated + */ + protected void setLabelTextHelper(IFigure figure, String text) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setText(text); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setText(text); + } else { + ((Label) figure).setText(text); + } + } + + /** + * @generated + */ + protected Image getLabelIconHelper(IFigure figure) { + if (figure instanceof WrappingLabel) { + return ((WrappingLabel) figure).getIcon(); + } else if (figure instanceof ILabelFigure) { + return ((ILabelFigure) figure).getIcon(); + } else { + return ((Label) figure).getIcon(); + } + } + + /** + * @generated + */ + protected void setLabelIconHelper(IFigure figure, Image icon) { + if (figure instanceof WrappingLabel) { + ((WrappingLabel) figure).setIcon(icon); + } else if (figure instanceof ILabelFigure) { + ((ILabelFigure) figure).setIcon(icon); + } else { + ((Label) figure).setIcon(icon); + } + } + + /** + * @generated + */ + public void setLabel(IFigure + figure) { + unregisterVisuals(); + setFigure(figure); + defaultText = getLabelTextHelper(figure); + registerVisuals(); + refreshVisuals(); + } + + /** + * @generated + */ + @Override + protected List getModelChildren() { + return Collections.EMPTY_LIST; + } + + /** + * @generated + */ + @Override + public IGraphicalEditPart getChildBySemanticHint(String semanticHint) { + return null; + } + + /** + * @generated + */ + public void setParser(IParser parser) { + this.parser = parser; + } + + /** + * @generated + */ + protected EObject getParserElement() { + return resolveSemanticElement(); + } + + /** + * @generated + */ + protected Image getLabelIcon() { + return null; + } + + /** + * @generated + */ + protected String getLabelText() { + String text = null; + EObject parserElement = getParserElement(); + if (parserElement != null && getParser() != null) { + text = getParser().getPrintString( + new EObjectAdapter(parserElement), + getParserOptions().intValue()); + } + if (text == null || text.length() == 0) { + text = defaultText; + } + return text; + } + + /** + * @generated + */ + @Override + public void setLabelText(String text) { + setLabelTextHelper(getFigure(), text); + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + @Override + public String getEditText() { + if (getParserElement() == null || getParser() == null) { + return ""; //$NON-NLS-1$ + } + return getParser().getEditString( + new EObjectAdapter(getParserElement()), + getParserOptions().intValue()); + } + + /** + * @generated + */ + protected boolean isEditable() { + return getParser() != null; + } + + /** + * @generated + */ + @Override + public ICellEditorValidator getEditTextValidator() { + return new ICellEditorValidator() { + + @Override + public String isValid(final Object value) { + if (value instanceof String) { + final EObject element = getParserElement(); + final IParser parser = getParser(); + try { + IParserEditStatus valid = + (IParserEditStatus) getEditingDomain().runExclusive( + new RunnableWithResult.Impl() { + + @Override + public void run() { + setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value)); + } + }); + return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage(); + } catch (InterruptedException ie) { + ie.printStackTrace(); + } + } + + // shouldn't get here + return null; + } + }; + } + + /** + * @generated + */ + @Override + public IContentAssistProcessor getCompletionProcessor() { + if (getParserElement() == null || getParser() == null) { + return null; + } + return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement())); + } + + /** + * @generated + */ + @Override + public ParserOptions getParserOptions() { + return ParserOptions.NONE; + } + + /** + * @generated + */ + @Override + public IParser getParser() { + if (parser == null) { + parser = UMLParserProvider.getParser(UMLElementTypes.UseCase_3096, getParserElement(), UMLVisualIDRegistry.getType(org.eclipse.papyrus.uml.diagram.composite.edit.parts.UseCaseFloatingLabelEditPartCN.VISUAL_ID)); + } + return parser; + } + + /** + * @generated + */ + protected DirectEditManager getManager() { + if (manager == null) { + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + } + return manager; + } + + /** + * @generated + */ + protected void setManager(DirectEditManager manager) { + this.manager = manager; + } + + /** + * @generated + */ + protected void performDirectEdit() { + BusyIndicator.showWhile(Display.getDefault(), new java.lang.Runnable() { + + @Override + public void run() { + getManager().show(); + } + }); + } + + /** + * @generated + */ + protected void performDirectEdit(Point eventLocation) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint()); + } + } + + /** + * @generated + */ + private void performDirectEdit(char initialCharacter) { + if (getManager() instanceof TextDirectEditManager) { + ((TextDirectEditManager) getManager()).show(initialCharacter); + } else { + performDirectEdit(); + } + } + + /** + * @generated + */ + @Override + protected void performDirectEditRequest(Request request) { + + final Request theRequest = request; + + if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) { + directEditionMode = getDirectEditionType(); + } + switch (directEditionMode) { + case IDirectEdition.NO_DIRECT_EDITION: + // no direct edition mode => does nothing + return; + case IDirectEdition.EXTENDED_DIRECT_EDITOR: + updateExtendedEditorConfiguration(); + if (configuration == null || configuration.getLanguage() == null) { + // Create default edit manager + setManager(new MultilineLabelDirectEditManager(this, + MultilineLabelDirectEditManager.getTextCellEditorClass(this), + UMLEditPartFactory.getTextCellEditorLocator(this))); + performDefaultDirectEditorEdit(theRequest); + } else { + configuration.preEditAction(resolveSemanticElement()); + Dialog dialog = null; + if (configuration instanceof ICustomDirectEditorConfiguration) { + setManager(((ICustomDirectEditorConfiguration) configuration).createDirectEditManager(this)); + initializeDirectEditManager(theRequest); + return; + } else if (configuration instanceof IPopupEditorConfiguration) { + IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this); + helper.showEditor(); + return; + } + else if (configuration instanceof IAdvancedEditorConfiguration) { + dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement())); + } else if (configuration instanceof IDirectEditorConfiguration) { + dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), + configuration); + } else { + return; + } + final Dialog finalDialog = dialog; + + if (Window.OK == dialog.open()) { + TransactionalEditingDomain domain = getEditingDomain(); + RecordingCommand command = new RecordingCommand(domain, "Edit Label") { + + @Override + protected void doExecute() { + configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue()); + + } + }; + domain.getCommandStack().execute(command); + } + } + break; + case IDirectEdition.DEFAULT_DIRECT_EDITOR: + initializeDirectEditManager(theRequest); + break; + default: + break; + } + } + + /** + * @generated + */ + protected void initializeDirectEditManager(final Request request) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + @Override + public void run() { + if (isActive() && isEditable()) { + if (request.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) request.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } + else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * @generated + */ + @Override + protected void refreshVisuals() { + super.refreshVisuals(); + refreshLabel(); + refreshFont(); + refreshFontColor(); + refreshUnderline(); + refreshStrikeThrough(); + } + + /** + * @generated + */ + protected void refreshLabel() { + EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY); + if (maskLabelPolicy == null) { + maskLabelPolicy = getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL); + } + if (maskLabelPolicy == null) { + View view = (View) getModel(); + if (view.isVisible()) { + setLabelTextHelper(getFigure(), getLabelText()); + setLabelIconHelper(getFigure(), getLabelIcon()); + } + else { + setLabelTextHelper(getFigure(), ""); //$NON-NLS-1$ + setLabelIconHelper(getFigure(), null); + } + } + Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); + if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback(); + } + Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE); + if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) { + ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback(); + } + } + + /** + * @generated + */ + protected void refreshUnderline() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline()); + } + if (resolveSemanticElement() instanceof Feature) { + if (((Feature) resolveSemanticElement()).isStatic()) { + ((WrappingLabel) getFigure()).setTextUnderline(true); + } + else { + ((WrappingLabel) getFigure()).setTextUnderline(false); + } + } + } + + /** + * @generated + */ + protected void refreshStrikeThrough() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null && getFigure() instanceof WrappingLabel) { + ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough()); + } + } + + /** + * @generated + */ + @Override + protected void refreshFont() { + FontStyle style = + (FontStyle) getFontStyleOwnerView().getStyle( + NotationPackage.eINSTANCE.getFontStyle()); + if (style != null) { + FontData fontData = new FontData( + style.getFontName(), style.getFontHeight(), + (style.isBold() ? SWT.BOLD : SWT.NORMAL) | + (style.isItalic() ? SWT.ITALIC : SWT.NORMAL)); + setFont(fontData); + } + } + + /** + * @generated + */ + @Override + protected void setFontColor(Color color) { + getFigure().setForegroundColor(color); + } + + /** + * @generated + */ + @Override + protected void addSemanticListeners() { + if (getParser() instanceof ISemanticParser) { + EObject element = resolveSemanticElement(); + parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element); + for (int i = 0; i < parserElements.size(); i++) { + addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$ + } + } else { + super.addSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected void removeSemanticListeners() { + if (parserElements != null) { + for (int i = 0; i < parserElements.size(); i++) { + removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$ + } + } else { + super.removeSemanticListeners(); + } + } + + /** + * @generated + */ + @Override + protected AccessibleEditPart getAccessibleEditPart() { + if (accessibleEP == null) { + accessibleEP = new AccessibleGraphicalEditPart() { + + @Override + public void getName(AccessibleEvent e) { + e.result = getLabelTextHelper(getFigure()); + } + }; + } + return accessibleEP; + } + + /** + * @generated + */ + private View getFontStyleOwnerView() { + return getPrimaryView(); + } + + /** + * Returns the kind of associated editor for direct edition. + * + * @return an int corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition + * @generated + */ + public int getDirectEditionType() { + if (checkExtendedEditor()) { + initExtendedEditorConfiguration(); + return IDirectEdition.EXTENDED_DIRECT_EDITOR; + } + if (checkDefaultEdition()) { + return IDirectEdition.DEFAULT_DIRECT_EDITOR; + } + + // not a named element. no specific editor => do nothing + return IDirectEdition.NO_DIRECT_EDITION; + } + + /** + * Checks if an extended editor is present. + * + * @return true if an extended editor is present. + * @generated + */ + protected boolean checkExtendedEditor() { + if (resolveSemanticElement() != null) { + return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName()); + } + return false; + } + + /** + * Checks if a default direct edition is available + * + * @return true if a default direct edition is available + * @generated + */ + protected boolean checkDefaultEdition() { + return (getParser() != null); + } + + /** + * Initializes the extended editor configuration + * + * @generated + */ + protected void initExtendedEditorConfiguration() { + if (configuration == null) { + final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("")) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName()); + } else { + configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName()); + } + } + } + + /** + * Updates the preference configuration + * + * @generated + */ + protected void updateExtendedEditorConfiguration() { + String languagePreferred = Activator.getDefault().getPreferenceStore().getString( + IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName()); + if (languagePreferred != null && !languagePreferred.equals("") && !languagePreferred.equals(configuration.getLanguage())) { + configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement() + .eClass().getInstanceClassName()); + } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) { + configuration = null; + } + } + + /** + * Performs the direct edit usually used by GMF editors. + * + * @param theRequest + * the direct edit request that starts the direct edit system + * @generated + */ + protected void performDefaultDirectEditorEdit(final Request theRequest) { + // initialize the direct edit manager + try { + getEditingDomain().runExclusive(new Runnable() { + + @Override + public void run() { + if (isActive() && isEditable()) { + if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) { + Character initialChar = (Character) theRequest.getExtendedData().get( + RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR); + performDirectEdit(initialChar.charValue()); + } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) { + DirectEditRequest editRequest = (DirectEditRequest) theRequest; + performDirectEdit(editRequest.getLocation()); + } else { + performDirectEdit(); + } + } + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + + /** + * @generated + */ + @Override + protected void handleNotificationEvent(Notification event) { + Object feature = event.getFeature(); + if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) { + Integer c = (Integer) event.getNewValue(); + setFontColor(DiagramColorRegistry.getInstance().getColor(c)); + } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) { + refreshUnderline(); + } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) { + refreshStrikeThrough(); + } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || + NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { + refreshFont(); + } else { + if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) { + refreshLabel(); + } + if (getParser() instanceof ISemanticParser) { + ISemanticParser modelParser = + (ISemanticParser) getParser(); + if (modelParser.areSemanticElementsAffected(null, event)) { + removeSemanticListeners(); + if (resolveSemanticElement() != null) { + addSemanticListeners(); + } + refreshLabel(); + } + } + } + super.handleNotificationEvent(event); + } + + /** + * @generated + */ + @Override + protected IFigure createFigure() { + IFigure label = createFigurePrim(); + defaultText = getLabelTextHelper(label); + return label; + } + + /** + * @generated + */ + protected IFigure createFigurePrim() { + return new PapyrusWrappingLabel(); + } + +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/UseCaseNameEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/UseCaseNameEditPart.java index dbe7e8d5d73..b3adde5c1ce 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/UseCaseNameEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/UseCaseNameEditPart.java @@ -864,7 +864,7 @@ public class UseCaseNameEditPart extends PapyrusCompartmentEditPart implements I * @generated */ protected void addOwnerElementListeners() { - addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); + addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/UseCaseNameEditPartCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/UseCaseNameEditPartCN.java index 3f18049403e..0e7d8407e3e 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/UseCaseNameEditPartCN.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/parts/UseCaseNameEditPartCN.java @@ -864,7 +864,7 @@ public class UseCaseNameEditPartCN extends PapyrusCompartmentEditPart implements * @generated */ protected void addOwnerElementListeners() { - addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); + addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel())); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/policies/EnumerationLiteralItemSemanticEditPolicyCLN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/policies/EnumerationLiteralItemSemanticEditPolicyCLN.java index ebe174b6408..7a2b801a0a1 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/policies/EnumerationLiteralItemSemanticEditPolicyCLN.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/policies/EnumerationLiteralItemSemanticEditPolicyCLN.java @@ -51,7 +51,7 @@ public class EnumerationLiteralItemSemanticEditPolicyCLN extends UMLBaseItemSema // delete host element List todestroy = new ArrayList(); todestroy.add(req.getElementToDestroy()); - //cmd.add(new org.eclipse.gmf.runtime.emf.type.core.commands.DestroyElementCommand(req)); + // cmd.add(new org.eclipse.gmf.runtime.emf.type.core.commands.DestroyElementCommand(req)); cmd.add(new EMFtoGMFCommandWrapper(new DeleteCommand(getEditingDomain(), todestroy))); } else { cmd.add(new org.eclipse.gmf.runtime.diagram.core.commands.DeleteCommand(getEditingDomain(), view)); diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/policies/OperationItemSemanticEditPolicyCLN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/policies/OperationItemSemanticEditPolicyCLN.java index 23a56c088fd..f05252f1043 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/policies/OperationItemSemanticEditPolicyCLN.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/policies/OperationItemSemanticEditPolicyCLN.java @@ -51,7 +51,7 @@ public class OperationItemSemanticEditPolicyCLN extends UMLBaseItemSemanticEditP // delete host element List todestroy = new ArrayList(); todestroy.add(req.getElementToDestroy()); - //cmd.add(new org.eclipse.gmf.runtime.emf.type.core.commands.DestroyElementCommand(req)); + // cmd.add(new org.eclipse.gmf.runtime.emf.type.core.commands.DestroyElementCommand(req)); cmd.add(new EMFtoGMFCommandWrapper(new DeleteCommand(getEditingDomain(), todestroy))); } else { cmd.add(new org.eclipse.gmf.runtime.diagram.core.commands.DeleteCommand(getEditingDomain(), view)); diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/policies/PropertyItemSemanticEditPolicyCLN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/policies/PropertyItemSemanticEditPolicyCLN.java index 0ad14b9b467..89b162f6c56 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/policies/PropertyItemSemanticEditPolicyCLN.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/policies/PropertyItemSemanticEditPolicyCLN.java @@ -51,7 +51,7 @@ public class PropertyItemSemanticEditPolicyCLN extends UMLBaseItemSemanticEditPo // delete host element List todestroy = new ArrayList(); todestroy.add(req.getElementToDestroy()); - //cmd.add(new org.eclipse.gmf.runtime.emf.type.core.commands.DestroyElementCommand(req)); + // cmd.add(new org.eclipse.gmf.runtime.emf.type.core.commands.DestroyElementCommand(req)); cmd.add(new EMFtoGMFCommandWrapper(new DeleteCommand(getEditingDomain(), todestroy))); } else { cmd.add(new org.eclipse.gmf.runtime.diagram.core.commands.DeleteCommand(getEditingDomain(), view)); diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/policies/UMLBaseItemSemanticEditPolicy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/policies/UMLBaseItemSemanticEditPolicy.java index 91057508a71..1cb89f7f6b1 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/policies/UMLBaseItemSemanticEditPolicy.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/policies/UMLBaseItemSemanticEditPolicy.java @@ -806,7 +806,7 @@ public class UMLBaseItemSemanticEditPolicy extends SemanticEditPolicy { */ public boolean canExistInformationFlow_4021(Package container, InformationFlow linkInstance, NamedElement source, NamedElement target) { try { - //Information Flow source constraint + // Information Flow source constraint if (source != null) { if (!((source instanceof Actor) || (source instanceof Node) @@ -833,7 +833,7 @@ public class UMLBaseItemSemanticEditPolicy extends SemanticEditPolicy { } } } - //Information Flow target constraint + // Information Flow target constraint if (target != null) { if (!((target instanceof Actor) || (target instanceof Node) diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/part/UMLDiagramEditorUtil.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/part/UMLDiagramEditorUtil.java index 8ee4a464e25..258995ef886 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/part/UMLDiagramEditorUtil.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/part/UMLDiagramEditorUtil.java @@ -182,6 +182,7 @@ public class UMLDiagramEditorUtil { * Create a new instance of domain element associated with canvas. * * + * * @generated */ private static Package createInitialModel() { @@ -192,6 +193,7 @@ public class UMLDiagramEditorUtil { * Store model element in the resource. * * + * * @generated */ private static void attachModelToResource(Package model, Resource resource) { diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/part/UMLDiagramUpdater.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/part/UMLDiagramUpdater.java index 592aae166b0..f5da0f844fa 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/part/UMLDiagramUpdater.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/part/UMLDiagramUpdater.java @@ -117,7 +117,7 @@ public class UMLDiagramUpdater implements DiagramUpdater { * @generated */ protected UMLDiagramUpdater() { - //to prevent instantiation allowing the override + // to prevent instantiation allowing the override } /** diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/part/UMLDocumentProvider.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/part/UMLDocumentProvider.java index cb2b473af14..1039b1e7238 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/part/UMLDocumentProvider.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/part/UMLDocumentProvider.java @@ -506,7 +506,6 @@ public class UMLDocumentProvider extends AbstractDocumentProvider implements IDi if (toCreateOrModify.exists()) { return ResourcesPlugin.getWorkspace().getRuleFactory().modifyRule(toCreateOrModify); } - IResource parent = toCreateOrModify; do { /* @@ -554,7 +553,7 @@ public class UMLDocumentProvider extends AbstractDocumentProvider implements IDi info.stopResourceListening(); fireElementStateChanging(element); try { - monitor.beginTask(Messages.UMLDocumentProvider_SaveDiagramTask, info.getResourceSet().getResources().size() + 1); //"Saving diagram" + monitor.beginTask(Messages.UMLDocumentProvider_SaveDiagramTask, info.getResourceSet().getResources().size() + 1); // "Saving diagram" for (Iterator it = info.getLoadedResourcesIterator(); it.hasNext();) { Resource nextResource = it.next(); monitor.setTaskName(NLS.bind( diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/part/UMLVisualIDRegistry.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/part/UMLVisualIDRegistry.java index 61a420179ed..3fa9611ffd9 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/part/UMLVisualIDRegistry.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/part/UMLVisualIDRegistry.java @@ -2763,6 +2763,9 @@ public class UMLVisualIDRegistry { if (ActivityCompositeNameEditPart.VISUAL_ID == nodeVisualID) { return true; } + if (ActivityCompositeFloatingLabelEditPart.VISUAL_ID == nodeVisualID) { + return true; + } if (ActivityCompositeCompartmentEditPart.VISUAL_ID == nodeVisualID) { return true; } @@ -2777,6 +2780,9 @@ public class UMLVisualIDRegistry { if (InteractionCompositeNameEditPart.VISUAL_ID == nodeVisualID) { return true; } + if (InteractionCompositeFloatingLabelEditPart.VISUAL_ID == nodeVisualID) { + return true; + } if (InteractionCompositeCompartmentEditPart.VISUAL_ID == nodeVisualID) { return true; } @@ -2791,6 +2797,9 @@ public class UMLVisualIDRegistry { if (ProtocolStateMachineCompositeNameEditPart.VISUAL_ID == nodeVisualID) { return true; } + if (ProtocolStateMachineCompositeFloatingLabelEditPart.VISUAL_ID == nodeVisualID) { + return true; + } if (ProtocolStateMachineCompositeCompartmentEditPart.VISUAL_ID == nodeVisualID) { return true; } @@ -2805,6 +2814,9 @@ public class UMLVisualIDRegistry { if (StateMachineCompositeNameEditPart.VISUAL_ID == nodeVisualID) { return true; } + if (StateMachineCompositeFloatingLabelEditPart.VISUAL_ID == nodeVisualID) { + return true; + } if (StateMachineCompositeCompartmentEditPart.VISUAL_ID == nodeVisualID) { return true; } @@ -2819,6 +2831,9 @@ public class UMLVisualIDRegistry { if (FunctionBehaviorCompositeNameEditPart.VISUAL_ID == nodeVisualID) { return true; } + if (FunctionBehaviorCompositeFloatingLabelEditPart.VISUAL_ID == nodeVisualID) { + return true; + } if (FunctionBehaviorCompositeCompartmentEditPart.VISUAL_ID == nodeVisualID) { return true; } @@ -2833,6 +2848,9 @@ public class UMLVisualIDRegistry { if (OpaqueBehaviorCompositeNameEditPart.VISUAL_ID == nodeVisualID) { return true; } + if (OpaqueBehaviorCompositeFloatingLabelEditPart.VISUAL_ID == nodeVisualID) { + return true; + } if (OpaqueBehaviorCompositeCompartmentEditPart.VISUAL_ID == nodeVisualID) { return true; } @@ -2847,6 +2865,9 @@ public class UMLVisualIDRegistry { if (ComponentCompositeNameEditPart.VISUAL_ID == nodeVisualID) { return true; } + if (ComponentCompositeFloatingLabelEditPart.VISUAL_ID == nodeVisualID) { + return true; + } if (ComponentCompositeCompartmentEditPart.VISUAL_ID == nodeVisualID) { return true; } @@ -2858,6 +2879,9 @@ public class UMLVisualIDRegistry { if (DeviceCompositeNameEditPart.VISUAL_ID == nodeVisualID) { return true; } + if (DeviceCompositeFloatingLabelEditPart.VISUAL_ID == nodeVisualID) { + return true; + } if (DeviceCompositeCompartmentEditPart.VISUAL_ID == nodeVisualID) { return true; } @@ -2869,6 +2893,9 @@ public class UMLVisualIDRegistry { if (ExecutionEnvironmentCompositeNameEditPart.VISUAL_ID == nodeVisualID) { return true; } + if (ExecutionEnvironmentCompositeFloatingLabelEditPart.VISUAL_ID == nodeVisualID) { + return true; + } if (ExecutionEnvironmentCompositeCompartmentEditPart.VISUAL_ID == nodeVisualID) { return true; } @@ -2880,6 +2907,9 @@ public class UMLVisualIDRegistry { if (NodeCompositeNameEditPart.VISUAL_ID == nodeVisualID) { return true; } + if (NodeCompositeFloatingLabelEditPart.VISUAL_ID == nodeVisualID) { + return true; + } if (NodeCompositeCompartmentEditPart.VISUAL_ID == nodeVisualID) { return true; } @@ -2891,6 +2921,9 @@ public class UMLVisualIDRegistry { if (ClassCompositeNameEditPart.VISUAL_ID == nodeVisualID) { return true; } + if (ClassCompositeFloatingLabelEditPart.VISUAL_ID == nodeVisualID) { + return true; + } if (ClassCompositeCompartmentEditPart.VISUAL_ID == nodeVisualID) { return true; } @@ -2902,6 +2935,9 @@ public class UMLVisualIDRegistry { if (CollaborationCompositeNameEditPart.VISUAL_ID == nodeVisualID) { return true; } + if (CollaborationCompositeFloatingLabelEditPart.VISUAL_ID == nodeVisualID) { + return true; + } if (CollaborationCompositeCompartmentEditPart.VISUAL_ID == nodeVisualID) { return true; } @@ -2910,16 +2946,25 @@ public class UMLVisualIDRegistry { if (InterfaceNameEditPart.VISUAL_ID == nodeVisualID) { return true; } + if (InterfaceFloatingLabelEditPart.VISUAL_ID == nodeVisualID) { + return true; + } break; case PrimitiveTypeEditPart.VISUAL_ID: if (PrimitiveTypeNameEditPart.VISUAL_ID == nodeVisualID) { return true; } + if (PrimitiveTypeFloatingLabelEditPart.VISUAL_ID == nodeVisualID) { + return true; + } break; case EnumerationEditPart.VISUAL_ID: if (EnumerationNameEditPart.VISUAL_ID == nodeVisualID) { return true; } + if (EnumerationFloatingLabelEditPart.VISUAL_ID == nodeVisualID) { + return true; + } if (EnumerationEnumerationLiteralCompartmentEditPart.VISUAL_ID == nodeVisualID) { return true; } @@ -2931,6 +2976,9 @@ public class UMLVisualIDRegistry { if (DataTypeNameEditPart.VISUAL_ID == nodeVisualID) { return true; } + if (DataTypeFloatingLabelEditPart.VISUAL_ID == nodeVisualID) { + return true; + } if (DataTypeAttributeCompartmentEditPart.VISUAL_ID == nodeVisualID) { return true; } @@ -2942,56 +2990,89 @@ public class UMLVisualIDRegistry { if (ActorNameEditPart.VISUAL_ID == nodeVisualID) { return true; } + if (ActorFloatingLabelEditPart.VISUAL_ID == nodeVisualID) { + return true; + } break; case DeploymentSpecificationEditPart.VISUAL_ID: if (DeploymentSpecificationNameEditPart.VISUAL_ID == nodeVisualID) { return true; } + if (DeploymentSpecificationFloatingLabelEditPart.VISUAL_ID == nodeVisualID) { + return true; + } break; case ArtifactEditPart.VISUAL_ID: if (ArtifactNameEditPart.VISUAL_ID == nodeVisualID) { return true; } + if (ArtifactFloatingLabelEditPart.VISUAL_ID == nodeVisualID) { + return true; + } break; case InformationItemEditPart.VISUAL_ID: if (InformationItemNameEditPart.VISUAL_ID == nodeVisualID) { return true; } + if (InformationItemFloatingLabelEditPart.VISUAL_ID == nodeVisualID) { + return true; + } break; case SignalEditPart.VISUAL_ID: if (SignalNameEditPart.VISUAL_ID == nodeVisualID) { return true; } + if (SignalFloatingLabelEditPart.VISUAL_ID == nodeVisualID) { + return true; + } break; case UseCaseEditPart.VISUAL_ID: if (UseCaseNameEditPart.VISUAL_ID == nodeVisualID) { return true; } + if (UseCaseFloatingLabelEditPart.VISUAL_ID == nodeVisualID) { + return true; + } break; case SignalEventEditPart.VISUAL_ID: if (SignalEventNameEditPart.VISUAL_ID == nodeVisualID) { return true; } + if (SignalEventFloatingLabelEditPart.VISUAL_ID == nodeVisualID) { + return true; + } break; case CallEventEditPart.VISUAL_ID: if (CallEventNameEditPart.VISUAL_ID == nodeVisualID) { return true; } + if (CallEventFloatingLabelEditPart.VISUAL_ID == nodeVisualID) { + return true; + } break; case AnyReceiveEventEditPart.VISUAL_ID: if (AnyReceiveEventNameEditPart.VISUAL_ID == nodeVisualID) { return true; } + if (AnyReceiveEventFloatingLabelEditPart.VISUAL_ID == nodeVisualID) { + return true; + } break; case ChangeEventEditPart.VISUAL_ID: if (ChangeEventNameEditPart.VISUAL_ID == nodeVisualID) { return true; } + if (ChangeEventFloatingLabelEditPart.VISUAL_ID == nodeVisualID) { + return true; + } break; case TimeEventEditPart.VISUAL_ID: if (TimeEventNameEditPart.VISUAL_ID == nodeVisualID) { return true; } + if (TimeEventFloatingLabelEditPart.VISUAL_ID == nodeVisualID) { + return true; + } break; case DurationObservationEditPart.VISUAL_ID: if (DurationObservationNameEditPart.VISUAL_ID == nodeVisualID) { @@ -3013,71 +3094,113 @@ public class UMLVisualIDRegistry { if (LiteralBooleanNameEditPart.VISUAL_ID == nodeVisualID) { return true; } + if (LiteralBooleanFloatingLabelEditPart.VISUAL_ID == nodeVisualID) { + return true; + } break; case LiteralIntegerEditPart.VISUAL_ID: if (LiteralIntegerNameEditPart.VISUAL_ID == nodeVisualID) { return true; } + if (LiteralIntegerFloatingLabelEditPart.VISUAL_ID == nodeVisualID) { + return true; + } break; case LiteralNullEditPart.VISUAL_ID: if (LiteralNullNameEditPart.VISUAL_ID == nodeVisualID) { return true; } + if (LiteralNullFloatingLabelEditPart.VISUAL_ID == nodeVisualID) { + return true; + } break; case LiteralStringEditPart.VISUAL_ID: if (LiteralStringNameEditPart.VISUAL_ID == nodeVisualID) { return true; } + if (LiteralStringFloatingLabelEditPart.VISUAL_ID == nodeVisualID) { + return true; + } break; case LiteralUnlimitedNaturalEditPart.VISUAL_ID: if (LiteralUnlimitedNaturalNameEditPart.VISUAL_ID == nodeVisualID) { return true; } + if (LiteralUnlimitedNaturalFloatingLabelEditPart.VISUAL_ID == nodeVisualID) { + return true; + } break; case StringExpressionEditPart.VISUAL_ID: if (StringExpressionNameEditPart.VISUAL_ID == nodeVisualID) { return true; } + if (StringExpressionFloatingLabelEditPart.VISUAL_ID == nodeVisualID) { + return true; + } break; case OpaqueExpressionEditPart.VISUAL_ID: if (OpaqueExpressionNameEditPart.VISUAL_ID == nodeVisualID) { return true; } + if (OpaqueExpressionFloatingLabelEditPart.VISUAL_ID == nodeVisualID) { + return true; + } break; case TimeExpressionEditPart.VISUAL_ID: if (TimeExpressionNameEditPart.VISUAL_ID == nodeVisualID) { return true; } + if (TimeExpressionFloatingLabelEditPart.VISUAL_ID == nodeVisualID) { + return true; + } break; case ExpressionEditPart.VISUAL_ID: if (ExpressionNameEditPart.VISUAL_ID == nodeVisualID) { return true; } + if (ExpressionFloatingLabelEditPart.VISUAL_ID == nodeVisualID) { + return true; + } break; case DurationEditPart.VISUAL_ID: if (DurationNameEditPart.VISUAL_ID == nodeVisualID) { return true; } + if (DurationFloatingLabelEditPart.VISUAL_ID == nodeVisualID) { + return true; + } break; case TimeIntervalEditPart.VISUAL_ID: if (TimeIntervalNameEditPart.VISUAL_ID == nodeVisualID) { return true; } + if (TimeIntervalFloatingLabelEditPart.VISUAL_ID == nodeVisualID) { + return true; + } break; case DurationIntervalEditPart.VISUAL_ID: if (DurationIntervalNameEditPart.VISUAL_ID == nodeVisualID) { return true; } + if (DurationIntervalFloatingLabelEditPart.VISUAL_ID == nodeVisualID) { + return true; + } break; case IntervalEditPart.VISUAL_ID: if (IntervalNameEditPart.VISUAL_ID == nodeVisualID) { return true; } + if (IntervalFloatingLabelEditPart.VISUAL_ID == nodeVisualID) { + return true; + } break; case InstanceValueEditPart.VISUAL_ID: if (InstanceValueNameEditPart.VISUAL_ID == nodeVisualID) { return true; } + if (InstanceValueFloatingLabelEditPart.VISUAL_ID == nodeVisualID) { + return true; + } break; case CommentEditPart.VISUAL_ID: if (CommentBodyEditPart.VISUAL_ID == nodeVisualID) { @@ -3124,6 +3247,11 @@ public class UMLVisualIDRegistry { return true; } break; + case BehaviorPortEditPart.VISUAL_ID: + if (BehaviorPortFloatingLabelEditPart.VISUAL_ID == nodeVisualID) { + return true; + } + break; case PortEditPart.VISUAL_ID: if (PortNameEditPart.VISUAL_ID == nodeVisualID) { return true; @@ -3144,6 +3272,9 @@ public class UMLVisualIDRegistry { if (PropertyPartNameEditPartCN.VISUAL_ID == nodeVisualID) { return true; } + if (PropertyPartFloatingLabelEditPartCN.VISUAL_ID == nodeVisualID) { + return true; + } if (PropertyPartCompartmentEditPartCN.VISUAL_ID == nodeVisualID) { return true; } @@ -3155,16 +3286,25 @@ public class UMLVisualIDRegistry { if (CollaborationRoleNameEditPartCN.VISUAL_ID == nodeVisualID) { return true; } + if (CollaborationRoleFloatingLabelEditPartCN.VISUAL_ID == nodeVisualID) { + return true; + } break; case CollaborationUseEditPartCN.VISUAL_ID: if (CollaborationUseNameEditPart.VISUAL_ID == nodeVisualID) { return true; } + if (CollaborationUseFloatingLabelEditPartCN.VISUAL_ID == nodeVisualID) { + return true; + } break; case ActivityCompositeEditPartCN.VISUAL_ID: if (ActivityCompositeNameEditPartCN.VISUAL_ID == nodeVisualID) { return true; } + if (ActivityCompositeFloatingLabelEditPartCN.VISUAL_ID == nodeVisualID) { + return true; + } if (ActivityCompositeCompartmentEditPartCN.VISUAL_ID == nodeVisualID) { return true; } @@ -3179,6 +3319,9 @@ public class UMLVisualIDRegistry { if (InteractionCompositeNameEditPartCN.VISUAL_ID == nodeVisualID) { return true; } + if (InteractionCompositeFloatingLabelEditPartCN.VISUAL_ID == nodeVisualID) { + return true; + } if (InteractionCompositeCompartmentEditPartCN.VISUAL_ID == nodeVisualID) { return true; } @@ -3193,6 +3336,9 @@ public class UMLVisualIDRegistry { if (ProtocolStateMachineCompositeNameEditPartCN.VISUAL_ID == nodeVisualID) { return true; } + if (ProtocolStateMachineCompositeFloatingLabelEditPartCN.VISUAL_ID == nodeVisualID) { + return true; + } if (ProtocolStateMachineCompositeCompartmentEditPartCN.VISUAL_ID == nodeVisualID) { return true; } @@ -3207,6 +3353,9 @@ public class UMLVisualIDRegistry { if (StateMachineCompositeNameEditPartCN.VISUAL_ID == nodeVisualID) { return true; } + if (StateMachineCompositeFloatingLabelEditPartCN.VISUAL_ID == nodeVisualID) { + return true; + } if (StateMachineCompositeCompartmentEditPartCN.VISUAL_ID == nodeVisualID) { return true; } @@ -3221,6 +3370,9 @@ public class UMLVisualIDRegistry { if (FunctionBehaviorCompositeNameEditPartCN.VISUAL_ID == nodeVisualID) { return true; } + if (FunctionBehaviorCompositeFloatingLabelEditPartCN.VISUAL_ID == nodeVisualID) { + return true; + } if (FunctionBehaviorCompositeCompartmentEditPartCN.VISUAL_ID == nodeVisualID) { return true; } @@ -3235,6 +3387,9 @@ public class UMLVisualIDRegistry { if (OpaqueBehaviorCompositeNameEditPartCN.VISUAL_ID == nodeVisualID) { return true; } + if (OpaqueBehaviorCompositeFloatingLabelEditPartCN.VISUAL_ID == nodeVisualID) { + return true; + } if (OpaqueBehaviorCompositeCompartmentEditPartCN.VISUAL_ID == nodeVisualID) { return true; } @@ -3249,6 +3404,9 @@ public class UMLVisualIDRegistry { if (ComponentCompositeNameEditPartCN.VISUAL_ID == nodeVisualID) { return true; } + if (ComponentCompositeFloatingLabelEditPartCN.VISUAL_ID == nodeVisualID) { + return true; + } if (ComponentCompositeCompartmentEditPartCN.VISUAL_ID == nodeVisualID) { return true; } @@ -3260,6 +3418,9 @@ public class UMLVisualIDRegistry { if (DeviceCompositeNameEditPartCN.VISUAL_ID == nodeVisualID) { return true; } + if (DeviceCompositeFloatingLabelEditPartCN.VISUAL_ID == nodeVisualID) { + return true; + } if (DeviceCompositeCompartmentEditPartCN.VISUAL_ID == nodeVisualID) { return true; } @@ -3271,6 +3432,9 @@ public class UMLVisualIDRegistry { if (ExecutionEnvironmentCompositeNameEditPartCN.VISUAL_ID == nodeVisualID) { return true; } + if (ExecutionEnvironmentCompositeFloatingLabelEditPartCN.VISUAL_ID == nodeVisualID) { + return true; + } if (ExecutionEnvironmentCompositeCompartmentEditPartCN.VISUAL_ID == nodeVisualID) { return true; } @@ -3282,6 +3446,9 @@ public class UMLVisualIDRegistry { if (NodeCompositeNameEditPartCN.VISUAL_ID == nodeVisualID) { return true; } + if (NodeCompositeFloatingLabelEditPartCN.VISUAL_ID == nodeVisualID) { + return true; + } if (NodeCompositeCompartmentEditPartCN.VISUAL_ID == nodeVisualID) { return true; } @@ -3293,6 +3460,9 @@ public class UMLVisualIDRegistry { if (ClassCompositeNameEditPartCN.VISUAL_ID == nodeVisualID) { return true; } + if (ClassCompositeFloatingLabelEditPartCN.VISUAL_ID == nodeVisualID) { + return true; + } if (ClassCompositeCompartmentEditPartCN.VISUAL_ID == nodeVisualID) { return true; } @@ -3304,6 +3474,9 @@ public class UMLVisualIDRegistry { if (CollaborationCompositeNameEditPartCN.VISUAL_ID == nodeVisualID) { return true; } + if (CollaborationCompositeFloatingLabelEditPartCN.VISUAL_ID == nodeVisualID) { + return true; + } if (CollaborationCompositeCompartmentEditPartCN.VISUAL_ID == nodeVisualID) { return true; } @@ -3312,16 +3485,25 @@ public class UMLVisualIDRegistry { if (InterfaceNameEditPartCN.VISUAL_ID == nodeVisualID) { return true; } + if (InterfaceFloatingLabelEditPartCN.VISUAL_ID == nodeVisualID) { + return true; + } break; case PrimitiveTypeEditPartCN.VISUAL_ID: if (PrimitiveTypeNameEditPartCN.VISUAL_ID == nodeVisualID) { return true; } + if (PrimitiveTypeFloatingLabelEditPartCN.VISUAL_ID == nodeVisualID) { + return true; + } break; case EnumerationEditPartCN.VISUAL_ID: if (EnumerationNameEditPartCN.VISUAL_ID == nodeVisualID) { return true; } + if (EnumerationFloatingLabelEditPartCN.VISUAL_ID == nodeVisualID) { + return true; + } if (EnumerationEnumerationLiteralCompartmentEditPartCN.VISUAL_ID == nodeVisualID) { return true; } @@ -3333,6 +3515,9 @@ public class UMLVisualIDRegistry { if (DataTypeNameEditPartCN.VISUAL_ID == nodeVisualID) { return true; } + if (DataTypeFloatingLabelEditPartCN.VISUAL_ID == nodeVisualID) { + return true; + } if (DataTypeAttributeCompartmentEditPartCN.VISUAL_ID == nodeVisualID) { return true; } @@ -3344,31 +3529,49 @@ public class UMLVisualIDRegistry { if (ActorNameEditPartCN.VISUAL_ID == nodeVisualID) { return true; } + if (ActorFloatingLabelEditPartCN.VISUAL_ID == nodeVisualID) { + return true; + } break; case DeploymentSpecificationEditPartCN.VISUAL_ID: if (DeploymentSpecificationNameEditPartCN.VISUAL_ID == nodeVisualID) { return true; } + if (DeploymentSpecificationFloatingLabelEditPartCN.VISUAL_ID == nodeVisualID) { + return true; + } break; case ArtifactEditPartCN.VISUAL_ID: if (ArtifactNameEditPartCN.VISUAL_ID == nodeVisualID) { return true; } + if (ArtifactFloatingLabelEditPartCN.VISUAL_ID == nodeVisualID) { + return true; + } break; case InformationItemEditPartCN.VISUAL_ID: if (InformationItemNameEditPartCN.VISUAL_ID == nodeVisualID) { return true; } + if (InformationItemFloatingLabelEditPartCN.VISUAL_ID == nodeVisualID) { + return true; + } break; case SignalEditPartCN.VISUAL_ID: if (SignalNameEditPartCN.VISUAL_ID == nodeVisualID) { return true; } + if (SignalFloatingLabelEditPartCN.VISUAL_ID == nodeVisualID) { + return true; + } break; case UseCaseEditPartCN.VISUAL_ID: if (UseCaseNameEditPartCN.VISUAL_ID == nodeVisualID) { return true; } + if (UseCaseFloatingLabelEditPartCN.VISUAL_ID == nodeVisualID) { + return true; + } break; case CommentEditPartCN.VISUAL_ID: if (CommentBodyEditPartCN.VISUAL_ID == nodeVisualID) { @@ -5803,7 +6006,7 @@ public class UMLVisualIDRegistry { */ public static boolean checkNodeVisualID(View containerView, EObject domainElement, int candidate) { if (candidate == -1) { - //unrecognized id is always bad + // unrecognized id is always bad return false; } int basic = getNodeVisualID(containerView, domainElement); diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/providers/UMLParserProvider.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/providers/UMLParserProvider.java index 218fbb4940d..c23e590fff8 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/providers/UMLParserProvider.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/providers/UMLParserProvider.java @@ -59,6 +59,25 @@ public class UMLParserProvider extends AbstractProvider implements IParserProvid return activityName_5112Parser; } + /** + * @generated + */ + private IParser activityName_6079Parser; + + /** + * @generated + */ + private IParser getActivityName_6079Parser() { + if (activityName_6079Parser == null) { + EAttribute[] features = new EAttribute[] { + UMLPackage.eINSTANCE.getNamedElement_Name() + }; + MessageFormatParser parser = new MessageFormatParser(features); + activityName_6079Parser = parser; + } + return activityName_6079Parser; + } + /** * @generated */ @@ -81,6 +100,25 @@ public class UMLParserProvider extends AbstractProvider implements IParserProvid return interactionName_5113Parser; } + /** + * @generated + */ + private IParser interactionName_6080Parser; + + /** + * @generated + */ + private IParser getInteractionName_6080Parser() { + if (interactionName_6080Parser == null) { + EAttribute[] features = new EAttribute[] { + UMLPackage.eINSTANCE.getNamedElement_Name() + }; + MessageFormatParser parser = new MessageFormatParser(features); + interactionName_6080Parser = parser; + } + return interactionName_6080Parser; + } + /** * @generated */ @@ -106,35 +144,32 @@ public class UMLParserProvider extends AbstractProvider implements IParserProvid /** * @generated */ - private IParser stateMachineName_5115Parser; + private IParser protocolStateMachineName_6081Parser; /** * @generated */ - private IParser getStateMachineName_5115Parser() { - if (stateMachineName_5115Parser == null) { + private IParser getProtocolStateMachineName_6081Parser() { + if (protocolStateMachineName_6081Parser == null) { EAttribute[] features = new EAttribute[] { UMLPackage.eINSTANCE.getNamedElement_Name() }; MessageFormatParser parser = new MessageFormatParser(features); - parser.setViewPattern("{0} "); //$NON-NLS-1$ - parser.setEditorPattern("{0}"); //$NON-NLS-1$ - parser.setEditPattern("{0}"); //$NON-NLS-1$ - stateMachineName_5115Parser = parser; + protocolStateMachineName_6081Parser = parser; } - return stateMachineName_5115Parser; + return protocolStateMachineName_6081Parser; } /** * @generated */ - private IParser functionBehaviorName_5116Parser; + private IParser stateMachineName_5115Parser; /** * @generated */ - private IParser getFunctionBehaviorName_5116Parser() { - if (functionBehaviorName_5116Parser == null) { + private IParser getStateMachineName_5115Parser() { + if (stateMachineName_5115Parser == null) { EAttribute[] features = new EAttribute[] { UMLPackage.eINSTANCE.getNamedElement_Name() }; @@ -142,43 +177,40 @@ public class UMLParserProvider extends AbstractProvider implements IParserProvid parser.setViewPattern("{0} "); //$NON-NLS-1$ parser.setEditorPattern("{0}"); //$NON-NLS-1$ parser.setEditPattern("{0}"); //$NON-NLS-1$ - functionBehaviorName_5116Parser = parser; + stateMachineName_5115Parser = parser; } - return functionBehaviorName_5116Parser; + return stateMachineName_5115Parser; } /** * @generated */ - private IParser opaqueBehaviorName_5117Parser; + private IParser stateMachineName_6082Parser; /** * @generated */ - private IParser getOpaqueBehaviorName_5117Parser() { - if (opaqueBehaviorName_5117Parser == null) { + private IParser getStateMachineName_6082Parser() { + if (stateMachineName_6082Parser == null) { EAttribute[] features = new EAttribute[] { UMLPackage.eINSTANCE.getNamedElement_Name() }; MessageFormatParser parser = new MessageFormatParser(features); - parser.setViewPattern("{0} "); //$NON-NLS-1$ - parser.setEditorPattern("{0}"); //$NON-NLS-1$ - parser.setEditPattern("{0}"); //$NON-NLS-1$ - opaqueBehaviorName_5117Parser = parser; + stateMachineName_6082Parser = parser; } - return opaqueBehaviorName_5117Parser; + return stateMachineName_6082Parser; } /** * @generated */ - private IParser componentName_5121Parser; + private IParser functionBehaviorName_5116Parser; /** * @generated */ - private IParser getComponentName_5121Parser() { - if (componentName_5121Parser == null) { + private IParser getFunctionBehaviorName_5116Parser() { + if (functionBehaviorName_5116Parser == null) { EAttribute[] features = new EAttribute[] { UMLPackage.eINSTANCE.getNamedElement_Name() }; @@ -186,43 +218,40 @@ public class UMLParserProvider extends AbstractProvider implements IParserProvid parser.setViewPattern("{0} "); //$NON-NLS-1$ parser.setEditorPattern("{0}"); //$NON-NLS-1$ parser.setEditPattern("{0}"); //$NON-NLS-1$ - componentName_5121Parser = parser; + functionBehaviorName_5116Parser = parser; } - return componentName_5121Parser; + return functionBehaviorName_5116Parser; } /** * @generated */ - private IParser deviceName_5122Parser; + private IParser functionBehaviorName_6083Parser; /** * @generated */ - private IParser getDeviceName_5122Parser() { - if (deviceName_5122Parser == null) { + private IParser getFunctionBehaviorName_6083Parser() { + if (functionBehaviorName_6083Parser == null) { EAttribute[] features = new EAttribute[] { UMLPackage.eINSTANCE.getNamedElement_Name() }; MessageFormatParser parser = new MessageFormatParser(features); - parser.setViewPattern("{0} "); //$NON-NLS-1$ - parser.setEditorPattern("{0}"); //$NON-NLS-1$ - parser.setEditPattern("{0}"); //$NON-NLS-1$ - deviceName_5122Parser = parser; + functionBehaviorName_6083Parser = parser; } - return deviceName_5122Parser; + return functionBehaviorName_6083Parser; } /** * @generated */ - private IParser executionEnvironmentName_5123Parser; + private IParser opaqueBehaviorName_5117Parser; /** * @generated */ - private IParser getExecutionEnvironmentName_5123Parser() { - if (executionEnvironmentName_5123Parser == null) { + private IParser getOpaqueBehaviorName_5117Parser() { + if (opaqueBehaviorName_5117Parser == null) { EAttribute[] features = new EAttribute[] { UMLPackage.eINSTANCE.getNamedElement_Name() }; @@ -230,43 +259,40 @@ public class UMLParserProvider extends AbstractProvider implements IParserProvid parser.setViewPattern("{0} "); //$NON-NLS-1$ parser.setEditorPattern("{0}"); //$NON-NLS-1$ parser.setEditPattern("{0}"); //$NON-NLS-1$ - executionEnvironmentName_5123Parser = parser; + opaqueBehaviorName_5117Parser = parser; } - return executionEnvironmentName_5123Parser; + return opaqueBehaviorName_5117Parser; } /** * @generated */ - private IParser nodeName_5124Parser; + private IParser opaqueBehaviorName_6084Parser; /** * @generated */ - private IParser getNodeName_5124Parser() { - if (nodeName_5124Parser == null) { + private IParser getOpaqueBehaviorName_6084Parser() { + if (opaqueBehaviorName_6084Parser == null) { EAttribute[] features = new EAttribute[] { UMLPackage.eINSTANCE.getNamedElement_Name() }; MessageFormatParser parser = new MessageFormatParser(features); - parser.setViewPattern("{0} "); //$NON-NLS-1$ - parser.setEditorPattern("{0}"); //$NON-NLS-1$ - parser.setEditPattern("{0}"); //$NON-NLS-1$ - nodeName_5124Parser = parser; + opaqueBehaviorName_6084Parser = parser; } - return nodeName_5124Parser; + return opaqueBehaviorName_6084Parser; } /** * @generated */ - private IParser className_5156Parser; + private IParser componentName_5121Parser; /** * @generated */ - private IParser getClassName_5156Parser() { - if (className_5156Parser == null) { + private IParser getComponentName_5121Parser() { + if (componentName_5121Parser == null) { EAttribute[] features = new EAttribute[] { UMLPackage.eINSTANCE.getNamedElement_Name() }; @@ -274,43 +300,40 @@ public class UMLParserProvider extends AbstractProvider implements IParserProvid parser.setViewPattern("{0} "); //$NON-NLS-1$ parser.setEditorPattern("{0}"); //$NON-NLS-1$ parser.setEditPattern("{0}"); //$NON-NLS-1$ - className_5156Parser = parser; + componentName_5121Parser = parser; } - return className_5156Parser; + return componentName_5121Parser; } /** * @generated */ - private IParser collaborationName_5158Parser; + private IParser componentName_6085Parser; /** * @generated */ - private IParser getCollaborationName_5158Parser() { - if (collaborationName_5158Parser == null) { + private IParser getComponentName_6085Parser() { + if (componentName_6085Parser == null) { EAttribute[] features = new EAttribute[] { UMLPackage.eINSTANCE.getNamedElement_Name() }; MessageFormatParser parser = new MessageFormatParser(features); - parser.setViewPattern("{0} "); //$NON-NLS-1$ - parser.setEditorPattern("{0}"); //$NON-NLS-1$ - parser.setEditPattern("{0}"); //$NON-NLS-1$ - collaborationName_5158Parser = parser; + componentName_6085Parser = parser; } - return collaborationName_5158Parser; + return componentName_6085Parser; } /** * @generated */ - private IParser interfaceName_5159Parser; + private IParser deviceName_5122Parser; /** * @generated */ - private IParser getInterfaceName_5159Parser() { - if (interfaceName_5159Parser == null) { + private IParser getDeviceName_5122Parser() { + if (deviceName_5122Parser == null) { EAttribute[] features = new EAttribute[] { UMLPackage.eINSTANCE.getNamedElement_Name() }; @@ -318,43 +341,40 @@ public class UMLParserProvider extends AbstractProvider implements IParserProvid parser.setViewPattern("{0} "); //$NON-NLS-1$ parser.setEditorPattern("{0}"); //$NON-NLS-1$ parser.setEditPattern("{0}"); //$NON-NLS-1$ - interfaceName_5159Parser = parser; + deviceName_5122Parser = parser; } - return interfaceName_5159Parser; + return deviceName_5122Parser; } /** * @generated */ - private IParser primitiveTypeName_5118Parser; + private IParser deviceName_6086Parser; /** * @generated */ - private IParser getPrimitiveTypeName_5118Parser() { - if (primitiveTypeName_5118Parser == null) { + private IParser getDeviceName_6086Parser() { + if (deviceName_6086Parser == null) { EAttribute[] features = new EAttribute[] { UMLPackage.eINSTANCE.getNamedElement_Name() }; MessageFormatParser parser = new MessageFormatParser(features); - parser.setViewPattern("{0} "); //$NON-NLS-1$ - parser.setEditorPattern("{0}"); //$NON-NLS-1$ - parser.setEditPattern("{0}"); //$NON-NLS-1$ - primitiveTypeName_5118Parser = parser; + deviceName_6086Parser = parser; } - return primitiveTypeName_5118Parser; + return deviceName_6086Parser; } /** * @generated */ - private IParser enumerationName_5119Parser; + private IParser executionEnvironmentName_5123Parser; /** * @generated */ - private IParser getEnumerationName_5119Parser() { - if (enumerationName_5119Parser == null) { + private IParser getExecutionEnvironmentName_5123Parser() { + if (executionEnvironmentName_5123Parser == null) { EAttribute[] features = new EAttribute[] { UMLPackage.eINSTANCE.getNamedElement_Name() }; @@ -362,43 +382,40 @@ public class UMLParserProvider extends AbstractProvider implements IParserProvid parser.setViewPattern("{0} "); //$NON-NLS-1$ parser.setEditorPattern("{0}"); //$NON-NLS-1$ parser.setEditPattern("{0}"); //$NON-NLS-1$ - enumerationName_5119Parser = parser; + executionEnvironmentName_5123Parser = parser; } - return enumerationName_5119Parser; + return executionEnvironmentName_5123Parser; } /** * @generated */ - private IParser dataTypeName_5120Parser; + private IParser executionEnvironmentName_6087Parser; /** * @generated */ - private IParser getDataTypeName_5120Parser() { - if (dataTypeName_5120Parser == null) { + private IParser getExecutionEnvironmentName_6087Parser() { + if (executionEnvironmentName_6087Parser == null) { EAttribute[] features = new EAttribute[] { UMLPackage.eINSTANCE.getNamedElement_Name() }; MessageFormatParser parser = new MessageFormatParser(features); - parser.setViewPattern("{0} "); //$NON-NLS-1$ - parser.setEditorPattern("{0}"); //$NON-NLS-1$ - parser.setEditPattern("{0}"); //$NON-NLS-1$ - dataTypeName_5120Parser = parser; + executionEnvironmentName_6087Parser = parser; } - return dataTypeName_5120Parser; + return executionEnvironmentName_6087Parser; } /** * @generated */ - private IParser actorName_5160Parser; + private IParser nodeName_5124Parser; /** * @generated */ - private IParser getActorName_5160Parser() { - if (actorName_5160Parser == null) { + private IParser getNodeName_5124Parser() { + if (nodeName_5124Parser == null) { EAttribute[] features = new EAttribute[] { UMLPackage.eINSTANCE.getNamedElement_Name() }; @@ -406,43 +423,40 @@ public class UMLParserProvider extends AbstractProvider implements IParserProvid parser.setViewPattern("{0} "); //$NON-NLS-1$ parser.setEditorPattern("{0}"); //$NON-NLS-1$ parser.setEditPattern("{0}"); //$NON-NLS-1$ - actorName_5160Parser = parser; + nodeName_5124Parser = parser; } - return actorName_5160Parser; + return nodeName_5124Parser; } /** * @generated */ - private IParser deploymentSpecificationName_5161Parser; + private IParser nodeName_6088Parser; /** * @generated */ - private IParser getDeploymentSpecificationName_5161Parser() { - if (deploymentSpecificationName_5161Parser == null) { + private IParser getNodeName_6088Parser() { + if (nodeName_6088Parser == null) { EAttribute[] features = new EAttribute[] { UMLPackage.eINSTANCE.getNamedElement_Name() }; MessageFormatParser parser = new MessageFormatParser(features); - parser.setViewPattern("{0} "); //$NON-NLS-1$ - parser.setEditorPattern("{0}"); //$NON-NLS-1$ - parser.setEditPattern("{0}"); //$NON-NLS-1$ - deploymentSpecificationName_5161Parser = parser; + nodeName_6088Parser = parser; } - return deploymentSpecificationName_5161Parser; + return nodeName_6088Parser; } /** * @generated */ - private IParser artifactName_5162Parser; + private IParser className_5156Parser; /** * @generated */ - private IParser getArtifactName_5162Parser() { - if (artifactName_5162Parser == null) { + private IParser getClassName_5156Parser() { + if (className_5156Parser == null) { EAttribute[] features = new EAttribute[] { UMLPackage.eINSTANCE.getNamedElement_Name() }; @@ -450,43 +464,40 @@ public class UMLParserProvider extends AbstractProvider implements IParserProvid parser.setViewPattern("{0} "); //$NON-NLS-1$ parser.setEditorPattern("{0}"); //$NON-NLS-1$ parser.setEditPattern("{0}"); //$NON-NLS-1$ - artifactName_5162Parser = parser; + className_5156Parser = parser; } - return artifactName_5162Parser; + return className_5156Parser; } /** * @generated */ - private IParser informationItemName_5163Parser; + private IParser className_6089Parser; /** * @generated */ - private IParser getInformationItemName_5163Parser() { - if (informationItemName_5163Parser == null) { + private IParser getClassName_6089Parser() { + if (className_6089Parser == null) { EAttribute[] features = new EAttribute[] { UMLPackage.eINSTANCE.getNamedElement_Name() }; MessageFormatParser parser = new MessageFormatParser(features); - parser.setViewPattern("{0} "); //$NON-NLS-1$ - parser.setEditorPattern("{0}"); //$NON-NLS-1$ - parser.setEditPattern("{0}"); //$NON-NLS-1$ - informationItemName_5163Parser = parser; + className_6089Parser = parser; } - return informationItemName_5163Parser; + return className_6089Parser; } /** * @generated */ - private IParser signalName_5164Parser; + private IParser collaborationName_5158Parser; /** * @generated */ - private IParser getSignalName_5164Parser() { - if (signalName_5164Parser == null) { + private IParser getCollaborationName_5158Parser() { + if (collaborationName_5158Parser == null) { EAttribute[] features = new EAttribute[] { UMLPackage.eINSTANCE.getNamedElement_Name() }; @@ -494,43 +505,40 @@ public class UMLParserProvider extends AbstractProvider implements IParserProvid parser.setViewPattern("{0} "); //$NON-NLS-1$ parser.setEditorPattern("{0}"); //$NON-NLS-1$ parser.setEditPattern("{0}"); //$NON-NLS-1$ - signalName_5164Parser = parser; + collaborationName_5158Parser = parser; } - return signalName_5164Parser; + return collaborationName_5158Parser; } /** * @generated */ - private IParser useCaseName_5165Parser; + private IParser collaborationName_6090Parser; /** * @generated */ - private IParser getUseCaseName_5165Parser() { - if (useCaseName_5165Parser == null) { + private IParser getCollaborationName_6090Parser() { + if (collaborationName_6090Parser == null) { EAttribute[] features = new EAttribute[] { UMLPackage.eINSTANCE.getNamedElement_Name() }; MessageFormatParser parser = new MessageFormatParser(features); - parser.setViewPattern("{0} "); //$NON-NLS-1$ - parser.setEditorPattern("{0}"); //$NON-NLS-1$ - parser.setEditPattern("{0}"); //$NON-NLS-1$ - useCaseName_5165Parser = parser; + collaborationName_6090Parser = parser; } - return useCaseName_5165Parser; + return collaborationName_6090Parser; } /** * @generated */ - private IParser signalEventName_5166Parser; + private IParser interfaceName_5159Parser; /** * @generated */ - private IParser getSignalEventName_5166Parser() { - if (signalEventName_5166Parser == null) { + private IParser getInterfaceName_5159Parser() { + if (interfaceName_5159Parser == null) { EAttribute[] features = new EAttribute[] { UMLPackage.eINSTANCE.getNamedElement_Name() }; @@ -538,43 +546,40 @@ public class UMLParserProvider extends AbstractProvider implements IParserProvid parser.setViewPattern("{0} "); //$NON-NLS-1$ parser.setEditorPattern("{0}"); //$NON-NLS-1$ parser.setEditPattern("{0}"); //$NON-NLS-1$ - signalEventName_5166Parser = parser; + interfaceName_5159Parser = parser; } - return signalEventName_5166Parser; + return interfaceName_5159Parser; } /** * @generated */ - private IParser callEventName_5167Parser; + private IParser interfaceName_6091Parser; /** * @generated */ - private IParser getCallEventName_5167Parser() { - if (callEventName_5167Parser == null) { + private IParser getInterfaceName_6091Parser() { + if (interfaceName_6091Parser == null) { EAttribute[] features = new EAttribute[] { UMLPackage.eINSTANCE.getNamedElement_Name() }; MessageFormatParser parser = new MessageFormatParser(features); - parser.setViewPattern("{0} "); //$NON-NLS-1$ - parser.setEditorPattern("{0}"); //$NON-NLS-1$ - parser.setEditPattern("{0}"); //$NON-NLS-1$ - callEventName_5167Parser = parser; + interfaceName_6091Parser = parser; } - return callEventName_5167Parser; + return interfaceName_6091Parser; } /** * @generated */ - private IParser anyReceiveEventName_5168Parser; + private IParser primitiveTypeName_5118Parser; /** * @generated */ - private IParser getAnyReceiveEventName_5168Parser() { - if (anyReceiveEventName_5168Parser == null) { + private IParser getPrimitiveTypeName_5118Parser() { + if (primitiveTypeName_5118Parser == null) { EAttribute[] features = new EAttribute[] { UMLPackage.eINSTANCE.getNamedElement_Name() }; @@ -582,43 +587,40 @@ public class UMLParserProvider extends AbstractProvider implements IParserProvid parser.setViewPattern("{0} "); //$NON-NLS-1$ parser.setEditorPattern("{0}"); //$NON-NLS-1$ parser.setEditPattern("{0}"); //$NON-NLS-1$ - anyReceiveEventName_5168Parser = parser; + primitiveTypeName_5118Parser = parser; } - return anyReceiveEventName_5168Parser; + return primitiveTypeName_5118Parser; } /** * @generated */ - private IParser changeEventName_5171Parser; + private IParser primitiveTypeName_6092Parser; /** * @generated */ - private IParser getChangeEventName_5171Parser() { - if (changeEventName_5171Parser == null) { + private IParser getPrimitiveTypeName_6092Parser() { + if (primitiveTypeName_6092Parser == null) { EAttribute[] features = new EAttribute[] { UMLPackage.eINSTANCE.getNamedElement_Name() }; MessageFormatParser parser = new MessageFormatParser(features); - parser.setViewPattern("{0} "); //$NON-NLS-1$ - parser.setEditorPattern("{0}"); //$NON-NLS-1$ - parser.setEditPattern("{0}"); //$NON-NLS-1$ - changeEventName_5171Parser = parser; + primitiveTypeName_6092Parser = parser; } - return changeEventName_5171Parser; + return primitiveTypeName_6092Parser; } /** * @generated */ - private IParser timeEventName_5172Parser; + private IParser enumerationName_5119Parser; /** * @generated */ - private IParser getTimeEventName_5172Parser() { - if (timeEventName_5172Parser == null) { + private IParser getEnumerationName_5119Parser() { + if (enumerationName_5119Parser == null) { EAttribute[] features = new EAttribute[] { UMLPackage.eINSTANCE.getNamedElement_Name() }; @@ -626,111 +628,122 @@ public class UMLParserProvider extends AbstractProvider implements IParserProvid parser.setViewPattern("{0} "); //$NON-NLS-1$ parser.setEditorPattern("{0}"); //$NON-NLS-1$ parser.setEditPattern("{0}"); //$NON-NLS-1$ - timeEventName_5172Parser = parser; + enumerationName_5119Parser = parser; } - return timeEventName_5172Parser; + return enumerationName_5119Parser; } /** * @generated */ - private IParser durationObservationName_5151Parser; + private IParser enumerationName_6093Parser; /** * @generated */ - private IParser getDurationObservationName_5151Parser() { - if (durationObservationName_5151Parser == null) { + private IParser getEnumerationName_6093Parser() { + if (enumerationName_6093Parser == null) { EAttribute[] features = new EAttribute[] { UMLPackage.eINSTANCE.getNamedElement_Name() }; MessageFormatParser parser = new MessageFormatParser(features); - durationObservationName_5151Parser = parser; + enumerationName_6093Parser = parser; } - return durationObservationName_5151Parser; + return enumerationName_6093Parser; } /** * @generated */ - private AppliedStereotypeParser durationObservationName_5152Parser; + private IParser dataTypeName_5120Parser; /** * @generated */ - private IParser getDurationObservationName_5152Parser() { - if (durationObservationName_5152Parser == null) { - durationObservationName_5152Parser = new AppliedStereotypeParser(); - } - return durationObservationName_5152Parser; + private IParser getDataTypeName_5120Parser() { + if (dataTypeName_5120Parser == null) { + EAttribute[] features = new EAttribute[] { + UMLPackage.eINSTANCE.getNamedElement_Name() + }; + MessageFormatParser parser = new MessageFormatParser(features); + parser.setViewPattern("{0} "); //$NON-NLS-1$ + parser.setEditorPattern("{0}"); //$NON-NLS-1$ + parser.setEditPattern("{0}"); //$NON-NLS-1$ + dataTypeName_5120Parser = parser; + } + return dataTypeName_5120Parser; } /** * @generated */ - private IParser timeObservationName_5142Parser; + private IParser dataTypeName_6094Parser; /** * @generated */ - private IParser getTimeObservationName_5142Parser() { - if (timeObservationName_5142Parser == null) { + private IParser getDataTypeName_6094Parser() { + if (dataTypeName_6094Parser == null) { EAttribute[] features = new EAttribute[] { UMLPackage.eINSTANCE.getNamedElement_Name() }; MessageFormatParser parser = new MessageFormatParser(features); - timeObservationName_5142Parser = parser; + dataTypeName_6094Parser = parser; } - return timeObservationName_5142Parser; + return dataTypeName_6094Parser; } /** * @generated */ - private AppliedStereotypeParser timeObservationName_5143Parser; + private IParser actorName_5160Parser; /** * @generated */ - private IParser getTimeObservationName_5143Parser() { - if (timeObservationName_5143Parser == null) { - timeObservationName_5143Parser = new AppliedStereotypeParser(); + private IParser getActorName_5160Parser() { + if (actorName_5160Parser == null) { + EAttribute[] features = new EAttribute[] { + UMLPackage.eINSTANCE.getNamedElement_Name() + }; + MessageFormatParser parser = new MessageFormatParser(features); + parser.setViewPattern("{0} "); //$NON-NLS-1$ + parser.setEditorPattern("{0}"); //$NON-NLS-1$ + parser.setEditPattern("{0}"); //$NON-NLS-1$ + actorName_5160Parser = parser; } - return timeObservationName_5143Parser; + return actorName_5160Parser; } /** * @generated */ - private IParser literalBooleanName_5178Parser; + private IParser actorName_6095Parser; /** * @generated */ - private IParser getLiteralBooleanName_5178Parser() { - if (literalBooleanName_5178Parser == null) { + private IParser getActorName_6095Parser() { + if (actorName_6095Parser == null) { EAttribute[] features = new EAttribute[] { UMLPackage.eINSTANCE.getNamedElement_Name() }; MessageFormatParser parser = new MessageFormatParser(features); - parser.setViewPattern("{0} "); //$NON-NLS-1$ - parser.setEditorPattern("{0}"); //$NON-NLS-1$ - parser.setEditPattern("{0}"); //$NON-NLS-1$ - literalBooleanName_5178Parser = parser; + actorName_6095Parser = parser; } - return literalBooleanName_5178Parser; + return actorName_6095Parser; } /** * @generated */ - private IParser literalIntegerName_5179Parser; + private IParser deploymentSpecificationName_5161Parser; /** * @generated */ - private IParser getLiteralIntegerName_5179Parser() { - if (literalIntegerName_5179Parser == null) { + private IParser getDeploymentSpecificationName_5161Parser() { + if (deploymentSpecificationName_5161Parser == null) { EAttribute[] features = new EAttribute[] { UMLPackage.eINSTANCE.getNamedElement_Name() }; @@ -738,43 +751,40 @@ public class UMLParserProvider extends AbstractProvider implements IParserProvid parser.setViewPattern("{0} "); //$NON-NLS-1$ parser.setEditorPattern("{0}"); //$NON-NLS-1$ parser.setEditPattern("{0}"); //$NON-NLS-1$ - literalIntegerName_5179Parser = parser; + deploymentSpecificationName_5161Parser = parser; } - return literalIntegerName_5179Parser; + return deploymentSpecificationName_5161Parser; } /** * @generated */ - private IParser literalNullName_5180Parser; + private IParser deploymentSpecificationName_6096Parser; /** * @generated */ - private IParser getLiteralNullName_5180Parser() { - if (literalNullName_5180Parser == null) { + private IParser getDeploymentSpecificationName_6096Parser() { + if (deploymentSpecificationName_6096Parser == null) { EAttribute[] features = new EAttribute[] { UMLPackage.eINSTANCE.getNamedElement_Name() }; MessageFormatParser parser = new MessageFormatParser(features); - parser.setViewPattern("{0} "); //$NON-NLS-1$ - parser.setEditorPattern("{0}"); //$NON-NLS-1$ - parser.setEditPattern("{0}"); //$NON-NLS-1$ - literalNullName_5180Parser = parser; + deploymentSpecificationName_6096Parser = parser; } - return literalNullName_5180Parser; + return deploymentSpecificationName_6096Parser; } /** * @generated */ - private IParser literalStringName_5181Parser; + private IParser artifactName_5162Parser; /** * @generated */ - private IParser getLiteralStringName_5181Parser() { - if (literalStringName_5181Parser == null) { + private IParser getArtifactName_5162Parser() { + if (artifactName_5162Parser == null) { EAttribute[] features = new EAttribute[] { UMLPackage.eINSTANCE.getNamedElement_Name() }; @@ -782,43 +792,40 @@ public class UMLParserProvider extends AbstractProvider implements IParserProvid parser.setViewPattern("{0} "); //$NON-NLS-1$ parser.setEditorPattern("{0}"); //$NON-NLS-1$ parser.setEditPattern("{0}"); //$NON-NLS-1$ - literalStringName_5181Parser = parser; + artifactName_5162Parser = parser; } - return literalStringName_5181Parser; + return artifactName_5162Parser; } /** * @generated */ - private IParser literalUnlimitedNaturalName_5182Parser; + private IParser artifactName_6097Parser; /** * @generated */ - private IParser getLiteralUnlimitedNaturalName_5182Parser() { - if (literalUnlimitedNaturalName_5182Parser == null) { + private IParser getArtifactName_6097Parser() { + if (artifactName_6097Parser == null) { EAttribute[] features = new EAttribute[] { UMLPackage.eINSTANCE.getNamedElement_Name() }; MessageFormatParser parser = new MessageFormatParser(features); - parser.setViewPattern("{0} "); //$NON-NLS-1$ - parser.setEditorPattern("{0}"); //$NON-NLS-1$ - parser.setEditPattern("{0}"); //$NON-NLS-1$ - literalUnlimitedNaturalName_5182Parser = parser; + artifactName_6097Parser = parser; } - return literalUnlimitedNaturalName_5182Parser; + return artifactName_6097Parser; } /** * @generated */ - private IParser stringExpressionName_5183Parser; + private IParser informationItemName_5163Parser; /** * @generated */ - private IParser getStringExpressionName_5183Parser() { - if (stringExpressionName_5183Parser == null) { + private IParser getInformationItemName_5163Parser() { + if (informationItemName_5163Parser == null) { EAttribute[] features = new EAttribute[] { UMLPackage.eINSTANCE.getNamedElement_Name() }; @@ -826,43 +833,40 @@ public class UMLParserProvider extends AbstractProvider implements IParserProvid parser.setViewPattern("{0} "); //$NON-NLS-1$ parser.setEditorPattern("{0}"); //$NON-NLS-1$ parser.setEditPattern("{0}"); //$NON-NLS-1$ - stringExpressionName_5183Parser = parser; + informationItemName_5163Parser = parser; } - return stringExpressionName_5183Parser; + return informationItemName_5163Parser; } /** * @generated */ - private IParser opaqueExpressionName_5184Parser; + private IParser informationItemName_6098Parser; /** * @generated */ - private IParser getOpaqueExpressionName_5184Parser() { - if (opaqueExpressionName_5184Parser == null) { + private IParser getInformationItemName_6098Parser() { + if (informationItemName_6098Parser == null) { EAttribute[] features = new EAttribute[] { UMLPackage.eINSTANCE.getNamedElement_Name() }; MessageFormatParser parser = new MessageFormatParser(features); - parser.setViewPattern("{0} "); //$NON-NLS-1$ - parser.setEditorPattern("{0}"); //$NON-NLS-1$ - parser.setEditPattern("{0}"); //$NON-NLS-1$ - opaqueExpressionName_5184Parser = parser; + informationItemName_6098Parser = parser; } - return opaqueExpressionName_5184Parser; + return informationItemName_6098Parser; } /** * @generated */ - private IParser timeExpressionName_5185Parser; + private IParser signalName_5164Parser; /** * @generated */ - private IParser getTimeExpressionName_5185Parser() { - if (timeExpressionName_5185Parser == null) { + private IParser getSignalName_5164Parser() { + if (signalName_5164Parser == null) { EAttribute[] features = new EAttribute[] { UMLPackage.eINSTANCE.getNamedElement_Name() }; @@ -870,43 +874,40 @@ public class UMLParserProvider extends AbstractProvider implements IParserProvid parser.setViewPattern("{0} "); //$NON-NLS-1$ parser.setEditorPattern("{0}"); //$NON-NLS-1$ parser.setEditPattern("{0}"); //$NON-NLS-1$ - timeExpressionName_5185Parser = parser; + signalName_5164Parser = parser; } - return timeExpressionName_5185Parser; + return signalName_5164Parser; } /** * @generated */ - private IParser expressionName_5186Parser; + private IParser signalName_6099Parser; /** * @generated */ - private IParser getExpressionName_5186Parser() { - if (expressionName_5186Parser == null) { + private IParser getSignalName_6099Parser() { + if (signalName_6099Parser == null) { EAttribute[] features = new EAttribute[] { UMLPackage.eINSTANCE.getNamedElement_Name() }; MessageFormatParser parser = new MessageFormatParser(features); - parser.setViewPattern("{0} "); //$NON-NLS-1$ - parser.setEditorPattern("{0}"); //$NON-NLS-1$ - parser.setEditPattern("{0}"); //$NON-NLS-1$ - expressionName_5186Parser = parser; + signalName_6099Parser = parser; } - return expressionName_5186Parser; + return signalName_6099Parser; } /** * @generated */ - private IParser durationName_5187Parser; + private IParser useCaseName_5165Parser; /** * @generated */ - private IParser getDurationName_5187Parser() { - if (durationName_5187Parser == null) { + private IParser getUseCaseName_5165Parser() { + if (useCaseName_5165Parser == null) { EAttribute[] features = new EAttribute[] { UMLPackage.eINSTANCE.getNamedElement_Name() }; @@ -914,43 +915,40 @@ public class UMLParserProvider extends AbstractProvider implements IParserProvid parser.setViewPattern("{0} "); //$NON-NLS-1$ parser.setEditorPattern("{0}"); //$NON-NLS-1$ parser.setEditPattern("{0}"); //$NON-NLS-1$ - durationName_5187Parser = parser; + useCaseName_5165Parser = parser; } - return durationName_5187Parser; + return useCaseName_5165Parser; } /** * @generated */ - private IParser timeIntervalName_5188Parser; + private IParser useCaseName_6100Parser; /** * @generated */ - private IParser getTimeIntervalName_5188Parser() { - if (timeIntervalName_5188Parser == null) { + private IParser getUseCaseName_6100Parser() { + if (useCaseName_6100Parser == null) { EAttribute[] features = new EAttribute[] { UMLPackage.eINSTANCE.getNamedElement_Name() }; MessageFormatParser parser = new MessageFormatParser(features); - parser.setViewPattern("{0} "); //$NON-NLS-1$ - parser.setEditorPattern("{0}"); //$NON-NLS-1$ - parser.setEditPattern("{0}"); //$NON-NLS-1$ - timeIntervalName_5188Parser = parser; + useCaseName_6100Parser = parser; } - return timeIntervalName_5188Parser; + return useCaseName_6100Parser; } /** * @generated */ - private IParser durationIntervalName_5189Parser; + private IParser signalEventName_5166Parser; /** * @generated */ - private IParser getDurationIntervalName_5189Parser() { - if (durationIntervalName_5189Parser == null) { + private IParser getSignalEventName_5166Parser() { + if (signalEventName_5166Parser == null) { EAttribute[] features = new EAttribute[] { UMLPackage.eINSTANCE.getNamedElement_Name() }; @@ -958,43 +956,40 @@ public class UMLParserProvider extends AbstractProvider implements IParserProvid parser.setViewPattern("{0} "); //$NON-NLS-1$ parser.setEditorPattern("{0}"); //$NON-NLS-1$ parser.setEditPattern("{0}"); //$NON-NLS-1$ - durationIntervalName_5189Parser = parser; + signalEventName_5166Parser = parser; } - return durationIntervalName_5189Parser; + return signalEventName_5166Parser; } /** * @generated */ - private IParser intervalName_5190Parser; + private IParser signalEventName_6101Parser; /** * @generated */ - private IParser getIntervalName_5190Parser() { - if (intervalName_5190Parser == null) { + private IParser getSignalEventName_6101Parser() { + if (signalEventName_6101Parser == null) { EAttribute[] features = new EAttribute[] { UMLPackage.eINSTANCE.getNamedElement_Name() }; MessageFormatParser parser = new MessageFormatParser(features); - parser.setViewPattern("{0} "); //$NON-NLS-1$ - parser.setEditorPattern("{0}"); //$NON-NLS-1$ - parser.setEditPattern("{0}"); //$NON-NLS-1$ - intervalName_5190Parser = parser; + signalEventName_6101Parser = parser; } - return intervalName_5190Parser; + return signalEventName_6101Parser; } /** * @generated */ - private IParser instanceValueName_5191Parser; + private IParser callEventName_5167Parser; /** * @generated */ - private IParser getInstanceValueName_5191Parser() { - if (instanceValueName_5191Parser == null) { + private IParser getCallEventName_5167Parser() { + if (callEventName_5167Parser == null) { EAttribute[] features = new EAttribute[] { UMLPackage.eINSTANCE.getNamedElement_Name() }; @@ -1002,334 +997,1522 @@ public class UMLParserProvider extends AbstractProvider implements IParserProvid parser.setViewPattern("{0} "); //$NON-NLS-1$ parser.setEditorPattern("{0}"); //$NON-NLS-1$ parser.setEditPattern("{0}"); //$NON-NLS-1$ - instanceValueName_5191Parser = parser; + callEventName_5167Parser = parser; } - return instanceValueName_5191Parser; + return callEventName_5167Parser; } /** * @generated */ - private CommentParser commentBody_5192Parser; + private IParser callEventName_6102Parser; /** * @generated */ - private IParser getCommentBody_5192Parser() { - if (commentBody_5192Parser == null) { - commentBody_5192Parser = new CommentParser(); + private IParser getCallEventName_6102Parser() { + if (callEventName_6102Parser == null) { + EAttribute[] features = new EAttribute[] { + UMLPackage.eINSTANCE.getNamedElement_Name() + }; + MessageFormatParser parser = new MessageFormatParser(features); + callEventName_6102Parser = parser; } - return commentBody_5192Parser; + return callEventName_6102Parser; } /** * @generated */ - private IParser durationConstraintName_5193Parser; + private IParser anyReceiveEventName_5168Parser; /** * @generated */ - private IParser getDurationConstraintName_5193Parser() { - if (durationConstraintName_5193Parser == null) { + private IParser getAnyReceiveEventName_5168Parser() { + if (anyReceiveEventName_5168Parser == null) { EAttribute[] features = new EAttribute[] { UMLPackage.eINSTANCE.getNamedElement_Name() }; MessageFormatParser parser = new MessageFormatParser(features); - durationConstraintName_5193Parser = parser; + parser.setViewPattern("{0} "); //$NON-NLS-1$ + parser.setEditorPattern("{0}"); //$NON-NLS-1$ + parser.setEditPattern("{0}"); //$NON-NLS-1$ + anyReceiveEventName_5168Parser = parser; } - return durationConstraintName_5193Parser; + return anyReceiveEventName_5168Parser; } /** * @generated */ - private ConstraintParser durationConstraintSpecification_6035Parser; + private IParser anyReceiveEventName_6103Parser; /** * @generated */ - private IParser getDurationConstraintSpecification_6035Parser() { - if (durationConstraintSpecification_6035Parser == null) { - durationConstraintSpecification_6035Parser = new ConstraintParser(); + private IParser getAnyReceiveEventName_6103Parser() { + if (anyReceiveEventName_6103Parser == null) { + EAttribute[] features = new EAttribute[] { + UMLPackage.eINSTANCE.getNamedElement_Name() + }; + MessageFormatParser parser = new MessageFormatParser(features); + anyReceiveEventName_6103Parser = parser; } - return durationConstraintSpecification_6035Parser; + return anyReceiveEventName_6103Parser; } /** * @generated */ - private IParser timeConstraintName_5194Parser; + private IParser changeEventName_5171Parser; /** * @generated */ - private IParser getTimeConstraintName_5194Parser() { - if (timeConstraintName_5194Parser == null) { + private IParser getChangeEventName_5171Parser() { + if (changeEventName_5171Parser == null) { EAttribute[] features = new EAttribute[] { UMLPackage.eINSTANCE.getNamedElement_Name() }; MessageFormatParser parser = new MessageFormatParser(features); - timeConstraintName_5194Parser = parser; + parser.setViewPattern("{0} "); //$NON-NLS-1$ + parser.setEditorPattern("{0}"); //$NON-NLS-1$ + parser.setEditPattern("{0}"); //$NON-NLS-1$ + changeEventName_5171Parser = parser; } - return timeConstraintName_5194Parser; + return changeEventName_5171Parser; } /** * @generated */ - private ConstraintParser timeConstraintSpecification_6036Parser; + private IParser changeEventName_6104Parser; /** * @generated */ - private IParser getTimeConstraintSpecification_6036Parser() { - if (timeConstraintSpecification_6036Parser == null) { - timeConstraintSpecification_6036Parser = new ConstraintParser(); + private IParser getChangeEventName_6104Parser() { + if (changeEventName_6104Parser == null) { + EAttribute[] features = new EAttribute[] { + UMLPackage.eINSTANCE.getNamedElement_Name() + }; + MessageFormatParser parser = new MessageFormatParser(features); + changeEventName_6104Parser = parser; } - return timeConstraintSpecification_6036Parser; + return changeEventName_6104Parser; } /** * @generated */ - private IParser intervalConstraintName_5195Parser; + private IParser timeEventName_5172Parser; /** * @generated */ - private IParser getIntervalConstraintName_5195Parser() { - if (intervalConstraintName_5195Parser == null) { + private IParser getTimeEventName_5172Parser() { + if (timeEventName_5172Parser == null) { EAttribute[] features = new EAttribute[] { UMLPackage.eINSTANCE.getNamedElement_Name() }; MessageFormatParser parser = new MessageFormatParser(features); - intervalConstraintName_5195Parser = parser; + parser.setViewPattern("{0} "); //$NON-NLS-1$ + parser.setEditorPattern("{0}"); //$NON-NLS-1$ + parser.setEditPattern("{0}"); //$NON-NLS-1$ + timeEventName_5172Parser = parser; } - return intervalConstraintName_5195Parser; + return timeEventName_5172Parser; } /** * @generated */ - private ConstraintParser intervalConstraintSpecification_6037Parser; + private IParser timeEventName_6105Parser; /** * @generated */ - private IParser getIntervalConstraintSpecification_6037Parser() { - if (intervalConstraintSpecification_6037Parser == null) { - intervalConstraintSpecification_6037Parser = new ConstraintParser(); + private IParser getTimeEventName_6105Parser() { + if (timeEventName_6105Parser == null) { + EAttribute[] features = new EAttribute[] { + UMLPackage.eINSTANCE.getNamedElement_Name() + }; + MessageFormatParser parser = new MessageFormatParser(features); + timeEventName_6105Parser = parser; } - return intervalConstraintSpecification_6037Parser; + return timeEventName_6105Parser; } /** * @generated */ - private IParser interactionConstraintName_5196Parser; + private IParser durationObservationName_5151Parser; /** * @generated */ - private IParser getInteractionConstraintName_5196Parser() { - if (interactionConstraintName_5196Parser == null) { + private IParser getDurationObservationName_5151Parser() { + if (durationObservationName_5151Parser == null) { EAttribute[] features = new EAttribute[] { UMLPackage.eINSTANCE.getNamedElement_Name() }; MessageFormatParser parser = new MessageFormatParser(features); - interactionConstraintName_5196Parser = parser; + durationObservationName_5151Parser = parser; } - return interactionConstraintName_5196Parser; + return durationObservationName_5151Parser; } /** * @generated */ - private ConstraintParser interactionConstraintSpecification_6038Parser; + private AppliedStereotypeParser durationObservationName_5152Parser; /** * @generated */ - private IParser getInteractionConstraintSpecification_6038Parser() { - if (interactionConstraintSpecification_6038Parser == null) { - interactionConstraintSpecification_6038Parser = new ConstraintParser(); + private IParser getDurationObservationName_5152Parser() { + if (durationObservationName_5152Parser == null) { + durationObservationName_5152Parser = new AppliedStereotypeParser(); } - return interactionConstraintSpecification_6038Parser; + return durationObservationName_5152Parser; } /** * @generated */ - private IParser constraintName_5197Parser; + private IParser timeObservationName_5142Parser; + + /** + * @generated + */ + private IParser getTimeObservationName_5142Parser() { + if (timeObservationName_5142Parser == null) { + EAttribute[] features = new EAttribute[] { + UMLPackage.eINSTANCE.getNamedElement_Name() + }; + MessageFormatParser parser = new MessageFormatParser(features); + timeObservationName_5142Parser = parser; + } + return timeObservationName_5142Parser; + } + + /** + * @generated + */ + private AppliedStereotypeParser timeObservationName_5143Parser; + + /** + * @generated + */ + private IParser getTimeObservationName_5143Parser() { + if (timeObservationName_5143Parser == null) { + timeObservationName_5143Parser = new AppliedStereotypeParser(); + } + return timeObservationName_5143Parser; + } + + /** + * @generated + */ + private IParser literalBooleanName_5178Parser; + + /** + * @generated + */ + private IParser getLiteralBooleanName_5178Parser() { + if (literalBooleanName_5178Parser == null) { + EAttribute[] features = new EAttribute[] { + UMLPackage.eINSTANCE.getNamedElement_Name() + }; + MessageFormatParser parser = new MessageFormatParser(features); + parser.setViewPattern("{0} "); //$NON-NLS-1$ + parser.setEditorPattern("{0}"); //$NON-NLS-1$ + parser.setEditPattern("{0}"); //$NON-NLS-1$ + literalBooleanName_5178Parser = parser; + } + return literalBooleanName_5178Parser; + } + + /** + * @generated + */ + private IParser literalBooleanName_6106Parser; + + /** + * @generated + */ + private IParser getLiteralBooleanName_6106Parser() { + if (literalBooleanName_6106Parser == null) { + EAttribute[] features = new EAttribute[] { + UMLPackage.eINSTANCE.getNamedElement_Name() + }; + MessageFormatParser parser = new MessageFormatParser(features); + literalBooleanName_6106Parser = parser; + } + return literalBooleanName_6106Parser; + } + + /** + * @generated + */ + private IParser literalIntegerName_5179Parser; + + /** + * @generated + */ + private IParser getLiteralIntegerName_5179Parser() { + if (literalIntegerName_5179Parser == null) { + EAttribute[] features = new EAttribute[] { + UMLPackage.eINSTANCE.getNamedElement_Name() + }; + MessageFormatParser parser = new MessageFormatParser(features); + parser.setViewPattern("{0} "); //$NON-NLS-1$ + parser.setEditorPattern("{0}"); //$NON-NLS-1$ + parser.setEditPattern("{0}"); //$NON-NLS-1$ + literalIntegerName_5179Parser = parser; + } + return literalIntegerName_5179Parser; + } + + /** + * @generated + */ + private IParser literalIntegerName_6107Parser; + + /** + * @generated + */ + private IParser getLiteralIntegerName_6107Parser() { + if (literalIntegerName_6107Parser == null) { + EAttribute[] features = new EAttribute[] { + UMLPackage.eINSTANCE.getNamedElement_Name() + }; + MessageFormatParser parser = new MessageFormatParser(features); + literalIntegerName_6107Parser = parser; + } + return literalIntegerName_6107Parser; + } + + /** + * @generated + */ + private IParser literalNullName_5180Parser; + + /** + * @generated + */ + private IParser getLiteralNullName_5180Parser() { + if (literalNullName_5180Parser == null) { + EAttribute[] features = new EAttribute[] { + UMLPackage.eINSTANCE.getNamedElement_Name() + }; + MessageFormatParser parser = new MessageFormatParser(features); + parser.setViewPattern("{0} "); //$NON-NLS-1$ + parser.setEditorPattern("{0}"); //$NON-NLS-1$ + parser.setEditPattern("{0}"); //$NON-NLS-1$ + literalNullName_5180Parser = parser; + } + return literalNullName_5180Parser; + } + + /** + * @generated + */ + private IParser literalNullName_6108Parser; + + /** + * @generated + */ + private IParser getLiteralNullName_6108Parser() { + if (literalNullName_6108Parser == null) { + EAttribute[] features = new EAttribute[] { + UMLPackage.eINSTANCE.getNamedElement_Name() + }; + MessageFormatParser parser = new MessageFormatParser(features); + literalNullName_6108Parser = parser; + } + return literalNullName_6108Parser; + } + + /** + * @generated + */ + private IParser literalStringName_5181Parser; + + /** + * @generated + */ + private IParser getLiteralStringName_5181Parser() { + if (literalStringName_5181Parser == null) { + EAttribute[] features = new EAttribute[] { + UMLPackage.eINSTANCE.getNamedElement_Name() + }; + MessageFormatParser parser = new MessageFormatParser(features); + parser.setViewPattern("{0} "); //$NON-NLS-1$ + parser.setEditorPattern("{0}"); //$NON-NLS-1$ + parser.setEditPattern("{0}"); //$NON-NLS-1$ + literalStringName_5181Parser = parser; + } + return literalStringName_5181Parser; + } + + /** + * @generated + */ + private IParser literalStringName_6109Parser; + + /** + * @generated + */ + private IParser getLiteralStringName_6109Parser() { + if (literalStringName_6109Parser == null) { + EAttribute[] features = new EAttribute[] { + UMLPackage.eINSTANCE.getNamedElement_Name() + }; + MessageFormatParser parser = new MessageFormatParser(features); + literalStringName_6109Parser = parser; + } + return literalStringName_6109Parser; + } + + /** + * @generated + */ + private IParser literalUnlimitedNaturalName_5182Parser; + + /** + * @generated + */ + private IParser getLiteralUnlimitedNaturalName_5182Parser() { + if (literalUnlimitedNaturalName_5182Parser == null) { + EAttribute[] features = new EAttribute[] { + UMLPackage.eINSTANCE.getNamedElement_Name() + }; + MessageFormatParser parser = new MessageFormatParser(features); + parser.setViewPattern("{0} "); //$NON-NLS-1$ + parser.setEditorPattern("{0}"); //$NON-NLS-1$ + parser.setEditPattern("{0}"); //$NON-NLS-1$ + literalUnlimitedNaturalName_5182Parser = parser; + } + return literalUnlimitedNaturalName_5182Parser; + } + + /** + * @generated + */ + private IParser literalUnlimitedNaturalName_6110Parser; + + /** + * @generated + */ + private IParser getLiteralUnlimitedNaturalName_6110Parser() { + if (literalUnlimitedNaturalName_6110Parser == null) { + EAttribute[] features = new EAttribute[] { + UMLPackage.eINSTANCE.getNamedElement_Name() + }; + MessageFormatParser parser = new MessageFormatParser(features); + literalUnlimitedNaturalName_6110Parser = parser; + } + return literalUnlimitedNaturalName_6110Parser; + } + + /** + * @generated + */ + private IParser stringExpressionName_5183Parser; + + /** + * @generated + */ + private IParser getStringExpressionName_5183Parser() { + if (stringExpressionName_5183Parser == null) { + EAttribute[] features = new EAttribute[] { + UMLPackage.eINSTANCE.getNamedElement_Name() + }; + MessageFormatParser parser = new MessageFormatParser(features); + parser.setViewPattern("{0} "); //$NON-NLS-1$ + parser.setEditorPattern("{0}"); //$NON-NLS-1$ + parser.setEditPattern("{0}"); //$NON-NLS-1$ + stringExpressionName_5183Parser = parser; + } + return stringExpressionName_5183Parser; + } + + /** + * @generated + */ + private IParser stringExpressionName_6111Parser; + + /** + * @generated + */ + private IParser getStringExpressionName_6111Parser() { + if (stringExpressionName_6111Parser == null) { + EAttribute[] features = new EAttribute[] { + UMLPackage.eINSTANCE.getNamedElement_Name() + }; + MessageFormatParser parser = new MessageFormatParser(features); + stringExpressionName_6111Parser = parser; + } + return stringExpressionName_6111Parser; + } + + /** + * @generated + */ + private IParser opaqueExpressionName_5184Parser; + + /** + * @generated + */ + private IParser getOpaqueExpressionName_5184Parser() { + if (opaqueExpressionName_5184Parser == null) { + EAttribute[] features = new EAttribute[] { + UMLPackage.eINSTANCE.getNamedElement_Name() + }; + MessageFormatParser parser = new MessageFormatParser(features); + parser.setViewPattern("{0} "); //$NON-NLS-1$ + parser.setEditorPattern("{0}"); //$NON-NLS-1$ + parser.setEditPattern("{0}"); //$NON-NLS-1$ + opaqueExpressionName_5184Parser = parser; + } + return opaqueExpressionName_5184Parser; + } + + /** + * @generated + */ + private IParser opaqueExpressionName_6112Parser; + + /** + * @generated + */ + private IParser getOpaqueExpressionName_6112Parser() { + if (opaqueExpressionName_6112Parser == null) { + EAttribute[] features = new EAttribute[] { + UMLPackage.eINSTANCE.getNamedElement_Name() + }; + MessageFormatParser parser = new MessageFormatParser(features); + opaqueExpressionName_6112Parser = parser; + } + return opaqueExpressionName_6112Parser; + } + + /** + * @generated + */ + private IParser timeExpressionName_5185Parser; + + /** + * @generated + */ + private IParser getTimeExpressionName_5185Parser() { + if (timeExpressionName_5185Parser == null) { + EAttribute[] features = new EAttribute[] { + UMLPackage.eINSTANCE.getNamedElement_Name() + }; + MessageFormatParser parser = new MessageFormatParser(features); + parser.setViewPattern("{0} "); //$NON-NLS-1$ + parser.setEditorPattern("{0}"); //$NON-NLS-1$ + parser.setEditPattern("{0}"); //$NON-NLS-1$ + timeExpressionName_5185Parser = parser; + } + return timeExpressionName_5185Parser; + } + + /** + * @generated + */ + private IParser timeExpressionName_6113Parser; + + /** + * @generated + */ + private IParser getTimeExpressionName_6113Parser() { + if (timeExpressionName_6113Parser == null) { + EAttribute[] features = new EAttribute[] { + UMLPackage.eINSTANCE.getNamedElement_Name() + }; + MessageFormatParser parser = new MessageFormatParser(features); + timeExpressionName_6113Parser = parser; + } + return timeExpressionName_6113Parser; + } + + /** + * @generated + */ + private IParser expressionName_5186Parser; + + /** + * @generated + */ + private IParser getExpressionName_5186Parser() { + if (expressionName_5186Parser == null) { + EAttribute[] features = new EAttribute[] { + UMLPackage.eINSTANCE.getNamedElement_Name() + }; + MessageFormatParser parser = new MessageFormatParser(features); + parser.setViewPattern("{0} "); //$NON-NLS-1$ + parser.setEditorPattern("{0}"); //$NON-NLS-1$ + parser.setEditPattern("{0}"); //$NON-NLS-1$ + expressionName_5186Parser = parser; + } + return expressionName_5186Parser; + } + + /** + * @generated + */ + private IParser expressionName_6114Parser; + + /** + * @generated + */ + private IParser getExpressionName_6114Parser() { + if (expressionName_6114Parser == null) { + EAttribute[] features = new EAttribute[] { + UMLPackage.eINSTANCE.getNamedElement_Name() + }; + MessageFormatParser parser = new MessageFormatParser(features); + expressionName_6114Parser = parser; + } + return expressionName_6114Parser; + } + + /** + * @generated + */ + private IParser durationName_5187Parser; + + /** + * @generated + */ + private IParser getDurationName_5187Parser() { + if (durationName_5187Parser == null) { + EAttribute[] features = new EAttribute[] { + UMLPackage.eINSTANCE.getNamedElement_Name() + }; + MessageFormatParser parser = new MessageFormatParser(features); + parser.setViewPattern("{0} "); //$NON-NLS-1$ + parser.setEditorPattern("{0}"); //$NON-NLS-1$ + parser.setEditPattern("{0}"); //$NON-NLS-1$ + durationName_5187Parser = parser; + } + return durationName_5187Parser; + } + + /** + * @generated + */ + private IParser durationName_6115Parser; + + /** + * @generated + */ + private IParser getDurationName_6115Parser() { + if (durationName_6115Parser == null) { + EAttribute[] features = new EAttribute[] { + UMLPackage.eINSTANCE.getNamedElement_Name() + }; + MessageFormatParser parser = new MessageFormatParser(features); + durationName_6115Parser = parser; + } + return durationName_6115Parser; + } + + /** + * @generated + */ + private IParser timeIntervalName_5188Parser; + + /** + * @generated + */ + private IParser getTimeIntervalName_5188Parser() { + if (timeIntervalName_5188Parser == null) { + EAttribute[] features = new EAttribute[] { + UMLPackage.eINSTANCE.getNamedElement_Name() + }; + MessageFormatParser parser = new MessageFormatParser(features); + parser.setViewPattern("{0} "); //$NON-NLS-1$ + parser.setEditorPattern("{0}"); //$NON-NLS-1$ + parser.setEditPattern("{0}"); //$NON-NLS-1$ + timeIntervalName_5188Parser = parser; + } + return timeIntervalName_5188Parser; + } + + /** + * @generated + */ + private IParser timeIntervalName_6116Parser; + + /** + * @generated + */ + private IParser getTimeIntervalName_6116Parser() { + if (timeIntervalName_6116Parser == null) { + EAttribute[] features = new EAttribute[] { + UMLPackage.eINSTANCE.getNamedElement_Name() + }; + MessageFormatParser parser = new MessageFormatParser(features); + timeIntervalName_6116Parser = parser; + } + return timeIntervalName_6116Parser; + } + + /** + * @generated + */ + private IParser durationIntervalName_5189Parser; + + /** + * @generated + */ + private IParser getDurationIntervalName_5189Parser() { + if (durationIntervalName_5189Parser == null) { + EAttribute[] features = new EAttribute[] { + UMLPackage.eINSTANCE.getNamedElement_Name() + }; + MessageFormatParser parser = new MessageFormatParser(features); + parser.setViewPattern("{0} "); //$NON-NLS-1$ + parser.setEditorPattern("{0}"); //$NON-NLS-1$ + parser.setEditPattern("{0}"); //$NON-NLS-1$ + durationIntervalName_5189Parser = parser; + } + return durationIntervalName_5189Parser; + } + + /** + * @generated + */ + private IParser durationIntervalName_6117Parser; + + /** + * @generated + */ + private IParser getDurationIntervalName_6117Parser() { + if (durationIntervalName_6117Parser == null) { + EAttribute[] features = new EAttribute[] { + UMLPackage.eINSTANCE.getNamedElement_Name() + }; + MessageFormatParser parser = new MessageFormatParser(features); + durationIntervalName_6117Parser = parser; + } + return durationIntervalName_6117Parser; + } + + /** + * @generated + */ + private IParser intervalName_5190Parser; + + /** + * @generated + */ + private IParser getIntervalName_5190Parser() { + if (intervalName_5190Parser == null) { + EAttribute[] features = new EAttribute[] { + UMLPackage.eINSTANCE.getNamedElement_Name() + }; + MessageFormatParser parser = new MessageFormatParser(features); + parser.setViewPattern("{0} "); //$NON-NLS-1$ + parser.setEditorPattern("{0}"); //$NON-NLS-1$ + parser.setEditPattern("{0}"); //$NON-NLS-1$ + intervalName_5190Parser = parser; + } + return intervalName_5190Parser; + } + + /** + * @generated + */ + private IParser intervalName_6118Parser; + + /** + * @generated + */ + private IParser getIntervalName_6118Parser() { + if (intervalName_6118Parser == null) { + EAttribute[] features = new EAttribute[] { + UMLPackage.eINSTANCE.getNamedElement_Name() + }; + MessageFormatParser parser = new MessageFormatParser(features); + intervalName_6118Parser = parser; + } + return intervalName_6118Parser; + } + + /** + * @generated + */ + private IParser instanceValueName_5191Parser; + + /** + * @generated + */ + private IParser getInstanceValueName_5191Parser() { + if (instanceValueName_5191Parser == null) { + EAttribute[] features = new EAttribute[] { + UMLPackage.eINSTANCE.getNamedElement_Name() + }; + MessageFormatParser parser = new MessageFormatParser(features); + parser.setViewPattern("{0} "); //$NON-NLS-1$ + parser.setEditorPattern("{0}"); //$NON-NLS-1$ + parser.setEditPattern("{0}"); //$NON-NLS-1$ + instanceValueName_5191Parser = parser; + } + return instanceValueName_5191Parser; + } + + /** + * @generated + */ + private IParser instanceValueName_6119Parser; + + /** + * @generated + */ + private IParser getInstanceValueName_6119Parser() { + if (instanceValueName_6119Parser == null) { + EAttribute[] features = new EAttribute[] { + UMLPackage.eINSTANCE.getNamedElement_Name() + }; + MessageFormatParser parser = new MessageFormatParser(features); + instanceValueName_6119Parser = parser; + } + return instanceValueName_6119Parser; + } + + /** + * @generated + */ + private CommentParser commentBody_5192Parser; + + /** + * @generated + */ + private IParser getCommentBody_5192Parser() { + if (commentBody_5192Parser == null) { + commentBody_5192Parser = new CommentParser(); + } + return commentBody_5192Parser; + } + + /** + * @generated + */ + private IParser durationConstraintName_5193Parser; + + /** + * @generated + */ + private IParser getDurationConstraintName_5193Parser() { + if (durationConstraintName_5193Parser == null) { + EAttribute[] features = new EAttribute[] { + UMLPackage.eINSTANCE.getNamedElement_Name() + }; + MessageFormatParser parser = new MessageFormatParser(features); + durationConstraintName_5193Parser = parser; + } + return durationConstraintName_5193Parser; + } + + /** + * @generated + */ + private ConstraintParser durationConstraintSpecification_6035Parser; + + /** + * @generated + */ + private IParser getDurationConstraintSpecification_6035Parser() { + if (durationConstraintSpecification_6035Parser == null) { + durationConstraintSpecification_6035Parser = new ConstraintParser(); + } + return durationConstraintSpecification_6035Parser; + } + + /** + * @generated + */ + private IParser timeConstraintName_5194Parser; + + /** + * @generated + */ + private IParser getTimeConstraintName_5194Parser() { + if (timeConstraintName_5194Parser == null) { + EAttribute[] features = new EAttribute[] { + UMLPackage.eINSTANCE.getNamedElement_Name() + }; + MessageFormatParser parser = new MessageFormatParser(features); + timeConstraintName_5194Parser = parser; + } + return timeConstraintName_5194Parser; + } + + /** + * @generated + */ + private ConstraintParser timeConstraintSpecification_6036Parser; + + /** + * @generated + */ + private IParser getTimeConstraintSpecification_6036Parser() { + if (timeConstraintSpecification_6036Parser == null) { + timeConstraintSpecification_6036Parser = new ConstraintParser(); + } + return timeConstraintSpecification_6036Parser; + } + + /** + * @generated + */ + private IParser intervalConstraintName_5195Parser; + + /** + * @generated + */ + private IParser getIntervalConstraintName_5195Parser() { + if (intervalConstraintName_5195Parser == null) { + EAttribute[] features = new EAttribute[] { + UMLPackage.eINSTANCE.getNamedElement_Name() + }; + MessageFormatParser parser = new MessageFormatParser(features); + intervalConstraintName_5195Parser = parser; + } + return intervalConstraintName_5195Parser; + } + + /** + * @generated + */ + private ConstraintParser intervalConstraintSpecification_6037Parser; + + /** + * @generated + */ + private IParser getIntervalConstraintSpecification_6037Parser() { + if (intervalConstraintSpecification_6037Parser == null) { + intervalConstraintSpecification_6037Parser = new ConstraintParser(); + } + return intervalConstraintSpecification_6037Parser; + } + + /** + * @generated + */ + private IParser interactionConstraintName_5196Parser; + + /** + * @generated + */ + private IParser getInteractionConstraintName_5196Parser() { + if (interactionConstraintName_5196Parser == null) { + EAttribute[] features = new EAttribute[] { + UMLPackage.eINSTANCE.getNamedElement_Name() + }; + MessageFormatParser parser = new MessageFormatParser(features); + interactionConstraintName_5196Parser = parser; + } + return interactionConstraintName_5196Parser; + } + + /** + * @generated + */ + private ConstraintParser interactionConstraintSpecification_6038Parser; + + /** + * @generated + */ + private IParser getInteractionConstraintSpecification_6038Parser() { + if (interactionConstraintSpecification_6038Parser == null) { + interactionConstraintSpecification_6038Parser = new ConstraintParser(); + } + return interactionConstraintSpecification_6038Parser; + } + + /** + * @generated + */ + private IParser constraintName_5197Parser; + + /** + * @generated + */ + private IParser getConstraintName_5197Parser() { + if (constraintName_5197Parser == null) { + EAttribute[] features = new EAttribute[] { + UMLPackage.eINSTANCE.getNamedElement_Name() + }; + MessageFormatParser parser = new MessageFormatParser(features); + constraintName_5197Parser = parser; + } + return constraintName_5197Parser; + } + + /** + * @generated + */ + private ConstraintParser constraintSpecification_6039Parser; + + /** + * @generated + */ + private IParser getConstraintSpecification_6039Parser() { + if (constraintSpecification_6039Parser == null) { + constraintSpecification_6039Parser = new ConstraintParser(); + } + return constraintSpecification_6039Parser; + } + + /** + * @generated + */ + private IParser nodeName_6053Parser; + + /** + * @generated + */ + private IParser getNodeName_6053Parser() { + if (nodeName_6053Parser == null) { + EAttribute[] features = new EAttribute[] { + UMLPackage.eINSTANCE.getNamedElement_Name() + }; + MessageFormatParser parser = new MessageFormatParser(features); + nodeName_6053Parser = parser; + } + return nodeName_6053Parser; + } + + /** + * @generated + */ + private IParser portName_5125Parser; + + /** + * @generated + */ + private IParser getPortName_5125Parser() { + if (portName_5125Parser == null) { + EAttribute[] features = new EAttribute[] { + UMLPackage.eINSTANCE.getNamedElement_Name() + }; + MessageFormatParser parser = new MessageFormatParser(features); + portName_5125Parser = parser; + } + return portName_5125Parser; + } + + /** + * @generated + */ + private AppliedStereotypeParser portName_6029Parser; + + /** + * @generated + */ + private IParser getPortName_6029Parser() { + if (portName_6029Parser == null) { + portName_6029Parser = new AppliedStereotypeParser(); + } + return portName_6029Parser; + } + + /** + * @generated + */ + private IParser parameterName_6033Parser; + + /** + * @generated + */ + private IParser getParameterName_6033Parser() { + if (parameterName_6033Parser == null) { + EAttribute[] features = new EAttribute[] { + UMLPackage.eINSTANCE.getNamedElement_Name() + }; + MessageFormatParser parser = new MessageFormatParser(features); + parameterName_6033Parser = parser; + } + return parameterName_6033Parser; + } + + /** + * @generated + */ + private AppliedStereotypeParser parameterName_6034Parser; + + /** + * @generated + */ + private IParser getParameterName_6034Parser() { + if (parameterName_6034Parser == null) { + parameterName_6034Parser = new AppliedStereotypeParser(); + } + return parameterName_6034Parser; + } + + /** + * @generated + */ + private IParser propertyName_5126Parser; + + /** + * @generated + */ + private IParser getPropertyName_5126Parser() { + if (propertyName_5126Parser == null) { + EAttribute[] features = new EAttribute[] { + UMLPackage.eINSTANCE.getNamedElement_Name() + }; + MessageFormatParser parser = new MessageFormatParser(features); + propertyName_5126Parser = parser; + } + return propertyName_5126Parser; + } + + /** + * @generated + */ + private IParser propertyName_6054Parser; + + /** + * @generated + */ + private IParser getPropertyName_6054Parser() { + if (propertyName_6054Parser == null) { + EAttribute[] features = new EAttribute[] { + UMLPackage.eINSTANCE.getNamedElement_Name() + }; + MessageFormatParser parser = new MessageFormatParser(features); + propertyName_6054Parser = parser; + } + return propertyName_6054Parser; + } + + /** + * @generated + */ + private IParser connectableElementName_5198Parser; + + /** + * @generated + */ + private IParser getConnectableElementName_5198Parser() { + if (connectableElementName_5198Parser == null) { + EAttribute[] features = new EAttribute[] { + UMLPackage.eINSTANCE.getNamedElement_Name() + }; + MessageFormatParser parser = new MessageFormatParser(features); + parser.setViewPattern("{0}"); //$NON-NLS-1$ + parser.setEditorPattern("{0}"); //$NON-NLS-1$ + parser.setEditPattern("{0}"); //$NON-NLS-1$ + connectableElementName_5198Parser = parser; + } + return connectableElementName_5198Parser; + } /** * @generated */ - private IParser getConstraintName_5197Parser() { - if (constraintName_5197Parser == null) { + private IParser connectableElementName_6055Parser; + + /** + * @generated + */ + private IParser getConnectableElementName_6055Parser() { + if (connectableElementName_6055Parser == null) { EAttribute[] features = new EAttribute[] { UMLPackage.eINSTANCE.getNamedElement_Name() }; MessageFormatParser parser = new MessageFormatParser(features); - constraintName_5197Parser = parser; + connectableElementName_6055Parser = parser; } - return constraintName_5197Parser; + return connectableElementName_6055Parser; } /** * @generated */ - private ConstraintParser constraintSpecification_6039Parser; + private IParser collaborationUseName_5127Parser; /** * @generated */ - private IParser getConstraintSpecification_6039Parser() { - if (constraintSpecification_6039Parser == null) { - constraintSpecification_6039Parser = new ConstraintParser(); + private IParser getCollaborationUseName_5127Parser() { + if (collaborationUseName_5127Parser == null) { + EAttribute[] features = new EAttribute[] { + UMLPackage.eINSTANCE.getNamedElement_Name() + }; + MessageFormatParser parser = new MessageFormatParser(features); + collaborationUseName_5127Parser = parser; } - return constraintSpecification_6039Parser; + return collaborationUseName_5127Parser; } /** * @generated */ - private IParser portName_5125Parser; + private IParser collaborationUseName_6056Parser; /** * @generated */ - private IParser getPortName_5125Parser() { - if (portName_5125Parser == null) { + private IParser getCollaborationUseName_6056Parser() { + if (collaborationUseName_6056Parser == null) { EAttribute[] features = new EAttribute[] { UMLPackage.eINSTANCE.getNamedElement_Name() }; MessageFormatParser parser = new MessageFormatParser(features); - portName_5125Parser = parser; + collaborationUseName_6056Parser = parser; } - return portName_5125Parser; + return collaborationUseName_6056Parser; } /** * @generated */ - private AppliedStereotypeParser portName_6029Parser; + private IParser activityName_5128Parser; /** * @generated */ - private IParser getPortName_6029Parser() { - if (portName_6029Parser == null) { - portName_6029Parser = new AppliedStereotypeParser(); + private IParser getActivityName_5128Parser() { + if (activityName_5128Parser == null) { + EAttribute[] features = new EAttribute[] { + UMLPackage.eINSTANCE.getNamedElement_Name() + }; + MessageFormatParser parser = new MessageFormatParser(features); + parser.setViewPattern("{0} "); //$NON-NLS-1$ + parser.setEditorPattern("{0}"); //$NON-NLS-1$ + parser.setEditPattern("{0}"); //$NON-NLS-1$ + activityName_5128Parser = parser; } - return portName_6029Parser; + return activityName_5128Parser; } /** * @generated */ - private IParser parameterName_6033Parser; + private IParser activityName_6057Parser; /** * @generated */ - private IParser getParameterName_6033Parser() { - if (parameterName_6033Parser == null) { + private IParser getActivityName_6057Parser() { + if (activityName_6057Parser == null) { EAttribute[] features = new EAttribute[] { UMLPackage.eINSTANCE.getNamedElement_Name() }; MessageFormatParser parser = new MessageFormatParser(features); - parameterName_6033Parser = parser; + activityName_6057Parser = parser; } - return parameterName_6033Parser; + return activityName_6057Parser; } /** * @generated */ - private AppliedStereotypeParser parameterName_6034Parser; + private IParser interactionName_5129Parser; /** * @generated */ - private IParser getParameterName_6034Parser() { - if (parameterName_6034Parser == null) { - parameterName_6034Parser = new AppliedStereotypeParser(); + private IParser getInteractionName_5129Parser() { + if (interactionName_5129Parser == null) { + EAttribute[] features = new EAttribute[] { + UMLPackage.eINSTANCE.getNamedElement_Name() + }; + MessageFormatParser parser = new MessageFormatParser(features); + parser.setViewPattern("{0} "); //$NON-NLS-1$ + parser.setEditorPattern("{0}"); //$NON-NLS-1$ + parser.setEditPattern("{0}"); //$NON-NLS-1$ + interactionName_5129Parser = parser; + } + return interactionName_5129Parser; + } + + /** + * @generated + */ + private IParser interactionName_6058Parser; + + /** + * @generated + */ + private IParser getInteractionName_6058Parser() { + if (interactionName_6058Parser == null) { + EAttribute[] features = new EAttribute[] { + UMLPackage.eINSTANCE.getNamedElement_Name() + }; + MessageFormatParser parser = new MessageFormatParser(features); + interactionName_6058Parser = parser; + } + return interactionName_6058Parser; + } + + /** + * @generated + */ + private IParser protocolStateMachineName_5130Parser; + + /** + * @generated + */ + private IParser getProtocolStateMachineName_5130Parser() { + if (protocolStateMachineName_5130Parser == null) { + EAttribute[] features = new EAttribute[] { + UMLPackage.eINSTANCE.getNamedElement_Name() + }; + MessageFormatParser parser = new MessageFormatParser(features); + parser.setViewPattern("{0} "); //$NON-NLS-1$ + parser.setEditorPattern("{0}"); //$NON-NLS-1$ + parser.setEditPattern("{0}"); //$NON-NLS-1$ + protocolStateMachineName_5130Parser = parser; + } + return protocolStateMachineName_5130Parser; + } + + /** + * @generated + */ + private IParser protocolStateMachineName_6059Parser; + + /** + * @generated + */ + private IParser getProtocolStateMachineName_6059Parser() { + if (protocolStateMachineName_6059Parser == null) { + EAttribute[] features = new EAttribute[] { + UMLPackage.eINSTANCE.getNamedElement_Name() + }; + MessageFormatParser parser = new MessageFormatParser(features); + protocolStateMachineName_6059Parser = parser; + } + return protocolStateMachineName_6059Parser; + } + + /** + * @generated + */ + private IParser stateMachineName_5131Parser; + + /** + * @generated + */ + private IParser getStateMachineName_5131Parser() { + if (stateMachineName_5131Parser == null) { + EAttribute[] features = new EAttribute[] { + UMLPackage.eINSTANCE.getNamedElement_Name() + }; + MessageFormatParser parser = new MessageFormatParser(features); + parser.setViewPattern("{0} "); //$NON-NLS-1$ + parser.setEditorPattern("{0}"); //$NON-NLS-1$ + parser.setEditPattern("{0}"); //$NON-NLS-1$ + stateMachineName_5131Parser = parser; + } + return stateMachineName_5131Parser; + } + + /** + * @generated + */ + private IParser stateMachineName_6060Parser; + + /** + * @generated + */ + private IParser getStateMachineName_6060Parser() { + if (stateMachineName_6060Parser == null) { + EAttribute[] features = new EAttribute[] { + UMLPackage.eINSTANCE.getNamedElement_Name() + }; + MessageFormatParser parser = new MessageFormatParser(features); + stateMachineName_6060Parser = parser; + } + return stateMachineName_6060Parser; + } + + /** + * @generated + */ + private IParser functionBehaviorName_5132Parser; + + /** + * @generated + */ + private IParser getFunctionBehaviorName_5132Parser() { + if (functionBehaviorName_5132Parser == null) { + EAttribute[] features = new EAttribute[] { + UMLPackage.eINSTANCE.getNamedElement_Name() + }; + MessageFormatParser parser = new MessageFormatParser(features); + parser.setViewPattern("{0} "); //$NON-NLS-1$ + parser.setEditorPattern("{0}"); //$NON-NLS-1$ + parser.setEditPattern("{0}"); //$NON-NLS-1$ + functionBehaviorName_5132Parser = parser; + } + return functionBehaviorName_5132Parser; + } + + /** + * @generated + */ + private IParser functionBehaviorName_6061Parser; + + /** + * @generated + */ + private IParser getFunctionBehaviorName_6061Parser() { + if (functionBehaviorName_6061Parser == null) { + EAttribute[] features = new EAttribute[] { + UMLPackage.eINSTANCE.getNamedElement_Name() + }; + MessageFormatParser parser = new MessageFormatParser(features); + functionBehaviorName_6061Parser = parser; + } + return functionBehaviorName_6061Parser; + } + + /** + * @generated + */ + private IParser opaqueBehaviorName_5133Parser; + + /** + * @generated + */ + private IParser getOpaqueBehaviorName_5133Parser() { + if (opaqueBehaviorName_5133Parser == null) { + EAttribute[] features = new EAttribute[] { + UMLPackage.eINSTANCE.getNamedElement_Name() + }; + MessageFormatParser parser = new MessageFormatParser(features); + parser.setViewPattern("{0} "); //$NON-NLS-1$ + parser.setEditorPattern("{0}"); //$NON-NLS-1$ + parser.setEditPattern("{0}"); //$NON-NLS-1$ + opaqueBehaviorName_5133Parser = parser; + } + return opaqueBehaviorName_5133Parser; + } + + /** + * @generated + */ + private IParser opaqueBehaviorName_6062Parser; + + /** + * @generated + */ + private IParser getOpaqueBehaviorName_6062Parser() { + if (opaqueBehaviorName_6062Parser == null) { + EAttribute[] features = new EAttribute[] { + UMLPackage.eINSTANCE.getNamedElement_Name() + }; + MessageFormatParser parser = new MessageFormatParser(features); + opaqueBehaviorName_6062Parser = parser; + } + return opaqueBehaviorName_6062Parser; + } + + /** + * @generated + */ + private IParser componentName_5137Parser; + + /** + * @generated + */ + private IParser getComponentName_5137Parser() { + if (componentName_5137Parser == null) { + EAttribute[] features = new EAttribute[] { + UMLPackage.eINSTANCE.getNamedElement_Name() + }; + MessageFormatParser parser = new MessageFormatParser(features); + parser.setViewPattern("{0} "); //$NON-NLS-1$ + parser.setEditorPattern("{0}"); //$NON-NLS-1$ + parser.setEditPattern("{0}"); //$NON-NLS-1$ + componentName_5137Parser = parser; } - return parameterName_6034Parser; + return componentName_5137Parser; } /** * @generated */ - private IParser propertyName_5126Parser; + private IParser componentName_6063Parser; /** * @generated */ - private IParser getPropertyName_5126Parser() { - if (propertyName_5126Parser == null) { + private IParser getComponentName_6063Parser() { + if (componentName_6063Parser == null) { EAttribute[] features = new EAttribute[] { UMLPackage.eINSTANCE.getNamedElement_Name() }; MessageFormatParser parser = new MessageFormatParser(features); - propertyName_5126Parser = parser; + componentName_6063Parser = parser; } - return propertyName_5126Parser; + return componentName_6063Parser; } /** * @generated */ - private IParser connectableElementName_5198Parser; + private IParser deviceName_5138Parser; /** * @generated */ - private IParser getConnectableElementName_5198Parser() { - if (connectableElementName_5198Parser == null) { + private IParser getDeviceName_5138Parser() { + if (deviceName_5138Parser == null) { EAttribute[] features = new EAttribute[] { UMLPackage.eINSTANCE.getNamedElement_Name() }; MessageFormatParser parser = new MessageFormatParser(features); - parser.setViewPattern("{0}"); //$NON-NLS-1$ + parser.setViewPattern("{0} "); //$NON-NLS-1$ parser.setEditorPattern("{0}"); //$NON-NLS-1$ parser.setEditPattern("{0}"); //$NON-NLS-1$ - connectableElementName_5198Parser = parser; + deviceName_5138Parser = parser; } - return connectableElementName_5198Parser; + return deviceName_5138Parser; } /** * @generated */ - private IParser collaborationUseName_5127Parser; + private IParser deviceName_6064Parser; /** * @generated */ - private IParser getCollaborationUseName_5127Parser() { - if (collaborationUseName_5127Parser == null) { + private IParser getDeviceName_6064Parser() { + if (deviceName_6064Parser == null) { EAttribute[] features = new EAttribute[] { UMLPackage.eINSTANCE.getNamedElement_Name() }; MessageFormatParser parser = new MessageFormatParser(features); - collaborationUseName_5127Parser = parser; + deviceName_6064Parser = parser; } - return collaborationUseName_5127Parser; + return deviceName_6064Parser; } /** * @generated */ - private IParser activityName_5128Parser; + private IParser executionEnvironmentName_5139Parser; /** * @generated */ - private IParser getActivityName_5128Parser() { - if (activityName_5128Parser == null) { + private IParser getExecutionEnvironmentName_5139Parser() { + if (executionEnvironmentName_5139Parser == null) { EAttribute[] features = new EAttribute[] { UMLPackage.eINSTANCE.getNamedElement_Name() }; @@ -1337,43 +2520,40 @@ public class UMLParserProvider extends AbstractProvider implements IParserProvid parser.setViewPattern("{0} "); //$NON-NLS-1$ parser.setEditorPattern("{0}"); //$NON-NLS-1$ parser.setEditPattern("{0}"); //$NON-NLS-1$ - activityName_5128Parser = parser; + executionEnvironmentName_5139Parser = parser; } - return activityName_5128Parser; + return executionEnvironmentName_5139Parser; } /** * @generated */ - private IParser interactionName_5129Parser; + private IParser executionEnvironmentName_6065Parser; /** * @generated */ - private IParser getInteractionName_5129Parser() { - if (interactionName_5129Parser == null) { + private IParser getExecutionEnvironmentName_6065Parser() { + if (executionEnvironmentName_6065Parser == null) { EAttribute[] features = new EAttribute[] { UMLPackage.eINSTANCE.getNamedElement_Name() }; MessageFormatParser parser = new MessageFormatParser(features); - parser.setViewPattern("{0} "); //$NON-NLS-1$ - parser.setEditorPattern("{0}"); //$NON-NLS-1$ - parser.setEditPattern("{0}"); //$NON-NLS-1$ - interactionName_5129Parser = parser; + executionEnvironmentName_6065Parser = parser; } - return interactionName_5129Parser; + return executionEnvironmentName_6065Parser; } /** * @generated */ - private IParser protocolStateMachineName_5130Parser; + private IParser nodeName_5140Parser; /** * @generated */ - private IParser getProtocolStateMachineName_5130Parser() { - if (protocolStateMachineName_5130Parser == null) { + private IParser getNodeName_5140Parser() { + if (nodeName_5140Parser == null) { EAttribute[] features = new EAttribute[] { UMLPackage.eINSTANCE.getNamedElement_Name() }; @@ -1381,43 +2561,40 @@ public class UMLParserProvider extends AbstractProvider implements IParserProvid parser.setViewPattern("{0} "); //$NON-NLS-1$ parser.setEditorPattern("{0}"); //$NON-NLS-1$ parser.setEditPattern("{0}"); //$NON-NLS-1$ - protocolStateMachineName_5130Parser = parser; + nodeName_5140Parser = parser; } - return protocolStateMachineName_5130Parser; + return nodeName_5140Parser; } /** * @generated */ - private IParser stateMachineName_5131Parser; + private IParser nodeName_6066Parser; /** * @generated */ - private IParser getStateMachineName_5131Parser() { - if (stateMachineName_5131Parser == null) { + private IParser getNodeName_6066Parser() { + if (nodeName_6066Parser == null) { EAttribute[] features = new EAttribute[] { UMLPackage.eINSTANCE.getNamedElement_Name() }; MessageFormatParser parser = new MessageFormatParser(features); - parser.setViewPattern("{0} "); //$NON-NLS-1$ - parser.setEditorPattern("{0}"); //$NON-NLS-1$ - parser.setEditPattern("{0}"); //$NON-NLS-1$ - stateMachineName_5131Parser = parser; + nodeName_6066Parser = parser; } - return stateMachineName_5131Parser; + return nodeName_6066Parser; } /** * @generated */ - private IParser functionBehaviorName_5132Parser; + private IParser className_5155Parser; /** * @generated */ - private IParser getFunctionBehaviorName_5132Parser() { - if (functionBehaviorName_5132Parser == null) { + private IParser getClassName_5155Parser() { + if (className_5155Parser == null) { EAttribute[] features = new EAttribute[] { UMLPackage.eINSTANCE.getNamedElement_Name() }; @@ -1425,43 +2602,40 @@ public class UMLParserProvider extends AbstractProvider implements IParserProvid parser.setViewPattern("{0} "); //$NON-NLS-1$ parser.setEditorPattern("{0}"); //$NON-NLS-1$ parser.setEditPattern("{0}"); //$NON-NLS-1$ - functionBehaviorName_5132Parser = parser; + className_5155Parser = parser; } - return functionBehaviorName_5132Parser; + return className_5155Parser; } /** * @generated */ - private IParser opaqueBehaviorName_5133Parser; + private IParser className_6067Parser; /** * @generated */ - private IParser getOpaqueBehaviorName_5133Parser() { - if (opaqueBehaviorName_5133Parser == null) { + private IParser getClassName_6067Parser() { + if (className_6067Parser == null) { EAttribute[] features = new EAttribute[] { UMLPackage.eINSTANCE.getNamedElement_Name() }; MessageFormatParser parser = new MessageFormatParser(features); - parser.setViewPattern("{0} "); //$NON-NLS-1$ - parser.setEditorPattern("{0}"); //$NON-NLS-1$ - parser.setEditPattern("{0}"); //$NON-NLS-1$ - opaqueBehaviorName_5133Parser = parser; + className_6067Parser = parser; } - return opaqueBehaviorName_5133Parser; + return className_6067Parser; } /** * @generated */ - private IParser componentName_5137Parser; + private IParser collaborationName_5141Parser; /** * @generated */ - private IParser getComponentName_5137Parser() { - if (componentName_5137Parser == null) { + private IParser getCollaborationName_5141Parser() { + if (collaborationName_5141Parser == null) { EAttribute[] features = new EAttribute[] { UMLPackage.eINSTANCE.getNamedElement_Name() }; @@ -1469,43 +2643,40 @@ public class UMLParserProvider extends AbstractProvider implements IParserProvid parser.setViewPattern("{0} "); //$NON-NLS-1$ parser.setEditorPattern("{0}"); //$NON-NLS-1$ parser.setEditPattern("{0}"); //$NON-NLS-1$ - componentName_5137Parser = parser; + collaborationName_5141Parser = parser; } - return componentName_5137Parser; + return collaborationName_5141Parser; } /** * @generated */ - private IParser deviceName_5138Parser; + private IParser collaborationName_6068Parser; /** * @generated */ - private IParser getDeviceName_5138Parser() { - if (deviceName_5138Parser == null) { + private IParser getCollaborationName_6068Parser() { + if (collaborationName_6068Parser == null) { EAttribute[] features = new EAttribute[] { UMLPackage.eINSTANCE.getNamedElement_Name() }; MessageFormatParser parser = new MessageFormatParser(features); - parser.setViewPattern("{0} "); //$NON-NLS-1$ - parser.setEditorPattern("{0}"); //$NON-NLS-1$ - parser.setEditPattern("{0}"); //$NON-NLS-1$ - deviceName_5138Parser = parser; + collaborationName_6068Parser = parser; } - return deviceName_5138Parser; + return collaborationName_6068Parser; } /** * @generated */ - private IParser executionEnvironmentName_5139Parser; + private IParser interfaceName_5154Parser; /** * @generated */ - private IParser getExecutionEnvironmentName_5139Parser() { - if (executionEnvironmentName_5139Parser == null) { + private IParser getInterfaceName_5154Parser() { + if (interfaceName_5154Parser == null) { EAttribute[] features = new EAttribute[] { UMLPackage.eINSTANCE.getNamedElement_Name() }; @@ -1513,43 +2684,40 @@ public class UMLParserProvider extends AbstractProvider implements IParserProvid parser.setViewPattern("{0} "); //$NON-NLS-1$ parser.setEditorPattern("{0}"); //$NON-NLS-1$ parser.setEditPattern("{0}"); //$NON-NLS-1$ - executionEnvironmentName_5139Parser = parser; + interfaceName_5154Parser = parser; } - return executionEnvironmentName_5139Parser; + return interfaceName_5154Parser; } /** * @generated */ - private IParser nodeName_5140Parser; + private IParser interfaceName_6069Parser; /** * @generated */ - private IParser getNodeName_5140Parser() { - if (nodeName_5140Parser == null) { + private IParser getInterfaceName_6069Parser() { + if (interfaceName_6069Parser == null) { EAttribute[] features = new EAttribute[] { UMLPackage.eINSTANCE.getNamedElement_Name() }; MessageFormatParser parser = new MessageFormatParser(features); - parser.setViewPattern("{0} "); //$NON-NLS-1$ - parser.setEditorPattern("{0}"); //$NON-NLS-1$ - parser.setEditPattern("{0}"); //$NON-NLS-1$ - nodeName_5140Parser = parser; + interfaceName_6069Parser = parser; } - return nodeName_5140Parser; + return interfaceName_6069Parser; } /** * @generated */ - private IParser className_5155Parser; + private IParser primitiveTypeName_5134Parser; /** * @generated */ - private IParser getClassName_5155Parser() { - if (className_5155Parser == null) { + private IParser getPrimitiveTypeName_5134Parser() { + if (primitiveTypeName_5134Parser == null) { EAttribute[] features = new EAttribute[] { UMLPackage.eINSTANCE.getNamedElement_Name() }; @@ -1557,43 +2725,40 @@ public class UMLParserProvider extends AbstractProvider implements IParserProvid parser.setViewPattern("{0} "); //$NON-NLS-1$ parser.setEditorPattern("{0}"); //$NON-NLS-1$ parser.setEditPattern("{0}"); //$NON-NLS-1$ - className_5155Parser = parser; + primitiveTypeName_5134Parser = parser; } - return className_5155Parser; + return primitiveTypeName_5134Parser; } /** * @generated */ - private IParser collaborationName_5141Parser; + private IParser primitiveTypeName_6070Parser; /** * @generated */ - private IParser getCollaborationName_5141Parser() { - if (collaborationName_5141Parser == null) { + private IParser getPrimitiveTypeName_6070Parser() { + if (primitiveTypeName_6070Parser == null) { EAttribute[] features = new EAttribute[] { UMLPackage.eINSTANCE.getNamedElement_Name() }; MessageFormatParser parser = new MessageFormatParser(features); - parser.setViewPattern("{0} "); //$NON-NLS-1$ - parser.setEditorPattern("{0}"); //$NON-NLS-1$ - parser.setEditPattern("{0}"); //$NON-NLS-1$ - collaborationName_5141Parser = parser; + primitiveTypeName_6070Parser = parser; } - return collaborationName_5141Parser; + return primitiveTypeName_6070Parser; } /** * @generated */ - private IParser interfaceName_5154Parser; + private IParser enumerationName_5135Parser; /** * @generated */ - private IParser getInterfaceName_5154Parser() { - if (interfaceName_5154Parser == null) { + private IParser getEnumerationName_5135Parser() { + if (enumerationName_5135Parser == null) { EAttribute[] features = new EAttribute[] { UMLPackage.eINSTANCE.getNamedElement_Name() }; @@ -1601,43 +2766,40 @@ public class UMLParserProvider extends AbstractProvider implements IParserProvid parser.setViewPattern("{0} "); //$NON-NLS-1$ parser.setEditorPattern("{0}"); //$NON-NLS-1$ parser.setEditPattern("{0}"); //$NON-NLS-1$ - interfaceName_5154Parser = parser; + enumerationName_5135Parser = parser; } - return interfaceName_5154Parser; + return enumerationName_5135Parser; } /** * @generated */ - private IParser primitiveTypeName_5134Parser; + private IParser enumerationName_6071Parser; /** * @generated */ - private IParser getPrimitiveTypeName_5134Parser() { - if (primitiveTypeName_5134Parser == null) { + private IParser getEnumerationName_6071Parser() { + if (enumerationName_6071Parser == null) { EAttribute[] features = new EAttribute[] { UMLPackage.eINSTANCE.getNamedElement_Name() }; MessageFormatParser parser = new MessageFormatParser(features); - parser.setViewPattern("{0} "); //$NON-NLS-1$ - parser.setEditorPattern("{0}"); //$NON-NLS-1$ - parser.setEditPattern("{0}"); //$NON-NLS-1$ - primitiveTypeName_5134Parser = parser; + enumerationName_6071Parser = parser; } - return primitiveTypeName_5134Parser; + return enumerationName_6071Parser; } /** * @generated */ - private IParser enumerationName_5135Parser; + private IParser dataTypeName_5136Parser; /** * @generated */ - private IParser getEnumerationName_5135Parser() { - if (enumerationName_5135Parser == null) { + private IParser getDataTypeName_5136Parser() { + if (dataTypeName_5136Parser == null) { EAttribute[] features = new EAttribute[] { UMLPackage.eINSTANCE.getNamedElement_Name() }; @@ -1645,31 +2807,28 @@ public class UMLParserProvider extends AbstractProvider implements IParserProvid parser.setViewPattern("{0} "); //$NON-NLS-1$ parser.setEditorPattern("{0}"); //$NON-NLS-1$ parser.setEditPattern("{0}"); //$NON-NLS-1$ - enumerationName_5135Parser = parser; + dataTypeName_5136Parser = parser; } - return enumerationName_5135Parser; + return dataTypeName_5136Parser; } /** * @generated */ - private IParser dataTypeName_5136Parser; + private IParser dataTypeName_6072Parser; /** * @generated */ - private IParser getDataTypeName_5136Parser() { - if (dataTypeName_5136Parser == null) { + private IParser getDataTypeName_6072Parser() { + if (dataTypeName_6072Parser == null) { EAttribute[] features = new EAttribute[] { UMLPackage.eINSTANCE.getNamedElement_Name() }; MessageFormatParser parser = new MessageFormatParser(features); - parser.setViewPattern("{0} "); //$NON-NLS-1$ - parser.setEditorPattern("{0}"); //$NON-NLS-1$ - parser.setEditPattern("{0}"); //$NON-NLS-1$ - dataTypeName_5136Parser = parser; + dataTypeName_6072Parser = parser; } - return dataTypeName_5136Parser; + return dataTypeName_6072Parser; } /** @@ -1694,6 +2853,25 @@ public class UMLParserProvider extends AbstractProvider implements IParserProvid return actorName_5144Parser; } + /** + * @generated + */ + private IParser actorName_6073Parser; + + /** + * @generated + */ + private IParser getActorName_6073Parser() { + if (actorName_6073Parser == null) { + EAttribute[] features = new EAttribute[] { + UMLPackage.eINSTANCE.getNamedElement_Name() + }; + MessageFormatParser parser = new MessageFormatParser(features); + actorName_6073Parser = parser; + } + return actorName_6073Parser; + } + /** * @generated */ @@ -1716,6 +2894,25 @@ public class UMLParserProvider extends AbstractProvider implements IParserProvid return deploymentSpecificationName_5145Parser; } + /** + * @generated + */ + private IParser deploymentSpecificationName_6074Parser; + + /** + * @generated + */ + private IParser getDeploymentSpecificationName_6074Parser() { + if (deploymentSpecificationName_6074Parser == null) { + EAttribute[] features = new EAttribute[] { + UMLPackage.eINSTANCE.getNamedElement_Name() + }; + MessageFormatParser parser = new MessageFormatParser(features); + deploymentSpecificationName_6074Parser = parser; + } + return deploymentSpecificationName_6074Parser; + } + /** * @generated */ @@ -1738,6 +2935,25 @@ public class UMLParserProvider extends AbstractProvider implements IParserProvid return artifactName_5146Parser; } + /** + * @generated + */ + private IParser artifactName_6075Parser; + + /** + * @generated + */ + private IParser getArtifactName_6075Parser() { + if (artifactName_6075Parser == null) { + EAttribute[] features = new EAttribute[] { + UMLPackage.eINSTANCE.getNamedElement_Name() + }; + MessageFormatParser parser = new MessageFormatParser(features); + artifactName_6075Parser = parser; + } + return artifactName_6075Parser; + } + /** * @generated */ @@ -1760,6 +2976,25 @@ public class UMLParserProvider extends AbstractProvider implements IParserProvid return informationItemName_5147Parser; } + /** + * @generated + */ + private IParser informationItemName_6076Parser; + + /** + * @generated + */ + private IParser getInformationItemName_6076Parser() { + if (informationItemName_6076Parser == null) { + EAttribute[] features = new EAttribute[] { + UMLPackage.eINSTANCE.getNamedElement_Name() + }; + MessageFormatParser parser = new MessageFormatParser(features); + informationItemName_6076Parser = parser; + } + return informationItemName_6076Parser; + } + /** * @generated */ @@ -1782,6 +3017,25 @@ public class UMLParserProvider extends AbstractProvider implements IParserProvid return signalName_5148Parser; } + /** + * @generated + */ + private IParser signalName_6077Parser; + + /** + * @generated + */ + private IParser getSignalName_6077Parser() { + if (signalName_6077Parser == null) { + EAttribute[] features = new EAttribute[] { + UMLPackage.eINSTANCE.getNamedElement_Name() + }; + MessageFormatParser parser = new MessageFormatParser(features); + signalName_6077Parser = parser; + } + return signalName_6077Parser; + } + /** * @generated */ @@ -1804,6 +3058,25 @@ public class UMLParserProvider extends AbstractProvider implements IParserProvid return useCaseName_5149Parser; } + /** + * @generated + */ + private IParser useCaseName_6078Parser; + + /** + * @generated + */ + private IParser getUseCaseName_6078Parser() { + if (useCaseName_6078Parser == null) { + EAttribute[] features = new EAttribute[] { + UMLPackage.eINSTANCE.getNamedElement_Name() + }; + MessageFormatParser parser = new MessageFormatParser(features); + useCaseName_6078Parser = parser; + } + return useCaseName_6078Parser; + } + /** * @generated */ @@ -2506,84 +3779,138 @@ public class UMLParserProvider extends AbstractProvider implements IParserProvid switch (visualID) { case ActivityCompositeNameEditPart.VISUAL_ID: return getActivityName_5112Parser(); + case ActivityCompositeFloatingLabelEditPart.VISUAL_ID: + return getActivityName_6079Parser(); case InteractionCompositeNameEditPart.VISUAL_ID: return getInteractionName_5113Parser(); + case InteractionCompositeFloatingLabelEditPart.VISUAL_ID: + return getInteractionName_6080Parser(); case ProtocolStateMachineCompositeNameEditPart.VISUAL_ID: return getProtocolStateMachineName_5114Parser(); + case ProtocolStateMachineCompositeFloatingLabelEditPart.VISUAL_ID: + return getProtocolStateMachineName_6081Parser(); case StateMachineCompositeNameEditPart.VISUAL_ID: return getStateMachineName_5115Parser(); + case StateMachineCompositeFloatingLabelEditPart.VISUAL_ID: + return getStateMachineName_6082Parser(); case FunctionBehaviorCompositeNameEditPart.VISUAL_ID: return getFunctionBehaviorName_5116Parser(); + case FunctionBehaviorCompositeFloatingLabelEditPart.VISUAL_ID: + return getFunctionBehaviorName_6083Parser(); case OpaqueBehaviorCompositeNameEditPart.VISUAL_ID: return getOpaqueBehaviorName_5117Parser(); + case OpaqueBehaviorCompositeFloatingLabelEditPart.VISUAL_ID: + return getOpaqueBehaviorName_6084Parser(); case ComponentCompositeNameEditPart.VISUAL_ID: return getComponentName_5121Parser(); + case ComponentCompositeFloatingLabelEditPart.VISUAL_ID: + return getComponentName_6085Parser(); case DeviceCompositeNameEditPart.VISUAL_ID: return getDeviceName_5122Parser(); + case DeviceCompositeFloatingLabelEditPart.VISUAL_ID: + return getDeviceName_6086Parser(); case ExecutionEnvironmentCompositeNameEditPart.VISUAL_ID: return getExecutionEnvironmentName_5123Parser(); + case ExecutionEnvironmentCompositeFloatingLabelEditPart.VISUAL_ID: + return getExecutionEnvironmentName_6087Parser(); case NodeCompositeNameEditPart.VISUAL_ID: return getNodeName_5124Parser(); + case NodeCompositeFloatingLabelEditPart.VISUAL_ID: + return getNodeName_6088Parser(); case ClassCompositeNameEditPart.VISUAL_ID: return getClassName_5156Parser(); + case ClassCompositeFloatingLabelEditPart.VISUAL_ID: + return getClassName_6089Parser(); case CollaborationCompositeNameEditPart.VISUAL_ID: return getCollaborationName_5158Parser(); + case CollaborationCompositeFloatingLabelEditPart.VISUAL_ID: + return getCollaborationName_6090Parser(); case InterfaceNameEditPart.VISUAL_ID: return getInterfaceName_5159Parser(); + case InterfaceFloatingLabelEditPart.VISUAL_ID: + return getInterfaceName_6091Parser(); case PrimitiveTypeNameEditPart.VISUAL_ID: return getPrimitiveTypeName_5118Parser(); + case PrimitiveTypeFloatingLabelEditPart.VISUAL_ID: + return getPrimitiveTypeName_6092Parser(); case EnumerationNameEditPart.VISUAL_ID: return getEnumerationName_5119Parser(); + case EnumerationFloatingLabelEditPart.VISUAL_ID: + return getEnumerationName_6093Parser(); case DataTypeNameEditPart.VISUAL_ID: return getDataTypeName_5120Parser(); + case DataTypeFloatingLabelEditPart.VISUAL_ID: + return getDataTypeName_6094Parser(); case ActorNameEditPart.VISUAL_ID: return getActorName_5160Parser(); + case ActorFloatingLabelEditPart.VISUAL_ID: + return getActorName_6095Parser(); case DeploymentSpecificationNameEditPart.VISUAL_ID: return getDeploymentSpecificationName_5161Parser(); + case DeploymentSpecificationFloatingLabelEditPart.VISUAL_ID: + return getDeploymentSpecificationName_6096Parser(); case ArtifactNameEditPart.VISUAL_ID: return getArtifactName_5162Parser(); + case ArtifactFloatingLabelEditPart.VISUAL_ID: + return getArtifactName_6097Parser(); case InformationItemNameEditPart.VISUAL_ID: return getInformationItemName_5163Parser(); + case InformationItemFloatingLabelEditPart.VISUAL_ID: + return getInformationItemName_6098Parser(); case SignalNameEditPart.VISUAL_ID: return getSignalName_5164Parser(); + case SignalFloatingLabelEditPart.VISUAL_ID: + return getSignalName_6099Parser(); case UseCaseNameEditPart.VISUAL_ID: return getUseCaseName_5165Parser(); + case UseCaseFloatingLabelEditPart.VISUAL_ID: + return getUseCaseName_6100Parser(); case SignalEventNameEditPart.VISUAL_ID: return getSignalEventName_5166Parser(); + case SignalEventFloatingLabelEditPart.VISUAL_ID: + return getSignalEventName_6101Parser(); case CallEventNameEditPart.VISUAL_ID: return getCallEventName_5167Parser(); + case CallEventFloatingLabelEditPart.VISUAL_ID: + return getCallEventName_6102Parser(); case AnyReceiveEventNameEditPart.VISUAL_ID: return getAnyReceiveEventName_5168Parser(); + case AnyReceiveEventFloatingLabelEditPart.VISUAL_ID: + return getAnyReceiveEventName_6103Parser(); case ChangeEventNameEditPart.VISUAL_ID: return getChangeEventName_5171Parser(); + case ChangeEventFloatingLabelEditPart.VISUAL_ID: + return getChangeEventName_6104Parser(); case TimeEventNameEditPart.VISUAL_ID: return getTimeEventName_5172Parser(); + case TimeEventFloatingLabelEditPart.VISUAL_ID: + return getTimeEventName_6105Parser(); case DurationObservationNameEditPart.VISUAL_ID: return getDurationObservationName_5151Parser(); @@ -2597,45 +3924,73 @@ public class UMLParserProvider extends AbstractProvider implements IParserProvid case LiteralBooleanNameEditPart.VISUAL_ID: return getLiteralBooleanName_5178Parser(); + case LiteralBooleanFloatingLabelEditPart.VISUAL_ID: + return getLiteralBooleanName_6106Parser(); case LiteralIntegerNameEditPart.VISUAL_ID: return getLiteralIntegerName_5179Parser(); + case LiteralIntegerFloatingLabelEditPart.VISUAL_ID: + return getLiteralIntegerName_6107Parser(); case LiteralNullNameEditPart.VISUAL_ID: return getLiteralNullName_5180Parser(); + case LiteralNullFloatingLabelEditPart.VISUAL_ID: + return getLiteralNullName_6108Parser(); case LiteralStringNameEditPart.VISUAL_ID: return getLiteralStringName_5181Parser(); + case LiteralStringFloatingLabelEditPart.VISUAL_ID: + return getLiteralStringName_6109Parser(); case LiteralUnlimitedNaturalNameEditPart.VISUAL_ID: return getLiteralUnlimitedNaturalName_5182Parser(); + case LiteralUnlimitedNaturalFloatingLabelEditPart.VISUAL_ID: + return getLiteralUnlimitedNaturalName_6110Parser(); case StringExpressionNameEditPart.VISUAL_ID: return getStringExpressionName_5183Parser(); + case StringExpressionFloatingLabelEditPart.VISUAL_ID: + return getStringExpressionName_6111Parser(); case OpaqueExpressionNameEditPart.VISUAL_ID: return getOpaqueExpressionName_5184Parser(); + case OpaqueExpressionFloatingLabelEditPart.VISUAL_ID: + return getOpaqueExpressionName_6112Parser(); case TimeExpressionNameEditPart.VISUAL_ID: return getTimeExpressionName_5185Parser(); + case TimeExpressionFloatingLabelEditPart.VISUAL_ID: + return getTimeExpressionName_6113Parser(); case ExpressionNameEditPart.VISUAL_ID: return getExpressionName_5186Parser(); + case ExpressionFloatingLabelEditPart.VISUAL_ID: + return getExpressionName_6114Parser(); case DurationNameEditPart.VISUAL_ID: return getDurationName_5187Parser(); + case DurationFloatingLabelEditPart.VISUAL_ID: + return getDurationName_6115Parser(); case TimeIntervalNameEditPart.VISUAL_ID: return getTimeIntervalName_5188Parser(); + case TimeIntervalFloatingLabelEditPart.VISUAL_ID: + return getTimeIntervalName_6116Parser(); case DurationIntervalNameEditPart.VISUAL_ID: return getDurationIntervalName_5189Parser(); + case DurationIntervalFloatingLabelEditPart.VISUAL_ID: + return getDurationIntervalName_6117Parser(); case IntervalNameEditPart.VISUAL_ID: return getIntervalName_5190Parser(); + case IntervalFloatingLabelEditPart.VISUAL_ID: + return getIntervalName_6118Parser(); case InstanceValueNameEditPart.VISUAL_ID: return getInstanceValueName_5191Parser(); + case InstanceValueFloatingLabelEditPart.VISUAL_ID: + return getInstanceValueName_6119Parser(); case CommentBodyEditPart.VISUAL_ID: return getCommentBody_5192Parser(); @@ -2665,6 +4020,8 @@ public class UMLParserProvider extends AbstractProvider implements IParserProvid case ConstraintSpecificationEditPart.VISUAL_ID: return getConstraintSpecification_6039Parser(); + case BehaviorPortFloatingLabelEditPart.VISUAL_ID: + return getNodeName_6053Parser(); case PortNameEditPart.VISUAL_ID: return getPortName_5125Parser(); @@ -2678,78 +4035,128 @@ public class UMLParserProvider extends AbstractProvider implements IParserProvid case PropertyPartNameEditPartCN.VISUAL_ID: return getPropertyName_5126Parser(); + case PropertyPartFloatingLabelEditPartCN.VISUAL_ID: + return getPropertyName_6054Parser(); case CollaborationRoleNameEditPartCN.VISUAL_ID: return getConnectableElementName_5198Parser(); + case CollaborationRoleFloatingLabelEditPartCN.VISUAL_ID: + return getConnectableElementName_6055Parser(); case CollaborationUseNameEditPart.VISUAL_ID: return getCollaborationUseName_5127Parser(); + case CollaborationUseFloatingLabelEditPartCN.VISUAL_ID: + return getCollaborationUseName_6056Parser(); case ActivityCompositeNameEditPartCN.VISUAL_ID: return getActivityName_5128Parser(); + case ActivityCompositeFloatingLabelEditPartCN.VISUAL_ID: + return getActivityName_6057Parser(); case InteractionCompositeNameEditPartCN.VISUAL_ID: return getInteractionName_5129Parser(); + case InteractionCompositeFloatingLabelEditPartCN.VISUAL_ID: + return getInteractionName_6058Parser(); case ProtocolStateMachineCompositeNameEditPartCN.VISUAL_ID: return getProtocolStateMachineName_5130Parser(); + case ProtocolStateMachineCompositeFloatingLabelEditPartCN.VISUAL_ID: + return getProtocolStateMachineName_6059Parser(); case StateMachineCompositeNameEditPartCN.VISUAL_ID: return getStateMachineName_5131Parser(); + case StateMachineCompositeFloatingLabelEditPartCN.VISUAL_ID: + return getStateMachineName_6060Parser(); case FunctionBehaviorCompositeNameEditPartCN.VISUAL_ID: return getFunctionBehaviorName_5132Parser(); + case FunctionBehaviorCompositeFloatingLabelEditPartCN.VISUAL_ID: + return getFunctionBehaviorName_6061Parser(); case OpaqueBehaviorCompositeNameEditPartCN.VISUAL_ID: return getOpaqueBehaviorName_5133Parser(); + case OpaqueBehaviorCompositeFloatingLabelEditPartCN.VISUAL_ID: + return getOpaqueBehaviorName_6062Parser(); case ComponentCompositeNameEditPartCN.VISUAL_ID: return getComponentName_5137Parser(); + case ComponentCompositeFloatingLabelEditPartCN.VISUAL_ID: + return getComponentName_6063Parser(); case DeviceCompositeNameEditPartCN.VISUAL_ID: return getDeviceName_5138Parser(); + case DeviceCompositeFloatingLabelEditPartCN.VISUAL_ID: + return getDeviceName_6064Parser(); case ExecutionEnvironmentCompositeNameEditPartCN.VISUAL_ID: return getExecutionEnvironmentName_5139Parser(); + case ExecutionEnvironmentCompositeFloatingLabelEditPartCN.VISUAL_ID: + return getExecutionEnvironmentName_6065Parser(); case NodeCompositeNameEditPartCN.VISUAL_ID: return getNodeName_5140Parser(); + case NodeCompositeFloatingLabelEditPartCN.VISUAL_ID: + return getNodeName_6066Parser(); case ClassCompositeNameEditPartCN.VISUAL_ID: return getClassName_5155Parser(); + case ClassCompositeFloatingLabelEditPartCN.VISUAL_ID: + return getClassName_6067Parser(); case CollaborationCompositeNameEditPartCN.VISUAL_ID: return getCollaborationName_5141Parser(); + case CollaborationCompositeFloatingLabelEditPartCN.VISUAL_ID: + return getCollaborationName_6068Parser(); case InterfaceNameEditPartCN.VISUAL_ID: return getInterfaceName_5154Parser(); + case InterfaceFloatingLabelEditPartCN.VISUAL_ID: + return getInterfaceName_6069Parser(); case PrimitiveTypeNameEditPartCN.VISUAL_ID: return getPrimitiveTypeName_5134Parser(); + case PrimitiveTypeFloatingLabelEditPartCN.VISUAL_ID: + return getPrimitiveTypeName_6070Parser(); case EnumerationNameEditPartCN.VISUAL_ID: return getEnumerationName_5135Parser(); + case EnumerationFloatingLabelEditPartCN.VISUAL_ID: + return getEnumerationName_6071Parser(); case DataTypeNameEditPartCN.VISUAL_ID: return getDataTypeName_5136Parser(); + case DataTypeFloatingLabelEditPartCN.VISUAL_ID: + return getDataTypeName_6072Parser(); case ActorNameEditPartCN.VISUAL_ID: return getActorName_5144Parser(); + case ActorFloatingLabelEditPartCN.VISUAL_ID: + return getActorName_6073Parser(); case DeploymentSpecificationNameEditPartCN.VISUAL_ID: return getDeploymentSpecificationName_5145Parser(); + case DeploymentSpecificationFloatingLabelEditPartCN.VISUAL_ID: + return getDeploymentSpecificationName_6074Parser(); case ArtifactNameEditPartCN.VISUAL_ID: return getArtifactName_5146Parser(); + case ArtifactFloatingLabelEditPartCN.VISUAL_ID: + return getArtifactName_6075Parser(); case InformationItemNameEditPartCN.VISUAL_ID: return getInformationItemName_5147Parser(); + case InformationItemFloatingLabelEditPartCN.VISUAL_ID: + return getInformationItemName_6076Parser(); case SignalNameEditPartCN.VISUAL_ID: return getSignalName_5148Parser(); + case SignalFloatingLabelEditPartCN.VISUAL_ID: + return getSignalName_6077Parser(); case UseCaseNameEditPartCN.VISUAL_ID: return getUseCaseName_5149Parser(); + case UseCaseFloatingLabelEditPartCN.VISUAL_ID: + return getUseCaseName_6078Parser(); case CommentBodyEditPartCN.VISUAL_ID: return getCommentBody_5150Parser(); diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/providers/UMLViewProvider.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/providers/UMLViewProvider.java index 42472d5aaca..bdb3df72ada 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/providers/UMLViewProvider.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/providers/UMLViewProvider.java @@ -92,10 +92,10 @@ public class UMLViewProvider extends AbstractProvider implements IViewProvider { */ 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; + * 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; */ // check Diagram Type should be the class diagram @@ -121,7 +121,7 @@ public class UMLViewProvider extends AbstractProvider implements IViewProvider { *

* This method can be overloaded when diagram editor inherits from another one, but should never be null *

- * + * * @return the unique identifier of the diagram for which views are provided. */ return CompositeStructureDiagramEditPart.MODEL_ID; @@ -303,7 +303,7 @@ public class UMLViewProvider extends AbstractProvider implements IViewProvider { */ protected boolean provides(CreateEdgeViewOperation op) { IElementType elementType = getSemanticElementType(op.getSemanticAdapter()); - //RS: add code for extended types creation + // RS: add code for extended types creation if (elementType instanceof IExtendedHintedElementType) { IElementType closestNonExtendedType = ElementTypeUtils.getClosestDiagramType(elementType); if (!UMLElementTypes.isKnownElementType(closestNonExtendedType) || (!(closestNonExtendedType instanceof IHintedType))) { @@ -314,9 +314,9 @@ public class UMLViewProvider extends AbstractProvider implements IViewProvider { return false; // foreign element type } } - //if (!org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes.isKnownElementType(elementType) || (!(elementType instanceof org.eclipse.gmf.runtime.emf.type.core.IHintedType))) { - // return false; // foreign element type - //} + // if (!org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes.isKnownElementType(elementType) || (!(elementType instanceof org.eclipse.gmf.runtime.emf.type.core.IHintedType))) { + // return false; // foreign element type + // } // END R.S. String elementTypeHint = ((IHintedType) elementType).getSemanticHint(); if (elementTypeHint == null || (op.getSemanticHint() != null && !elementTypeHint.equals(op.getSemanticHint()))) { @@ -603,6 +603,11 @@ public class UMLViewProvider extends AbstractProvider implements IViewProvider { PreferenceInitializerForElementHelper.initFontStyleFromPrefs(node, prefStore, "Activity"); Node label5112 = createLabel(node, UMLVisualIDRegistry.getType(ActivityCompositeNameEditPart.VISUAL_ID)); + Node label6079 = createLabel(node, UMLVisualIDRegistry.getType(ActivityCompositeFloatingLabelEditPart.VISUAL_ID)); + label6079.setLayoutConstraint(NotationFactory.eINSTANCE.createLocation()); + Location location6079 = (Location) label6079.getLayoutConstraint(); + location6079.setX(0); + location6079.setY(5); createCompartment(node, UMLVisualIDRegistry.getType(ActivityCompositeCompartmentEditPart.VISUAL_ID), true, true, false, false); PreferenceInitializerForElementHelper.initCompartmentsStatusFromPrefs(node, prefStore, "Activity"); return node; @@ -623,6 +628,11 @@ public class UMLViewProvider extends AbstractProvider implements IViewProvider { PreferenceInitializerForElementHelper.initFontStyleFromPrefs(node, prefStore, "Interaction"); Node label5113 = createLabel(node, UMLVisualIDRegistry.getType(InteractionCompositeNameEditPart.VISUAL_ID)); + Node label6080 = createLabel(node, UMLVisualIDRegistry.getType(InteractionCompositeFloatingLabelEditPart.VISUAL_ID)); + label6080.setLayoutConstraint(NotationFactory.eINSTANCE.createLocation()); + Location location6080 = (Location) label6080.getLayoutConstraint(); + location6080.setX(0); + location6080.setY(5); createCompartment(node, UMLVisualIDRegistry.getType(InteractionCompositeCompartmentEditPart.VISUAL_ID), true, true, false, false); PreferenceInitializerForElementHelper.initCompartmentsStatusFromPrefs(node, prefStore, "Interaction"); return node; @@ -643,6 +653,11 @@ public class UMLViewProvider extends AbstractProvider implements IViewProvider { PreferenceInitializerForElementHelper.initFontStyleFromPrefs(node, prefStore, "ProtocolStateMachine"); Node label5114 = createLabel(node, UMLVisualIDRegistry.getType(ProtocolStateMachineCompositeNameEditPart.VISUAL_ID)); + Node label6081 = createLabel(node, UMLVisualIDRegistry.getType(ProtocolStateMachineCompositeFloatingLabelEditPart.VISUAL_ID)); + label6081.setLayoutConstraint(NotationFactory.eINSTANCE.createLocation()); + Location location6081 = (Location) label6081.getLayoutConstraint(); + location6081.setX(0); + location6081.setY(5); createCompartment(node, UMLVisualIDRegistry.getType(ProtocolStateMachineCompositeCompartmentEditPart.VISUAL_ID), true, true, false, false); PreferenceInitializerForElementHelper.initCompartmentsStatusFromPrefs(node, prefStore, "ProtocolStateMachine"); return node; @@ -663,6 +678,11 @@ public class UMLViewProvider extends AbstractProvider implements IViewProvider { PreferenceInitializerForElementHelper.initFontStyleFromPrefs(node, prefStore, "StateMachine"); Node label5115 = createLabel(node, UMLVisualIDRegistry.getType(StateMachineCompositeNameEditPart.VISUAL_ID)); + Node label6082 = createLabel(node, UMLVisualIDRegistry.getType(StateMachineCompositeFloatingLabelEditPart.VISUAL_ID)); + label6082.setLayoutConstraint(NotationFactory.eINSTANCE.createLocation()); + Location location6082 = (Location) label6082.getLayoutConstraint(); + location6082.setX(0); + location6082.setY(5); createCompartment(node, UMLVisualIDRegistry.getType(StateMachineCompositeCompartmentEditPart.VISUAL_ID), true, true, false, false); PreferenceInitializerForElementHelper.initCompartmentsStatusFromPrefs(node, prefStore, "StateMachine"); return node; @@ -683,6 +703,11 @@ public class UMLViewProvider extends AbstractProvider implements IViewProvider { PreferenceInitializerForElementHelper.initFontStyleFromPrefs(node, prefStore, "FunctionBehavior"); Node label5116 = createLabel(node, UMLVisualIDRegistry.getType(FunctionBehaviorCompositeNameEditPart.VISUAL_ID)); + Node label6083 = createLabel(node, UMLVisualIDRegistry.getType(FunctionBehaviorCompositeFloatingLabelEditPart.VISUAL_ID)); + label6083.setLayoutConstraint(NotationFactory.eINSTANCE.createLocation()); + Location location6083 = (Location) label6083.getLayoutConstraint(); + location6083.setX(0); + location6083.setY(5); createCompartment(node, UMLVisualIDRegistry.getType(FunctionBehaviorCompositeCompartmentEditPart.VISUAL_ID), true, true, false, false); PreferenceInitializerForElementHelper.initCompartmentsStatusFromPrefs(node, prefStore, "FunctionBehavior"); return node; @@ -703,6 +728,11 @@ public class UMLViewProvider extends AbstractProvider implements IViewProvider { PreferenceInitializerForElementHelper.initFontStyleFromPrefs(node, prefStore, "OpaqueBehavior"); Node label5117 = createLabel(node, UMLVisualIDRegistry.getType(OpaqueBehaviorCompositeNameEditPart.VISUAL_ID)); + Node label6084 = createLabel(node, UMLVisualIDRegistry.getType(OpaqueBehaviorCompositeFloatingLabelEditPart.VISUAL_ID)); + label6084.setLayoutConstraint(NotationFactory.eINSTANCE.createLocation()); + Location location6084 = (Location) label6084.getLayoutConstraint(); + location6084.setX(0); + location6084.setY(5); createCompartment(node, UMLVisualIDRegistry.getType(OpaqueBehaviorCompositeCompartmentEditPart.VISUAL_ID), true, true, false, false); PreferenceInitializerForElementHelper.initCompartmentsStatusFromPrefs(node, prefStore, "OpaqueBehavior"); return node; @@ -723,6 +753,11 @@ public class UMLViewProvider extends AbstractProvider implements IViewProvider { PreferenceInitializerForElementHelper.initFontStyleFromPrefs(node, prefStore, "Component"); Node label5121 = createLabel(node, UMLVisualIDRegistry.getType(ComponentCompositeNameEditPart.VISUAL_ID)); + Node label6085 = createLabel(node, UMLVisualIDRegistry.getType(ComponentCompositeFloatingLabelEditPart.VISUAL_ID)); + label6085.setLayoutConstraint(NotationFactory.eINSTANCE.createLocation()); + Location location6085 = (Location) label6085.getLayoutConstraint(); + location6085.setX(0); + location6085.setY(5); createCompartment(node, UMLVisualIDRegistry.getType(ComponentCompositeCompartmentEditPart.VISUAL_ID), true, true, false, false); PreferenceInitializerForElementHelper.initCompartmentsStatusFromPrefs(node, prefStore, "Component"); return node; @@ -743,6 +778,11 @@ public class UMLViewProvider extends AbstractProvider implements IViewProvider { PreferenceInitializerForElementHelper.initFontStyleFromPrefs(node, prefStore, "Device"); Node label5122 = createLabel(node, UMLVisualIDRegistry.getType(DeviceCompositeNameEditPart.VISUAL_ID)); + Node label6086 = createLabel(node, UMLVisualIDRegistry.getType(DeviceCompositeFloatingLabelEditPart.VISUAL_ID)); + label6086.setLayoutConstraint(NotationFactory.eINSTANCE.createLocation()); + Location location6086 = (Location) label6086.getLayoutConstraint(); + location6086.setX(0); + location6086.setY(5); createCompartment(node, UMLVisualIDRegistry.getType(DeviceCompositeCompartmentEditPart.VISUAL_ID), true, true, false, false); PreferenceInitializerForElementHelper.initCompartmentsStatusFromPrefs(node, prefStore, "Device"); return node; @@ -763,6 +803,11 @@ public class UMLViewProvider extends AbstractProvider implements IViewProvider { PreferenceInitializerForElementHelper.initFontStyleFromPrefs(node, prefStore, "ExecutionEnvironment"); Node label5123 = createLabel(node, UMLVisualIDRegistry.getType(ExecutionEnvironmentCompositeNameEditPart.VISUAL_ID)); + Node label6087 = createLabel(node, UMLVisualIDRegistry.getType(ExecutionEnvironmentCompositeFloatingLabelEditPart.VISUAL_ID)); + label6087.setLayoutConstraint(NotationFactory.eINSTANCE.createLocation()); + Location location6087 = (Location) label6087.getLayoutConstraint(); + location6087.setX(0); + location6087.setY(5); createCompartment(node, UMLVisualIDRegistry.getType(ExecutionEnvironmentCompositeCompartmentEditPart.VISUAL_ID), true, true, false, false); PreferenceInitializerForElementHelper.initCompartmentsStatusFromPrefs(node, prefStore, "ExecutionEnvironment"); return node; @@ -783,6 +828,11 @@ public class UMLViewProvider extends AbstractProvider implements IViewProvider { PreferenceInitializerForElementHelper.initFontStyleFromPrefs(node, prefStore, "Node"); Node label5124 = createLabel(node, UMLVisualIDRegistry.getType(NodeCompositeNameEditPart.VISUAL_ID)); + Node label6088 = createLabel(node, UMLVisualIDRegistry.getType(NodeCompositeFloatingLabelEditPart.VISUAL_ID)); + label6088.setLayoutConstraint(NotationFactory.eINSTANCE.createLocation()); + Location location6088 = (Location) label6088.getLayoutConstraint(); + location6088.setX(0); + location6088.setY(5); createCompartment(node, UMLVisualIDRegistry.getType(NodeCompositeCompartmentEditPart.VISUAL_ID), true, true, false, false); PreferenceInitializerForElementHelper.initCompartmentsStatusFromPrefs(node, prefStore, "Node"); return node; @@ -803,6 +853,11 @@ public class UMLViewProvider extends AbstractProvider implements IViewProvider { PreferenceInitializerForElementHelper.initFontStyleFromPrefs(node, prefStore, "Class"); Node label5156 = createLabel(node, UMLVisualIDRegistry.getType(ClassCompositeNameEditPart.VISUAL_ID)); + Node label6089 = createLabel(node, UMLVisualIDRegistry.getType(ClassCompositeFloatingLabelEditPart.VISUAL_ID)); + label6089.setLayoutConstraint(NotationFactory.eINSTANCE.createLocation()); + Location location6089 = (Location) label6089.getLayoutConstraint(); + location6089.setX(0); + location6089.setY(5); createCompartment(node, UMLVisualIDRegistry.getType(ClassCompositeCompartmentEditPart.VISUAL_ID), true, true, false, false); PreferenceInitializerForElementHelper.initCompartmentsStatusFromPrefs(node, prefStore, "Class"); return node; @@ -823,6 +878,11 @@ public class UMLViewProvider extends AbstractProvider implements IViewProvider { PreferenceInitializerForElementHelper.initFontStyleFromPrefs(node, prefStore, "Collaboration"); Node label5158 = createLabel(node, UMLVisualIDRegistry.getType(CollaborationCompositeNameEditPart.VISUAL_ID)); + Node label6090 = createLabel(node, UMLVisualIDRegistry.getType(CollaborationCompositeFloatingLabelEditPart.VISUAL_ID)); + label6090.setLayoutConstraint(NotationFactory.eINSTANCE.createLocation()); + Location location6090 = (Location) label6090.getLayoutConstraint(); + location6090.setX(0); + location6090.setY(5); createCompartment(node, UMLVisualIDRegistry.getType(CollaborationCompositeCompartmentEditPart.VISUAL_ID), true, true, false, false); PreferenceInitializerForElementHelper.initCompartmentsStatusFromPrefs(node, prefStore, "Collaboration"); return node; @@ -843,6 +903,11 @@ public class UMLViewProvider extends AbstractProvider implements IViewProvider { PreferenceInitializerForElementHelper.initFontStyleFromPrefs(node, prefStore, "Interface"); Node label5159 = createLabel(node, UMLVisualIDRegistry.getType(InterfaceNameEditPart.VISUAL_ID)); + Node label6091 = createLabel(node, UMLVisualIDRegistry.getType(InterfaceFloatingLabelEditPart.VISUAL_ID)); + label6091.setLayoutConstraint(NotationFactory.eINSTANCE.createLocation()); + Location location6091 = (Location) label6091.getLayoutConstraint(); + location6091.setX(0); + location6091.setY(5); return node; } @@ -861,6 +926,11 @@ public class UMLViewProvider extends AbstractProvider implements IViewProvider { PreferenceInitializerForElementHelper.initFontStyleFromPrefs(node, prefStore, "PrimitiveType"); Node label5118 = createLabel(node, UMLVisualIDRegistry.getType(PrimitiveTypeNameEditPart.VISUAL_ID)); + Node label6092 = createLabel(node, UMLVisualIDRegistry.getType(PrimitiveTypeFloatingLabelEditPart.VISUAL_ID)); + label6092.setLayoutConstraint(NotationFactory.eINSTANCE.createLocation()); + Location location6092 = (Location) label6092.getLayoutConstraint(); + location6092.setX(0); + location6092.setY(5); return node; } @@ -879,6 +949,11 @@ public class UMLViewProvider extends AbstractProvider implements IViewProvider { PreferenceInitializerForElementHelper.initFontStyleFromPrefs(node, prefStore, "Enumeration"); Node label5119 = createLabel(node, UMLVisualIDRegistry.getType(EnumerationNameEditPart.VISUAL_ID)); + Node label6093 = createLabel(node, UMLVisualIDRegistry.getType(EnumerationFloatingLabelEditPart.VISUAL_ID)); + label6093.setLayoutConstraint(NotationFactory.eINSTANCE.createLocation()); + Location location6093 = (Location) label6093.getLayoutConstraint(); + location6093.setX(0); + location6093.setY(5); createCompartment(node, UMLVisualIDRegistry.getType(EnumerationEnumerationLiteralCompartmentEditPart.VISUAL_ID), true, true, true, true); PreferenceInitializerForElementHelper.initCompartmentsStatusFromPrefs(node, prefStore, "Enumeration"); return node; @@ -899,6 +974,11 @@ public class UMLViewProvider extends AbstractProvider implements IViewProvider { PreferenceInitializerForElementHelper.initFontStyleFromPrefs(node, prefStore, "DataType"); Node label5120 = createLabel(node, UMLVisualIDRegistry.getType(DataTypeNameEditPart.VISUAL_ID)); + Node label6094 = createLabel(node, UMLVisualIDRegistry.getType(DataTypeFloatingLabelEditPart.VISUAL_ID)); + label6094.setLayoutConstraint(NotationFactory.eINSTANCE.createLocation()); + Location location6094 = (Location) label6094.getLayoutConstraint(); + location6094.setX(0); + location6094.setY(5); createCompartment(node, UMLVisualIDRegistry.getType(DataTypeAttributeCompartmentEditPart.VISUAL_ID), true, true, true, true); createCompartment(node, UMLVisualIDRegistry.getType(DataTypeOperationCompartmentEditPart.VISUAL_ID), true, true, true, true); PreferenceInitializerForElementHelper.initCompartmentsStatusFromPrefs(node, prefStore, "DataType"); @@ -920,6 +1000,11 @@ public class UMLViewProvider extends AbstractProvider implements IViewProvider { PreferenceInitializerForElementHelper.initFontStyleFromPrefs(node, prefStore, "Actor"); Node label5160 = createLabel(node, UMLVisualIDRegistry.getType(ActorNameEditPart.VISUAL_ID)); + Node label6095 = createLabel(node, UMLVisualIDRegistry.getType(ActorFloatingLabelEditPart.VISUAL_ID)); + label6095.setLayoutConstraint(NotationFactory.eINSTANCE.createLocation()); + Location location6095 = (Location) label6095.getLayoutConstraint(); + location6095.setX(0); + location6095.setY(5); return node; } @@ -938,6 +1023,11 @@ public class UMLViewProvider extends AbstractProvider implements IViewProvider { PreferenceInitializerForElementHelper.initFontStyleFromPrefs(node, prefStore, "DeploymentSpecification"); Node label5161 = createLabel(node, UMLVisualIDRegistry.getType(DeploymentSpecificationNameEditPart.VISUAL_ID)); + Node label6096 = createLabel(node, UMLVisualIDRegistry.getType(DeploymentSpecificationFloatingLabelEditPart.VISUAL_ID)); + label6096.setLayoutConstraint(NotationFactory.eINSTANCE.createLocation()); + Location location6096 = (Location) label6096.getLayoutConstraint(); + location6096.setX(0); + location6096.setY(5); return node; } @@ -956,6 +1046,11 @@ public class UMLViewProvider extends AbstractProvider implements IViewProvider { PreferenceInitializerForElementHelper.initFontStyleFromPrefs(node, prefStore, "Artifact"); Node label5162 = createLabel(node, UMLVisualIDRegistry.getType(ArtifactNameEditPart.VISUAL_ID)); + Node label6097 = createLabel(node, UMLVisualIDRegistry.getType(ArtifactFloatingLabelEditPart.VISUAL_ID)); + label6097.setLayoutConstraint(NotationFactory.eINSTANCE.createLocation()); + Location location6097 = (Location) label6097.getLayoutConstraint(); + location6097.setX(0); + location6097.setY(5); return node; } @@ -974,6 +1069,11 @@ public class UMLViewProvider extends AbstractProvider implements IViewProvider { PreferenceInitializerForElementHelper.initFontStyleFromPrefs(node, prefStore, "InformationItem"); Node label5163 = createLabel(node, UMLVisualIDRegistry.getType(InformationItemNameEditPart.VISUAL_ID)); + Node label6098 = createLabel(node, UMLVisualIDRegistry.getType(InformationItemFloatingLabelEditPart.VISUAL_ID)); + label6098.setLayoutConstraint(NotationFactory.eINSTANCE.createLocation()); + Location location6098 = (Location) label6098.getLayoutConstraint(); + location6098.setX(0); + location6098.setY(5); return node; } @@ -992,6 +1092,11 @@ public class UMLViewProvider extends AbstractProvider implements IViewProvider { PreferenceInitializerForElementHelper.initFontStyleFromPrefs(node, prefStore, "Signal"); Node label5164 = createLabel(node, UMLVisualIDRegistry.getType(SignalNameEditPart.VISUAL_ID)); + Node label6099 = createLabel(node, UMLVisualIDRegistry.getType(SignalFloatingLabelEditPart.VISUAL_ID)); + label6099.setLayoutConstraint(NotationFactory.eINSTANCE.createLocation()); + Location location6099 = (Location) label6099.getLayoutConstraint(); + location6099.setX(0); + location6099.setY(5); return node; } @@ -1010,6 +1115,11 @@ public class UMLViewProvider extends AbstractProvider implements IViewProvider { PreferenceInitializerForElementHelper.initFontStyleFromPrefs(node, prefStore, "UseCase"); Node label5165 = createLabel(node, UMLVisualIDRegistry.getType(UseCaseNameEditPart.VISUAL_ID)); + Node label6100 = createLabel(node, UMLVisualIDRegistry.getType(UseCaseFloatingLabelEditPart.VISUAL_ID)); + label6100.setLayoutConstraint(NotationFactory.eINSTANCE.createLocation()); + Location location6100 = (Location) label6100.getLayoutConstraint(); + location6100.setX(0); + location6100.setY(5); return node; } @@ -1028,6 +1138,11 @@ public class UMLViewProvider extends AbstractProvider implements IViewProvider { PreferenceInitializerForElementHelper.initFontStyleFromPrefs(node, prefStore, "SignalEvent"); Node label5166 = createLabel(node, UMLVisualIDRegistry.getType(SignalEventNameEditPart.VISUAL_ID)); + Node label6101 = createLabel(node, UMLVisualIDRegistry.getType(SignalEventFloatingLabelEditPart.VISUAL_ID)); + label6101.setLayoutConstraint(NotationFactory.eINSTANCE.createLocation()); + Location location6101 = (Location) label6101.getLayoutConstraint(); + location6101.setX(0); + location6101.setY(5); return node; } @@ -1046,6 +1161,11 @@ public class UMLViewProvider extends AbstractProvider implements IViewProvider { PreferenceInitializerForElementHelper.initFontStyleFromPrefs(node, prefStore, "CallEvent"); Node label5167 = createLabel(node, UMLVisualIDRegistry.getType(CallEventNameEditPart.VISUAL_ID)); + Node label6102 = createLabel(node, UMLVisualIDRegistry.getType(CallEventFloatingLabelEditPart.VISUAL_ID)); + label6102.setLayoutConstraint(NotationFactory.eINSTANCE.createLocation()); + Location location6102 = (Location) label6102.getLayoutConstraint(); + location6102.setX(0); + location6102.setY(5); return node; } @@ -1064,6 +1184,11 @@ public class UMLViewProvider extends AbstractProvider implements IViewProvider { PreferenceInitializerForElementHelper.initFontStyleFromPrefs(node, prefStore, "AnyReceiveEvent"); Node label5168 = createLabel(node, UMLVisualIDRegistry.getType(AnyReceiveEventNameEditPart.VISUAL_ID)); + Node label6103 = createLabel(node, UMLVisualIDRegistry.getType(AnyReceiveEventFloatingLabelEditPart.VISUAL_ID)); + label6103.setLayoutConstraint(NotationFactory.eINSTANCE.createLocation()); + Location location6103 = (Location) label6103.getLayoutConstraint(); + location6103.setX(0); + location6103.setY(5); return node; } @@ -1082,6 +1207,11 @@ public class UMLViewProvider extends AbstractProvider implements IViewProvider { PreferenceInitializerForElementHelper.initFontStyleFromPrefs(node, prefStore, "ChangeEvent"); Node label5171 = createLabel(node, UMLVisualIDRegistry.getType(ChangeEventNameEditPart.VISUAL_ID)); + Node label6104 = createLabel(node, UMLVisualIDRegistry.getType(ChangeEventFloatingLabelEditPart.VISUAL_ID)); + label6104.setLayoutConstraint(NotationFactory.eINSTANCE.createLocation()); + Location location6104 = (Location) label6104.getLayoutConstraint(); + location6104.setX(0); + location6104.setY(5); return node; } @@ -1100,6 +1230,11 @@ public class UMLViewProvider extends AbstractProvider implements IViewProvider { PreferenceInitializerForElementHelper.initFontStyleFromPrefs(node, prefStore, "TimeEvent"); Node label5172 = createLabel(node, UMLVisualIDRegistry.getType(TimeEventNameEditPart.VISUAL_ID)); + Node label6105 = createLabel(node, UMLVisualIDRegistry.getType(TimeEventFloatingLabelEditPart.VISUAL_ID)); + label6105.setLayoutConstraint(NotationFactory.eINSTANCE.createLocation()); + Location location6105 = (Location) label6105.getLayoutConstraint(); + location6105.setX(0); + location6105.setY(5); return node; } @@ -1172,6 +1307,11 @@ public class UMLViewProvider extends AbstractProvider implements IViewProvider { PreferenceInitializerForElementHelper.initFontStyleFromPrefs(node, prefStore, "LiteralBoolean"); Node label5178 = createLabel(node, UMLVisualIDRegistry.getType(LiteralBooleanNameEditPart.VISUAL_ID)); + Node label6106 = createLabel(node, UMLVisualIDRegistry.getType(LiteralBooleanFloatingLabelEditPart.VISUAL_ID)); + label6106.setLayoutConstraint(NotationFactory.eINSTANCE.createLocation()); + Location location6106 = (Location) label6106.getLayoutConstraint(); + location6106.setX(0); + location6106.setY(5); return node; } @@ -1190,6 +1330,11 @@ public class UMLViewProvider extends AbstractProvider implements IViewProvider { PreferenceInitializerForElementHelper.initFontStyleFromPrefs(node, prefStore, "LiteralInteger"); Node label5179 = createLabel(node, UMLVisualIDRegistry.getType(LiteralIntegerNameEditPart.VISUAL_ID)); + Node label6107 = createLabel(node, UMLVisualIDRegistry.getType(LiteralIntegerFloatingLabelEditPart.VISUAL_ID)); + label6107.setLayoutConstraint(NotationFactory.eINSTANCE.createLocation()); + Location location6107 = (Location) label6107.getLayoutConstraint(); + location6107.setX(0); + location6107.setY(5); return node; } @@ -1208,6 +1353,11 @@ public class UMLViewProvider extends AbstractProvider implements IViewProvider { PreferenceInitializerForElementHelper.initFontStyleFromPrefs(node, prefStore, "LiteralNull"); Node label5180 = createLabel(node, UMLVisualIDRegistry.getType(LiteralNullNameEditPart.VISUAL_ID)); + Node label6108 = createLabel(node, UMLVisualIDRegistry.getType(LiteralNullFloatingLabelEditPart.VISUAL_ID)); + label6108.setLayoutConstraint(NotationFactory.eINSTANCE.createLocation()); + Location location6108 = (Location) label6108.getLayoutConstraint(); + location6108.setX(0); + location6108.setY(5); return node; } @@ -1226,6 +1376,11 @@ public class UMLViewProvider extends AbstractProvider implements IViewProvider { PreferenceInitializerForElementHelper.initFontStyleFromPrefs(node, prefStore, "LiteralString"); Node label5181 = createLabel(node, UMLVisualIDRegistry.getType(LiteralStringNameEditPart.VISUAL_ID)); + Node label6109 = createLabel(node, UMLVisualIDRegistry.getType(LiteralStringFloatingLabelEditPart.VISUAL_ID)); + label6109.setLayoutConstraint(NotationFactory.eINSTANCE.createLocation()); + Location location6109 = (Location) label6109.getLayoutConstraint(); + location6109.setX(0); + location6109.setY(5); return node; } @@ -1244,6 +1399,11 @@ public class UMLViewProvider extends AbstractProvider implements IViewProvider { PreferenceInitializerForElementHelper.initFontStyleFromPrefs(node, prefStore, "LiteralUnlimitedNatural"); Node label5182 = createLabel(node, UMLVisualIDRegistry.getType(LiteralUnlimitedNaturalNameEditPart.VISUAL_ID)); + Node label6110 = createLabel(node, UMLVisualIDRegistry.getType(LiteralUnlimitedNaturalFloatingLabelEditPart.VISUAL_ID)); + label6110.setLayoutConstraint(NotationFactory.eINSTANCE.createLocation()); + Location location6110 = (Location) label6110.getLayoutConstraint(); + location6110.setX(0); + location6110.setY(5); return node; } @@ -1262,6 +1422,11 @@ public class UMLViewProvider extends AbstractProvider implements IViewProvider { PreferenceInitializerForElementHelper.initFontStyleFromPrefs(node, prefStore, "StringExpression"); Node label5183 = createLabel(node, UMLVisualIDRegistry.getType(StringExpressionNameEditPart.VISUAL_ID)); + Node label6111 = createLabel(node, UMLVisualIDRegistry.getType(StringExpressionFloatingLabelEditPart.VISUAL_ID)); + label6111.setLayoutConstraint(NotationFactory.eINSTANCE.createLocation()); + Location location6111 = (Location) label6111.getLayoutConstraint(); + location6111.setX(0); + location6111.setY(5); return node; } @@ -1280,6 +1445,11 @@ public class UMLViewProvider extends AbstractProvider implements IViewProvider { PreferenceInitializerForElementHelper.initFontStyleFromPrefs(node, prefStore, "OpaqueExpression"); Node label5184 = createLabel(node, UMLVisualIDRegistry.getType(OpaqueExpressionNameEditPart.VISUAL_ID)); + Node label6112 = createLabel(node, UMLVisualIDRegistry.getType(OpaqueExpressionFloatingLabelEditPart.VISUAL_ID)); + label6112.setLayoutConstraint(NotationFactory.eINSTANCE.createLocation()); + Location location6112 = (Location) label6112.getLayoutConstraint(); + location6112.setX(0); + location6112.setY(5); return node; } @@ -1298,6 +1468,11 @@ public class UMLViewProvider extends AbstractProvider implements IViewProvider { PreferenceInitializerForElementHelper.initFontStyleFromPrefs(node, prefStore, "TimeExpression"); Node label5185 = createLabel(node, UMLVisualIDRegistry.getType(TimeExpressionNameEditPart.VISUAL_ID)); + Node label6113 = createLabel(node, UMLVisualIDRegistry.getType(TimeExpressionFloatingLabelEditPart.VISUAL_ID)); + label6113.setLayoutConstraint(NotationFactory.eINSTANCE.createLocation()); + Location location6113 = (Location) label6113.getLayoutConstraint(); + location6113.setX(0); + location6113.setY(5); return node; } @@ -1316,6 +1491,11 @@ public class UMLViewProvider extends AbstractProvider implements IViewProvider { PreferenceInitializerForElementHelper.initFontStyleFromPrefs(node, prefStore, "Expression"); Node label5186 = createLabel(node, UMLVisualIDRegistry.getType(ExpressionNameEditPart.VISUAL_ID)); + Node label6114 = createLabel(node, UMLVisualIDRegistry.getType(ExpressionFloatingLabelEditPart.VISUAL_ID)); + label6114.setLayoutConstraint(NotationFactory.eINSTANCE.createLocation()); + Location location6114 = (Location) label6114.getLayoutConstraint(); + location6114.setX(0); + location6114.setY(5); return node; } @@ -1334,6 +1514,11 @@ public class UMLViewProvider extends AbstractProvider implements IViewProvider { PreferenceInitializerForElementHelper.initFontStyleFromPrefs(node, prefStore, "Duration"); Node label5187 = createLabel(node, UMLVisualIDRegistry.getType(DurationNameEditPart.VISUAL_ID)); + Node label6115 = createLabel(node, UMLVisualIDRegistry.getType(DurationFloatingLabelEditPart.VISUAL_ID)); + label6115.setLayoutConstraint(NotationFactory.eINSTANCE.createLocation()); + Location location6115 = (Location) label6115.getLayoutConstraint(); + location6115.setX(0); + location6115.setY(5); return node; } @@ -1352,6 +1537,11 @@ public class UMLViewProvider extends AbstractProvider implements IViewProvider { PreferenceInitializerForElementHelper.initFontStyleFromPrefs(node, prefStore, "TimeInterval"); Node label5188 = createLabel(node, UMLVisualIDRegistry.getType(TimeIntervalNameEditPart.VISUAL_ID)); + Node label6116 = createLabel(node, UMLVisualIDRegistry.getType(TimeIntervalFloatingLabelEditPart.VISUAL_ID)); + label6116.setLayoutConstraint(NotationFactory.eINSTANCE.createLocation()); + Location location6116 = (Location) label6116.getLayoutConstraint(); + location6116.setX(0); + location6116.setY(5); return node; } @@ -1370,6 +1560,11 @@ public class UMLViewProvider extends AbstractProvider implements IViewProvider { PreferenceInitializerForElementHelper.initFontStyleFromPrefs(node, prefStore, "DurationInterval"); Node label5189 = createLabel(node, UMLVisualIDRegistry.getType(DurationIntervalNameEditPart.VISUAL_ID)); + Node label6117 = createLabel(node, UMLVisualIDRegistry.getType(DurationIntervalFloatingLabelEditPart.VISUAL_ID)); + label6117.setLayoutConstraint(NotationFactory.eINSTANCE.createLocation()); + Location location6117 = (Location) label6117.getLayoutConstraint(); + location6117.setX(0); + location6117.setY(5); return node; } @@ -1388,6 +1583,11 @@ public class UMLViewProvider extends AbstractProvider implements IViewProvider { PreferenceInitializerForElementHelper.initFontStyleFromPrefs(node, prefStore, "Interval"); Node label5190 = createLabel(node, UMLVisualIDRegistry.getType(IntervalNameEditPart.VISUAL_ID)); + Node label6118 = createLabel(node, UMLVisualIDRegistry.getType(IntervalFloatingLabelEditPart.VISUAL_ID)); + label6118.setLayoutConstraint(NotationFactory.eINSTANCE.createLocation()); + Location location6118 = (Location) label6118.getLayoutConstraint(); + location6118.setX(0); + location6118.setY(5); return node; } @@ -1406,6 +1606,11 @@ public class UMLViewProvider extends AbstractProvider implements IViewProvider { PreferenceInitializerForElementHelper.initFontStyleFromPrefs(node, prefStore, "InstanceValue"); Node label5191 = createLabel(node, UMLVisualIDRegistry.getType(InstanceValueNameEditPart.VISUAL_ID)); + Node label6119 = createLabel(node, UMLVisualIDRegistry.getType(InstanceValueFloatingLabelEditPart.VISUAL_ID)); + label6119.setLayoutConstraint(NotationFactory.eINSTANCE.createLocation()); + Location location6119 = (Location) label6119.getLayoutConstraint(); + location6119.setX(0); + location6119.setY(5); return node; } @@ -1534,6 +1739,11 @@ public class UMLViewProvider extends AbstractProvider implements IViewProvider { // initializeFromPreferences final IPreferenceStore prefStore = (IPreferenceStore) preferencesHint.getPreferenceStore(); + Node label6053 = createLabel(node, UMLVisualIDRegistry.getType(BehaviorPortFloatingLabelEditPart.VISUAL_ID)); + label6053.setLayoutConstraint(NotationFactory.eINSTANCE.createLocation()); + Location location6053 = (Location) label6053.getLayoutConstraint(); + location6053.setX(0); + location6053.setY(5); return node; } @@ -1603,6 +1813,11 @@ public class UMLViewProvider extends AbstractProvider implements IViewProvider { PreferenceInitializerForElementHelper.initFontStyleFromPrefs(node, prefStore, "Property"); Node label5126 = createLabel(node, UMLVisualIDRegistry.getType(PropertyPartNameEditPartCN.VISUAL_ID)); + Node label6054 = createLabel(node, UMLVisualIDRegistry.getType(PropertyPartFloatingLabelEditPartCN.VISUAL_ID)); + label6054.setLayoutConstraint(NotationFactory.eINSTANCE.createLocation()); + Location location6054 = (Location) label6054.getLayoutConstraint(); + location6054.setX(0); + location6054.setY(5); createCompartment(node, UMLVisualIDRegistry.getType(PropertyPartCompartmentEditPartCN.VISUAL_ID), true, true, false, false); PreferenceInitializerForElementHelper.initCompartmentsStatusFromPrefs(node, prefStore, "Property"); return node; @@ -1622,6 +1837,11 @@ public class UMLViewProvider extends AbstractProvider implements IViewProvider { PreferenceInitializerForElementHelper.initFontStyleFromPrefs(node, prefStore, "CollaborationRole"); Node label5198 = createLabel(node, UMLVisualIDRegistry.getType(CollaborationRoleNameEditPartCN.VISUAL_ID)); + Node label6055 = createLabel(node, UMLVisualIDRegistry.getType(CollaborationRoleFloatingLabelEditPartCN.VISUAL_ID)); + label6055.setLayoutConstraint(NotationFactory.eINSTANCE.createLocation()); + Location location6055 = (Location) label6055.getLayoutConstraint(); + location6055.setX(0); + location6055.setY(5); return node; } @@ -1639,6 +1859,11 @@ public class UMLViewProvider extends AbstractProvider implements IViewProvider { PreferenceInitializerForElementHelper.initFontStyleFromPrefs(node, prefStore, "CollaborationUse"); Node label5127 = createLabel(node, UMLVisualIDRegistry.getType(CollaborationUseNameEditPart.VISUAL_ID)); + Node label6056 = createLabel(node, UMLVisualIDRegistry.getType(CollaborationUseFloatingLabelEditPartCN.VISUAL_ID)); + label6056.setLayoutConstraint(NotationFactory.eINSTANCE.createLocation()); + Location location6056 = (Location) label6056.getLayoutConstraint(); + location6056.setX(0); + location6056.setY(5); return node; } @@ -1656,6 +1881,11 @@ public class UMLViewProvider extends AbstractProvider implements IViewProvider { PreferenceInitializerForElementHelper.initFontStyleFromPrefs(node, prefStore, "Activity"); Node label5128 = createLabel(node, UMLVisualIDRegistry.getType(ActivityCompositeNameEditPartCN.VISUAL_ID)); + Node label6057 = createLabel(node, UMLVisualIDRegistry.getType(ActivityCompositeFloatingLabelEditPartCN.VISUAL_ID)); + label6057.setLayoutConstraint(NotationFactory.eINSTANCE.createLocation()); + Location location6057 = (Location) label6057.getLayoutConstraint(); + location6057.setX(0); + location6057.setY(5); createCompartment(node, UMLVisualIDRegistry.getType(ActivityCompositeCompartmentEditPartCN.VISUAL_ID), true, true, false, false); PreferenceInitializerForElementHelper.initCompartmentsStatusFromPrefs(node, prefStore, "Activity"); return node; @@ -1675,6 +1905,11 @@ public class UMLViewProvider extends AbstractProvider implements IViewProvider { PreferenceInitializerForElementHelper.initFontStyleFromPrefs(node, prefStore, "Interaction"); Node label5129 = createLabel(node, UMLVisualIDRegistry.getType(InteractionCompositeNameEditPartCN.VISUAL_ID)); + Node label6058 = createLabel(node, UMLVisualIDRegistry.getType(InteractionCompositeFloatingLabelEditPartCN.VISUAL_ID)); + label6058.setLayoutConstraint(NotationFactory.eINSTANCE.createLocation()); + Location location6058 = (Location) label6058.getLayoutConstraint(); + location6058.setX(0); + location6058.setY(5); createCompartment(node, UMLVisualIDRegistry.getType(InteractionCompositeCompartmentEditPartCN.VISUAL_ID), true, true, false, false); PreferenceInitializerForElementHelper.initCompartmentsStatusFromPrefs(node, prefStore, "Interaction"); return node; @@ -1694,6 +1929,11 @@ public class UMLViewProvider extends AbstractProvider implements IViewProvider { PreferenceInitializerForElementHelper.initFontStyleFromPrefs(node, prefStore, "ProtocolStateMachine"); Node label5130 = createLabel(node, UMLVisualIDRegistry.getType(ProtocolStateMachineCompositeNameEditPartCN.VISUAL_ID)); + Node label6059 = createLabel(node, UMLVisualIDRegistry.getType(ProtocolStateMachineCompositeFloatingLabelEditPartCN.VISUAL_ID)); + label6059.setLayoutConstraint(NotationFactory.eINSTANCE.createLocation()); + Location location6059 = (Location) label6059.getLayoutConstraint(); + location6059.setX(0); + location6059.setY(5); createCompartment(node, UMLVisualIDRegistry.getType(ProtocolStateMachineCompositeCompartmentEditPartCN.VISUAL_ID), true, true, false, false); PreferenceInitializerForElementHelper.initCompartmentsStatusFromPrefs(node, prefStore, "ProtocolStateMachine"); return node; @@ -1713,6 +1953,11 @@ public class UMLViewProvider extends AbstractProvider implements IViewProvider { PreferenceInitializerForElementHelper.initFontStyleFromPrefs(node, prefStore, "StateMachine"); Node label5131 = createLabel(node, UMLVisualIDRegistry.getType(StateMachineCompositeNameEditPartCN.VISUAL_ID)); + Node label6060 = createLabel(node, UMLVisualIDRegistry.getType(StateMachineCompositeFloatingLabelEditPartCN.VISUAL_ID)); + label6060.setLayoutConstraint(NotationFactory.eINSTANCE.createLocation()); + Location location6060 = (Location) label6060.getLayoutConstraint(); + location6060.setX(0); + location6060.setY(5); createCompartment(node, UMLVisualIDRegistry.getType(StateMachineCompositeCompartmentEditPartCN.VISUAL_ID), true, true, false, false); PreferenceInitializerForElementHelper.initCompartmentsStatusFromPrefs(node, prefStore, "StateMachine"); return node; @@ -1732,6 +1977,11 @@ public class UMLViewProvider extends AbstractProvider implements IViewProvider { PreferenceInitializerForElementHelper.initFontStyleFromPrefs(node, prefStore, "FunctionBehavior"); Node label5132 = createLabel(node, UMLVisualIDRegistry.getType(FunctionBehaviorCompositeNameEditPartCN.VISUAL_ID)); + Node label6061 = createLabel(node, UMLVisualIDRegistry.getType(FunctionBehaviorCompositeFloatingLabelEditPartCN.VISUAL_ID)); + label6061.setLayoutConstraint(NotationFactory.eINSTANCE.createLocation()); + Location location6061 = (Location) label6061.getLayoutConstraint(); + location6061.setX(0); + location6061.setY(5); createCompartment(node, UMLVisualIDRegistry.getType(FunctionBehaviorCompositeCompartmentEditPartCN.VISUAL_ID), true, true, false, false); PreferenceInitializerForElementHelper.initCompartmentsStatusFromPrefs(node, prefStore, "FunctionBehavior"); return node; @@ -1751,6 +2001,11 @@ public class UMLViewProvider extends AbstractProvider implements IViewProvider { PreferenceInitializerForElementHelper.initFontStyleFromPrefs(node, prefStore, "OpaqueBehavior"); Node label5133 = createLabel(node, UMLVisualIDRegistry.getType(OpaqueBehaviorCompositeNameEditPartCN.VISUAL_ID)); + Node label6062 = createLabel(node, UMLVisualIDRegistry.getType(OpaqueBehaviorCompositeFloatingLabelEditPartCN.VISUAL_ID)); + label6062.setLayoutConstraint(NotationFactory.eINSTANCE.createLocation()); + Location location6062 = (Location) label6062.getLayoutConstraint(); + location6062.setX(0); + location6062.setY(5); createCompartment(node, UMLVisualIDRegistry.getType(OpaqueBehaviorCompositeCompartmentEditPartCN.VISUAL_ID), true, true, false, false); PreferenceInitializerForElementHelper.initCompartmentsStatusFromPrefs(node, prefStore, "OpaqueBehavior"); return node; @@ -1770,6 +2025,11 @@ public class UMLViewProvider extends AbstractProvider implements IViewProvider { PreferenceInitializerForElementHelper.initFontStyleFromPrefs(node, prefStore, "Component"); Node label5137 = createLabel(node, UMLVisualIDRegistry.getType(ComponentCompositeNameEditPartCN.VISUAL_ID)); + Node label6063 = createLabel(node, UMLVisualIDRegistry.getType(ComponentCompositeFloatingLabelEditPartCN.VISUAL_ID)); + label6063.setLayoutConstraint(NotationFactory.eINSTANCE.createLocation()); + Location location6063 = (Location) label6063.getLayoutConstraint(); + location6063.setX(0); + location6063.setY(5); createCompartment(node, UMLVisualIDRegistry.getType(ComponentCompositeCompartmentEditPartCN.VISUAL_ID), true, true, false, false); PreferenceInitializerForElementHelper.initCompartmentsStatusFromPrefs(node, prefStore, "Component"); return node; @@ -1789,6 +2049,11 @@ public class UMLViewProvider extends AbstractProvider implements IViewProvider { PreferenceInitializerForElementHelper.initFontStyleFromPrefs(node, prefStore, "Device"); Node label5138 = createLabel(node, UMLVisualIDRegistry.getType(DeviceCompositeNameEditPartCN.VISUAL_ID)); + Node label6064 = createLabel(node, UMLVisualIDRegistry.getType(DeviceCompositeFloatingLabelEditPartCN.VISUAL_ID)); + label6064.setLayoutConstraint(NotationFactory.eINSTANCE.createLocation()); + Location location6064 = (Location) label6064.getLayoutConstraint(); + location6064.setX(0); + location6064.setY(5); createCompartment(node, UMLVisualIDRegistry.getType(DeviceCompositeCompartmentEditPartCN.VISUAL_ID), true, true, false, false); PreferenceInitializerForElementHelper.initCompartmentsStatusFromPrefs(node, prefStore, "Device"); return node; @@ -1808,6 +2073,11 @@ public class UMLViewProvider extends AbstractProvider implements IViewProvider { PreferenceInitializerForElementHelper.initFontStyleFromPrefs(node, prefStore, "ExecutionEnvironment"); Node label5139 = createLabel(node, UMLVisualIDRegistry.getType(ExecutionEnvironmentCompositeNameEditPartCN.VISUAL_ID)); + Node label6065 = createLabel(node, UMLVisualIDRegistry.getType(ExecutionEnvironmentCompositeFloatingLabelEditPartCN.VISUAL_ID)); + label6065.setLayoutConstraint(NotationFactory.eINSTANCE.createLocation()); + Location location6065 = (Location) label6065.getLayoutConstraint(); + location6065.setX(0); + location6065.setY(5); createCompartment(node, UMLVisualIDRegistry.getType(ExecutionEnvironmentCompositeCompartmentEditPartCN.VISUAL_ID), true, true, false, false); PreferenceInitializerForElementHelper.initCompartmentsStatusFromPrefs(node, prefStore, "ExecutionEnvironment"); return node; @@ -1827,6 +2097,11 @@ public class UMLViewProvider extends AbstractProvider implements IViewProvider { PreferenceInitializerForElementHelper.initFontStyleFromPrefs(node, prefStore, "Node"); Node label5140 = createLabel(node, UMLVisualIDRegistry.getType(NodeCompositeNameEditPartCN.VISUAL_ID)); + Node label6066 = createLabel(node, UMLVisualIDRegistry.getType(NodeCompositeFloatingLabelEditPartCN.VISUAL_ID)); + label6066.setLayoutConstraint(NotationFactory.eINSTANCE.createLocation()); + Location location6066 = (Location) label6066.getLayoutConstraint(); + location6066.setX(0); + location6066.setY(5); createCompartment(node, UMLVisualIDRegistry.getType(NodeCompositeCompartmentEditPartCN.VISUAL_ID), true, true, false, false); PreferenceInitializerForElementHelper.initCompartmentsStatusFromPrefs(node, prefStore, "Node"); return node; @@ -1846,6 +2121,11 @@ public class UMLViewProvider extends AbstractProvider implements IViewProvider { PreferenceInitializerForElementHelper.initFontStyleFromPrefs(node, prefStore, "Class"); Node label5155 = createLabel(node, UMLVisualIDRegistry.getType(ClassCompositeNameEditPartCN.VISUAL_ID)); + Node label6067 = createLabel(node, UMLVisualIDRegistry.getType(ClassCompositeFloatingLabelEditPartCN.VISUAL_ID)); + label6067.setLayoutConstraint(NotationFactory.eINSTANCE.createLocation()); + Location location6067 = (Location) label6067.getLayoutConstraint(); + location6067.setX(0); + location6067.setY(5); createCompartment(node, UMLVisualIDRegistry.getType(ClassCompositeCompartmentEditPartCN.VISUAL_ID), true, true, false, false); PreferenceInitializerForElementHelper.initCompartmentsStatusFromPrefs(node, prefStore, "Class"); return node; @@ -1865,6 +2145,11 @@ public class UMLViewProvider extends AbstractProvider implements IViewProvider { PreferenceInitializerForElementHelper.initFontStyleFromPrefs(node, prefStore, "Collaboration"); Node label5141 = createLabel(node, UMLVisualIDRegistry.getType(CollaborationCompositeNameEditPartCN.VISUAL_ID)); + Node label6068 = createLabel(node, UMLVisualIDRegistry.getType(CollaborationCompositeFloatingLabelEditPartCN.VISUAL_ID)); + label6068.setLayoutConstraint(NotationFactory.eINSTANCE.createLocation()); + Location location6068 = (Location) label6068.getLayoutConstraint(); + location6068.setX(0); + location6068.setY(5); createCompartment(node, UMLVisualIDRegistry.getType(CollaborationCompositeCompartmentEditPartCN.VISUAL_ID), true, true, false, false); PreferenceInitializerForElementHelper.initCompartmentsStatusFromPrefs(node, prefStore, "Collaboration"); return node; @@ -1884,6 +2169,11 @@ public class UMLViewProvider extends AbstractProvider implements IViewProvider { PreferenceInitializerForElementHelper.initFontStyleFromPrefs(node, prefStore, "Interface"); Node label5154 = createLabel(node, UMLVisualIDRegistry.getType(InterfaceNameEditPartCN.VISUAL_ID)); + Node label6069 = createLabel(node, UMLVisualIDRegistry.getType(InterfaceFloatingLabelEditPartCN.VISUAL_ID)); + label6069.setLayoutConstraint(NotationFactory.eINSTANCE.createLocation()); + Location location6069 = (Location) label6069.getLayoutConstraint(); + location6069.setX(0); + location6069.setY(5); return node; } @@ -1901,6 +2191,11 @@ public class UMLViewProvider extends AbstractProvider implements IViewProvider { PreferenceInitializerForElementHelper.initFontStyleFromPrefs(node, prefStore, "PrimitiveType"); Node label5134 = createLabel(node, UMLVisualIDRegistry.getType(PrimitiveTypeNameEditPartCN.VISUAL_ID)); + Node label6070 = createLabel(node, UMLVisualIDRegistry.getType(PrimitiveTypeFloatingLabelEditPartCN.VISUAL_ID)); + label6070.setLayoutConstraint(NotationFactory.eINSTANCE.createLocation()); + Location location6070 = (Location) label6070.getLayoutConstraint(); + location6070.setX(0); + location6070.setY(5); return node; } @@ -1918,6 +2213,11 @@ public class UMLViewProvider extends AbstractProvider implements IViewProvider { PreferenceInitializerForElementHelper.initFontStyleFromPrefs(node, prefStore, "Enumeration"); Node label5135 = createLabel(node, UMLVisualIDRegistry.getType(EnumerationNameEditPartCN.VISUAL_ID)); + Node label6071 = createLabel(node, UMLVisualIDRegistry.getType(EnumerationFloatingLabelEditPartCN.VISUAL_ID)); + label6071.setLayoutConstraint(NotationFactory.eINSTANCE.createLocation()); + Location location6071 = (Location) label6071.getLayoutConstraint(); + location6071.setX(0); + location6071.setY(5); createCompartment(node, UMLVisualIDRegistry.getType(EnumerationEnumerationLiteralCompartmentEditPartCN.VISUAL_ID), true, true, true, true); PreferenceInitializerForElementHelper.initCompartmentsStatusFromPrefs(node, prefStore, "Enumeration"); return node; @@ -1937,6 +2237,11 @@ public class UMLViewProvider extends AbstractProvider implements IViewProvider { PreferenceInitializerForElementHelper.initFontStyleFromPrefs(node, prefStore, "DataType"); Node label5136 = createLabel(node, UMLVisualIDRegistry.getType(DataTypeNameEditPartCN.VISUAL_ID)); + Node label6072 = createLabel(node, UMLVisualIDRegistry.getType(DataTypeFloatingLabelEditPartCN.VISUAL_ID)); + label6072.setLayoutConstraint(NotationFactory.eINSTANCE.createLocation()); + Location location6072 = (Location) label6072.getLayoutConstraint(); + location6072.setX(0); + location6072.setY(5); createCompartment(node, UMLVisualIDRegistry.getType(DataTypeAttributeCompartmentEditPartCN.VISUAL_ID), true, true, true, true); createCompartment(node, UMLVisualIDRegistry.getType(DataTypeOperationCompartmentEditPartCN.VISUAL_ID), true, true, true, true); PreferenceInitializerForElementHelper.initCompartmentsStatusFromPrefs(node, prefStore, "DataType"); @@ -1957,6 +2262,11 @@ public class UMLViewProvider extends AbstractProvider implements IViewProvider { PreferenceInitializerForElementHelper.initFontStyleFromPrefs(node, prefStore, "Actor"); Node label5144 = createLabel(node, UMLVisualIDRegistry.getType(ActorNameEditPartCN.VISUAL_ID)); + Node label6073 = createLabel(node, UMLVisualIDRegistry.getType(ActorFloatingLabelEditPartCN.VISUAL_ID)); + label6073.setLayoutConstraint(NotationFactory.eINSTANCE.createLocation()); + Location location6073 = (Location) label6073.getLayoutConstraint(); + location6073.setX(0); + location6073.setY(5); return node; } @@ -1974,6 +2284,11 @@ public class UMLViewProvider extends AbstractProvider implements IViewProvider { PreferenceInitializerForElementHelper.initFontStyleFromPrefs(node, prefStore, "DeploymentSpecification"); Node label5145 = createLabel(node, UMLVisualIDRegistry.getType(DeploymentSpecificationNameEditPartCN.VISUAL_ID)); + Node label6074 = createLabel(node, UMLVisualIDRegistry.getType(DeploymentSpecificationFloatingLabelEditPartCN.VISUAL_ID)); + label6074.setLayoutConstraint(NotationFactory.eINSTANCE.createLocation()); + Location location6074 = (Location) label6074.getLayoutConstraint(); + location6074.setX(0); + location6074.setY(5); return node; } @@ -1991,6 +2306,11 @@ public class UMLViewProvider extends AbstractProvider implements IViewProvider { PreferenceInitializerForElementHelper.initFontStyleFromPrefs(node, prefStore, "Artifact"); Node label5146 = createLabel(node, UMLVisualIDRegistry.getType(ArtifactNameEditPartCN.VISUAL_ID)); + Node label6075 = createLabel(node, UMLVisualIDRegistry.getType(ArtifactFloatingLabelEditPartCN.VISUAL_ID)); + label6075.setLayoutConstraint(NotationFactory.eINSTANCE.createLocation()); + Location location6075 = (Location) label6075.getLayoutConstraint(); + location6075.setX(0); + location6075.setY(5); return node; } @@ -2008,6 +2328,11 @@ public class UMLViewProvider extends AbstractProvider implements IViewProvider { PreferenceInitializerForElementHelper.initFontStyleFromPrefs(node, prefStore, "InformationItem"); Node label5147 = createLabel(node, UMLVisualIDRegistry.getType(InformationItemNameEditPartCN.VISUAL_ID)); + Node label6076 = createLabel(node, UMLVisualIDRegistry.getType(InformationItemFloatingLabelEditPartCN.VISUAL_ID)); + label6076.setLayoutConstraint(NotationFactory.eINSTANCE.createLocation()); + Location location6076 = (Location) label6076.getLayoutConstraint(); + location6076.setX(0); + location6076.setY(5); return node; } @@ -2025,6 +2350,11 @@ public class UMLViewProvider extends AbstractProvider implements IViewProvider { PreferenceInitializerForElementHelper.initFontStyleFromPrefs(node, prefStore, "Signal"); Node label5148 = createLabel(node, UMLVisualIDRegistry.getType(SignalNameEditPartCN.VISUAL_ID)); + Node label6077 = createLabel(node, UMLVisualIDRegistry.getType(SignalFloatingLabelEditPartCN.VISUAL_ID)); + label6077.setLayoutConstraint(NotationFactory.eINSTANCE.createLocation()); + Location location6077 = (Location) label6077.getLayoutConstraint(); + location6077.setX(0); + location6077.setY(5); return node; } @@ -2042,6 +2372,11 @@ public class UMLViewProvider extends AbstractProvider implements IViewProvider { PreferenceInitializerForElementHelper.initFontStyleFromPrefs(node, prefStore, "UseCase"); Node label5149 = createLabel(node, UMLVisualIDRegistry.getType(UseCaseNameEditPartCN.VISUAL_ID)); + Node label6078 = createLabel(node, UMLVisualIDRegistry.getType(UseCaseFloatingLabelEditPartCN.VISUAL_ID)); + label6078.setLayoutConstraint(NotationFactory.eINSTANCE.createLocation()); + Location location6078 = (Location) label6078.getLayoutConstraint(); + location6078.setX(0); + location6078.setY(5); return node; } @@ -2215,10 +2550,10 @@ public class UMLViewProvider extends AbstractProvider implements IViewProvider { // initializePreferences final IPreferenceStore prefStore = (IPreferenceStore) preferencesHint.getPreferenceStore(); - //org.eclipse.gmf.runtime.notation.Routing routing = org.eclipse.gmf.runtime.notation.Routing.get(prefStore.getInt(org.eclipse.gmf.runtime.diagram.ui.preferences.IPreferenceConstants.PREF_LINE_STYLE)); - //if (routing != null) { - // org.eclipse.gmf.runtime.diagram.core.util.ViewUtil.setStructuralFeatureValue(edge, org.eclipse.gmf.runtime.notation.NotationPackage.eINSTANCE.getRoutingStyle_Routing(), routing); - //} + // org.eclipse.gmf.runtime.notation.Routing routing = org.eclipse.gmf.runtime.notation.Routing.get(prefStore.getInt(org.eclipse.gmf.runtime.diagram.ui.preferences.IPreferenceConstants.PREF_LINE_STYLE)); + // if (routing != null) { + // org.eclipse.gmf.runtime.diagram.core.util.ViewUtil.setStructuralFeatureValue(edge, org.eclipse.gmf.runtime.notation.NotationPackage.eINSTANCE.getRoutingStyle_Routing(), routing); + // } return edge; } @@ -2241,10 +2576,10 @@ public class UMLViewProvider extends AbstractProvider implements IViewProvider { // initializePreferences final IPreferenceStore prefStore = (IPreferenceStore) preferencesHint.getPreferenceStore(); - //org.eclipse.gmf.runtime.notation.Routing routing = org.eclipse.gmf.runtime.notation.Routing.get(prefStore.getInt(org.eclipse.gmf.runtime.diagram.ui.preferences.IPreferenceConstants.PREF_LINE_STYLE)); - //if (routing != null) { - // org.eclipse.gmf.runtime.diagram.core.util.ViewUtil.setStructuralFeatureValue(edge, org.eclipse.gmf.runtime.notation.NotationPackage.eINSTANCE.getRoutingStyle_Routing(), routing); - //} + // org.eclipse.gmf.runtime.notation.Routing routing = org.eclipse.gmf.runtime.notation.Routing.get(prefStore.getInt(org.eclipse.gmf.runtime.diagram.ui.preferences.IPreferenceConstants.PREF_LINE_STYLE)); + // if (routing != null) { + // org.eclipse.gmf.runtime.diagram.core.util.ViewUtil.setStructuralFeatureValue(edge, org.eclipse.gmf.runtime.notation.NotationPackage.eINSTANCE.getRoutingStyle_Routing(), routing); + // } return edge; } @@ -2268,10 +2603,10 @@ public class UMLViewProvider extends AbstractProvider implements IViewProvider { final IPreferenceStore prefStore = (IPreferenceStore) preferencesHint.getPreferenceStore(); PreferenceInitializerForElementHelper.initFontStyleFromPrefs(edge, prefStore, "CommentAnnotatedElement"); - //org.eclipse.gmf.runtime.notation.Routing routing = org.eclipse.gmf.runtime.notation.Routing.get(prefStore.getInt(org.eclipse.gmf.runtime.diagram.ui.preferences.IPreferenceConstants.PREF_LINE_STYLE)); - //if (routing != null) { - // org.eclipse.gmf.runtime.diagram.core.util.ViewUtil.setStructuralFeatureValue(edge, org.eclipse.gmf.runtime.notation.NotationPackage.eINSTANCE.getRoutingStyle_Routing(), routing); - //} + // org.eclipse.gmf.runtime.notation.Routing routing = org.eclipse.gmf.runtime.notation.Routing.get(prefStore.getInt(org.eclipse.gmf.runtime.diagram.ui.preferences.IPreferenceConstants.PREF_LINE_STYLE)); + // if (routing != null) { + // org.eclipse.gmf.runtime.diagram.core.util.ViewUtil.setStructuralFeatureValue(edge, org.eclipse.gmf.runtime.notation.NotationPackage.eINSTANCE.getRoutingStyle_Routing(), routing); + // } return edge; } @@ -2295,10 +2630,10 @@ public class UMLViewProvider extends AbstractProvider implements IViewProvider { final IPreferenceStore prefStore = (IPreferenceStore) preferencesHint.getPreferenceStore(); PreferenceInitializerForElementHelper.initFontStyleFromPrefs(edge, prefStore, "ConstraintConstrainedElement"); - //org.eclipse.gmf.runtime.notation.Routing routing = org.eclipse.gmf.runtime.notation.Routing.get(prefStore.getInt(org.eclipse.gmf.runtime.diagram.ui.preferences.IPreferenceConstants.PREF_LINE_STYLE)); - //if (routing != null) { - // org.eclipse.gmf.runtime.diagram.core.util.ViewUtil.setStructuralFeatureValue(edge, org.eclipse.gmf.runtime.notation.NotationPackage.eINSTANCE.getRoutingStyle_Routing(), routing); - //} + // org.eclipse.gmf.runtime.notation.Routing routing = org.eclipse.gmf.runtime.notation.Routing.get(prefStore.getInt(org.eclipse.gmf.runtime.diagram.ui.preferences.IPreferenceConstants.PREF_LINE_STYLE)); + // if (routing != null) { + // org.eclipse.gmf.runtime.diagram.core.util.ViewUtil.setStructuralFeatureValue(edge, org.eclipse.gmf.runtime.notation.NotationPackage.eINSTANCE.getRoutingStyle_Routing(), routing); + // } return edge; } @@ -2322,10 +2657,10 @@ public class UMLViewProvider extends AbstractProvider implements IViewProvider { final IPreferenceStore prefStore = (IPreferenceStore) preferencesHint.getPreferenceStore(); PreferenceInitializerForElementHelper.initFontStyleFromPrefs(edge, prefStore, "ComponentRealization"); - //org.eclipse.gmf.runtime.notation.Routing routing = org.eclipse.gmf.runtime.notation.Routing.get(prefStore.getInt(org.eclipse.gmf.runtime.diagram.ui.preferences.IPreferenceConstants.PREF_LINE_STYLE)); - //if (routing != null) { - // org.eclipse.gmf.runtime.diagram.core.util.ViewUtil.setStructuralFeatureValue(edge, org.eclipse.gmf.runtime.notation.NotationPackage.eINSTANCE.getRoutingStyle_Routing(), routing); - //} + // org.eclipse.gmf.runtime.notation.Routing routing = org.eclipse.gmf.runtime.notation.Routing.get(prefStore.getInt(org.eclipse.gmf.runtime.diagram.ui.preferences.IPreferenceConstants.PREF_LINE_STYLE)); + // if (routing != null) { + // org.eclipse.gmf.runtime.diagram.core.util.ViewUtil.setStructuralFeatureValue(edge, org.eclipse.gmf.runtime.notation.NotationPackage.eINSTANCE.getRoutingStyle_Routing(), routing); + // } Node label6001 = createLabel(edge, UMLVisualIDRegistry.getType(ComponentRealizationNameEditPart.VISUAL_ID)); label6001.setLayoutConstraint(NotationFactory.eINSTANCE.createLocation()); Location location6001 = (Location) label6001.getLayoutConstraint(); @@ -2359,10 +2694,10 @@ public class UMLViewProvider extends AbstractProvider implements IViewProvider { final IPreferenceStore prefStore = (IPreferenceStore) preferencesHint.getPreferenceStore(); PreferenceInitializerForElementHelper.initFontStyleFromPrefs(edge, prefStore, "InterfaceRealization"); - //org.eclipse.gmf.runtime.notation.Routing routing = org.eclipse.gmf.runtime.notation.Routing.get(prefStore.getInt(org.eclipse.gmf.runtime.diagram.ui.preferences.IPreferenceConstants.PREF_LINE_STYLE)); - //if (routing != null) { - // org.eclipse.gmf.runtime.diagram.core.util.ViewUtil.setStructuralFeatureValue(edge, org.eclipse.gmf.runtime.notation.NotationPackage.eINSTANCE.getRoutingStyle_Routing(), routing); - //} + // org.eclipse.gmf.runtime.notation.Routing routing = org.eclipse.gmf.runtime.notation.Routing.get(prefStore.getInt(org.eclipse.gmf.runtime.diagram.ui.preferences.IPreferenceConstants.PREF_LINE_STYLE)); + // if (routing != null) { + // org.eclipse.gmf.runtime.diagram.core.util.ViewUtil.setStructuralFeatureValue(edge, org.eclipse.gmf.runtime.notation.NotationPackage.eINSTANCE.getRoutingStyle_Routing(), routing); + // } Node label6002 = createLabel(edge, UMLVisualIDRegistry.getType(InterfaceRealizationNameEditPart.VISUAL_ID)); label6002.setLayoutConstraint(NotationFactory.eINSTANCE.createLocation()); Location location6002 = (Location) label6002.getLayoutConstraint(); @@ -2396,10 +2731,10 @@ public class UMLViewProvider extends AbstractProvider implements IViewProvider { final IPreferenceStore prefStore = (IPreferenceStore) preferencesHint.getPreferenceStore(); PreferenceInitializerForElementHelper.initFontStyleFromPrefs(edge, prefStore, "Substitution"); - //org.eclipse.gmf.runtime.notation.Routing routing = org.eclipse.gmf.runtime.notation.Routing.get(prefStore.getInt(org.eclipse.gmf.runtime.diagram.ui.preferences.IPreferenceConstants.PREF_LINE_STYLE)); - //if (routing != null) { - // org.eclipse.gmf.runtime.diagram.core.util.ViewUtil.setStructuralFeatureValue(edge, org.eclipse.gmf.runtime.notation.NotationPackage.eINSTANCE.getRoutingStyle_Routing(), routing); - //} + // org.eclipse.gmf.runtime.notation.Routing routing = org.eclipse.gmf.runtime.notation.Routing.get(prefStore.getInt(org.eclipse.gmf.runtime.diagram.ui.preferences.IPreferenceConstants.PREF_LINE_STYLE)); + // if (routing != null) { + // org.eclipse.gmf.runtime.diagram.core.util.ViewUtil.setStructuralFeatureValue(edge, org.eclipse.gmf.runtime.notation.NotationPackage.eINSTANCE.getRoutingStyle_Routing(), routing); + // } Node label6003 = createLabel(edge, UMLVisualIDRegistry.getType(SubstitutionNameEditPart.VISUAL_ID)); label6003.setLayoutConstraint(NotationFactory.eINSTANCE.createLocation()); Location location6003 = (Location) label6003.getLayoutConstraint(); @@ -2433,10 +2768,10 @@ public class UMLViewProvider extends AbstractProvider implements IViewProvider { final IPreferenceStore prefStore = (IPreferenceStore) preferencesHint.getPreferenceStore(); PreferenceInitializerForElementHelper.initFontStyleFromPrefs(edge, prefStore, "Realization"); - //org.eclipse.gmf.runtime.notation.Routing routing = org.eclipse.gmf.runtime.notation.Routing.get(prefStore.getInt(org.eclipse.gmf.runtime.diagram.ui.preferences.IPreferenceConstants.PREF_LINE_STYLE)); - //if (routing != null) { - // org.eclipse.gmf.runtime.diagram.core.util.ViewUtil.setStructuralFeatureValue(edge, org.eclipse.gmf.runtime.notation.NotationPackage.eINSTANCE.getRoutingStyle_Routing(), routing); - //} + // org.eclipse.gmf.runtime.notation.Routing routing = org.eclipse.gmf.runtime.notation.Routing.get(prefStore.getInt(org.eclipse.gmf.runtime.diagram.ui.preferences.IPreferenceConstants.PREF_LINE_STYLE)); + // if (routing != null) { + // org.eclipse.gmf.runtime.diagram.core.util.ViewUtil.setStructuralFeatureValue(edge, org.eclipse.gmf.runtime.notation.NotationPackage.eINSTANCE.getRoutingStyle_Routing(), routing); + // } Node label6004 = createLabel(edge, UMLVisualIDRegistry.getType(RealizationNameEditPart.VISUAL_ID)); label6004.setLayoutConstraint(NotationFactory.eINSTANCE.createLocation()); Location location6004 = (Location) label6004.getLayoutConstraint(); @@ -2470,10 +2805,10 @@ public class UMLViewProvider extends AbstractProvider implements IViewProvider { final IPreferenceStore prefStore = (IPreferenceStore) preferencesHint.getPreferenceStore(); PreferenceInitializerForElementHelper.initFontStyleFromPrefs(edge, prefStore, "Manifestation"); - //org.eclipse.gmf.runtime.notation.Routing routing = org.eclipse.gmf.runtime.notation.Routing.get(prefStore.getInt(org.eclipse.gmf.runtime.diagram.ui.preferences.IPreferenceConstants.PREF_LINE_STYLE)); - //if (routing != null) { - // org.eclipse.gmf.runtime.diagram.core.util.ViewUtil.setStructuralFeatureValue(edge, org.eclipse.gmf.runtime.notation.NotationPackage.eINSTANCE.getRoutingStyle_Routing(), routing); - //} + // org.eclipse.gmf.runtime.notation.Routing routing = org.eclipse.gmf.runtime.notation.Routing.get(prefStore.getInt(org.eclipse.gmf.runtime.diagram.ui.preferences.IPreferenceConstants.PREF_LINE_STYLE)); + // if (routing != null) { + // org.eclipse.gmf.runtime.diagram.core.util.ViewUtil.setStructuralFeatureValue(edge, org.eclipse.gmf.runtime.notation.NotationPackage.eINSTANCE.getRoutingStyle_Routing(), routing); + // } Node label6005 = createLabel(edge, UMLVisualIDRegistry.getType(ManifestationNameEditPart.VISUAL_ID)); label6005.setLayoutConstraint(NotationFactory.eINSTANCE.createLocation()); Location location6005 = (Location) label6005.getLayoutConstraint(); @@ -2507,10 +2842,10 @@ public class UMLViewProvider extends AbstractProvider implements IViewProvider { final IPreferenceStore prefStore = (IPreferenceStore) preferencesHint.getPreferenceStore(); PreferenceInitializerForElementHelper.initFontStyleFromPrefs(edge, prefStore, "Abstraction"); - //org.eclipse.gmf.runtime.notation.Routing routing = org.eclipse.gmf.runtime.notation.Routing.get(prefStore.getInt(org.eclipse.gmf.runtime.diagram.ui.preferences.IPreferenceConstants.PREF_LINE_STYLE)); - //if (routing != null) { - // org.eclipse.gmf.runtime.diagram.core.util.ViewUtil.setStructuralFeatureValue(edge, org.eclipse.gmf.runtime.notation.NotationPackage.eINSTANCE.getRoutingStyle_Routing(), routing); - //} + // org.eclipse.gmf.runtime.notation.Routing routing = org.eclipse.gmf.runtime.notation.Routing.get(prefStore.getInt(org.eclipse.gmf.runtime.diagram.ui.preferences.IPreferenceConstants.PREF_LINE_STYLE)); + // if (routing != null) { + // org.eclipse.gmf.runtime.diagram.core.util.ViewUtil.setStructuralFeatureValue(edge, org.eclipse.gmf.runtime.notation.NotationPackage.eINSTANCE.getRoutingStyle_Routing(), routing); + // } Node label6006 = createLabel(edge, UMLVisualIDRegistry.getType(AbstractionNameEditPart.VISUAL_ID)); label6006.setLayoutConstraint(NotationFactory.eINSTANCE.createLocation()); Location location6006 = (Location) label6006.getLayoutConstraint(); @@ -2544,10 +2879,10 @@ public class UMLViewProvider extends AbstractProvider implements IViewProvider { final IPreferenceStore prefStore = (IPreferenceStore) preferencesHint.getPreferenceStore(); PreferenceInitializerForElementHelper.initFontStyleFromPrefs(edge, prefStore, "Usage"); - //org.eclipse.gmf.runtime.notation.Routing routing = org.eclipse.gmf.runtime.notation.Routing.get(prefStore.getInt(org.eclipse.gmf.runtime.diagram.ui.preferences.IPreferenceConstants.PREF_LINE_STYLE)); - //if (routing != null) { - // org.eclipse.gmf.runtime.diagram.core.util.ViewUtil.setStructuralFeatureValue(edge, org.eclipse.gmf.runtime.notation.NotationPackage.eINSTANCE.getRoutingStyle_Routing(), routing); - //} + // org.eclipse.gmf.runtime.notation.Routing routing = org.eclipse.gmf.runtime.notation.Routing.get(prefStore.getInt(org.eclipse.gmf.runtime.diagram.ui.preferences.IPreferenceConstants.PREF_LINE_STYLE)); + // if (routing != null) { + // org.eclipse.gmf.runtime.diagram.core.util.ViewUtil.setStructuralFeatureValue(edge, org.eclipse.gmf.runtime.notation.NotationPackage.eINSTANCE.getRoutingStyle_Routing(), routing); + // } Node label6007 = createLabel(edge, UMLVisualIDRegistry.getType(UsageNameEditPart.VISUAL_ID)); label6007.setLayoutConstraint(NotationFactory.eINSTANCE.createLocation()); Location location6007 = (Location) label6007.getLayoutConstraint(); @@ -2581,10 +2916,10 @@ public class UMLViewProvider extends AbstractProvider implements IViewProvider { final IPreferenceStore prefStore = (IPreferenceStore) preferencesHint.getPreferenceStore(); PreferenceInitializerForElementHelper.initFontStyleFromPrefs(edge, prefStore, "Deployment"); - //org.eclipse.gmf.runtime.notation.Routing routing = org.eclipse.gmf.runtime.notation.Routing.get(prefStore.getInt(org.eclipse.gmf.runtime.diagram.ui.preferences.IPreferenceConstants.PREF_LINE_STYLE)); - //if (routing != null) { - // org.eclipse.gmf.runtime.diagram.core.util.ViewUtil.setStructuralFeatureValue(edge, org.eclipse.gmf.runtime.notation.NotationPackage.eINSTANCE.getRoutingStyle_Routing(), routing); - //} + // org.eclipse.gmf.runtime.notation.Routing routing = org.eclipse.gmf.runtime.notation.Routing.get(prefStore.getInt(org.eclipse.gmf.runtime.diagram.ui.preferences.IPreferenceConstants.PREF_LINE_STYLE)); + // if (routing != null) { + // org.eclipse.gmf.runtime.diagram.core.util.ViewUtil.setStructuralFeatureValue(edge, org.eclipse.gmf.runtime.notation.NotationPackage.eINSTANCE.getRoutingStyle_Routing(), routing); + // } Node label6008 = createLabel(edge, UMLVisualIDRegistry.getType(DeploymentNameEditPart.VISUAL_ID)); label6008.setLayoutConstraint(NotationFactory.eINSTANCE.createLocation()); Location location6008 = (Location) label6008.getLayoutConstraint(); @@ -2618,10 +2953,10 @@ public class UMLViewProvider extends AbstractProvider implements IViewProvider { final IPreferenceStore prefStore = (IPreferenceStore) preferencesHint.getPreferenceStore(); PreferenceInitializerForElementHelper.initFontStyleFromPrefs(edge, prefStore, "RoleBinding"); - //org.eclipse.gmf.runtime.notation.Routing routing = org.eclipse.gmf.runtime.notation.Routing.get(prefStore.getInt(org.eclipse.gmf.runtime.diagram.ui.preferences.IPreferenceConstants.PREF_LINE_STYLE)); - //if (routing != null) { - // org.eclipse.gmf.runtime.diagram.core.util.ViewUtil.setStructuralFeatureValue(edge, org.eclipse.gmf.runtime.notation.NotationPackage.eINSTANCE.getRoutingStyle_Routing(), routing); - //} + // org.eclipse.gmf.runtime.notation.Routing routing = org.eclipse.gmf.runtime.notation.Routing.get(prefStore.getInt(org.eclipse.gmf.runtime.diagram.ui.preferences.IPreferenceConstants.PREF_LINE_STYLE)); + // if (routing != null) { + // org.eclipse.gmf.runtime.diagram.core.util.ViewUtil.setStructuralFeatureValue(edge, org.eclipse.gmf.runtime.notation.NotationPackage.eINSTANCE.getRoutingStyle_Routing(), routing); + // } Node label6027 = createLabel(edge, UMLVisualIDRegistry.getType(RoleBindingRoleNameEditPart.VISUAL_ID)); label6027.setLayoutConstraint(NotationFactory.eINSTANCE.createLocation()); Location location6027 = (Location) label6027.getLayoutConstraint(); @@ -2655,10 +2990,10 @@ public class UMLViewProvider extends AbstractProvider implements IViewProvider { final IPreferenceStore prefStore = (IPreferenceStore) preferencesHint.getPreferenceStore(); PreferenceInitializerForElementHelper.initFontStyleFromPrefs(edge, prefStore, "Dependency"); - //org.eclipse.gmf.runtime.notation.Routing routing = org.eclipse.gmf.runtime.notation.Routing.get(prefStore.getInt(org.eclipse.gmf.runtime.diagram.ui.preferences.IPreferenceConstants.PREF_LINE_STYLE)); - //if (routing != null) { - // org.eclipse.gmf.runtime.diagram.core.util.ViewUtil.setStructuralFeatureValue(edge, org.eclipse.gmf.runtime.notation.NotationPackage.eINSTANCE.getRoutingStyle_Routing(), routing); - //} + // org.eclipse.gmf.runtime.notation.Routing routing = org.eclipse.gmf.runtime.notation.Routing.get(prefStore.getInt(org.eclipse.gmf.runtime.diagram.ui.preferences.IPreferenceConstants.PREF_LINE_STYLE)); + // if (routing != null) { + // org.eclipse.gmf.runtime.diagram.core.util.ViewUtil.setStructuralFeatureValue(edge, org.eclipse.gmf.runtime.notation.NotationPackage.eINSTANCE.getRoutingStyle_Routing(), routing); + // } Node label6009 = createLabel(edge, UMLVisualIDRegistry.getType(DependencyNameEditPart.VISUAL_ID)); label6009.setLayoutConstraint(NotationFactory.eINSTANCE.createLocation()); Location location6009 = (Location) label6009.getLayoutConstraint(); @@ -2692,10 +3027,10 @@ public class UMLViewProvider extends AbstractProvider implements IViewProvider { final IPreferenceStore prefStore = (IPreferenceStore) preferencesHint.getPreferenceStore(); PreferenceInitializerForElementHelper.initFontStyleFromPrefs(edge, prefStore, "Connector"); - //org.eclipse.gmf.runtime.notation.Routing routing = org.eclipse.gmf.runtime.notation.Routing.get(prefStore.getInt(org.eclipse.gmf.runtime.diagram.ui.preferences.IPreferenceConstants.PREF_LINE_STYLE)); - //if (routing != null) { - // org.eclipse.gmf.runtime.diagram.core.util.ViewUtil.setStructuralFeatureValue(edge, org.eclipse.gmf.runtime.notation.NotationPackage.eINSTANCE.getRoutingStyle_Routing(), routing); - //} + // org.eclipse.gmf.runtime.notation.Routing routing = org.eclipse.gmf.runtime.notation.Routing.get(prefStore.getInt(org.eclipse.gmf.runtime.diagram.ui.preferences.IPreferenceConstants.PREF_LINE_STYLE)); + // if (routing != null) { + // org.eclipse.gmf.runtime.diagram.core.util.ViewUtil.setStructuralFeatureValue(edge, org.eclipse.gmf.runtime.notation.NotationPackage.eINSTANCE.getRoutingStyle_Routing(), routing); + // } Node label6025 = createLabel(edge, UMLVisualIDRegistry.getType(ConnectorAppliedStereotypeEditPart.VISUAL_ID)); label6025.setLayoutConstraint(NotationFactory.eINSTANCE.createLocation()); Location location6025 = (Location) label6025.getLayoutConstraint(); @@ -2739,10 +3074,10 @@ public class UMLViewProvider extends AbstractProvider implements IViewProvider { final IPreferenceStore prefStore = (IPreferenceStore) preferencesHint.getPreferenceStore(); PreferenceInitializerForElementHelper.initFontStyleFromPrefs(edge, prefStore, "Generalization"); - //org.eclipse.gmf.runtime.notation.Routing routing = org.eclipse.gmf.runtime.notation.Routing.get(prefStore.getInt(org.eclipse.gmf.runtime.diagram.ui.preferences.IPreferenceConstants.PREF_LINE_STYLE)); - //if (routing != null) { - // org.eclipse.gmf.runtime.diagram.core.util.ViewUtil.setStructuralFeatureValue(edge, org.eclipse.gmf.runtime.notation.NotationPackage.eINSTANCE.getRoutingStyle_Routing(), routing); - //} + // org.eclipse.gmf.runtime.notation.Routing routing = org.eclipse.gmf.runtime.notation.Routing.get(prefStore.getInt(org.eclipse.gmf.runtime.diagram.ui.preferences.IPreferenceConstants.PREF_LINE_STYLE)); + // if (routing != null) { + // org.eclipse.gmf.runtime.diagram.core.util.ViewUtil.setStructuralFeatureValue(edge, org.eclipse.gmf.runtime.notation.NotationPackage.eINSTANCE.getRoutingStyle_Routing(), routing); + // } Node label6024 = createLabel(edge, UMLVisualIDRegistry.getType(GeneralizationAppliedStereotypeEditPart.VISUAL_ID)); label6024.setLayoutConstraint(NotationFactory.eINSTANCE.createLocation()); Location location6024 = (Location) label6024.getLayoutConstraint(); @@ -2771,10 +3106,10 @@ public class UMLViewProvider extends AbstractProvider implements IViewProvider { final IPreferenceStore prefStore = (IPreferenceStore) preferencesHint.getPreferenceStore(); PreferenceInitializerForElementHelper.initFontStyleFromPrefs(edge, prefStore, "TimeObservationEvent"); - //org.eclipse.gmf.runtime.notation.Routing routing = org.eclipse.gmf.runtime.notation.Routing.get(prefStore.getInt(org.eclipse.gmf.runtime.diagram.ui.preferences.IPreferenceConstants.PREF_LINE_STYLE)); - //if (routing != null) { - // org.eclipse.gmf.runtime.diagram.core.util.ViewUtil.setStructuralFeatureValue(edge, org.eclipse.gmf.runtime.notation.NotationPackage.eINSTANCE.getRoutingStyle_Routing(), routing); - //} + // org.eclipse.gmf.runtime.notation.Routing routing = org.eclipse.gmf.runtime.notation.Routing.get(prefStore.getInt(org.eclipse.gmf.runtime.diagram.ui.preferences.IPreferenceConstants.PREF_LINE_STYLE)); + // if (routing != null) { + // org.eclipse.gmf.runtime.diagram.core.util.ViewUtil.setStructuralFeatureValue(edge, org.eclipse.gmf.runtime.notation.NotationPackage.eINSTANCE.getRoutingStyle_Routing(), routing); + // } return edge; } @@ -2798,10 +3133,10 @@ public class UMLViewProvider extends AbstractProvider implements IViewProvider { final IPreferenceStore prefStore = (IPreferenceStore) preferencesHint.getPreferenceStore(); PreferenceInitializerForElementHelper.initFontStyleFromPrefs(edge, prefStore, "DurationObservationEvent"); - //org.eclipse.gmf.runtime.notation.Routing routing = org.eclipse.gmf.runtime.notation.Routing.get(prefStore.getInt(org.eclipse.gmf.runtime.diagram.ui.preferences.IPreferenceConstants.PREF_LINE_STYLE)); - //if (routing != null) { - // org.eclipse.gmf.runtime.diagram.core.util.ViewUtil.setStructuralFeatureValue(edge, org.eclipse.gmf.runtime.notation.NotationPackage.eINSTANCE.getRoutingStyle_Routing(), routing); - //} + // org.eclipse.gmf.runtime.notation.Routing routing = org.eclipse.gmf.runtime.notation.Routing.get(prefStore.getInt(org.eclipse.gmf.runtime.diagram.ui.preferences.IPreferenceConstants.PREF_LINE_STYLE)); + // if (routing != null) { + // org.eclipse.gmf.runtime.diagram.core.util.ViewUtil.setStructuralFeatureValue(edge, org.eclipse.gmf.runtime.notation.NotationPackage.eINSTANCE.getRoutingStyle_Routing(), routing); + // } return edge; } @@ -2825,10 +3160,10 @@ public class UMLViewProvider extends AbstractProvider implements IViewProvider { final IPreferenceStore prefStore = (IPreferenceStore) preferencesHint.getPreferenceStore(); ViewUtil.setStructuralFeatureValue(edge, NotationPackage.eINSTANCE.getLineStyle_LineColor(), FigureUtilities.colorToInteger(ColorConstants.black)); - //org.eclipse.gmf.runtime.notation.Routing routing = org.eclipse.gmf.runtime.notation.Routing.get(prefStore.getInt(org.eclipse.gmf.runtime.diagram.ui.preferences.IPreferenceConstants.PREF_LINE_STYLE)); - //if (routing != null) { - // org.eclipse.gmf.runtime.diagram.core.util.ViewUtil.setStructuralFeatureValue(edge, org.eclipse.gmf.runtime.notation.NotationPackage.eINSTANCE.getRoutingStyle_Routing(), routing); - //} + // org.eclipse.gmf.runtime.notation.Routing routing = org.eclipse.gmf.runtime.notation.Routing.get(prefStore.getInt(org.eclipse.gmf.runtime.diagram.ui.preferences.IPreferenceConstants.PREF_LINE_STYLE)); + // if (routing != null) { + // org.eclipse.gmf.runtime.diagram.core.util.ViewUtil.setStructuralFeatureValue(edge, org.eclipse.gmf.runtime.notation.NotationPackage.eINSTANCE.getRoutingStyle_Routing(), routing); + // } Node label6030 = createLabel(edge, UMLVisualIDRegistry.getType(RepresentationTagLabelEditPart.VISUAL_ID)); label6030.setLayoutConstraint(NotationFactory.eINSTANCE.createLocation()); Location location6030 = (Location) label6030.getLayoutConstraint(); @@ -2857,10 +3192,10 @@ public class UMLViewProvider extends AbstractProvider implements IViewProvider { final IPreferenceStore prefStore = (IPreferenceStore) preferencesHint.getPreferenceStore(); PreferenceInitializerForElementHelper.initFontStyleFromPrefs(edge, prefStore, "InformationFlow"); - //org.eclipse.gmf.runtime.notation.Routing routing = org.eclipse.gmf.runtime.notation.Routing.get(prefStore.getInt(org.eclipse.gmf.runtime.diagram.ui.preferences.IPreferenceConstants.PREF_LINE_STYLE)); - //if (routing != null) { - // org.eclipse.gmf.runtime.diagram.core.util.ViewUtil.setStructuralFeatureValue(edge, org.eclipse.gmf.runtime.notation.NotationPackage.eINSTANCE.getRoutingStyle_Routing(), routing); - //} + // org.eclipse.gmf.runtime.notation.Routing routing = org.eclipse.gmf.runtime.notation.Routing.get(prefStore.getInt(org.eclipse.gmf.runtime.diagram.ui.preferences.IPreferenceConstants.PREF_LINE_STYLE)); + // if (routing != null) { + // org.eclipse.gmf.runtime.diagram.core.util.ViewUtil.setStructuralFeatureValue(edge, org.eclipse.gmf.runtime.notation.NotationPackage.eINSTANCE.getRoutingStyle_Routing(), routing); + // } Node label6031 = createLabel(edge, UMLVisualIDRegistry.getType(InformationFlowConveyedLabelEditPart.VISUAL_ID)); label6031.setLayoutConstraint(NotationFactory.eINSTANCE.createLocation()); Location location6031 = (Location) label6031.getLayoutConstraint(); @@ -2901,9 +3236,9 @@ public class UMLViewProvider extends AbstractProvider implements IViewProvider { * @generated */ protected Node createCompartment(View owner, String hint, boolean canCollapse, boolean hasTitle, boolean canSort, boolean canFilter) { - //SemanticListCompartment rv = NotationFactory.eINSTANCE.createSemanticListCompartment(); - //rv.setShowTitle(showTitle); - //rv.setCollapsed(isCollapsed); + // SemanticListCompartment rv = NotationFactory.eINSTANCE.createSemanticListCompartment(); + // rv.setShowTitle(showTitle); + // rv.setCollapsed(isCollapsed); Node rv; if (canCollapse) { rv = NotationFactory.eINSTANCE.createBasicCompartment(); diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/sheet/UMLPropertySection.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/sheet/UMLPropertySection.java index 8a4803aedee..66cdd8e29bd 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/sheet/UMLPropertySection.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/sheet/UMLPropertySection.java @@ -26,7 +26,7 @@ public class UMLPropertySection extends DefaultPropertySection implements IPrope */ @Override protected Object transformSelection(Object selected) { - selected = /*super.*/transformSelectionToDomain(selected); + selected = /* super. */transformSelectionToDomain(selected); return selected; } } diff --git a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite.tests/test/org/eclipse/papyrus/uml/diagram/composite/test/canonical/TestCompositeDiagramActivityChildNode.java b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite.tests/test/org/eclipse/papyrus/uml/diagram/composite/test/canonical/TestCompositeDiagramActivityChildNode.java index 2cd4d1e0797..16a7ac36f28 100644 --- a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite.tests/test/org/eclipse/papyrus/uml/diagram/composite/test/canonical/TestCompositeDiagramActivityChildNode.java +++ b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite.tests/test/org/eclipse/papyrus/uml/diagram/composite/test/canonical/TestCompositeDiagramActivityChildNode.java @@ -35,10 +35,12 @@ public class TestCompositeDiagramActivityChildNode extends TestChildNode { public DiagramUpdater getDiagramUpdater() { return UMLDiagramUpdater.INSTANCE; } + @Override protected ICreationCommand getDiagramCommandCreation() { return new CreateCompositeDiagramCommand(); } + @Override protected CreateViewRequest createViewRequestShapeContainer() { return CreateViewRequestFactory.getCreateShapeRequest(UMLElementTypes.Activity_2060, getDiagramEditPart().getDiagramPreferencesHint()); @@ -60,9 +62,9 @@ public class TestCompositeDiagramActivityChildNode extends TestChildNode { @Test public void testToParameter() { setTestAffixedNode(true); - testToManageNode(UMLElementTypes.Parameter_3088, UMLPackage.eINSTANCE.getParameter(), UMLElementTypes.Activity_2060,false,3,0,1,1, false,null,0); + testToManageNode(UMLElementTypes.Parameter_3088, UMLPackage.eINSTANCE.getParameter(), UMLElementTypes.Activity_2060, false, 4, 0, 1, 1, false, null, 0); setTestAffixedNode(false); } - - + + } \ No newline at end of file diff --git a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite.tests/test/org/eclipse/papyrus/uml/diagram/composite/test/canonical/TestCompositeDiagramCompositeChildNode.java b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite.tests/test/org/eclipse/papyrus/uml/diagram/composite/test/canonical/TestCompositeDiagramCompositeChildNode.java index 500f4e88e25..33b9a848f72 100644 --- a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite.tests/test/org/eclipse/papyrus/uml/diagram/composite/test/canonical/TestCompositeDiagramCompositeChildNode.java +++ b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite.tests/test/org/eclipse/papyrus/uml/diagram/composite/test/canonical/TestCompositeDiagramCompositeChildNode.java @@ -36,10 +36,12 @@ public class TestCompositeDiagramCompositeChildNode extends TestChildNode { public DiagramUpdater getDiagramUpdater() { return UMLDiagramUpdater.INSTANCE; } + @Override protected ICreationCommand getDiagramCommandCreation() { return new CreateCompositeDiagramCommand(); } + @Override protected CreateViewRequest createViewRequestShapeContainer() { return CreateViewRequestFactory.getCreateShapeRequest(UMLElementTypes.Class_2073, getDiagramEditPart().getDiagramPreferencesHint()); @@ -57,252 +59,279 @@ public class TestCompositeDiagramCompositeChildNode extends TestChildNode { /** - * Test to manage Property. - */ + * Test to manage Property. + */ @Test public void testToProperty() { - testToManageNodeWithMask(UMLElementTypes.Property_3070, UMLPackage.eINSTANCE.getProperty(),UMLElementTypes.Class_2073, false,"Attribute",0); + testToManageNodeWithMask(UMLElementTypes.Property_3070, UMLPackage.eINSTANCE.getProperty(), UMLElementTypes.Class_2073, false, "Attribute", 0); } - + /** - * Test to manage CollaborationUse. - */ + * Test to manage CollaborationUse. + */ @Test - public void testToCollaborationUse() { - testToManageNode(UMLElementTypes.CollaborationUse_3071, UMLPackage.eINSTANCE.getCollaborationUse(),UMLElementTypes.Class_2073, false); + testToManageNode(UMLElementTypes.CollaborationUse_3071, UMLPackage.eINSTANCE.getCollaborationUse(), UMLElementTypes.Class_2073, false); } + /** - * Test to manage Activity. - */ + * Test to manage Activity. + */ @Test @InteractiveTest public void testToActivity() { - testToManageNode(UMLElementTypes.Activity_3072, UMLPackage.eINSTANCE.getActivity(),UMLElementTypes.Class_2073, true); + testToManageNode(UMLElementTypes.Activity_3072, UMLPackage.eINSTANCE.getActivity(), UMLElementTypes.Class_2073, true); } + /** - * Test to manage Interaction. - */ + * Test to manage Interaction. + */ @Test @InteractiveTest public void testToInteraction() { - testToManageNode(UMLElementTypes.Interaction_3073, UMLPackage.eINSTANCE.getInteraction(),UMLElementTypes.Class_2073, true); + testToManageNode(UMLElementTypes.Interaction_3073, UMLPackage.eINSTANCE.getInteraction(), UMLElementTypes.Class_2073, true); } + /** - * Test to manage ProtocolStateMachine. - */ + * Test to manage ProtocolStateMachine. + */ @Test @InteractiveTest public void testToProtocolStateMachine() { - testToManageNode(UMLElementTypes.ProtocolStateMachine_3074, UMLPackage.eINSTANCE.getProtocolStateMachine(),UMLElementTypes.Class_2073, true); + testToManageNode(UMLElementTypes.ProtocolStateMachine_3074, UMLPackage.eINSTANCE.getProtocolStateMachine(), UMLElementTypes.Class_2073, true); } + /** - * Test to manage StateMachine. - */ + * Test to manage StateMachine. + */ @Test @InteractiveTest public void testToStateMachine() { - testToManageNode(UMLElementTypes.StateMachine_3075, UMLPackage.eINSTANCE.getStateMachine(),UMLElementTypes.Class_2073, true); + testToManageNode(UMLElementTypes.StateMachine_3075, UMLPackage.eINSTANCE.getStateMachine(), UMLElementTypes.Class_2073, true); } + /** - * Test to manage FunctionBehavior. - */ + * Test to manage FunctionBehavior. + */ @Test @InteractiveTest public void testToFunctionBehavior() { - testToManageNode(UMLElementTypes.FunctionBehavior_3076, UMLPackage.eINSTANCE.getFunctionBehavior(),UMLElementTypes.Class_2073, true); + testToManageNode(UMLElementTypes.FunctionBehavior_3076, UMLPackage.eINSTANCE.getFunctionBehavior(), UMLElementTypes.Class_2073, true); } + /** - * Test to manage OpaqueBehavior. - */ + * Test to manage OpaqueBehavior. + */ @Test @InteractiveTest public void testToOpaqueBehavior() { - testToManageNode(UMLElementTypes.OpaqueBehavior_3077, UMLPackage.eINSTANCE.getOpaqueBehavior(),UMLElementTypes.Class_2073, true); + testToManageNode(UMLElementTypes.OpaqueBehavior_3077, UMLPackage.eINSTANCE.getOpaqueBehavior(), UMLElementTypes.Class_2073, true); } + /** - * Test to manage Component. - */ + * Test to manage Component. + */ @Test @InteractiveTest public void testToComponent() { - testToManageNode(UMLElementTypes.Component_3081, UMLPackage.eINSTANCE.getComponent(),UMLElementTypes.Class_2073, true); + testToManageNode(UMLElementTypes.Component_3081, UMLPackage.eINSTANCE.getComponent(), UMLElementTypes.Class_2073, true); } + /** - * Test to manage Device. - */ + * Test to manage Device. + */ @Test @InteractiveTest public void testToDevice() { - testToManageNode(UMLElementTypes.Device_3082, UMLPackage.eINSTANCE.getDevice(),UMLElementTypes.Class_2073, true); + testToManageNode(UMLElementTypes.Device_3082, UMLPackage.eINSTANCE.getDevice(), UMLElementTypes.Class_2073, true); } + /** - * Test to manage ExecutionEnvironment. - */ + * Test to manage ExecutionEnvironment. + */ @Test @InteractiveTest public void testToExecutionEnvironment() { - testToManageNode(UMLElementTypes.ExecutionEnvironment_3083, UMLPackage.eINSTANCE.getExecutionEnvironment(),UMLElementTypes.Class_2073, false); + testToManageNode(UMLElementTypes.ExecutionEnvironment_3083, UMLPackage.eINSTANCE.getExecutionEnvironment(), UMLElementTypes.Class_2073, false); } + /** - * Test to manage Node. - */ + * Test to manage Node. + */ @Test @InteractiveTest public void testToNode() { - testToManageNode(UMLElementTypes.Node_3084, UMLPackage.eINSTANCE.getNode(),UMLElementTypes.Class_2073, true); + testToManageNode(UMLElementTypes.Node_3084, UMLPackage.eINSTANCE.getNode(), UMLElementTypes.Class_2073, true); } + /** - * Test to manage Class. - */ + * Test to manage Class. + */ @Test @InteractiveTest public void testToClass() { - testToManageNode(UMLElementTypes.Class_3085, UMLPackage.eINSTANCE.getClass_(),UMLElementTypes.Class_2073, true); + testToManageNode(UMLElementTypes.Class_3085, UMLPackage.eINSTANCE.getClass_(), UMLElementTypes.Class_2073, true); } + /** - * Test to manage Collaboration. - */ + * Test to manage Collaboration. + */ @Test @InteractiveTest public void testToCollaboration() { - testToManageNode(UMLElementTypes.Collaboration_3086, UMLPackage.eINSTANCE.getCollaboration(),UMLElementTypes.Class_2073, true); + testToManageNode(UMLElementTypes.Collaboration_3086, UMLPackage.eINSTANCE.getCollaboration(), UMLElementTypes.Class_2073, true); } + /** - * Test to manage Interface. - */ + * Test to manage Interface. + */ @Test @InteractiveTest public void testToInterface() { - testToManageNode(UMLElementTypes.Interface_3087, UMLPackage.eINSTANCE.getInterface(),UMLElementTypes.Class_2073, true); + testToManageNode(UMLElementTypes.Interface_3087, UMLPackage.eINSTANCE.getInterface(), UMLElementTypes.Class_2073, true); } + /** - * Test to manage PrimitiveType. - */ + * Test to manage PrimitiveType. + */ @Test @InteractiveTest public void testToPrimitiveType() { - testToManageNode(UMLElementTypes.PrimitiveType_3078, UMLPackage.eINSTANCE.getPrimitiveType(),UMLElementTypes.Class_2073, true); + testToManageNode(UMLElementTypes.PrimitiveType_3078, UMLPackage.eINSTANCE.getPrimitiveType(), UMLElementTypes.Class_2073, true); } + /** - * Test to manage Enumeration. - */ + * Test to manage Enumeration. + */ @Test @InteractiveTest public void testToEnumeration() { - testToManageNode(UMLElementTypes.Enumeration_3079, UMLPackage.eINSTANCE.getEnumeration(),UMLElementTypes.Class_2073, true); + testToManageNode(UMLElementTypes.Enumeration_3079, UMLPackage.eINSTANCE.getEnumeration(), UMLElementTypes.Class_2073, true); } + /** - * Test to manage DataType. - */ + * Test to manage DataType. + */ @Test @InteractiveTest public void testToDataType() { - testToManageNode(UMLElementTypes.DataType_3080, UMLPackage.eINSTANCE.getDataType(),UMLElementTypes.Class_2073, true); + testToManageNode(UMLElementTypes.DataType_3080, UMLPackage.eINSTANCE.getDataType(), UMLElementTypes.Class_2073, true); } + /** - * Test to manage Actor. - */ + * Test to manage Actor. + */ @Test @InteractiveTest public void testToActor() { - testToManageNode(UMLElementTypes.Actor_3091, UMLPackage.eINSTANCE.getActor(),UMLElementTypes.Class_2073, true); + testToManageNode(UMLElementTypes.Actor_3091, UMLPackage.eINSTANCE.getActor(), UMLElementTypes.Class_2073, true); } + /** - * Test to manage DeploymentSpecification. - */ + * Test to manage DeploymentSpecification. + */ @Test @InteractiveTest public void testToDeploymentSpecification() { - testToManageNode(UMLElementTypes.DeploymentSpecification_3092, UMLPackage.eINSTANCE.getDeploymentSpecification(),UMLElementTypes.Class_2073, true); + testToManageNode(UMLElementTypes.DeploymentSpecification_3092, UMLPackage.eINSTANCE.getDeploymentSpecification(), UMLElementTypes.Class_2073, true); } + /** - * Test to manage Artifact. - */ + * Test to manage Artifact. + */ @Test @InteractiveTest public void testToArtifact() { - testToManageNode(UMLElementTypes.Artifact_3093, UMLPackage.eINSTANCE.getArtifact(),UMLElementTypes.Class_2073, true); + testToManageNode(UMLElementTypes.Artifact_3093, UMLPackage.eINSTANCE.getArtifact(), UMLElementTypes.Class_2073, true); } + /** - * Test to manage InformationItem. - */ + * Test to manage InformationItem. + */ @Test @InteractiveTest public void testToInformationItem() { - testToManageNode(UMLElementTypes.InformationItem_3094, UMLPackage.eINSTANCE.getInformationItem(),UMLElementTypes.Class_2073, true); + testToManageNode(UMLElementTypes.InformationItem_3094, UMLPackage.eINSTANCE.getInformationItem(), UMLElementTypes.Class_2073, true); } + /** - * Test to manage Signal. - */ + * Test to manage Signal. + */ @Test @InteractiveTest public void testToSignal() { - testToManageNode(UMLElementTypes.Signal_3095, UMLPackage.eINSTANCE.getSignal(),UMLElementTypes.Class_2073, true); + testToManageNode(UMLElementTypes.Signal_3095, UMLPackage.eINSTANCE.getSignal(), UMLElementTypes.Class_2073, true); } + /** - * Test to manage UseCase. - */ + * Test to manage UseCase. + */ @Test @InteractiveTest public void testToUseCase() { - testToManageNode(UMLElementTypes.UseCase_3096, UMLPackage.eINSTANCE.getUseCase(),UMLElementTypes.Class_2073, true); + testToManageNode(UMLElementTypes.UseCase_3096, UMLPackage.eINSTANCE.getUseCase(), UMLElementTypes.Class_2073, true); } + /** - * Test to manage Comment. - */ + * Test to manage Comment. + */ @Test public void testToComment() { - testToManageNode(UMLElementTypes.Comment_3097, UMLPackage.eINSTANCE.getComment(),UMLElementTypes.Class_2073, false); + testToManageNode(UMLElementTypes.Comment_3097, UMLPackage.eINSTANCE.getComment(), UMLElementTypes.Class_2073, false); } + /** - * Test to manage DurationConstraint. - */ + * Test to manage DurationConstraint. + */ @Test @InteractiveTest public void testToDurationConstraint() { - testToManageNode(UMLElementTypes.DurationConstraint_3116, UMLPackage.eINSTANCE.getDurationConstraint(),UMLElementTypes.Class_2073, true); + testToManageNode(UMLElementTypes.DurationConstraint_3116, UMLPackage.eINSTANCE.getDurationConstraint(), UMLElementTypes.Class_2073, true); } + /** - * Test to manage TimeConstraint. - */ + * Test to manage TimeConstraint. + */ @Test @InteractiveTest public void testToTimeConstraint() { - testToManageNode(UMLElementTypes.TimeConstraint_3117, UMLPackage.eINSTANCE.getTimeConstraint(),UMLElementTypes.Class_2073, true); + testToManageNode(UMLElementTypes.TimeConstraint_3117, UMLPackage.eINSTANCE.getTimeConstraint(), UMLElementTypes.Class_2073, true); } + /** - * Test to manage IntervalConstraint. - */ + * Test to manage IntervalConstraint. + */ @Test @InteractiveTest public void testToIntervalConstraint() { - testToManageNode(UMLElementTypes.IntervalConstraint_3118, UMLPackage.eINSTANCE.getIntervalConstraint(),UMLElementTypes.Class_2073, true); + testToManageNode(UMLElementTypes.IntervalConstraint_3118, UMLPackage.eINSTANCE.getIntervalConstraint(), UMLElementTypes.Class_2073, true); } + /** - * Test to manage InteractionConstraint. - */ + * Test to manage InteractionConstraint. + */ @Test @InteractiveTest public void testToInteractionConstraint() { - testToManageNode(UMLElementTypes.InteractionConstraint_3119, UMLPackage.eINSTANCE.getInteractionConstraint(),UMLElementTypes.Class_2073, true); + testToManageNode(UMLElementTypes.InteractionConstraint_3119, UMLPackage.eINSTANCE.getInteractionConstraint(), UMLElementTypes.Class_2073, true); } + /** - * Test to manage Constraint. - */ + * Test to manage Constraint. + */ @Test public void testToConstraint() { - testToManageNode(UMLElementTypes.Constraint_3120, UMLPackage.eINSTANCE.getConstraint(),UMLElementTypes.Class_2073, false); + testToManageNode(UMLElementTypes.Constraint_3120, UMLPackage.eINSTANCE.getConstraint(), UMLElementTypes.Class_2073, false); } - + /** - * Test to manage Port. - */ + * Test to manage Port. + */ @Test public void testToPort() { - setTestAffixedNode(true); - testToManageNode(UMLElementTypes.Port_3069, UMLPackage.eINSTANCE.getPort(), UMLElementTypes.Class_2073,false,3,0,1,1, true,null,0); - setTestAffixedNode(false); + setTestAffixedNode(true); + testToManageNode(UMLElementTypes.Port_3069, UMLPackage.eINSTANCE.getPort(), UMLElementTypes.Class_2073, false, 4, 0, 1, 1, true, null, 0); + setTestAffixedNode(false); } - + } -- cgit v1.2.3