From 83f2e29ec43eb448e781e8ca25d47663f24dd311 Mon Sep 17 00:00:00 2001 From: Francois Le Fevre - CEA Date: Fri, 17 Jul 2015 15:16:25 +0200 Subject: Bug 469690: [drag and drop]: implement an inhouse graph methodology. -initial implementation that redefines in the plugin the code embedded here https://git.eclipse.org/r/#/c/46240/ Change-Id: I3be59e12c3027e7718eca6153e55d5892c0f868b Signed-off-by: Francois Le Fevre - CEA --- .../.classpath | 7 + .../.project | 28 ++ .../.settings/org.eclipse.jdt.core.prefs | 291 ++++++++++++++ .../.settings/org.eclipse.jdt.ui.prefs | 68 ++++ .../.settings/org.eclipse.m2e.core.prefs | 4 + .../META-INF/MANIFEST.MF | 27 ++ .../about.html | 28 ++ .../build.properties | 7 + .../plugin.xml | 10 + .../pom.xml | 14 + .../papyrus/uml/diagram/dnd/smart/Activator.java | 69 ++++ .../uml/diagram/dnd/smart/graph/Uml2Graph.java | 429 +++++++++++++++++++++ .../smart/graph/api/AbstractUml2GraphServices.java | 70 ++++ .../dnd/smart/graph/api/Uml2GraphServices.java | 57 +++ .../dnd/smart/graph/model/AbstractUmlGraph.java | 57 +++ .../dnd/smart/graph/model/EClassComparator.java | 34 ++ .../dnd/smart/graph/model/EdgeEReference.java | 110 ++++++ .../diagram/dnd/smart/graph/model/IUmlGraph.java | 67 ++++ .../diagram/dnd/smart/graph/model/NodeEClass.java | 89 +++++ .../uml/diagram/dnd/smart/graph/model/Path.java | 83 ++++ .../diagram/dnd/smart/graph/model/UmlGraph.java | 56 +++ .../dnd/smart/graph/service/AllPathDetector.java | 258 +++++++++++++ .../graph/service/GenericUml2GraphServices.java | 88 +++++ .../diagram/dnd/smart/graph/util/FilterUtils.java | 120 ++++++ .../uml/diagram/dnd/smart/messages/Messages.java | 33 ++ .../diagram/dnd/smart/messages/messages.properties | 2 + .../dnd/smart/strategy/SmartDropStrategy.java | 207 ++++++++++ 27 files changed, 2313 insertions(+) create mode 100644 extraplugins/uml/org.eclipse.papyrus.uml.diagram.dnd.smart/.classpath create mode 100644 extraplugins/uml/org.eclipse.papyrus.uml.diagram.dnd.smart/.project create mode 100644 extraplugins/uml/org.eclipse.papyrus.uml.diagram.dnd.smart/.settings/org.eclipse.jdt.core.prefs create mode 100644 extraplugins/uml/org.eclipse.papyrus.uml.diagram.dnd.smart/.settings/org.eclipse.jdt.ui.prefs create mode 100644 extraplugins/uml/org.eclipse.papyrus.uml.diagram.dnd.smart/.settings/org.eclipse.m2e.core.prefs create mode 100644 extraplugins/uml/org.eclipse.papyrus.uml.diagram.dnd.smart/META-INF/MANIFEST.MF create mode 100644 extraplugins/uml/org.eclipse.papyrus.uml.diagram.dnd.smart/about.html create mode 100644 extraplugins/uml/org.eclipse.papyrus.uml.diagram.dnd.smart/build.properties create mode 100644 extraplugins/uml/org.eclipse.papyrus.uml.diagram.dnd.smart/plugin.xml create mode 100644 extraplugins/uml/org.eclipse.papyrus.uml.diagram.dnd.smart/pom.xml create mode 100644 extraplugins/uml/org.eclipse.papyrus.uml.diagram.dnd.smart/src/org/eclipse/papyrus/uml/diagram/dnd/smart/Activator.java create mode 100644 extraplugins/uml/org.eclipse.papyrus.uml.diagram.dnd.smart/src/org/eclipse/papyrus/uml/diagram/dnd/smart/graph/Uml2Graph.java create mode 100644 extraplugins/uml/org.eclipse.papyrus.uml.diagram.dnd.smart/src/org/eclipse/papyrus/uml/diagram/dnd/smart/graph/api/AbstractUml2GraphServices.java create mode 100644 extraplugins/uml/org.eclipse.papyrus.uml.diagram.dnd.smart/src/org/eclipse/papyrus/uml/diagram/dnd/smart/graph/api/Uml2GraphServices.java create mode 100644 extraplugins/uml/org.eclipse.papyrus.uml.diagram.dnd.smart/src/org/eclipse/papyrus/uml/diagram/dnd/smart/graph/model/AbstractUmlGraph.java create mode 100644 extraplugins/uml/org.eclipse.papyrus.uml.diagram.dnd.smart/src/org/eclipse/papyrus/uml/diagram/dnd/smart/graph/model/EClassComparator.java create mode 100644 extraplugins/uml/org.eclipse.papyrus.uml.diagram.dnd.smart/src/org/eclipse/papyrus/uml/diagram/dnd/smart/graph/model/EdgeEReference.java create mode 100644 extraplugins/uml/org.eclipse.papyrus.uml.diagram.dnd.smart/src/org/eclipse/papyrus/uml/diagram/dnd/smart/graph/model/IUmlGraph.java create mode 100644 extraplugins/uml/org.eclipse.papyrus.uml.diagram.dnd.smart/src/org/eclipse/papyrus/uml/diagram/dnd/smart/graph/model/NodeEClass.java create mode 100644 extraplugins/uml/org.eclipse.papyrus.uml.diagram.dnd.smart/src/org/eclipse/papyrus/uml/diagram/dnd/smart/graph/model/Path.java create mode 100644 extraplugins/uml/org.eclipse.papyrus.uml.diagram.dnd.smart/src/org/eclipse/papyrus/uml/diagram/dnd/smart/graph/model/UmlGraph.java create mode 100644 extraplugins/uml/org.eclipse.papyrus.uml.diagram.dnd.smart/src/org/eclipse/papyrus/uml/diagram/dnd/smart/graph/service/AllPathDetector.java create mode 100644 extraplugins/uml/org.eclipse.papyrus.uml.diagram.dnd.smart/src/org/eclipse/papyrus/uml/diagram/dnd/smart/graph/service/GenericUml2GraphServices.java create mode 100644 extraplugins/uml/org.eclipse.papyrus.uml.diagram.dnd.smart/src/org/eclipse/papyrus/uml/diagram/dnd/smart/graph/util/FilterUtils.java create mode 100644 extraplugins/uml/org.eclipse.papyrus.uml.diagram.dnd.smart/src/org/eclipse/papyrus/uml/diagram/dnd/smart/messages/Messages.java create mode 100644 extraplugins/uml/org.eclipse.papyrus.uml.diagram.dnd.smart/src/org/eclipse/papyrus/uml/diagram/dnd/smart/messages/messages.properties create mode 100644 extraplugins/uml/org.eclipse.papyrus.uml.diagram.dnd.smart/src/org/eclipse/papyrus/uml/diagram/dnd/smart/strategy/SmartDropStrategy.java (limited to 'extraplugins/uml') diff --git a/extraplugins/uml/org.eclipse.papyrus.uml.diagram.dnd.smart/.classpath b/extraplugins/uml/org.eclipse.papyrus.uml.diagram.dnd.smart/.classpath new file mode 100644 index 00000000000..2d1a4302f04 --- /dev/null +++ b/extraplugins/uml/org.eclipse.papyrus.uml.diagram.dnd.smart/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/extraplugins/uml/org.eclipse.papyrus.uml.diagram.dnd.smart/.project b/extraplugins/uml/org.eclipse.papyrus.uml.diagram.dnd.smart/.project new file mode 100644 index 00000000000..72051cfeff9 --- /dev/null +++ b/extraplugins/uml/org.eclipse.papyrus.uml.diagram.dnd.smart/.project @@ -0,0 +1,28 @@ + + + org.eclipse.papyrus.uml.diagram.dnd.smart + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/extraplugins/uml/org.eclipse.papyrus.uml.diagram.dnd.smart/.settings/org.eclipse.jdt.core.prefs b/extraplugins/uml/org.eclipse.papyrus.uml.diagram.dnd.smart/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 00000000000..4759947300a --- /dev/null +++ b/extraplugins/uml/org.eclipse.papyrus.uml.diagram.dnd.smart/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,291 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 +org.eclipse.jdt.core.compiler.compliance=1.5 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.5 +org.eclipse.jdt.core.formatter.align_type_members_on_columns=false +org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16 +org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation=0 +org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant=16 +org.eclipse.jdt.core.formatter.alignment_for_arguments_in_explicit_constructor_call=16 +org.eclipse.jdt.core.formatter.alignment_for_arguments_in_method_invocation=16 +org.eclipse.jdt.core.formatter.alignment_for_arguments_in_qualified_allocation_expression=16 +org.eclipse.jdt.core.formatter.alignment_for_assignment=0 +org.eclipse.jdt.core.formatter.alignment_for_binary_expression=16 +org.eclipse.jdt.core.formatter.alignment_for_compact_if=16 +org.eclipse.jdt.core.formatter.alignment_for_conditional_expression=80 +org.eclipse.jdt.core.formatter.alignment_for_enum_constants=0 +org.eclipse.jdt.core.formatter.alignment_for_expressions_in_array_initializer=16 +org.eclipse.jdt.core.formatter.alignment_for_method_declaration=0 +org.eclipse.jdt.core.formatter.alignment_for_multiple_fields=16 +org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration=16 +org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration=16 +org.eclipse.jdt.core.formatter.alignment_for_resources_in_try=80 +org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation=16 +org.eclipse.jdt.core.formatter.alignment_for_superclass_in_type_declaration=16 +org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_enum_declaration=16 +org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_type_declaration=16 +org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_constructor_declaration=16 +org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_method_declaration=16 +org.eclipse.jdt.core.formatter.alignment_for_union_type_in_multicatch=16 +org.eclipse.jdt.core.formatter.blank_lines_after_imports=1 +org.eclipse.jdt.core.formatter.blank_lines_after_package=1 +org.eclipse.jdt.core.formatter.blank_lines_before_field=0 +org.eclipse.jdt.core.formatter.blank_lines_before_first_class_body_declaration=0 +org.eclipse.jdt.core.formatter.blank_lines_before_imports=1 +org.eclipse.jdt.core.formatter.blank_lines_before_member_type=1 +org.eclipse.jdt.core.formatter.blank_lines_before_method=1 +org.eclipse.jdt.core.formatter.blank_lines_before_new_chunk=1 +org.eclipse.jdt.core.formatter.blank_lines_before_package=0 +org.eclipse.jdt.core.formatter.blank_lines_between_import_groups=1 +org.eclipse.jdt.core.formatter.blank_lines_between_type_declarations=1 +org.eclipse.jdt.core.formatter.brace_position_for_annotation_type_declaration=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_anonymous_type_declaration=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_array_initializer=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_block=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_block_in_case=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_constructor_declaration=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_enum_constant=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_enum_declaration=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_lambda_body=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_method_declaration=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_switch=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_type_declaration=end_of_line +org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_block_comment=false +org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_javadoc_comment=false +org.eclipse.jdt.core.formatter.comment.format_block_comments=true +org.eclipse.jdt.core.formatter.comment.format_header=false +org.eclipse.jdt.core.formatter.comment.format_html=true +org.eclipse.jdt.core.formatter.comment.format_javadoc_comments=true +org.eclipse.jdt.core.formatter.comment.format_line_comments=true +org.eclipse.jdt.core.formatter.comment.format_source_code=true +org.eclipse.jdt.core.formatter.comment.indent_parameter_description=true +org.eclipse.jdt.core.formatter.comment.indent_root_tags=true +org.eclipse.jdt.core.formatter.comment.insert_new_line_before_root_tags=insert +org.eclipse.jdt.core.formatter.comment.insert_new_line_for_parameter=insert +org.eclipse.jdt.core.formatter.comment.line_length=260 +org.eclipse.jdt.core.formatter.comment.new_lines_at_block_boundaries=true +org.eclipse.jdt.core.formatter.comment.new_lines_at_javadoc_boundaries=true +org.eclipse.jdt.core.formatter.comment.preserve_white_space_between_code_and_line_comments=false +org.eclipse.jdt.core.formatter.compact_else_if=true +org.eclipse.jdt.core.formatter.continuation_indentation=2 +org.eclipse.jdt.core.formatter.continuation_indentation_for_array_initializer=2 +org.eclipse.jdt.core.formatter.disabling_tag=@formatter\:off +org.eclipse.jdt.core.formatter.enabling_tag=@formatter\:on +org.eclipse.jdt.core.formatter.format_guardian_clause_on_one_line=false +org.eclipse.jdt.core.formatter.format_line_comment_starting_on_first_column=true +org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_annotation_declaration_header=true +org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_constant_header=true +org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_declaration_header=true +org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_type_header=true +org.eclipse.jdt.core.formatter.indent_breaks_compare_to_cases=true +org.eclipse.jdt.core.formatter.indent_empty_lines=false +org.eclipse.jdt.core.formatter.indent_statements_compare_to_block=true +org.eclipse.jdt.core.formatter.indent_statements_compare_to_body=true +org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_cases=true +org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_switch=false +org.eclipse.jdt.core.formatter.indentation.size=4 +org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_field=insert +org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_local_variable=insert +org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_method=insert +org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_package=insert +org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_parameter=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_type=insert +org.eclipse.jdt.core.formatter.insert_new_line_after_label=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_after_opening_brace_in_array_initializer=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_after_type_annotation=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_at_end_of_file_if_missing=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_before_catch_in_try_statement=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_before_closing_brace_in_array_initializer=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_before_else_in_if_statement=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_before_finally_in_try_statement=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_before_while_in_do_statement=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_in_empty_annotation_declaration=insert +org.eclipse.jdt.core.formatter.insert_new_line_in_empty_anonymous_type_declaration=insert +org.eclipse.jdt.core.formatter.insert_new_line_in_empty_block=insert +org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_constant=insert +org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_declaration=insert +org.eclipse.jdt.core.formatter.insert_new_line_in_empty_method_body=insert +org.eclipse.jdt.core.formatter.insert_new_line_in_empty_type_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_after_and_in_type_parameter=insert +org.eclipse.jdt.core.formatter.insert_space_after_assignment_operator=insert +org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation_type_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_binary_operator=insert +org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_arguments=insert +org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_parameters=insert +org.eclipse.jdt.core.formatter.insert_space_after_closing_brace_in_block=insert +org.eclipse.jdt.core.formatter.insert_space_after_closing_paren_in_cast=insert +org.eclipse.jdt.core.formatter.insert_space_after_colon_in_assert=insert +org.eclipse.jdt.core.formatter.insert_space_after_colon_in_case=insert +org.eclipse.jdt.core.formatter.insert_space_after_colon_in_conditional=insert +org.eclipse.jdt.core.formatter.insert_space_after_colon_in_for=insert +org.eclipse.jdt.core.formatter.insert_space_after_colon_in_labeled_statement=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_allocation_expression=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_annotation=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_array_initializer=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_parameters=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_throws=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_constant_arguments=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_declarations=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_explicitconstructorcall_arguments=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_increments=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_inits=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_parameters=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_throws=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_invocation_arguments=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_field_declarations=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_local_declarations=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_parameterized_type_reference=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_superinterfaces=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_arguments=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_parameters=insert +org.eclipse.jdt.core.formatter.insert_space_after_ellipsis=insert +org.eclipse.jdt.core.formatter.insert_space_after_lambda_arrow=insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_parameterized_type_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_arguments=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_parameters=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_brace_in_array_initializer=insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_allocation_expression=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_annotation=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_cast=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_catch=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_constructor_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_enum_constant=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_for=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_if=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_invocation=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_parenthesized_expression=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_switch=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_synchronized=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_try=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_while=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_postfix_operator=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_prefix_operator=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_question_in_conditional=insert +org.eclipse.jdt.core.formatter.insert_space_after_question_in_wildcard=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_for=insert +org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_try_resources=insert +org.eclipse.jdt.core.formatter.insert_space_after_unary_operator=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_and_in_type_parameter=insert +org.eclipse.jdt.core.formatter.insert_space_before_assignment_operator=insert +org.eclipse.jdt.core.formatter.insert_space_before_at_in_annotation_type_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_before_binary_operator=insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_parameterized_type_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_arguments=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_parameters=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_brace_in_array_initializer=insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_allocation_expression=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_annotation=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_cast=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_catch=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_constructor_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_enum_constant=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_for=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_if=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_invocation=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_parenthesized_expression=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_switch=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_synchronized=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_try=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_while=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_colon_in_assert=insert +org.eclipse.jdt.core.formatter.insert_space_before_colon_in_case=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_colon_in_conditional=insert +org.eclipse.jdt.core.formatter.insert_space_before_colon_in_default=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_colon_in_for=insert +org.eclipse.jdt.core.formatter.insert_space_before_colon_in_labeled_statement=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_allocation_expression=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_annotation=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_array_initializer=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_parameters=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_throws=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_constant_arguments=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_declarations=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_explicitconstructorcall_arguments=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_increments=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_inits=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_parameters=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_throws=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_invocation_arguments=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_field_declarations=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_local_declarations=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_parameterized_type_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_superinterfaces=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_arguments=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_parameters=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_ellipsis=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_lambda_arrow=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_parameterized_type_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_arguments=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_parameters=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_annotation_type_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_anonymous_type_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_array_initializer=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_block=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_constructor_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_constant=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_method_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_switch=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_type_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_allocation_expression=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_type_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation_type_member_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_catch=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_constructor_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_enum_constant=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_for=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_if=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_invocation=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_parenthesized_expression=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_switch=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_synchronized=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_try=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_while=insert +org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_return=insert +org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_throw=insert +org.eclipse.jdt.core.formatter.insert_space_before_postfix_operator=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_prefix_operator=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_question_in_conditional=insert +org.eclipse.jdt.core.formatter.insert_space_before_question_in_wildcard=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_semicolon=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_for=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_try_resources=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_unary_operator=do not insert +org.eclipse.jdt.core.formatter.insert_space_between_brackets_in_array_type_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_between_empty_braces_in_array_initializer=do not insert +org.eclipse.jdt.core.formatter.insert_space_between_empty_brackets_in_array_allocation_expression=do not insert +org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_annotation_type_member_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_constructor_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_enum_constant=do not insert +org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_invocation=do not insert +org.eclipse.jdt.core.formatter.join_lines_in_comments=false +org.eclipse.jdt.core.formatter.join_wrapped_lines=false +org.eclipse.jdt.core.formatter.keep_else_statement_on_same_line=false +org.eclipse.jdt.core.formatter.keep_empty_array_initializer_on_one_line=false +org.eclipse.jdt.core.formatter.keep_imple_if_on_one_line=false +org.eclipse.jdt.core.formatter.keep_then_statement_on_same_line=false +org.eclipse.jdt.core.formatter.lineSplit=260 +org.eclipse.jdt.core.formatter.never_indent_block_comments_on_first_column=false +org.eclipse.jdt.core.formatter.never_indent_line_comments_on_first_column=false +org.eclipse.jdt.core.formatter.number_of_blank_lines_at_beginning_of_method_body=0 +org.eclipse.jdt.core.formatter.number_of_empty_lines_to_preserve=5 +org.eclipse.jdt.core.formatter.put_empty_statement_on_new_line=true +org.eclipse.jdt.core.formatter.tabulation.char=tab +org.eclipse.jdt.core.formatter.tabulation.size=4 +org.eclipse.jdt.core.formatter.use_on_off_tags=false +org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations=false +org.eclipse.jdt.core.formatter.wrap_before_binary_operator=true +org.eclipse.jdt.core.formatter.wrap_before_or_operator_multicatch=true +org.eclipse.jdt.core.formatter.wrap_outer_expressions_when_nested=true diff --git a/extraplugins/uml/org.eclipse.papyrus.uml.diagram.dnd.smart/.settings/org.eclipse.jdt.ui.prefs b/extraplugins/uml/org.eclipse.papyrus.uml.diagram.dnd.smart/.settings/org.eclipse.jdt.ui.prefs new file mode 100644 index 00000000000..954281dbc31 --- /dev/null +++ b/extraplugins/uml/org.eclipse.papyrus.uml.diagram.dnd.smart/.settings/org.eclipse.jdt.ui.prefs @@ -0,0 +1,68 @@ +cleanup.add_default_serial_version_id=true +cleanup.add_generated_serial_version_id=false +cleanup.add_missing_annotations=true +cleanup.add_missing_deprecated_annotations=true +cleanup.add_missing_methods=false +cleanup.add_missing_nls_tags=false +cleanup.add_missing_override_annotations=true +cleanup.add_missing_override_annotations_interface_methods=true +cleanup.add_serial_version_id=false +cleanup.always_use_blocks=true +cleanup.always_use_parentheses_in_expressions=false +cleanup.always_use_this_for_non_static_field_access=false +cleanup.always_use_this_for_non_static_method_access=false +cleanup.convert_functional_interfaces=false +cleanup.convert_to_enhanced_for_loop=false +cleanup.correct_indentation=false +cleanup.format_source_code=false +cleanup.format_source_code_changes_only=false +cleanup.insert_inferred_type_arguments=false +cleanup.make_local_variable_final=true +cleanup.make_parameters_final=false +cleanup.make_private_fields_final=true +cleanup.make_type_abstract_if_missing_method=false +cleanup.make_variable_declarations_final=false +cleanup.never_use_blocks=false +cleanup.never_use_parentheses_in_expressions=true +cleanup.organize_imports=false +cleanup.qualify_static_field_accesses_with_declaring_class=false +cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true +cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true +cleanup.qualify_static_member_accesses_with_declaring_class=true +cleanup.qualify_static_method_accesses_with_declaring_class=false +cleanup.remove_private_constructors=true +cleanup.remove_redundant_type_arguments=true +cleanup.remove_trailing_whitespaces=true +cleanup.remove_trailing_whitespaces_all=true +cleanup.remove_trailing_whitespaces_ignore_empty=false +cleanup.remove_unnecessary_casts=true +cleanup.remove_unnecessary_nls_tags=true +cleanup.remove_unused_imports=true +cleanup.remove_unused_local_variables=false +cleanup.remove_unused_private_fields=true +cleanup.remove_unused_private_members=false +cleanup.remove_unused_private_methods=true +cleanup.remove_unused_private_types=true +cleanup.sort_members=false +cleanup.sort_members_all=false +cleanup.use_anonymous_class_creation=false +cleanup.use_blocks=true +cleanup.use_blocks_only_for_return_and_throw=false +cleanup.use_lambda=true +cleanup.use_parentheses_in_expressions=false +cleanup.use_this_for_non_static_field_access=false +cleanup.use_this_for_non_static_field_access_only_if_necessary=true +cleanup.use_this_for_non_static_method_access=false +cleanup.use_this_for_non_static_method_access_only_if_necessary=true +cleanup.use_type_arguments=false +cleanup_profile=_Papyrus +cleanup_settings_version=2 +eclipse.preferences.version=1 +formatter_profile=_Papyrus +formatter_settings_version=12 +org.eclipse.jdt.ui.ignorelowercasenames=true +org.eclipse.jdt.ui.importorder=java;javax;org;com; +org.eclipse.jdt.ui.javadoc=true +org.eclipse.jdt.ui.ondemandthreshold=99 +org.eclipse.jdt.ui.staticondemandthreshold=99 +org.eclipse.jdt.ui.text.custom_code_templates= diff --git a/extraplugins/uml/org.eclipse.papyrus.uml.diagram.dnd.smart/.settings/org.eclipse.m2e.core.prefs b/extraplugins/uml/org.eclipse.papyrus.uml.diagram.dnd.smart/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 00000000000..f897a7f1cb2 --- /dev/null +++ b/extraplugins/uml/org.eclipse.papyrus.uml.diagram.dnd.smart/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/extraplugins/uml/org.eclipse.papyrus.uml.diagram.dnd.smart/META-INF/MANIFEST.MF b/extraplugins/uml/org.eclipse.papyrus.uml.diagram.dnd.smart/META-INF/MANIFEST.MF new file mode 100644 index 00000000000..6d5cd0f803d --- /dev/null +++ b/extraplugins/uml/org.eclipse.papyrus.uml.diagram.dnd.smart/META-INF/MANIFEST.MF @@ -0,0 +1,27 @@ +Manifest-Version: 1.0 +Export-Package: org.eclipse.papyrus.uml.diagram.dnd.smart +Require-Bundle: org.eclipse.ui, + org.eclipse.papyrus.infra.gmfdiag.dnd;bundle-version="1.1.0", + org.eclipse.gmf.runtime.diagram.ui;bundle-version="1.5.0", + org.eclipse.papyrus.infra.core.log;bundle-version="1.1.0", + org.eclipse.uml2.uml;bundle-version="4.0.0", + org.eclipse.papyrus.uml.diagram.common;bundle-version="1.1.0", + org.eclipse.papyrus.infra.emf;bundle-version="1.1.0", + org.eclipse.papyrus.infra.widgets;bundle-version="1.1.0", + org.eclipse.papyrus.uml.tools;bundle-version="1.1.0", + org.eclipse.papyrus.uml.diagram.clazz;bundle-version="1.1.0", + org.eclipse.papyrus.infra.services.labelprovider;bundle-version="1.1.0", + org.eclipse.papyrus.uml.diagram.composite;bundle-version="1.1.0", + org.eclipse.papyrus.emf.facet.custom.ui;bundle-version="1.1.0", + org.eclipse.papyrus.infra.gmfdiag.common;bundle-version="1.1.0", + org.eclipse.papyrus.infra.services.edit;bundle-version="1.1.0" +Bundle-Vendor: Eclipse Modeling Project +Bundle-ActivationPolicy: lazy +Bundle-Version: 1.1.0.qualifier +Bundle-Name: Smart UML Drag and Drop +Bundle-Activator: org.eclipse.papyrus.uml.diagram.dnd.smart.Activator +Bundle-ManifestVersion: 2 +Bundle-SymbolicName: org.eclipse.papyrus.uml.diagram.dnd.smart;singleton:=tr + ue +Bundle-RequiredExecutionEnvironment: J2SE-1.5 + diff --git a/extraplugins/uml/org.eclipse.papyrus.uml.diagram.dnd.smart/about.html b/extraplugins/uml/org.eclipse.papyrus.uml.diagram.dnd.smart/about.html new file mode 100644 index 00000000000..dd02e0be168 --- /dev/null +++ b/extraplugins/uml/org.eclipse.papyrus.uml.diagram.dnd.smart/about.html @@ -0,0 +1,28 @@ + + + + +About + + +

About This Content

+ +

December 2, 2009

+

License

+ +

The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise +indicated below, the Content is provided to you under the terms and conditions of the +Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available +at http://www.eclipse.org/legal/epl-v10.html. +For purposes of the EPL, "Program" will mean the Content.

+ +

If you did not receive this Content directly from the Eclipse Foundation, the Content is +being redistributed by another party ("Redistributor") and different terms and conditions may +apply to your use of any object code in the Content. Check the Redistributor's license that was +provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise +indicated below, the terms and conditions of the EPL still apply to any source code in the Content +and such source code may be obtained at http://www.eclipse.org.

+ + + \ No newline at end of file diff --git a/extraplugins/uml/org.eclipse.papyrus.uml.diagram.dnd.smart/build.properties b/extraplugins/uml/org.eclipse.papyrus.uml.diagram.dnd.smart/build.properties new file mode 100644 index 00000000000..e3693a3b66e --- /dev/null +++ b/extraplugins/uml/org.eclipse.papyrus.uml.diagram.dnd.smart/build.properties @@ -0,0 +1,7 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + about.html,\ + plugin.xml +src.includes = about.html diff --git a/extraplugins/uml/org.eclipse.papyrus.uml.diagram.dnd.smart/plugin.xml b/extraplugins/uml/org.eclipse.papyrus.uml.diagram.dnd.smart/plugin.xml new file mode 100644 index 00000000000..f5d77cb7cf8 --- /dev/null +++ b/extraplugins/uml/org.eclipse.papyrus.uml.diagram.dnd.smart/plugin.xml @@ -0,0 +1,10 @@ + + + + + + + + diff --git a/extraplugins/uml/org.eclipse.papyrus.uml.diagram.dnd.smart/pom.xml b/extraplugins/uml/org.eclipse.papyrus.uml.diagram.dnd.smart/pom.xml new file mode 100644 index 00000000000..86dbb8587ce --- /dev/null +++ b/extraplugins/uml/org.eclipse.papyrus.uml.diagram.dnd.smart/pom.xml @@ -0,0 +1,14 @@ + + + 4.0.0 + + org.eclipse.papyrus.extra.releng + org.eclipse.papyrus + 1.1.0-SNAPSHOT + ../../../releng/extra/pom.xml + + org.eclipse.papyrus.uml.diagram.dnd.smart + org.eclipse.papyrus + 1.1.0-SNAPSHOT + eclipse-plugin + diff --git a/extraplugins/uml/org.eclipse.papyrus.uml.diagram.dnd.smart/src/org/eclipse/papyrus/uml/diagram/dnd/smart/Activator.java b/extraplugins/uml/org.eclipse.papyrus.uml.diagram.dnd.smart/src/org/eclipse/papyrus/uml/diagram/dnd/smart/Activator.java new file mode 100644 index 00000000000..1edda3a568f --- /dev/null +++ b/extraplugins/uml/org.eclipse.papyrus.uml.diagram.dnd.smart/src/org/eclipse/papyrus/uml/diagram/dnd/smart/Activator.java @@ -0,0 +1,69 @@ +/***************************************************************************** + * Copyright (c) 2015 CEA LIST. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Francois Le Fevre (CEA LIST) francois.le-fevre@cea.fr - Initial API and implementation + *****************************************************************************/ +package org.eclipse.papyrus.uml.diagram.dnd.smart; + +import org.eclipse.papyrus.infra.core.log.LogHelper; +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.osgi.framework.BundleContext; + +/** + * The activator class controls the plug-in life cycle + */ +public class Activator extends AbstractUIPlugin { + + // The plug-in ID + public static final String PLUGIN_ID = "org.eclipse.papyrus.uml.diagram.dnd"; //$NON-NLS-1$ + + // The shared instance + private static Activator plugin; + + public static LogHelper log; + + /** + * The constructor + */ + public Activator() { + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) + */ + @Override + public void start(BundleContext context) throws Exception { + super.start(context); + plugin = this; + log = new LogHelper(this); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) + */ + @Override + public void stop(BundleContext context) throws Exception { + plugin = null; + super.stop(context); + } + + /** + * Returns the shared instance + * + * @return the shared instance + */ + public static Activator getDefault() { + return plugin; + } + +} diff --git a/extraplugins/uml/org.eclipse.papyrus.uml.diagram.dnd.smart/src/org/eclipse/papyrus/uml/diagram/dnd/smart/graph/Uml2Graph.java b/extraplugins/uml/org.eclipse.papyrus.uml.diagram.dnd.smart/src/org/eclipse/papyrus/uml/diagram/dnd/smart/graph/Uml2Graph.java new file mode 100644 index 00000000000..c6394e3cc04 --- /dev/null +++ b/extraplugins/uml/org.eclipse.papyrus.uml.diagram.dnd.smart/src/org/eclipse/papyrus/uml/diagram/dnd/smart/graph/Uml2Graph.java @@ -0,0 +1,429 @@ +/***************************************************************************** + * Copyright (c) 2015 CEA LIST and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * CEA LIST - Initial API and implementation + * + *****************************************************************************/ +package org.eclipse.papyrus.uml.diagram.dnd.smart.graph; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.TreeSet; + +import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EReference; +import org.eclipse.papyrus.infra.emf.Activator; +import org.eclipse.papyrus.uml.diagram.dnd.smart.graph.model.EClassComparator; +import org.eclipse.papyrus.uml.diagram.dnd.smart.graph.model.EdgeEReference; +import org.eclipse.papyrus.uml.diagram.dnd.smart.graph.model.NodeEClass; +import org.eclipse.papyrus.uml.diagram.dnd.smart.graph.model.UmlGraph; +import org.eclipse.uml2.uml.UMLFactory; +import org.eclipse.uml2.uml.UMLPackage; + +/** + * Object model to manipulate the graph + * @author Francois Le Fevre - CEA francois.le-fevre@cea.fr + * + */ +public class Uml2Graph { + + private static Uml2Graph INSTANCE = null; + public static final String NAME_SPLITTER=new String("@"); + + private UmlGraph myGraph; + private HashMap nodeEClassMap; + private HashMap> eclass2ChildrenMap; + private HashMap> eclass2ParentMap; + private HashMap> eclass2ConcreteMap; + + private HashMap edgeEReferenceMap; + private UMLFactory umlFactory; + + public static Uml2Graph getInstance() + { + if (INSTANCE == null) + { INSTANCE = new Uml2Graph(); + } + return INSTANCE; + } + + private Uml2Graph(){ + Date start = new Date(); + //initialiaze the uml factory + umlFactory = UMLFactory.eINSTANCE; + + //create the graph + myGraph = new UmlGraph(); + + //prepare the map to navigate + nodeEClassMap = new HashMap(); + edgeEReferenceMap = new HashMap(); + eclass2ChildrenMap = new HashMap>(); + eclass2ParentMap = new HashMap>(); + eclass2ConcreteMap = new HashMap>(); + + extractNodesFromUml(); + + buildParent2ChildrenMap(); + buildChildren2ParentMap(); + + extractEdgesFromUml(); + + Date end = new Date(); + if(Activator.log.isDebugEnabled()){ + Activator.log.debug("Parsing of UML model2: done "+(end.getTime()-start.getTime())); + } + } + + private void buildChildren2ParentMap() { + + for(EClass eclass : eclass2ParentMap.keySet()){ + EList eclassParents = eclass2ParentMap.get(eclass); + for(EClass eclassParent : eclassParents){ + List eclassChildren = eclass2ChildrenMap.get(eclassParent); + if(eclassChildren==null){ + eclassChildren = new ArrayList(); + } + eclassChildren.add(eclass); + eclass2ChildrenMap.put(eclassParent, eclassChildren); + } + } + + } + + private void buildParent2ChildrenMap() { + for(NodeEClass nodeEClass : nodeEClassMap.values()){ + fillSpecificHierarchy(nodeEClass.geteClass()); + } + } + + /** + * Extract the parent Eclass information + * @param myEClass + */ + private void fillSpecificHierarchy(EClass myEClass){ + if(myEClass!=null){ + EList myEClassParents = myEClass.getEAllSuperTypes(); + eclass2ParentMap.put(myEClass,myEClassParents); + } + } + + private void extractNodesFromUml(){ + //TODO update to get all EClass directly + for(Method m : UMLPackage.eINSTANCE.getClass().getMethods()){ + if("interface org.eclipse.emf.ecore.EClass".equals(m.getReturnType().toString())){ + + if(Activator.log.isDebugEnabled()){ + Activator.log.debug("Will extract data from " + m.getName()); + + } + try { + //Explore the EClass + EClass myEclass = (EClass)m.invoke(umlFactory.getUMLPackage()); + exploreNode(myEclass); + + } catch (IllegalAccessException e) { + Activator.log.error(e.getMessage(),e); + } catch (IllegalArgumentException e) { + Activator.log.error(e.getMessage(),e); + } catch (InvocationTargetException e) { + Activator.log.error(e.getMessage(),e); + } + } + else{ + if(Activator.log.isDebugEnabled()){ + Activator.log.debug("No parsing of method which returns:" + m.getReturnType().toString()+"\t"+m.getName()); + } + } + } + } + + private void exploreNode(EClass myEClass){ + if(myEClass!=null){ + if(Activator.log.isDebugEnabled()){ + Activator.log.debug("exploreEClass "+myEClass.getInstanceClassName()+"\t"+myEClass.isAbstract()); + } + NodeEClass nodeEClass; + if(nodeEClassMap.get(myEClass.getInstanceClassName())==null){ + + nodeEClass = nodeEClassMap.get(myEClass.getInstanceClassName()); + if(nodeEClass==null){ + nodeEClass = new NodeEClass(myEClass.getInstanceClassName(),myEClass); + myGraph.addVertex(nodeEClass); + nodeEClassMap.put(myEClass.getInstanceClassName(),nodeEClass); + } + for(EReference er : myEClass.getEAllReferences()){ + if(!er.getEType().getInstanceClassName().startsWith("org.eclipse.emf.ecore.")){ + if(Activator.log.isDebugEnabled()){ + Activator.log.debug("exploreEClass AllContainments "+er.getEType().getInstanceClassName()); + } + + NodeEClass nodeEClassEReference = nodeEClassMap.get(er.getEType().getInstanceClassName()); + if(nodeEClassEReference==null){ + nodeEClassEReference = new NodeEClass(er.getEType().getInstanceClassName(),er.getEReferenceType()); + myGraph.addVertex(nodeEClassEReference); + nodeEClassMap.put(er.getEType().getInstanceClassName(),nodeEClassEReference); + + EList myEClassParents = er.getEReferenceType().getEAllSuperTypes(); + for(EClass myEClassParent : myEClassParents){ + NodeEClass nodeEClassEReference2 = nodeEClassMap.get(myEClassParent.getInstanceClassName()); + if(nodeEClassEReference2==null){ + nodeEClassEReference2 = new NodeEClass(myEClassParent.getInstanceClassName(),myEClassParent); + myGraph.addVertex(nodeEClassEReference2); + nodeEClassMap.put(myEClassParent.getInstanceClassName(),nodeEClassEReference2); + } + } + } + } + } + + EList myEClassParents = myEClass.getEAllSuperTypes(); + for(EClass myEClassParent : myEClassParents){ + NodeEClass nodeEClassEReference2 = nodeEClassMap.get(myEClassParent.getInstanceClassName()); + if(nodeEClassEReference2==null){ + nodeEClassEReference2 = new NodeEClass(myEClassParent.getInstanceClassName(),myEClassParent); + myGraph.addVertex(nodeEClassEReference2); + nodeEClassMap.put(myEClassParent.getInstanceClassName(),nodeEClassEReference2); + } + } + } + } + } + + + private void extractEdgesFromUml(){ + //TODO update to get all EClass directly + for(Method m : UMLPackage.eINSTANCE. getClass().getMethods()){ + if("interface org.eclipse.emf.ecore.EClass".equals(m.getReturnType().toString())){ + if(Activator.log.isDebugEnabled()){ + Activator.log.debug("Will extract data from " + m.getName()); + } + try { + //Explore the EClass + EClass myEclass = (EClass)m.invoke(umlFactory.getUMLPackage()); + exploreEdgesOfEClass(myEclass); + + } catch (IllegalAccessException e) { + Activator.log.error(e.getMessage(),e); + } catch (IllegalArgumentException e) { + Activator.log.error(e.getMessage(),e); + } catch (InvocationTargetException e) { + Activator.log.error(e.getMessage(),e); + } + } + else{ + if(Activator.log.isDebugEnabled()){ + Activator.log.debug("No parsing of method which returns:" + m.getReturnType().toString()+"\t"+m.getName()); + } + } + } + } + + private void exploreEdgesOfEClass(EClass myEClass){ + if(myEClass!=null){ + + + if(Activator.log.isDebugEnabled()){ + Activator.log.debug("exploreEdgesofEClass "+myEClass.getInstanceClassName()+"\t"+myEClass.isAbstract()); + } + NodeEClass source = nodeEClassMap.get(myEClass.getInstanceClassName()); + + for(EReference er : myEClass.getEAllReferences()){ + NodeEClass target = nodeEClassMap.get(er.getEType().getInstanceClassName()); + + if(source!=null && target !=null){ + //Filter the EReference + if(!"org.eclipse.emf.ecore.EAnnotation".equals(er.getEType().getInstanceClassName()) + && !"ownedElement".equals(er.getName()) + && !"owner".equals(er.getName()) + && !"ownedMember".equals(er.getName()) + && !"importedMember".equals(er.getName()) + && !"namespace".equals(er.getName()) + && !"member".equals(er.getName()) + && !"redefinedElement".equals(er.getName()) + && !"clientDependency".equals(er.getName()) + && !"packageImport".equals(er.getName()) + && !"elementImport".equals(er.getName()) + && !"ownedComment".equals(er.getName()) + ){ + + //Work with real Target + List targetConcretEclasses = getAllConcreteEClasses(target.geteClass()); + + NodeEClass targetConcretEclasseNode2; + EdgeEReference edgeEReference2; + String edgeName2; + boolean b; + for(EClass targetConcretEclasse : targetConcretEclasses){ + targetConcretEclasseNode2 = nodeEClassMap.get(targetConcretEclasse.getInstanceTypeName()); + edgeName2 = buildUniqName(myEClass, er, targetConcretEclasse); + edgeEReference2 = new EdgeEReference(edgeName2,er.eContainmentFeature().isContainment(), er,targetConcretEclasse); + b = myGraph.addEdge(edgeEReference2, source, targetConcretEclasseNode2); + if(!b){ + Activator.log.error("problem in creation of graph",new Error()); + } + edgeEReferenceMap.put(edgeName2,edgeEReference2); + } + + } + } + } + } + } + + /** + * Given an EClass, return all concrete EClasses, withitself if it is already a concrete EClass + * @param initialEClass + * @return + */ + public List getAllConcreteEClasses(EClass initialEClass){ + List result=null; + if(initialEClass!=null){ + + result = eclass2ConcreteMap.get(initialEClass); + + if(result==null){ + result = new ArrayList(); + TreeSet preResult = new TreeSet(new EClassComparator()); + + if(initialEClass!=null){ + + //Add it if it is alaready a concrete EClass + if(!initialEClass.isAbstract()){ + preResult.add(initialEClass); + if(Activator.log.isDebugEnabled()){ + Activator.log.debug("adding non abstract class: "+initialEClass.getInstanceTypeName()); + } + } + + //Explore its children + List potentialConcreteEClasses= eclass2ChildrenMap.get(initialEClass); + if(Activator.log.isDebugEnabled()){ + Activator.log.debug("exploring "+initialEClass.getInstanceTypeName()+ "\tchildren["+potentialConcreteEClasses+"]"); + } + if(potentialConcreteEClasses!=null){ + for(EClass potentialConcreteEClass: potentialConcreteEClasses){ + //Explore it again + preResult.addAll(getAllConcreteEClasses(potentialConcreteEClass)); + } + } + } + + result.addAll(preResult); + + eclass2ConcreteMap.put(initialEClass,result); + } + } + return result; + } + + public void computeStatusActions(EClass source,EClass target) { + NodeEClass sourceNode = nodeEClassMap.get(source.getInstanceTypeName()); + NodeEClass targetNode = nodeEClassMap.get(target.getInstanceTypeName()); + + Collection mySourceIncidentEdges = myGraph.getInEdges(sourceNode); + for(EdgeEReference myEdgeEReference : mySourceIncidentEdges){ + NodeEClass potentialIntermediate = myGraph.getSource(myEdgeEReference); + Collection mySourceIncidentEdges2 = myGraph.getInEdges(potentialIntermediate); + for(EdgeEReference myEdgeEReference2 : mySourceIncidentEdges2){ + NodeEClass potentialTarget = myGraph.getSource(myEdgeEReference2); + if(potentialTarget==targetNode){ + if(Activator.log.isDebugEnabled()){ + Activator.log.debug("Found path source["+source.getInstanceTypeName()+"] <- "+myEdgeEReference2.getName()+"["+potentialIntermediate.geteClass().getInstanceTypeName()+"] <- target["+target.getInstanceTypeName()+"]"); + } + } + } + + Collection mySourceIncidentEdges3 = myGraph.getOutEdges(potentialIntermediate); + for(EdgeEReference myEdgeEReference3 : mySourceIncidentEdges3){ + NodeEClass potentialTarget = myGraph.getSource(myEdgeEReference3); + if(potentialTarget==targetNode){ + if(Activator.log.isDebugEnabled()){ + Activator.log.debug("Found path source["+source.getInstanceTypeName()+"] <- "+myEdgeEReference3.getName()+"["+potentialIntermediate.geteClass().getInstanceTypeName()+"] -> target["+target.getInstanceTypeName()+"]"); + } + } + } + } + + Collection mySourceIncidentEdges3 = myGraph.getOutEdges(sourceNode); + for(EdgeEReference myEdgeEReferenceZ : mySourceIncidentEdges3){ + NodeEClass potentialIntermediate = myGraph.getSource(myEdgeEReferenceZ); + Collection mySourceIncidentEdges2 = myGraph.getInEdges(potentialIntermediate); + for(EdgeEReference myEdgeEReferenceE : mySourceIncidentEdges2){ + NodeEClass potentialTarget = myGraph.getSource(myEdgeEReferenceE); + if(potentialTarget==targetNode){ + if(Activator.log.isDebugEnabled()){ + Activator.log.debug("Found path source["+source.getInstanceTypeName()+"] <- "+myEdgeEReferenceZ.getName()+"["+potentialIntermediate.geteClass().getInstanceTypeName()+"] <- target["+target.getInstanceTypeName()+"]"); + } + } + } + + Collection mySourceIncidentEdges4 = myGraph.getOutEdges(potentialIntermediate); + for(EdgeEReference myEdgeEReference4 : mySourceIncidentEdges4){ + NodeEClass potentialTarget = myGraph.getSource(myEdgeEReference4); + if(potentialTarget==targetNode){ + if(Activator.log.isDebugEnabled()){ + Activator.log.debug("Found path source["+source.getInstanceTypeName()+"] <- "+myEdgeEReferenceZ.getName()+"["+potentialIntermediate.geteClass().getInstanceTypeName()+"] -> target["+target.getInstanceTypeName()+"]"); + } + } + } + } + } + + + /** + * Generate an unique name for a given EReference based on the source and target + * @param myEClass + * @param er + * @param targetConcreteEClass + * @return + */ + private String buildUniqName(EClass myEClass, EReference er, EClass targetConcreteEClass) { + return er.getName()+NAME_SPLITTER+myEClass.getInstanceTypeName()+NAME_SPLITTER+er.getEType().getInstanceTypeName()+NAME_SPLITTER+targetConcreteEClass.getInstanceTypeName(); + } + + public UmlGraph getUmlGraph() { + return myGraph; + } + + public HashMap getEclass2Node() { + return nodeEClassMap; + } + + public static Uml2Graph getINSTANCE() { + return INSTANCE; + } + + public HashMap getNodeEClassMap() { + return nodeEClassMap; + } + + public HashMap> getEclass2ChildrenMap() { + return eclass2ChildrenMap; + } + + public HashMap> getEclass2ParentMap() { + return eclass2ParentMap; + } + + public HashMap getEdgeEReferenceMap() { + return edgeEReferenceMap; + } + + public UMLFactory getUmlFactory() { + return umlFactory; + } + +} diff --git a/extraplugins/uml/org.eclipse.papyrus.uml.diagram.dnd.smart/src/org/eclipse/papyrus/uml/diagram/dnd/smart/graph/api/AbstractUml2GraphServices.java b/extraplugins/uml/org.eclipse.papyrus.uml.diagram.dnd.smart/src/org/eclipse/papyrus/uml/diagram/dnd/smart/graph/api/AbstractUml2GraphServices.java new file mode 100644 index 00000000000..c7150c4807c --- /dev/null +++ b/extraplugins/uml/org.eclipse.papyrus.uml.diagram.dnd.smart/src/org/eclipse/papyrus/uml/diagram/dnd/smart/graph/api/AbstractUml2GraphServices.java @@ -0,0 +1,70 @@ +/***************************************************************************** + * Copyright (c) 2015 CEA LIST and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * CEA LIST - Initial API and implementation + * + *****************************************************************************/ +package org.eclipse.papyrus.uml.diagram.dnd.smart.graph.api; + +import java.util.Set; + +import org.eclipse.papyrus.uml.diagram.dnd.smart.graph.Uml2Graph; +import org.eclipse.papyrus.uml.diagram.dnd.smart.graph.model.NodeEClass; +import org.eclipse.papyrus.uml.diagram.dnd.smart.graph.model.Path; +import org.eclipse.papyrus.uml.diagram.dnd.smart.graph.service.AllPathDetector; + + +/** + * Shared implementation to retrieve the set of path for a given drag and drop + * @author Francois Le Fevre - francois.le-fevre@cea.fr + * + */ +public abstract class AbstractUml2GraphServices implements Uml2GraphServices { + + protected AllPathDetector allPathDetector; + + /** + * The graph view of the UML model + */ + protected Uml2Graph uml2Graph; + + public AbstractUml2GraphServices(){ + allPathDetector = new AllPathDetector(); + uml2Graph = Uml2Graph.getInstance(); + } + + public AbstractUml2GraphServices(int depth, int threshold){ + allPathDetector = new AllPathDetector(depth, threshold); + uml2Graph = Uml2Graph.getInstance(); + } + + /** + * @see org.eclipse.papyrus.uml.diagram.dnd.smart.graph.api.Uml2GraphServices#proposedActionsFromDnd(org.eclipse.papyrus.uml.diagram.dnd.smart.graph.model.NodeEClass, org.eclipse.papyrus.uml.diagram.dnd.smart.graph.model.NodeEClass) + * + * @param source + * @param target + * @return + */ + public Set proposedActionsFromDnd(NodeEClass source, NodeEClass target) { + //Compute the paths and filter them + return allPathDetector.filterAnalysis(uml2Graph,source, target); + } + + /* + * Getter + */ + + /** + * @return the allPathDetector + */ + public AllPathDetector getAllPathDetector() { + return allPathDetector; + } + +} diff --git a/extraplugins/uml/org.eclipse.papyrus.uml.diagram.dnd.smart/src/org/eclipse/papyrus/uml/diagram/dnd/smart/graph/api/Uml2GraphServices.java b/extraplugins/uml/org.eclipse.papyrus.uml.diagram.dnd.smart/src/org/eclipse/papyrus/uml/diagram/dnd/smart/graph/api/Uml2GraphServices.java new file mode 100644 index 00000000000..c6b8365d00c --- /dev/null +++ b/extraplugins/uml/org.eclipse.papyrus.uml.diagram.dnd.smart/src/org/eclipse/papyrus/uml/diagram/dnd/smart/graph/api/Uml2GraphServices.java @@ -0,0 +1,57 @@ +/***************************************************************************** + * Copyright (c) 2015 CEA LIST and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * CEA LIST - Initial API and implementation + * + *****************************************************************************/ +package org.eclipse.papyrus.uml.diagram.dnd.smart.graph.api; + +import java.util.Collection; +import java.util.Set; + +import org.eclipse.emf.ecore.EClass; +import org.eclipse.papyrus.uml.diagram.dnd.smart.graph.model.NodeEClass; +import org.eclipse.papyrus.uml.diagram.dnd.smart.graph.model.Path; + +/** + * Interface defining services relative to given a source/target give me the set of possible actions + * @author Francois Le Fevre - francois.le-fevre@cea.fr + * + */ +public interface Uml2GraphServices { + + /** + * @param source the initial EClass selected by the user in the ModelExplorer + * @param target the targeted EClass selected by the user in the Diagram + * @return the set of path could not be null + */ + public Set proposedActionsFromDnd(EClass source, EClass target); + + /** + * @param source the initial EClass selected by the user in the ModelExplorer + * @param target the targeted EClass selected by the user in the Diagram + * @return the set of path could not be null + */ + public Set proposedActionsFromDnd(String source, String target); + + /** + * @param source the initial EClass selected by the user in the ModelExplorer + * @param target the targeted EClass selected by the user in the Diagram + * @return the set of path could not be null + */ + public Set proposedActionsFromDnd(NodeEClass source, NodeEClass target); + + /** + * @param source the initial EClass selected by the user in the ModelExplorer + * @param target the targeted EClass selected by the user in the Diagram + * @return the set of path could not be null + */ + public Collection proposedLitteralActionsFromDnd(String source, String target); + +} diff --git a/extraplugins/uml/org.eclipse.papyrus.uml.diagram.dnd.smart/src/org/eclipse/papyrus/uml/diagram/dnd/smart/graph/model/AbstractUmlGraph.java b/extraplugins/uml/org.eclipse.papyrus.uml.diagram.dnd.smart/src/org/eclipse/papyrus/uml/diagram/dnd/smart/graph/model/AbstractUmlGraph.java new file mode 100644 index 00000000000..7c46446cdce --- /dev/null +++ b/extraplugins/uml/org.eclipse.papyrus.uml.diagram.dnd.smart/src/org/eclipse/papyrus/uml/diagram/dnd/smart/graph/model/AbstractUmlGraph.java @@ -0,0 +1,57 @@ +/***************************************************************************** + * Copyright (c) 2015 CEA LIST and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * CEA LIST - Initial API and implementation + * + *****************************************************************************/ + +package org.eclipse.papyrus.uml.diagram.dnd.smart.graph.model; + +import java.util.Collection; +import java.util.HashMap; + +/** + * The main class dedicated to hold the graph defintion of an uml model + * @author flefevre + * + */ +public abstract class AbstractUmlGraph implements IUmlGraph{ + + protected HashMap edge2Source; + protected HashMap edge2Target; + + protected HashMap> source2InEdges; + protected HashMap> source2OutEdges; + + public AbstractUmlGraph(){ + edge2Source = new HashMap(); + edge2Target = new HashMap(); + + source2InEdges = new HashMap>() ; + source2OutEdges = new HashMap>() ; + } + + public NodeEClass getSource(EdgeEReference myEdgeEReference){ + return edge2Source.get(myEdgeEReference); + } + + public NodeEClass getDest(EdgeEReference myEdgeEReference){ + return edge2Target.get(myEdgeEReference); + } + + + public Collection getOutEdges(NodeEClass nodeEClassEReference){ + return source2OutEdges.get(nodeEClassEReference); + } + + public Collection getInEdges(NodeEClass nodeEClassEReference){ + return source2InEdges.get(nodeEClassEReference); + } + +} diff --git a/extraplugins/uml/org.eclipse.papyrus.uml.diagram.dnd.smart/src/org/eclipse/papyrus/uml/diagram/dnd/smart/graph/model/EClassComparator.java b/extraplugins/uml/org.eclipse.papyrus.uml.diagram.dnd.smart/src/org/eclipse/papyrus/uml/diagram/dnd/smart/graph/model/EClassComparator.java new file mode 100644 index 00000000000..8d4ad9d40c6 --- /dev/null +++ b/extraplugins/uml/org.eclipse.papyrus.uml.diagram.dnd.smart/src/org/eclipse/papyrus/uml/diagram/dnd/smart/graph/model/EClassComparator.java @@ -0,0 +1,34 @@ +/***************************************************************************** + * Copyright (c) 2015 CEA LIST and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * CEA LIST - Initial API and implementation + * + *****************************************************************************/ +package org.eclipse.papyrus.uml.diagram.dnd.smart.graph.model; + +import java.util.Comparator; + +import org.eclipse.emf.ecore.EClass; + +/** + * Comparator of two ECLass + * @author flefevre + * + */ +public class EClassComparator implements Comparator{ + + public int compare(EClass e1, EClass e2) { + if(e1.getName()!=null){ + return e1.getName().compareTo(e2.getName()); + } + else{ + return -1; + } + } +} diff --git a/extraplugins/uml/org.eclipse.papyrus.uml.diagram.dnd.smart/src/org/eclipse/papyrus/uml/diagram/dnd/smart/graph/model/EdgeEReference.java b/extraplugins/uml/org.eclipse.papyrus.uml.diagram.dnd.smart/src/org/eclipse/papyrus/uml/diagram/dnd/smart/graph/model/EdgeEReference.java new file mode 100644 index 00000000000..343da05c3be --- /dev/null +++ b/extraplugins/uml/org.eclipse.papyrus.uml.diagram.dnd.smart/src/org/eclipse/papyrus/uml/diagram/dnd/smart/graph/model/EdgeEReference.java @@ -0,0 +1,110 @@ +/***************************************************************************** + * Copyright (c) 2015 CEA LIST and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * CEA LIST - Initial API and implementation + * + *****************************************************************************/ +package org.eclipse.papyrus.uml.diagram.dnd.smart.graph.model; + +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EReference; + +/** + * Object model to manipulate the edges of the uml graph + * @author Francois Le Fevre - CEA francois.le-fevre@cea.fr + * + */ +public class EdgeEReference implements Comparable{ + + /** + * the name of the Ecore EdgeEreference + * + */ + private final String name; + /** + * is the EReference a composition + */ + private final boolean isComposition; + /** + * the Ecore Ereference + */ + private final EReference eReference; + /** + * the target class associated with the EReference + */ + private final EClass targetConcretEclasse; + + public EdgeEReference(String name, boolean isComposition, EReference eReference,EClass targetConcretEclasse) { + super(); + this.name = name; + this.isComposition=isComposition; + this.eReference = eReference; + this.targetConcretEclasse = targetConcretEclasse; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((eReference == null) ? 0 : eReference.hashCode()); + result = prime * result + (isComposition ? 1231 : 1237); + result = prime * result + ((name == null) ? 0 : name.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + EdgeEReference other = (EdgeEReference) obj; + if (eReference == null) { + if (other.eReference != null) + return false; + } else if (!eReference.equals(other.eReference)) + return false; + if (isComposition != other.isComposition) + return false; + if (name == null) { + if (other.name != null) + return false; + } else if (!name.equals(other.name)) + return false; + return true; + } + + public int compareTo(EdgeEReference o) { + + return this.getName().compareTo(o.getName()); + } + + /* + * getter methods + */ + + public EClass getTargetConcretEclasse() { + return targetConcretEclasse; + } + + public String getName() { + return name; + } + + public boolean isComposition() { + return isComposition; + } + + public EReference geteReference() { + return eReference; + } + +} diff --git a/extraplugins/uml/org.eclipse.papyrus.uml.diagram.dnd.smart/src/org/eclipse/papyrus/uml/diagram/dnd/smart/graph/model/IUmlGraph.java b/extraplugins/uml/org.eclipse.papyrus.uml.diagram.dnd.smart/src/org/eclipse/papyrus/uml/diagram/dnd/smart/graph/model/IUmlGraph.java new file mode 100644 index 00000000000..b3269c1449b --- /dev/null +++ b/extraplugins/uml/org.eclipse.papyrus.uml.diagram.dnd.smart/src/org/eclipse/papyrus/uml/diagram/dnd/smart/graph/model/IUmlGraph.java @@ -0,0 +1,67 @@ +/***************************************************************************** + * Copyright (c) 2015 CEA LIST and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * CEA LIST - Initial API and implementation + * + *****************************************************************************/ + +package org.eclipse.papyrus.uml.diagram.dnd.smart.graph.model; + +import java.util.Collection; + +/** + * Interface defining the contracts to add edge or vertex and the getter methods + * @author flefevre + * + */ +public interface IUmlGraph{ + + /** + * @param nodeEClassEReference non-null + */ + public void addVertex(NodeEClass nodeEClassEReference); + + /** + * @param edgeEReference non-null ecore ereference between the source and the target + * @param source non-null + * @param target non-null + * @return + */ + public boolean addEdge(EdgeEReference edgeEReference, NodeEClass source, NodeEClass target); + + /** + * given an Edge it should return the source NodeEClass + * @param myEdgeEReference + * @return + */ + public NodeEClass getSource(EdgeEReference myEdgeEReference); + + + /** + * given an Edge it should return the target NodeEClass + * @param myEdgeEReference + * @return + */ + public NodeEClass getDest(EdgeEReference myEdgeEReference); + + /** + * given a nodeEClass, return the collection of outgoing edges + * @param nodeEClassEReference + * @return + */ + public Collection getOutEdges(NodeEClass nodeEClassEReference); + + /** + * given a nodeEClass, return the collection of ingoing edges + * @param nodeEClassEReference + * @return + */ + public Collection getInEdges(NodeEClass nodeEClassEReference); + +} diff --git a/extraplugins/uml/org.eclipse.papyrus.uml.diagram.dnd.smart/src/org/eclipse/papyrus/uml/diagram/dnd/smart/graph/model/NodeEClass.java b/extraplugins/uml/org.eclipse.papyrus.uml.diagram.dnd.smart/src/org/eclipse/papyrus/uml/diagram/dnd/smart/graph/model/NodeEClass.java new file mode 100644 index 00000000000..382a87edcf9 --- /dev/null +++ b/extraplugins/uml/org.eclipse.papyrus.uml.diagram.dnd.smart/src/org/eclipse/papyrus/uml/diagram/dnd/smart/graph/model/NodeEClass.java @@ -0,0 +1,89 @@ +/***************************************************************************** + * Copyright (c) 2015 CEA LIST and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * CEA LIST - Initial API and implementation + * + *****************************************************************************/ +package org.eclipse.papyrus.uml.diagram.dnd.smart.graph.model; + +import org.eclipse.emf.ecore.EClass; + +/** + * Object model to manipulate the node of the uml graph + * @author Francois Le Fevre - CEA francois.le-fevre@cea.fr + * + */ +public class NodeEClass implements Comparable{ + + /** + * the name of the EClass + */ + private String name; + /** + * the ECore EClass + */ + private EClass eClass; + + public NodeEClass(String name, EClass eClass) { + super(); + this.name = name; + this.eClass = eClass; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((name == null) ? 0 : name.hashCode()); + return result; + } + + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + NodeEClass other = (NodeEClass) obj; + if (name == null) { + if (other.name != null) + return false; + } else if (!name.equals(other.name)) + return false; + return true; + } + + + public int compareTo(NodeEClass o) { + + return this.getName().compareTo(o.getName()); + } + + + @Override + public String toString() { + return name ; + } + + /* + * Getter methods + */ + + + public EClass geteClass() { + return eClass; + } + + public String getName() { + return name; + } +} diff --git a/extraplugins/uml/org.eclipse.papyrus.uml.diagram.dnd.smart/src/org/eclipse/papyrus/uml/diagram/dnd/smart/graph/model/Path.java b/extraplugins/uml/org.eclipse.papyrus.uml.diagram.dnd.smart/src/org/eclipse/papyrus/uml/diagram/dnd/smart/graph/model/Path.java new file mode 100644 index 00000000000..29d0f6ea638 --- /dev/null +++ b/extraplugins/uml/org.eclipse.papyrus.uml.diagram.dnd.smart/src/org/eclipse/papyrus/uml/diagram/dnd/smart/graph/model/Path.java @@ -0,0 +1,83 @@ +/***************************************************************************** + * Copyright (c) 2015 CEA LIST and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * CEA LIST - Initial API and implementation + * + *****************************************************************************/ +package org.eclipse.papyrus.uml.diagram.dnd.smart.graph.model; + +import java.util.List; + +/** + * A path is the succession of EdgeEReference between two NodeEClass + * @author Francois Le Fevre - CEA francois.le-fevre@cea.fr + */ +public class Path implements Comparable{ + + private final List way; + private final String name; + + public Path(List way) { + super(); + this.way = way; + this.name = getRepresentation(way); + } + + + private String getRepresentation(List path){ + StringBuffer tmp = new StringBuffer(); + for(EdgeEReference c : path){ + tmp.append(c.getName()+" _ "); + } + return tmp.toString(); + } + + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((name == null) ? 0 : name.hashCode()); + return result; + } + + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Path other = (Path) obj; + if (name == null) { + if (other.name != null) + return false; + } else if (!name.equals(other.name)) + return false; + return true; + } + + + public List getWay() { + return way; + } + + + public String getName() { + return name; + } + + + public int compareTo(Path o) { + return name.compareTo(o.getName()); + } + +} diff --git a/extraplugins/uml/org.eclipse.papyrus.uml.diagram.dnd.smart/src/org/eclipse/papyrus/uml/diagram/dnd/smart/graph/model/UmlGraph.java b/extraplugins/uml/org.eclipse.papyrus.uml.diagram.dnd.smart/src/org/eclipse/papyrus/uml/diagram/dnd/smart/graph/model/UmlGraph.java new file mode 100644 index 00000000000..393458310e6 --- /dev/null +++ b/extraplugins/uml/org.eclipse.papyrus.uml.diagram.dnd.smart/src/org/eclipse/papyrus/uml/diagram/dnd/smart/graph/model/UmlGraph.java @@ -0,0 +1,56 @@ +/***************************************************************************** + * Copyright (c) 2015 CEA LIST and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * CEA LIST - Initial API and implementation + * + *****************************************************************************/ + +package org.eclipse.papyrus.uml.diagram.dnd.smart.graph.model; + +import java.util.ArrayList; +import java.util.Collection; + +/** + * The main class dedicated to hold the graph defintion of an uml model + * @author flefevre + * + */ +public class UmlGraph extends AbstractUmlGraph{ + + public UmlGraph(){ + super(); + } + + public void addVertex(NodeEClass nodeEClassEReference){ + source2InEdges.put(nodeEClassEReference,new ArrayList()); + source2OutEdges.put(nodeEClassEReference,new ArrayList()); + } + + public boolean addEdge(EdgeEReference edgeEReference, NodeEClass source, NodeEClass target){ + edge2Source.put(edgeEReference, source); + edge2Target.put(edgeEReference, target); + + Collection ins = source2InEdges.get(target); + if(ins==null){ + ins = new ArrayList(); + } + ins.add(edgeEReference); + source2InEdges.put(target,ins); + + Collection outs = source2OutEdges.get(source); + if(outs==null){ + outs = new ArrayList(); + } + outs.add(edgeEReference); + source2OutEdges.put(source, outs); + + return true; + } + +} diff --git a/extraplugins/uml/org.eclipse.papyrus.uml.diagram.dnd.smart/src/org/eclipse/papyrus/uml/diagram/dnd/smart/graph/service/AllPathDetector.java b/extraplugins/uml/org.eclipse.papyrus.uml.diagram.dnd.smart/src/org/eclipse/papyrus/uml/diagram/dnd/smart/graph/service/AllPathDetector.java new file mode 100644 index 00000000000..a000b9ec0a4 --- /dev/null +++ b/extraplugins/uml/org.eclipse.papyrus.uml.diagram.dnd.smart/src/org/eclipse/papyrus/uml/diagram/dnd/smart/graph/service/AllPathDetector.java @@ -0,0 +1,258 @@ +/***************************************************************************** + * Copyright (c) 2015 CEA LIST and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * CEA LIST - Initial API and implementation + * + *****************************************************************************/ +package org.eclipse.papyrus.uml.diagram.dnd.smart.graph.service; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Set; +import java.util.TreeSet; + +import org.eclipse.papyrus.infra.emf.Activator; +import org.eclipse.papyrus.uml.diagram.dnd.smart.graph.Uml2Graph; +import org.eclipse.papyrus.uml.diagram.dnd.smart.graph.model.EdgeEReference; +import org.eclipse.papyrus.uml.diagram.dnd.smart.graph.model.NodeEClass; +import org.eclipse.papyrus.uml.diagram.dnd.smart.graph.model.Path; +import org.eclipse.papyrus.uml.diagram.dnd.smart.graph.model.UmlGraph; +import org.eclipse.papyrus.uml.diagram.dnd.smart.graph.util.FilterUtils; + +import java.util.Date; + +/** + * Class dedicated to compute the path between two nodes given an uml graph + * @author Francois Le Fevre - CEA francois.le-fevre@cea.fr + */ +public class AllPathDetector +{ + /** + * the maximum number of edges to walk throught + */ + protected int depth; + + /** + * the maximum number of path to filter + */ + protected int displayThreshold; + + protected HashMap > precomputePath; + + public AllPathDetector(){ + this.depth = 2; + this.displayThreshold=20; + precomputePath = new HashMap>(); + } + + public AllPathDetector(int depth, int threshold){ + this.depth = depth; + this.displayThreshold=threshold; + precomputePath = new HashMap>(); + } + + /** + * Given a graph, a start node and a end node, and the maximum steps , it will return a list of possible path between the two nodes + * @param graph + * @param startNode + * @param endNode + * @param maxDepth + * @return + */ + public List getAllPathsBetweenNodes(UmlGraph graph, + NodeEClass startNode, NodeEClass endNode, int maxDepth) + { + List allPaths = new ArrayList(); + + List currentPath = new ArrayList(); + + findAllPaths(startNode, startNode, endNode, currentPath, graph, maxDepth , 0 , allPaths); + + return allPaths; + } + + /** + * Recursive methods in charge to compute the different paths between a start and an end node given a maximum of edges to walk throught + * @param currentNode + * @param startNode + * @param endNode + * @param currentPath + * @param graph + * @param maxDepth + * @param currentDepth + * @param allPaths + */ + public void findAllPaths(NodeEClass currentNode, NodeEClass startNode, NodeEClass endNode, + List currentPath,UmlGraph graph, + int maxDepth, int currentDepth, List allPaths) + { + + Collection outgoingEdges = graph.getOutEdges(currentNode); + if (currentDepth < maxDepth) + { + for (EdgeEReference outEdge : outgoingEdges) + { + NodeEClass outNode = graph.getDest(outEdge); + if (outNode.equals(startNode)) + { + List cyclePath = new ArrayList(currentPath); + cyclePath.add(outEdge); + continue; + } + + List newPath = new ArrayList(currentPath); + newPath.add(outEdge); + + if (outNode.equals(endNode)) + { + Path myPath = new Path(newPath); + allPaths.add(myPath); + continue; + } + + findAllPaths(outNode, startNode, endNode, newPath, graph, maxDepth, currentDepth + 1, allPaths); + } + } + } + + /** + * Method in charge to filter the different paths found, to retrieve a shorter number of soultion. + * it is an heuristic. + * @param uml2graph + * @param source + * @param target + * @return + */ + public Set filterAnalysis(Uml2Graph uml2graph, NodeEClass source, NodeEClass target){ + Date startTime = new Date(); + + Set result = precomputePath.get(source.getName()+Uml2Graph.NAME_SPLITTER+target.getName()); + + if(result==null){ + result = new TreeSet(); + + List resultFull = getAllPathsBetweenNodes(uml2graph.getUmlGraph(), target ,source, depth); + Date endTime = new Date(); + + if(Activator.log.isDebugEnabled()){ + Activator.log.debug("path compute in "+(endTime.getTime()-startTime.getTime())); + } + + startTime = new Date(); + List hard = FilterUtils.hardFilter(resultFull); + + List tmp = new ArrayList(); + if(hard.size()<=displayThreshold){ + result.addAll(hard); + } + else{ + for(Path h : hard){ + if(h.getWay().size()<=2){ + tmp.add(h); + } + } + + if(tmp.size()<=displayThreshold){ + result.addAll(tmp); + } + } + + List soft = FilterUtils.softFilter(resultFull); + tmp = new ArrayList(); + if(soft.size()<=displayThreshold){ + result.addAll(soft); + } + else{ + for(Path s : soft){ + if(s.getWay().size()<=2){ + tmp.add(s); + } + } + + if(tmp.size()<=displayThreshold){ + result.addAll(tmp); + } + } + List trim = FilterUtils.trimFilter(resultFull); + tmp = new ArrayList(); + if(trim.size()<=displayThreshold){ + result.addAll(trim); + } + else{ + for(Path t : trim){ + if(t.getWay().size()<=2){ + tmp.add(t); + } + } + + if(tmp.size()<=displayThreshold){ + result.addAll(tmp); + } + } + List end = FilterUtils.endFilter(resultFull); + tmp = new ArrayList(); + if(end.size()<=displayThreshold){ + result.addAll(end); + } + else{ + for(Path e : end){ + if(e.getWay().size()<=2){ + tmp.add(e); + } + } + + if(tmp.size()<=displayThreshold){ + result.addAll(tmp); + } + } + + precomputePath.put(source.getName()+Uml2Graph.NAME_SPLITTER+target.getName(), result); + endTime = new Date(); + if(Activator.log.isDebugEnabled()){ + Activator.log.debug("path filter in "+(endTime.getTime()-startTime.getTime())); + } + } + + return result; + } + + /* + * getter and setter + */ + + /** + * @return the depth + */ + public int getDepth() { + return depth; + } + + /** + * @param depth the depth to set + */ + public void setDepth(int depth) { + this.depth = depth; + } + + /** + * @return the displayThreshold + */ + public int getDisplayThreshold() { + return displayThreshold; + } + + /** + * @param displayThreshold the displayThreshold to set + */ + public void setDisplayThreshold(int displayThreshold) { + this.displayThreshold = displayThreshold; + } +} \ No newline at end of file diff --git a/extraplugins/uml/org.eclipse.papyrus.uml.diagram.dnd.smart/src/org/eclipse/papyrus/uml/diagram/dnd/smart/graph/service/GenericUml2GraphServices.java b/extraplugins/uml/org.eclipse.papyrus.uml.diagram.dnd.smart/src/org/eclipse/papyrus/uml/diagram/dnd/smart/graph/service/GenericUml2GraphServices.java new file mode 100644 index 00000000000..729d16f6367 --- /dev/null +++ b/extraplugins/uml/org.eclipse.papyrus.uml.diagram.dnd.smart/src/org/eclipse/papyrus/uml/diagram/dnd/smart/graph/service/GenericUml2GraphServices.java @@ -0,0 +1,88 @@ +/***************************************************************************** + * Copyright (c) 2015 CEA LIST and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * CEA LIST - Initial API and implementation + * + *****************************************************************************/ +package org.eclipse.papyrus.uml.diagram.dnd.smart.graph.service; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Set; + +import org.eclipse.emf.ecore.EClass; +import org.eclipse.papyrus.uml.diagram.dnd.smart.graph.api.AbstractUml2GraphServices; +import org.eclipse.papyrus.uml.diagram.dnd.smart.graph.model.NodeEClass; +import org.eclipse.papyrus.uml.diagram.dnd.smart.graph.model.Path; + +/** + * One basic implementation to retrieve Path of actions given a set of source/target elements + * @author flefevre + * + */ +public class GenericUml2GraphServices extends AbstractUml2GraphServices { + + + public GenericUml2GraphServices() + { + super(); + } + + public GenericUml2GraphServices(int depth, int threshold) + { + super(depth,threshold); + } + + /** + * @see org.eclipse.papyrus.uml.diagram.dnd.smart.graph.api.Uml2GraphServices#proposedActionsFromDnd(org.eclipse.emf.ecore.EClass, org.eclipse.emf.ecore.EClass) + * + * @param source + * @param target + * @return + */ + public Set proposedActionsFromDnd(EClass source, EClass target) { + //Retrieve the node from the graph + NodeEClass mySourceNode = uml2Graph.getNodeEClassMap().get(source.getInstanceTypeName()); + NodeEClass myTargetNode = uml2Graph.getNodeEClassMap().get(target.getInstanceTypeName()); + //Compute the paths and filter them + return proposedActionsFromDnd(mySourceNode, myTargetNode) ; + } + + /** + * @see org.eclipse.papyrus.uml.diagram.dnd.smart.graph.api.Uml2GraphServices#proposedActionsFromDnd(java.lang.String, java.lang.String) + * + * @param source + * @param target + * @return + */ + public Set proposedActionsFromDnd(String source, String target) { + NodeEClass mySourceNode = uml2Graph.getNodeEClassMap().get(source); + NodeEClass myTargetNode = uml2Graph.getNodeEClassMap().get(target); + return proposedActionsFromDnd(mySourceNode, myTargetNode); + } + + /** + * @see org.eclipse.papyrus.uml.diagram.dnd.smart.graph.api.Uml2GraphServices#proposedLitteralActionsFromDnd(java.lang.String, java.lang.String) + * + * @param source + * @param target + * @return + */ + public Collection proposedLitteralActionsFromDnd(String source, String target) { + Collection result = new ArrayList(); + + Set paths= proposedActionsFromDnd(source, target); + + for(Path p :paths){ + result.add(p.getName()+"\n"); + } + return result; + } + +} diff --git a/extraplugins/uml/org.eclipse.papyrus.uml.diagram.dnd.smart/src/org/eclipse/papyrus/uml/diagram/dnd/smart/graph/util/FilterUtils.java b/extraplugins/uml/org.eclipse.papyrus.uml.diagram.dnd.smart/src/org/eclipse/papyrus/uml/diagram/dnd/smart/graph/util/FilterUtils.java new file mode 100644 index 00000000000..9310dc5f922 --- /dev/null +++ b/extraplugins/uml/org.eclipse.papyrus.uml.diagram.dnd.smart/src/org/eclipse/papyrus/uml/diagram/dnd/smart/graph/util/FilterUtils.java @@ -0,0 +1,120 @@ +/***************************************************************************** + * Copyright (c) 2015 CEA LIST and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * CEA LIST - Initial API and implementation + * + *****************************************************************************/ + +package org.eclipse.papyrus.uml.diagram.dnd.smart.graph.util; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.papyrus.uml.diagram.dnd.smart.graph.Uml2Graph; +import org.eclipse.papyrus.uml.diagram.dnd.smart.graph.model.EdgeEReference; +import org.eclipse.papyrus.uml.diagram.dnd.smart.graph.model.Path; + +/** + * A set of filter methods in charge to reduce the number of paths found. + * @author flefevre + * + */ +public class FilterUtils { + + public static List hardFilter(List bs){ + List result = new ArrayList(); + + boolean isprint; + for(Path b : bs){ + isprint=true; + for(EdgeEReference c : b.getWay()){ + String[] names = c.getName().split(Uml2Graph.NAME_SPLITTER); + if(!names[2].equals(names[3])){ + isprint=false; + break; + } + } + + if(isprint){ + result.add(b); + } + } + + return result; + } + + public static List softFilter(List bs){ + List result = new ArrayList(); + + boolean isprint; + for(Path b : bs){ + isprint=false; + for(EdgeEReference c : b.getWay()){ + String[] names = c.getName().split(Uml2Graph.NAME_SPLITTER); + if(names[2].equals(names[3])){ + isprint=true; + } + } + + if(isprint){ + result.add(b); + } + } + + return result; + } + + public static List endFilter(List bs){ + List result = new ArrayList(); + + boolean isprint; + for(Path b : bs){ + isprint=false; + + EdgeEReference c = b.getWay().get(b.getWay().size()-1); + String[] names = c.getName().split(Uml2Graph.NAME_SPLITTER); + if(names[2].equals(names[3])){ + isprint=true; + } + + if(isprint){ + result.add(b); + } + } + + return result; + } + + public static List startFilter(List bs){ + List result = new ArrayList(); + + boolean isprint; + for(Path b : bs){ + isprint=false; + + EdgeEReference c = b.getWay().get(0); + String[] names = c.getName().split(Uml2Graph.NAME_SPLITTER); + if(names[2].equals(names[3])){ + isprint=true; + } + + if(isprint){ + result.add(b); + } + } + + return result; + } + + public static List trimFilter(List bs){ + List tmp = endFilter(bs); + return startFilter(tmp); + } + +} diff --git a/extraplugins/uml/org.eclipse.papyrus.uml.diagram.dnd.smart/src/org/eclipse/papyrus/uml/diagram/dnd/smart/messages/Messages.java b/extraplugins/uml/org.eclipse.papyrus.uml.diagram.dnd.smart/src/org/eclipse/papyrus/uml/diagram/dnd/smart/messages/Messages.java new file mode 100644 index 00000000000..efd8cf6961b --- /dev/null +++ b/extraplugins/uml/org.eclipse.papyrus.uml.diagram.dnd.smart/src/org/eclipse/papyrus/uml/diagram/dnd/smart/messages/Messages.java @@ -0,0 +1,33 @@ +/***************************************************************************** + * Copyright (c) 2015 CEA LIST and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * CEA LIST - Initial API and implementation + * + *****************************************************************************/ +package org.eclipse.papyrus.uml.diagram.dnd.smart.messages; + +import org.eclipse.osgi.util.NLS; + +/** + * @author flefevre + * + */ +public class Messages extends NLS { + private static final String BUNDLE_NAME = "org.eclipse.papyrus.uml.diagram.dnd.smart.messages.messages"; //$NON-NLS-1$ + public static String SmartDropStrategy_Description; + public static String SmartDropStrategy_Label; + + static { + // initialize resource bundle + NLS.initializeMessages(BUNDLE_NAME, Messages.class); + } + + private Messages() { + } +} diff --git a/extraplugins/uml/org.eclipse.papyrus.uml.diagram.dnd.smart/src/org/eclipse/papyrus/uml/diagram/dnd/smart/messages/messages.properties b/extraplugins/uml/org.eclipse.papyrus.uml.diagram.dnd.smart/src/org/eclipse/papyrus/uml/diagram/dnd/smart/messages/messages.properties new file mode 100644 index 00000000000..7a3a252cb88 --- /dev/null +++ b/extraplugins/uml/org.eclipse.papyrus.uml.diagram.dnd.smart/src/org/eclipse/papyrus/uml/diagram/dnd/smart/messages/messages.properties @@ -0,0 +1,2 @@ +SmartDropStrategy_Description=SmartDrop an eobject into a target eobject +SmartDropStrategy_Label=SmartDrop will propose you any available command. \ No newline at end of file diff --git a/extraplugins/uml/org.eclipse.papyrus.uml.diagram.dnd.smart/src/org/eclipse/papyrus/uml/diagram/dnd/smart/strategy/SmartDropStrategy.java b/extraplugins/uml/org.eclipse.papyrus.uml.diagram.dnd.smart/src/org/eclipse/papyrus/uml/diagram/dnd/smart/strategy/SmartDropStrategy.java new file mode 100644 index 00000000000..fa6044e3dde --- /dev/null +++ b/extraplugins/uml/org.eclipse.papyrus.uml.diagram.dnd.smart/src/org/eclipse/papyrus/uml/diagram/dnd/smart/strategy/SmartDropStrategy.java @@ -0,0 +1,207 @@ +/***************************************************************************** + * Copyright (c) 2015 CEA LIST and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * CEA LIST - Initial API and implementation + * + *****************************************************************************/ +package org.eclipse.papyrus.uml.diagram.dnd.smart.strategy; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Set; + +import org.eclipse.draw2d.geometry.Point; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.EReference; +import org.eclipse.emf.ecore.util.FeatureMapUtil; +import org.eclipse.gef.EditPart; +import org.eclipse.gef.Request; +import org.eclipse.gef.commands.Command; +import org.eclipse.gmf.runtime.common.core.command.CompositeCommand; +import org.eclipse.gmf.runtime.diagram.ui.commands.CommandProxy; +import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy; +import org.eclipse.gmf.runtime.diagram.ui.requests.DropObjectsRequest; +import org.eclipse.gmf.runtime.emf.core.util.EMFCoreUtil; +import org.eclipse.papyrus.infra.gmfdiag.dnd.strategy.TransactionalCommandsDropStrategy; +import org.eclipse.papyrus.infra.services.edit.service.ElementEditServiceUtils; +import org.eclipse.papyrus.infra.services.edit.service.IElementEditService; +import org.eclipse.papyrus.uml.diagram.dnd.smart.Activator; +import org.eclipse.papyrus.uml.diagram.dnd.smart.graph.model.EdgeEReference; +import org.eclipse.papyrus.uml.diagram.dnd.smart.graph.model.Path; +import org.eclipse.papyrus.uml.diagram.dnd.smart.graph.service.GenericUml2GraphServices; +import org.eclipse.papyrus.uml.diagram.dnd.smart.messages.Messages; +import org.eclipse.swt.graphics.Image; + +/** + * A DropStrategy to "Signal" a Class. + * Drop a signal on a Class operation section to type it. + * This will create a new Reception operation in the interaction, typed by the dropped classifier. + * + * @author Francois Le Fevre + * + */ +public class SmartDropStrategy extends TransactionalCommandsDropStrategy { + + GenericUml2GraphServices genericUml2GraphServices; + + public SmartDropStrategy(){ + genericUml2GraphServices = new GenericUml2GraphServices(); + } + + public String getLabel() { + return Messages.SmartDropStrategy_Label; + } + + public String getDescription() { + return Messages.SmartDropStrategy_Description; + } + + public Image getImage() { + return null; + } + + public String getID() { + return Activator.PLUGIN_ID + ".smart.represents"; //$NON-NLS-1$ + } + + /** + * @see org.eclipse.papyrus.infra.gmfdiag.dnd.strategy.DropStrategy#getPriority() + * + * @return + * @deprecated + */ + public int getPriority() { + return 0; + } + + /** + * @see org.eclipse.papyrus.infra.gmfdiag.dnd.strategy.TransactionalCommandsDropStrategy#doGetCommands(org.eclipse.gef.Request, org.eclipse.gef.EditPart) + * + * @param request + * @param targetEditPart + * @return + */ + @Override + protected List doGetCommands(Request request, final EditPart targetEditPart) { + List sourceElements = getSourceEObjects(request); + // The only supported case is "Drop a single signal on a single Operation of a Classifier" + if (sourceElements.size() != 1) { + return null; + } + final EObject sourceElement = sourceElements.get(0); + + final EObject targetElement = getTargetSemanticElement(targetEditPart); + + final Set paths = genericUml2GraphServices.proposedActionsFromDnd(sourceElement.eClass(), targetElement.eClass()); + if(Activator.log.isDebugEnabled()){ + Activator.log.debug("paths size "+paths.size()); + } + + IElementEditService provider = ElementEditServiceUtils.getCommandProvider(sourceElement); + if(provider == null) { + return null; + } + + List myCommands = new ArrayList(); + + for(final Path p : paths){ + + CompositeCommand cc = new CompositeCommand(getLabel()); + + Command resultCommand = new Command(getLabel()) { + @SuppressWarnings("unchecked") + @Override + public void execute() { + EObject container= targetElement; + + //Filter to have only one command + //Doing the initial cascade from Target to Source + for(int i=0; i< p.getWay().size()-1 ; i++){ + EdgeEReference er = p.getWay().get(i); + if(Activator.log.isDebugEnabled()){ + Activator.log.debug("creation of "+er.geteReference().getName()+"\tin "+container.toString()+"\twith "+ er.getTargetConcretEclasse().getInstanceTypeName()); + } + + // Creates the slot + EObject newlyIntermediateEObject = EMFCoreUtil.create(container, er.geteReference(), er.getTargetConcretEclasse()); + + //set name + if(newlyIntermediateEObject.eClass().getEStructuralFeature("name")!=null){ + newlyIntermediateEObject.eSet(newlyIntermediateEObject.eClass().getEStructuralFeature("name"), er.geteReference().getName());//$NON-NLS-1$ + } + + container=newlyIntermediateEObject; + } + //Finally the set the final intermediate with the Source + EReference er = p.getWay().get(p.getWay().size()-1).geteReference(); + if (FeatureMapUtil.isMany(container,er)) { + ((Collection) container.eGet(er)).add(sourceElement); + } else { + container.eSet(er, sourceElement); + } + + //Graphical command: key question on which element + DropObjectsRequest dropObjectsRequest = new DropObjectsRequest(); + ArrayList list = new ArrayList(); + if(Activator.log.isDebugEnabled()){ + Activator.log.debug("will display "+container); + } + + list.add(container); + dropObjectsRequest.setObjects(list); + dropObjectsRequest.setLocation(new Point(-1,-1)); + Command command = targetEditPart.getCommand(dropObjectsRequest); + if( command!=null){ + command.execute(); + } + } + }; + cc.add(new CommandProxy(resultCommand)); + + + if(cc.canExecute()){ + ICommandProxy ic = new ICommandProxy(cc.reduce()); + String[] shortty = p.getName().split(" _ "); + String name = new String(); + String splitter = new String(""); + + if(shortty.length>1){ + + name = name.concat("create a "); + int n=0; + for(String s : shortty){ + String[] t = s.split("@"); + + if(n==shortty.length-1){ + splitter = " with your dropped element referenced as "; + name = name.concat(splitter+ t[0].replace("org.eclipse.uml2.uml.", "")+"("+t[3].replace("org.eclipse.uml2.uml.", "")+")"); + } + else{ + name = name.concat(splitter+ t[0].replace("org.eclipse.uml2.uml.", "")+"("+t[3].replace("org.eclipse.uml2.uml.", "")+")"); + splitter = " with "; + } + n++; + } + } + else{ + String[] t = shortty[0].split("@"); + name = name.concat("create a reference of your dropped element as ("+t[3].replace("org.eclipse.uml2.uml.", "")+")"); + } + + ic.setLabel("SmartDrop "+(shortty.length-1)+": "+name); + myCommands.add(ic); + } + + } + + return myCommands; + } + +} -- cgit v1.2.3