diff options
author | Mickael ADAM | 2016-03-16 14:49:43 +0000 |
---|---|---|
committer | Mickael ADAM | 2016-09-01 09:55:09 +0000 |
commit | 75ecec82c71fc8aa66cca8eb69e9af6826d1fdfb (patch) | |
tree | 590f763976234be004160837806de13410011579 /plugins/customization/org.eclipse.papyrus.customization.palette | |
parent | 54b12e645d111ca4f66fef2c512ac53ecfbfc0eb (diff) | |
download | org.eclipse.papyrus-75ecec82c71fc8aa66cca8eb69e9af6826d1fdfb.tar.gz org.eclipse.papyrus-75ecec82c71fc8aa66cca8eb69e9af6826d1fdfb.tar.xz org.eclipse.papyrus-75ecec82c71fc8aa66cca8eb69e9af6826d1fdfb.zip |
Bug 482669 - [Palette] New Palette configuration models shall be
editable with an advance UI
https://bugs.eclipse.org/bugs/show_bug.cgi?id=482669
Patch set 27:
- rebase & maj dependency version
Patch set 25:
- Fix dependency version
Patch set 24:
- update version to 3.0.0 or 2.1
- take into account of new elemntType version (no more Ids)
- refactor ProdileWSModelIndexer to use URI
Patch set 23:
- rebase
- remove CustomElmtTypeFactory
Patch set 20:
- Fix missing id in manual created advices
Patch set 17:
- Fix bugs from NiF review
patch set 16:
- Fix a bug of drag a stereotype then a metaclass => NPE
patch set 16:
- fix ProfileWorkspaceModelIndex
- add shouldIndex(IFile file) to IndexHandler
patch set 15:
- fix a build.properties
Patch set 14:
- some minors fixes
Patch set 13:
- Finalize properties view for actions
- implements validators.
- Adds plugins to oep.customization.feature
Patch set 12:
- implement properties view for SetValue Advice, SetStereotype and
Runtime advice.
- new Explorer dialog(Stereotype, Profile, GenericElement)
-...
Patch set 11:
- final implementation of apply stereotype action properties view
- fix feedback from NIF previous review.
- fix enable button of generic multipleValueEditor
- Styled text for stereotype explorer
- add profile explorer
- add stereotype attribute explorer
- many fixes
Patch set 10:
- Move created plugin in customization feature
Patch set 9:
-Fix pom dependencies
Patch set 8:
- implementation of property view for StereotypesToAplly of Action.
- create a Icon Value editor instead of IconDescriptor
- Create stereotype selection dialog which display all available
stereotype
- Create Profile workspace indexer
Patch set X:
- create StringWithClear Editor
- rename property plugin
- remove assistant and newChild implementation for palette
- use of icon 12*12 from oep.infr.widget
Patch set 5:
- Fix pom file
Patch set 4:
- inlude all changes from palette customization branch
Patch set 3:
- Adds clear filter button for icon explorer.
- Adds some newChild management requirement.
Patch set 2:
- Gets all declared advice kind in add actions.
- Adds icon+description to AdviceKindExtensionPoint.
- Adds createAdviceBindingConfiguration to
AbstractAdviceBindingFactory.
- Gets default actions EMF properties view when no View defined in ctx
- Manage action buttons enable.
Patch set 1:
- Adds actions management
- Adds properties View for adviceConfiguration
- Adds ctrl+clic to create old local palette
Conflicts:
plugins/uml/properties/org.eclipse.papyrus.uml.properties/META-INF/MANIFEST.MF
Change-Id: I1f5caeb9eb411df2886f29ae02d807bb69b79be2
Signed-off-by: Mickael ADAM <mickael.adam@ALL4TEC.net>
Diffstat (limited to 'plugins/customization/org.eclipse.papyrus.customization.palette')
30 files changed, 12350 insertions, 9137 deletions
diff --git a/plugins/customization/org.eclipse.papyrus.customization.palette/.classpath b/plugins/customization/org.eclipse.papyrus.customization.palette/.classpath index 2d1a4302f04..eca7bdba8f0 100644 --- a/plugins/customization/org.eclipse.papyrus.customization.palette/.classpath +++ b/plugins/customization/org.eclipse.papyrus.customization.palette/.classpath @@ -1,7 +1,7 @@ -<?xml version="1.0" encoding="UTF-8"?>
-<classpath>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
- <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
- <classpathentry kind="src" path="src"/>
- <classpathentry kind="output" path="bin"/>
-</classpath>
+<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/> + <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> + <classpathentry kind="src" path="src"/> + <classpathentry kind="output" path="bin"/> +</classpath> diff --git a/plugins/customization/org.eclipse.papyrus.customization.palette/.settings/org.eclipse.jdt.core.prefs b/plugins/customization/org.eclipse.papyrus.customization.palette/.settings/org.eclipse.jdt.core.prefs index 4759947300a..b3aa6d60f94 100644 --- a/plugins/customization/org.eclipse.papyrus.customization.palette/.settings/org.eclipse.jdt.core.prefs +++ b/plugins/customization/org.eclipse.papyrus.customization.palette/.settings/org.eclipse.jdt.core.prefs @@ -1,291 +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
+eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 +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/plugins/customization/org.eclipse.papyrus.customization.palette/META-INF/MANIFEST.MF b/plugins/customization/org.eclipse.papyrus.customization.palette/META-INF/MANIFEST.MF index 980dac227c5..5527cdd7295 100644 --- a/plugins/customization/org.eclipse.papyrus.customization.palette/META-INF/MANIFEST.MF +++ b/plugins/customization/org.eclipse.papyrus.customization.palette/META-INF/MANIFEST.MF @@ -2,14 +2,32 @@ Manifest-Version: 1.0 Export-Package: org.eclipse.papyrus.customization.palette, org.eclipse.papyrus.customization.palette.dialog, org.eclipse.papyrus.customization.palette.proxies -Require-Bundle: org.eclipse.pde;bundle-version="[3.12.0,4.0.0)", +Require-Bundle: org.eclipse.uml2.uml;bundle-version="[5.2.0,6.0.0)", + org.eclipse.pde;bundle-version="[3.12.0,4.0.0)", org.eclipse.pde.ui;bundle-version="[3.9.0,4.0.0)", - org.eclipse.papyrus.uml.diagram.common;bundle-version="[3.0.0,4.0.0)";visibility:=reexport + org.eclipse.core.runtime;bundle-version="[3.12.0,4.0.0)", + org.eclipse.ui.views.properties.tabbed;bundle-version="[3.7.0,4.0.0)", + org.eclipse.gmf.runtime.diagram.ui;bundle-version="[1.8.0,2.0.0)", + org.eclipse.papyrus.infra.core.log;bundle-version="[1.2.0,2.0.0)", + org.eclipse.papyrus.infra.core.sasheditor;bundle-version="[2.0.0,3.0.0)", + org.eclipse.papyrus.infra.core;bundle-version="[2.0.0,3.0.0)", + org.eclipse.papyrus.infra.emf;bundle-version="[2.0.0,3.0.0)", + org.eclipse.papyrus.emf.facet.custom.ui;bundle-version="[2.0.0,3.0.0)", + org.eclipse.papyrus.emf.facet.custom.core;bundle-version="[2.0.0,3.0.0)", + org.eclipse.papyrus.uml.diagram.common;bundle-version="[3.0.0,4.0.0)", + org.eclipse.papyrus.uml.diagram.paletteconfiguration;bundle-version="[3.0.0,4.0.0)", + org.eclipse.papyrus.uml.diagram.paletteconfiguration.editor;bundle-version="[3.0.0,4.0.0)", + org.eclipse.papyrus.views.properties;bundle-version="[3.0.0,4.0.0)", + org.eclipse.papyrus.infra.widgets;bundle-version="[3.0.0,4.0.0)", + org.eclipse.papyrus.infra.gmfdiag.dnd;bundle-version="[1.2.0,2.0.0)", + org.eclipse.papyrus.infra.types;bundle-version="[3.0.0,4.0.0)", + org.eclipse.papyrus.infra.types.editor;bundle-version="[3.0.0,4.0.0)", + org.eclipse.papyrus.uml.diagram.paletteconfiguration.edit;bundle-version="[3.0.0,4.0.0)" Bundle-Vendor: %providerName Bundle-ClassPath: . -Bundle-Version: 2.0.0.qualifier +Bundle-Version: 3.0.0.qualifier Bundle-Localization: plugin Bundle-Name: %pluginName Bundle-ManifestVersion: 2 Bundle-SymbolicName: org.eclipse.papyrus.customization.palette;singleton:=true -Bundle-RequiredExecutionEnvironment: J2SE-1.5 +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 diff --git a/plugins/customization/org.eclipse.papyrus.customization.palette/pom.xml b/plugins/customization/org.eclipse.papyrus.customization.palette/pom.xml index c1b165930da..f8b06ae6bc6 100644 --- a/plugins/customization/org.eclipse.papyrus.customization.palette/pom.xml +++ b/plugins/customization/org.eclipse.papyrus.customization.palette/pom.xml @@ -7,6 +7,6 @@ <version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>org.eclipse.papyrus.customization.palette</artifactId>
- <version>2.0.0-SNAPSHOT</version>
+ <version>3.0.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
</project>
\ No newline at end of file diff --git a/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/Messages.java b/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/Messages.java index ade2f5a6bed..39c59829cd1 100644 --- a/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/Messages.java +++ b/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/Messages.java @@ -1,36 +1,301 @@ -/*****************************************************************************
- * Copyright (c) 2010 CEA LIST.
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Remi Schnekenburger (CEA LIST) remi.schnekenburger@cea.fr - Initial API and implementation
- *****************************************************************************/
-package org.eclipse.papyrus.customization.palette;
-
-import org.eclipse.osgi.util.NLS;
-
-/**
- * Messages for the plugin
- */
-public class Messages extends NLS {
-
- private static final String BUNDLE_NAME = "org.eclipse.papyrus.customization.palette.messages"; //$NON-NLS-1$
-
- public static String BundleIconExplorerDialog_Message;
-
- public static String BundleIconExplorerDialog_Title;
-
- public static String BundleIconExplorerDialog_UnknownFileName;
-
- static {
- // initialize resource bundle
- NLS.initializeMessages(BUNDLE_NAME, Messages.class);
- }
-
- private Messages() {
- }
-}
+/***************************************************************************** + * Copyright (c) 2010 CEA LIST. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Remi Schnekenburger (CEA LIST) remi.schnekenburger@cea.fr - Initial API and implementation + *****************************************************************************/ +package org.eclipse.papyrus.customization.palette; + +import org.eclipse.osgi.util.NLS; + +/** + * Messages for the plugin + */ +public class Messages extends NLS { + + private static final String BUNDLE_NAME = "org.eclipse.papyrus.customization.palette.messages"; //$NON-NLS-1$ + + static { + // initialize resource bundle + NLS.initializeMessages(BUNDLE_NAME, Messages.class); + } + + private Messages() { + } + + public static String BundleIconExplorerDialog_Message; + + public static String BundleIconExplorerDialog_Title; + + public static String BundleIconExplorerDialog_UnknownFileName; + + public static String ExportPaletteConfigurationWizard_error_cant_read_file; + + public static String ExportPaletteConfigurationWizard_error_file_not_existe; + + public static String ExportPaletteConfigurationWizard_Export_description; + + public static String ExportPaletteConfigurationWizard_ExportWiazrdLabel; + + public static String ExportPaletteConfigurationWizard_export_palette; + + public static String PaletteConfigurationWizard_EditionPaletteInfoPageWizard_Tilte; + + public static String PaletteConfigurationWizard_EditPaletteWizardLabel; + + public static String PaletteConfigurationWizard_NewPaletteContentPageWizard_Description; + + public static String PaletteConfigurationWizard_NewPaletteContentPageWizard_Title; + + public static String PaletteConfigurationWizard_NewPaletteDefaultName; + + public static String PaletteConfigurationWizard_PaletteInfoPageWizard_Description; + + public static String PaletteConfigurationWizard_NewPaletteInfoPageWizard_Title; + + public static String PaletteConfigurationWizard_NewPaletteWizardLabel; + + public static String PaletteConfigurationWizard_ImpossibleToReadDefinitionOfTheFile; + + public static String PaletteConfigurationWizard_FileDontExist; + + public static String PaletteConfigurationContentPage_NewTool; + + public static String PaletteConfigurationContentPage_Separator; + + public static String PaletteConfigurationContentPage_Stack; + + public static String PaletteConfigurationContentPage_UMLTools; + + public static String PaletteConfigurationContentPage_UnknownElement; + + public static String PaletteConfigurationContentPage_CreateAnElementWithAStereotype; + + public static String PaletteConfigurationContentPage_Drawer; + + // ///////////////////////// Palette Customisation + // ///////////////////////////////////// + + public static String Dialog_Export_Palette_Tooltip; + + /** Tooltip for the add button */ + public static String PapyrusPaletteCustomizerDialog_AddButtonTooltip; + + /** Tooltip for the remove button */ + public static String PapyrusPaletteCustomizerDialog_RemoveButtonTooltip; + + public static String AbstractDeployPaletteConfigurationHandler_ConfigureDeploymentOfThePalette; + + public static String AbstractDeployPaletteConfigurationHandler_Deploy; + + public static String AbstractDeployPaletteConfigurationHandler_Editor; + + public static String AbstractDeployPaletteConfigurationHandler_Error_UserCancelDialog; + + public static String AbstractDeployPaletteConfigurationHandler_Error_ContentDialogNotValid; + + public static String AbstractDeployPaletteConfigurationHandler_Error_SomeErrorsOccured; + + public static String AbstractDeployPaletteConfigurationHandler_Identifier; + + public static String AbstractDeployPaletteConfigurationHandler_Priority; + + public static String AbstractDeployPaletteConfigurationHandler_Profiles; + + public static String AbstractDeployPaletteConfigurationHandler_Success; + + public static String AbstractDeployPaletteConfigurationHandler_ThePaletteConfigurationHasBeenSuccessfullyDeployedAndActivated; + + public static String AbstractDeployPaletteConfigurationHandler_TheSelectedElementIsNotAFile; + + /** label for the available palettes viewer */ + public static String Available_Palettes; + + /** label for the palette tree viewer */ + public static String Palette_Viewer; + + /** label for the palette name in the wizard */ + public static String Local_Palette_Name; + + /** label for the palette id in the wizard */ + public static String Local_Palette_Id; + + /** label for the editor id in the palette wizard */ + public static String Local_Palette_Editor_Id; + + /** tooltip for the palette name in the palette wizard */ + public static String Local_Palette_Name_Tooltip; + + /** tooltip for the palette id in the palette wizard */ + public static String Local_Palette_Id_Tooltip; + + /** tooltip for the editor id in the palette wizard */ + public static String Local_Palette_Editor_Id_Tooltip; + + /** label for the provider priority in the palette wizard */ + public static String Local_Palette_Priority; + + /** tooltip for the provider priority in the palette wizard */ + public static String Local_Palette_Priority_Tooltip; + + /** label for the advanced button, when advanced are not shown */ + public static String Dialog_Advanced_Button_Closed; + + /** label for the advanced button, when advanced are shown */ + public static String Dialog_Advanced_Button_Opened; + + /** Error message for the wizard page, when priority is not correctly filled */ + public static String Local_Palette_Error_Priority; + + /** + * Error message for the wizard page, when palette ID is not correctly + * filled + */ + public static String Local_Palette_Error_PaletteId; + + /** Error message for the wizard page, when name is not correctly filled */ + public static String Local_Palette_Error_Name; + + /** + * Error message for the wizard page, when Editor ID is not correctly filled + */ + public static String Local_Palette_Error_EditorId; + + /** Name of the information page */ + public static String Local_Palette_InfoPage_Name; + + /** Title of the information page */ + public static String Local_Palette_InfoPage_Title; + + /** Name of the content page */ + public static String Local_Palette_ContentPage_Name; + + /** Title of the content page */ + public static String Local_Palette_ContentPage_Title; + + /** name of the available tools group */ + public static String Local_Palette_Available_Tools; + + /** tooltip for the show/hide drawer button */ + public static String Local_Palette_ShowDrawers_Tooltip; + + /** tooltip for the show/hide drawer button */ + public static String Local_Palette_ShowTools_Tooltip; + + /** palette preview label */ + public static String Local_Palette_Palette_Preview; + + /** Title for dialog box when palette to delete is not a local palette */ + public static String Dialog_Not_Local_Palette_Title; + + /** Message for dialog box when palette to delete is not a local palette */ + public static String Dialog_Not_Local_Palette_Message; + + /** Title for dialog box when palette to restore is not an extended palette */ + public static String Dialog_Not_Extended_Palette_Title; + + /** Message for dialog box when palette to restore is not an extended palette */ + public static String Dialog_Not_Extended_Palette_Message; + + /** Tooltip for the restore palette button. */ + public static String Dialog_Restore_Palette_Tooltip; + + /** tooltip for the delete palette button */ + public static String Dialog_Delete_Palette_Tooltip; + + /** tooltip for the create palette button */ + public static String Dialog_Create_Palette_Tooltip; + + /** tooltip for the edit palette button */ + public static String Dialog_Edit_Palette_Tooltip; + + /** tooltip for the create drawer button */ + public static String Local_Palette_Create_Drawer_Tooltip; + + /** tooltip for the create separator button */ + public static String Local_Palette_Create_Separator_Tooltip; + + /** tooltip for the create separator button */ + public static String Local_Palette_Create_Tool_Tooltip; + + /** tooltip for the create stack button */ + public static String Local_Palette_Create_Stack_Tooltip; + + /** name of the drawer wizard page */ + public static String Wizard_Drawer_Page_Name; + + /** title of the drawer wizard page */ + public static String Wizard_Drawer_Page_Title; + + /** error on the name in the drawer wizard */ + public static String Wizard_Drawer_Error_Name; + + /** error on the id in the drawer wizard */ + public static String Wizard_Drawer_Error_Id; + + /** error on the icon in the drawer wizard */ + public static String Wizard_Drawer_Error_Icon; + + /** label for the id field */ + public static String Wizard_Drawer_Id; + + /** tooltip for the id field */ + public static String Wizard_Drawer_Id_Tooltip; + + /** label for the name field */ + public static String Wizard_Drawer_Name; + + /** tooltip for the name field */ + public static String Wizard_Drawer_Name_Tooltip; + + /** tooltip for the icon field */ + public static String Wizard_Drawer_Icon_Tooltip; + + /** name for the icon field */ + public static String Wizard_Drawer_Icon; + + /** tooltip for the tool item */ + public static String Local_Palette_SwitchToolsContentProvider_Tooltip; + + /** + * tooltip for the edit local palette action disabled because of bad + * selection + */ + public static String PapyrusPaletteCustomizerDialog_EditButtonTooltip_LocalPaletteNotSelected; + + /** tooltip for the edit local palette action */ + public static String PapyrusPaletteCustomizerDialog_EditButtonTooltip_LocalPaletteSelected; + + /** + * tooltip for the edit local palette action disabled because of missing + * profiles + */ + public static String PapyrusPaletteCustomizerDialog_EditButtonTooltip_MissingProfile; + + /** label for the name text editor for a given proxy */ + public static String Local_Palette_Entry_Name; + + /** label for the description editor for a given proxy */ + public static String Local_Palette_Entry_Description; + + /** label for the group information about entry */ + public static String Local_Palette_Entry_Information; + + /** label for the icon information about entry */ + public static String Local_Palette_Entry_Icon; + + /** label for the referenced entry information about entry */ + public static String Local_Palette_Entry_Reference; + + /** label for the composite displaying the lis of aspect actions */ + public static String Aspect_Action_Information_List_Label; + + /** label for the tooltip of the edit drawer icon */ + public static String PapyrusPaletteCustomizerDialog_EditButtonTooltip; + +} diff --git a/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/PaletteConstants.java b/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/PaletteConstants.java new file mode 100644 index 00000000000..35ad4b1a6b6 --- /dev/null +++ b/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/PaletteConstants.java @@ -0,0 +1,53 @@ +/***************************************************************************** + * Copyright (c) 2016 CEA LIST and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Mickael ADAM (ALL4TEC) mickael.adam@all4tec.net - Initial API and Implementation + *****************************************************************************/ + +package org.eclipse.papyrus.customization.palette; + +import java.util.Arrays; +import java.util.Collections; + +import org.eclipse.papyrus.infra.types.presentation.TypesConfigurationsEditorPlugin; +import org.eclipse.papyrus.uml.diagram.paletteconfiguration.presentation.PaletteConfigurationEditorPlugin; + +/** + * The palette customization plugin constants. + */ +public class PaletteConstants { + + /** + * Constructor. + */ + private PaletteConstants() { + // to prevent instantiation + } + + /** the file extension for palette configuration */ + public static final String PALETTECONFIGURATION_EXTENSION = Collections.unmodifiableList(Arrays.asList(PaletteConfigurationEditorPlugin.INSTANCE.getString("_UI_PaletteconfigurationEditorFilenameExtensions").split("\\s*,\\s*"))).get(0); //$NON-NLS-1$ //$NON-NLS-2$ + + /** the file extension for element type files */ + public static final String ELEMENTTYPE_EXTENSION = Collections.unmodifiableList(Arrays.asList(TypesConfigurationsEditorPlugin.INSTANCE.getString("_UI_ElementtypesconfigurationsEditorFilenameExtensions").split("\\s*,\\s*"))).get(0); //$NON-NLS-1$ //$NON-NLS-2$ + + /** The postfix for semantic element type model file. */ + public static final String ELEMENTTYPE_SEMENTIC_IDENTIFIER_POSTFIX = "_Semantic"; //$NON-NLS-1$ + + /** The postfix for ui element type model file. */ + public static final String ELEMENTTYPE_UI_IDENTIFIER_POSTFIX = "_UI";//$NON-NLS-1$ + + /** The enumeration of the context of the palette configuration model in case of customization */ + public enum PaletteModelContextEnum { + New, // It's a new palette from scratch. Files will be place on local folder. + Workspace, // It's a workspace palette. Files will be place on WS. + Plugin, // It's a palette coming from a plugin definition. It's read-only, a copy and associated files will be placed on local folder + Local // It's come from the local folder + }; + +} diff --git a/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/dialog/AbstractPaletteConfigurationWizard.java b/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/dialog/AbstractPaletteConfigurationWizard.java new file mode 100644 index 00000000000..c6b92702601 --- /dev/null +++ b/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/dialog/AbstractPaletteConfigurationWizard.java @@ -0,0 +1,461 @@ +/***************************************************************************** + * Copyright (c) 2016 CEA LIST and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Mickael ADAM (ALL4TEC) mickael.adam@all4tec.net - Initial API and Implementation + *****************************************************************************/ +package org.eclipse.papyrus.customization.palette.dialog; + +import java.io.File; +import java.io.IOException; +import java.util.Collection; +import java.util.Collections; + +import org.eclipse.emf.common.command.Command; +import org.eclipse.emf.common.command.CompoundCommand; +import org.eclipse.emf.common.notify.Adapter; +import org.eclipse.emf.common.util.URI; +import org.eclipse.emf.ecore.provider.EcoreItemProviderAdapterFactory; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.ecore.resource.ResourceSet; +import org.eclipse.emf.edit.command.AddCommand; +import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain; +import org.eclipse.emf.edit.provider.ComposedAdapterFactory; +import org.eclipse.emf.edit.provider.ReflectiveItemProviderAdapterFactory; +import org.eclipse.emf.edit.provider.resource.ResourceItemProviderAdapterFactory; +import org.eclipse.emf.edit.provider.resource.ResourceSetItemProvider; +import org.eclipse.emf.transaction.impl.TransactionalEditingDomainImpl; +import org.eclipse.gmf.runtime.common.core.service.ProviderPriority; +import org.eclipse.jface.wizard.Wizard; +import org.eclipse.papyrus.customization.palette.Messages; +import org.eclipse.papyrus.customization.palette.PaletteConstants; +import org.eclipse.papyrus.customization.palette.PaletteConstants.PaletteModelContextEnum; +import org.eclipse.papyrus.customization.palette.utils.PaletteUtils; +import org.eclipse.papyrus.infra.types.ElementTypeSetConfiguration; +import org.eclipse.papyrus.infra.types.ElementTypesConfigurationsFactory; +import org.eclipse.papyrus.uml.diagram.common.Activator; +import org.eclipse.papyrus.uml.diagram.common.part.PaletteUtil; +import org.eclipse.papyrus.uml.diagram.common.part.PapyrusPalettePreferences; +import org.eclipse.papyrus.uml.diagram.common.service.PapyrusPaletteService; +import org.eclipse.papyrus.uml.diagram.common.service.PapyrusPaletteService.ProviderDescriptor; +import org.eclipse.papyrus.uml.diagram.paletteconfiguration.PaletteConfiguration; +import org.eclipse.papyrus.uml.diagram.paletteconfiguration.PaletteRessourcesConstants; +import org.eclipse.papyrus.uml.diagram.paletteconfiguration.provider.CustomPaletteconfigurationItemProviderAdapterFactory; +import org.eclipse.papyrus.uml.diagram.paletteconfiguration.utils.CreatePaletteItemUtil; +import org.eclipse.ui.IEditorPart; + +/** + * Abstract class for wizard of edition of palette configuration models. + */ +public abstract class AbstractPaletteConfigurationWizard extends Wizard { + + /** + * The dot string constant. + */ + protected static final String STR_DOT = "."; //$NON-NLS-1$ + + /** the palette resource */ + protected Resource paletteResource; + + /** the element type resource for the ui */ + protected Resource elementTypeUIResource; + + /** the element type resource for the semantic */ + protected Resource elementTypeSemResource; + + /** the string builder */ + protected StringBuilder stringBuilder = new StringBuilder(); + + /** customizer used by the palette viewer */ + protected ProviderDescriptor descriptor; + + /** the editing domain */ + protected AdapterFactoryEditingDomain editingDomain; + + /** the adapter factory */ + protected ComposedAdapterFactory adapterFactory; + + /** The context of the palette contribution */ + protected PaletteModelContextEnum paletteContext; + + /** Editor part in which the palette is displayed */ + protected IEditorPart editorPart; + + /** the provider priority */ + protected ProviderPriority priority; + + /** + * Constructor. + */ + public AbstractPaletteConfigurationWizard(final IEditorPart part, final ProviderDescriptor descriptor) { + this.editorPart = part; + this.descriptor = descriptor; + // initialize the context + paletteContext = PaletteUtils.getPaletteModelContext(descriptor); + + ProviderPriority localPalettePriority = null; + if (PaletteModelContextEnum.New.equals(paletteContext)) { + // Create New Palette + setWindowTitle(Messages.PaletteConfigurationWizard_NewPaletteWizardLabel); + } else { + // Edit Palette + localPalettePriority = PapyrusPalettePreferences.getLocalPalettePriority(descriptor.getContributionID()); + setWindowTitle(Messages.PaletteConfigurationWizard_EditPaletteWizardLabel); + } + + initPriority(localPalettePriority); + + initializeEditingDomain(); + + createResources(); + } + + /** + * inits the priority value + * + * @param value + * value to set + */ + protected void initPriority(final ProviderPriority value) { + if (null != value) { + this.priority = value; + } else { + // by default, Medium + this.priority = ProviderPriority.MEDIUM; + } + } + + /** + * unloads resources. + */ + protected void unloadRessources() { + if (null != paletteResource && paletteResource.isLoaded()) { + paletteResource.unload(); + } + if (null != elementTypeSemResource && elementTypeSemResource.isLoaded()) { + elementTypeSemResource.unload(); + } + if (null != elementTypeUIResource && elementTypeUIResource.isLoaded()) { + elementTypeUIResource.unload(); + } + } + + + /** + * delete resources. + */ + public void deleteResource() { + unloadRessources(); + try { + if (null != paletteResource) { + paletteResource.delete(Collections.EMPTY_MAP); + } + if (null != elementTypeSemResource) { + elementTypeSemResource.delete(Collections.EMPTY_MAP); + } + if (null != elementTypeUIResource) { + elementTypeUIResource.delete(Collections.EMPTY_MAP); + } + } catch (IOException e) { + Activator.log.error(e); + } + } + + + + /** + * Clear the string builder. + */ + protected void clearStringBuilder() { + stringBuilder.setLength(0); // set length of buffer to 0 + stringBuilder.trimToSize(); // trim the underlying buffer + } + + /** + * {@inheritDoc} + */ + @Override + public boolean performFinish() { + + // Save files + saveResources(); + + // Load models on papyrus( Palettes, element types, etc...) + deployModels(); + + // unload ressources + unloadRessources(); + + return true; + } + + /** + * Load models on papyrus( Palettes, element types, etc...). + */ + abstract protected void deployModels(); + + /** + * save resources() + */ + abstract protected void saveResources(); + + /** + * {@inheritDoc} + */ + @Override + public boolean performCancel() { + unloadRessources(); + return super.performCancel(); + } + + /** + * create the resource and set it the palette configuration model + */ + protected void createResources() { + createPaletteResource(); + createElementTypesResources(); + } + + + /** + * Create Element type resources. + */ + protected void createElementTypesResources() { + + URI elementTypeUIURI = null; + URI elementTypeSemURI = null; + + File elementTypeUIFile = null; + File elementTypeSemFile = null; + + switch (paletteContext) { + + case New: + PaletteConfiguration paletteModel = (PaletteConfiguration) paletteResource.getContents().get(0); + clearStringBuilder(); + stringBuilder.append(paletteModel.getId()); + stringBuilder.append(PaletteConstants.ELEMENTTYPE_UI_IDENTIFIER_POSTFIX); + stringBuilder.append(STR_DOT); + stringBuilder.append(PaletteConstants.ELEMENTTYPE_EXTENSION); + String pathUI = Activator.getDefault().getStateLocation().append(stringBuilder.toString()).toString(); + + clearStringBuilder(); + stringBuilder.append(paletteModel.getId()); + stringBuilder.append(PaletteConstants.ELEMENTTYPE_SEMENTIC_IDENTIFIER_POSTFIX); + stringBuilder.append(STR_DOT); + stringBuilder.append(PaletteConstants.ELEMENTTYPE_EXTENSION); + String pathSem = Activator.getDefault().getStateLocation().append(stringBuilder.toString()).toString(); + + elementTypeUIFile = new File(pathUI); + elementTypeSemFile = new File(pathSem); + break; + + case Local: + clearStringBuilder(); + stringBuilder.append(((PapyrusPaletteService.LocalExtendedProviderDescriptor) descriptor).getContributionID()); + stringBuilder.append(PaletteConstants.ELEMENTTYPE_UI_IDENTIFIER_POSTFIX); + stringBuilder.append(STR_DOT); + stringBuilder.append(PaletteConstants.ELEMENTTYPE_EXTENSION); + elementTypeUIFile = Activator.getDefault().getStateLocation().append(stringBuilder.toString()).toFile(); + + clearStringBuilder(); + stringBuilder.append(((PapyrusPaletteService.LocalExtendedProviderDescriptor) descriptor).getContributionID()); + stringBuilder.append(PaletteConstants.ELEMENTTYPE_SEMENTIC_IDENTIFIER_POSTFIX); + stringBuilder.append(STR_DOT); + stringBuilder.append(PaletteConstants.ELEMENTTYPE_EXTENSION); + elementTypeSemFile = Activator.getDefault().getStateLocation().append(stringBuilder.toString()).toFile(); + break; + + case Plugin: + String path = PapyrusPalettePreferences.getPaletteRedefinition(descriptor.getContributionID()); + path = path.substring(0, path.length() - PaletteConstants.PALETTECONFIGURATION_EXTENSION.length() - 1); + + clearStringBuilder(); + stringBuilder.append(path); + stringBuilder.append(PaletteConstants.ELEMENTTYPE_UI_IDENTIFIER_POSTFIX); + stringBuilder.append(STR_DOT); + stringBuilder.append(PaletteConstants.ELEMENTTYPE_EXTENSION); + elementTypeUIFile = Activator.getDefault().getStateLocation().append(stringBuilder.toString()).toFile(); + + clearStringBuilder(); + stringBuilder.append(path); + stringBuilder.append(PaletteConstants.ELEMENTTYPE_SEMENTIC_IDENTIFIER_POSTFIX); + stringBuilder.append(STR_DOT); + stringBuilder.append(PaletteConstants.ELEMENTTYPE_EXTENSION); + elementTypeSemFile = Activator.getDefault().getStateLocation().append(stringBuilder.toString()).toFile(); + break; + + case Workspace: + Object contributions = ((PapyrusPaletteService.LocalProviderDescriptor) descriptor).getDescription().getContributions(); + if (contributions instanceof String) { + + elementTypeUIFile = new File(((String) contributions).replace(STR_DOT + PaletteConstants.PALETTECONFIGURATION_EXTENSION, PaletteConstants.ELEMENTTYPE_UI_IDENTIFIER_POSTFIX + STR_DOT + + PaletteConstants.ELEMENTTYPE_EXTENSION)); + elementTypeSemFile = new File(((String) contributions).replace(STR_DOT + PaletteConstants.PALETTECONFIGURATION_EXTENSION, PaletteConstants.ELEMENTTYPE_SEMENTIC_IDENTIFIER_POSTFIX + STR_DOT + PaletteConstants.ELEMENTTYPE_EXTENSION)); + + elementTypeUIURI = URI.createPlatformResourceURI(elementTypeUIFile.getPath(), false); + elementTypeSemURI = URI.createPlatformResourceURI(elementTypeSemFile.getPath(), false); + } + break; + + default: + break; + } + + if (null == elementTypeUIFile || null == elementTypeSemURI) { + elementTypeUIURI = URI.createFileURI(elementTypeUIFile.getAbsolutePath()); + elementTypeSemURI = URI.createFileURI(elementTypeSemFile.getAbsolutePath()); + } + + // Create resource + elementTypeUIResource = editingDomain.getResourceSet().createResource(elementTypeUIURI); + elementTypeSemResource = editingDomain.getResourceSet().createResource(elementTypeSemURI); + + if (!PaletteUtils.notErrorOnFile(elementTypeUIFile) && !PaletteUtils.notErrorOnFile(elementTypeSemFile)) { + + ElementTypeSetConfiguration emptyElementTypeModelUI = getEmptyElementTypeModel(elementTypeUIResource.getURI().lastSegment().replace(STR_DOT + PaletteConstants.ELEMENTTYPE_EXTENSION, ""));//$NON-NLS-1$ + ElementTypeSetConfiguration emptyElementTypeModelSem = getEmptyElementTypeModel(elementTypeSemResource.getURI().lastSegment().replace(STR_DOT + PaletteConstants.ELEMENTTYPE_EXTENSION, ""));//$NON-NLS-1$ + + // Add it to the resource + CompoundCommand compoundCommand = new CompoundCommand(); + compoundCommand.append(new AddCommand(editingDomain, elementTypeUIResource.getContents(), emptyElementTypeModelUI)); + compoundCommand.append(new AddCommand(editingDomain, elementTypeSemResource.getContents(), emptyElementTypeModelSem)); + editingDomain.getCommandStack().execute(compoundCommand); + } + + if (null != elementTypeUIResource || null != elementTypeSemResource) { + try { + elementTypeUIResource.load(Collections.emptyMap()); + elementTypeSemResource.load(Collections.emptyMap()); + + elementTypeUIResource.getResourceSet().getLoadOptions().put(PaletteRessourcesConstants.ELEMENTTYPE_UI_RESSOURCE_IDENTIFIER, elementTypeUIResource); + elementTypeSemResource.getResourceSet().getLoadOptions().put(PaletteRessourcesConstants.ELEMENTTYPE_SEMENTIC_RESSOURCE_IDENTIFIER, elementTypeSemResource); + } catch (IOException e) { + Activator.log.error(e); + } + } + } + + + + /** + * @return An empty Element type model with intialIdentifier as identifier. + */ + protected ElementTypeSetConfiguration getEmptyElementTypeModel(final String initialIdentifer) { + // Create elementType models + ElementTypeSetConfiguration elementTypeUI = ElementTypesConfigurationsFactory.eINSTANCE.createElementTypeSetConfiguration(); + elementTypeUI.setIdentifier(initialIdentifer); + elementTypeUI.setName(initialIdentifer); + elementTypeUI.setMetamodelNsURI(initialIdentifer); + return elementTypeUI; + } + + /** + * Create palette resource. + */ + protected void createPaletteResource() { + + URI fileURI = null; + + switch (paletteContext) { + + case New: + // Create a volatile default file (not to be save) + // Create a initial void model + PaletteConfiguration paletteModel = CreatePaletteItemUtil.createInitialModel(); + + clearStringBuilder(); + stringBuilder.append("NewPalette");//$NON-NLS-1$ + stringBuilder.append(STR_DOT); + stringBuilder.append(PaletteConstants.PALETTECONFIGURATION_EXTENSION); + + String path = Activator.getDefault().getStateLocation().append(stringBuilder.toString()).toString();// $NON-NLS-1$ + fileURI = URI.createFileURI(path); + + paletteResource = editingDomain.getResourceSet().createResource(fileURI); + // Add it to the resource + Command addCommand = new AddCommand(editingDomain, paletteResource.getContents(), paletteModel); + editingDomain.getCommandStack().execute(addCommand); + break; + + case Local: + clearStringBuilder(); + stringBuilder.append(((PapyrusPaletteService.LocalExtendedProviderDescriptor) descriptor).getContributionID()); + stringBuilder.append(STR_DOT); + stringBuilder.append(PaletteConstants.PALETTECONFIGURATION_EXTENSION); + + File file = Activator.getDefault().getStateLocation().append(stringBuilder.toString()).toFile(); + + if (PaletteUtils.notErrorOnFile(file)) { + fileURI = URI.createFileURI(file.getAbsolutePath()); + paletteResource = editingDomain.getResourceSet().createResource(fileURI); + } + break; + + case Plugin: + fileURI = PaletteUtil.getRedefinitionFileURI(descriptor.getContributionID()); + if (null != fileURI) { + paletteResource = editingDomain.getResourceSet().createResource(fileURI); + } + break; + + case Workspace: + Object contributions = ((PapyrusPaletteService.LocalProviderDescriptor) descriptor).getDescription().getContributions(); + if (contributions instanceof String) { + fileURI = URI.createPlatformResourceURI((String) contributions, false); + paletteResource = editingDomain.getResourceSet().createResource(fileURI); + } + break; + + default: + break; + + } + + if (null != paletteResource) { + try { + paletteResource.load(Collections.emptyMap()); + paletteResource.getResourceSet().getLoadOptions().put(PaletteRessourcesConstants.PALETTE_RESSOURCE_IDENTIFIER, paletteResource); + } catch (IOException e) { + Activator.log.error(e); + } + } + } + + /** + * This sets up the editing domain for the model editor. + */ + protected void initializeEditingDomain() { + // Create an adapter factory that yields item providers. + // + adapterFactory = new ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE); + + adapterFactory.addAdapterFactory(new ResourceItemProviderAdapterFactory() { + @Override + public Adapter createResourceSetAdapter() { + return new ResourceSetItemProvider(this) { + @Override + public Collection<?> getChildren(final Object object) { + ResourceSet resourceSet = (ResourceSet) object; + if (!resourceSet.getResources().isEmpty() && resourceSet.getResources().get(0).getContents().get(0) instanceof PaletteConfiguration) { + return ((PaletteConfiguration) resourceSet.getResources().get(0).getContents().get(0)).getDrawerConfigurations(); // For Drawers as root + } + return Collections.emptyList(); + } + }; + } + }); + adapterFactory.addAdapterFactory(new CustomPaletteconfigurationItemProviderAdapterFactory()); + adapterFactory.addAdapterFactory(new EcoreItemProviderAdapterFactory()); + adapterFactory.addAdapterFactory(new ReflectiveItemProviderAdapterFactory()); + + // Create the editing domain with a special command stack. + editingDomain = new TransactionalEditingDomainImpl(adapterFactory); + } + +} diff --git a/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/dialog/AspectActionsInformationComposite.java b/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/dialog/AspectActionsInformationComposite.java index ca10c220bc8..5a1ffad1299 100644 --- a/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/dialog/AspectActionsInformationComposite.java +++ b/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/dialog/AspectActionsInformationComposite.java @@ -1,547 +1,574 @@ -/*****************************************************************************
- * Copyright (c) 2010 CEA LIST.
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Remi Schnekenburger (CEA LIST) remi.schnekenburger@cea.fr - Initial API and implementation
- *****************************************************************************/
-package org.eclipse.papyrus.customization.palette.dialog;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
-import org.eclipse.jface.viewers.ILabelProvider;
-import org.eclipse.jface.viewers.ILabelProviderListener;
-import org.eclipse.jface.viewers.ISelectionChangedListener;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.ITreeContentProvider;
-import org.eclipse.jface.viewers.ITreeSelection;
-import org.eclipse.jface.viewers.SelectionChangedEvent;
-import org.eclipse.jface.viewers.StructuredSelection;
-import org.eclipse.jface.viewers.TreeViewer;
-import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.papyrus.uml.diagram.common.Activator;
-import org.eclipse.papyrus.uml.diagram.common.Messages;
-import org.eclipse.papyrus.uml.diagram.common.service.palette.AspectToolService;
-import org.eclipse.papyrus.uml.diagram.common.service.palette.IAspectAction;
-import org.eclipse.papyrus.uml.diagram.common.service.palette.IAspectActionProvider;
-import org.eclipse.papyrus.uml.diagram.common.service.palette.IPaletteAspectToolEntryProxy;
-import org.eclipse.papyrus.uml.diagram.common.service.palette.IPostAction;
-import org.eclipse.papyrus.uml.diagram.common.service.palette.IPreAction;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.MouseEvent;
-import org.eclipse.swt.events.MouseListener;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Menu;
-import org.eclipse.swt.widgets.MenuItem;
-import org.eclipse.swt.widgets.Text;
-import org.eclipse.ui.part.PageBook;
-import org.eclipse.uml2.uml.Profile;
-
-
-/**
- * Class in charge of the composite in the {@link LocalPaletteContentPage}
- */
-public class AspectActionsInformationComposite {
-
- /** add icon path */
- private static final String ICONS_ADD = "/icons/obj16/Add_16x16.gif";
-
- /** remove icon path */
- protected static final String ICONS_REMOVE = "/icons/delete.gif";
-
- /** move up icon path */
- protected static final String ICONS_UP = "/icons/arrow_up.gif";
-
- /** move down icon path */
- protected static final String ICONS_DOWN = "/icons/arrow_down.gif";
-
- /** proxy name text */
- protected Text nameText;
-
- /** proxy description text */
- protected Text descriptionText;
-
- /** proxy icon text */
- protected Text iconText;
-
- /** referenced proxy text */
- protected Text referencedText;
-
- /** current selected action proxy */
- protected PaletteEntryProxy selectedEntryProxy;
-
- /** tree viewer for the list of aspect actions */
- protected TreeViewer viewer;
-
- /** page book where specific pages are displayed for configuration of the aspect actions */
- protected PageBook actionDescriptionComposite;
-
- /** list of applied profiles */
- protected List<Profile> appliedProfiles;
-
- /** remove aspect action button */
- protected Button removeActionButton;
-
- /** add aspect action button */
- protected Button addActionButton;
-
- /** move up aspect action button */
- protected Button moveUpActionButton;
-
- /** move down aspect action button */
- protected Button moveDownActionButton;
-
- /**
- * Creates the content for this composite
- *
- * @param parent
- * the conainer of the created content
- * @return the created composite
- */
- public Composite createComposite(Composite parent, List<Profile> appliedProfiles) {
- this.appliedProfiles = appliedProfiles;
- Composite composite = new Composite(parent, SWT.NONE);
- GridLayout layout = new GridLayout(2, false);
- layout.marginWidth = 0;
- layout.marginHeight = 0;
- composite.setLayout(layout);
- GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
- data.horizontalSpan = 4;
- composite.setLayoutData(data);
-
- // composite for the list of aspect actions
- Composite actionList = new Composite(composite, SWT.NONE);
- layout = new GridLayout(5, false);
- layout.marginWidth = 0;
- layout.marginHeight = 0;
- actionList.setLayout(layout);
- data = new GridData(SWT.FILL, SWT.FILL, false, true);
- actionList.setLayoutData(data);
-
- Label aspectListLabel = new Label(actionList, SWT.LEAD);
- aspectListLabel.setText(Messages.Aspect_Action_Information_List_Label);
- data = new GridData(SWT.FILL, SWT.CENTER, true, false);
- data.horizontalIndent = 5;
- aspectListLabel.setLayoutData(data);
-
- addActionButton = new Button(actionList, SWT.NONE);
- addActionButton.setImage(Activator.getPluginIconImage(Activator.ID, ICONS_ADD));
- addActionButton.addMouseListener(new MouseListener() {
-
- public void mouseUp(MouseEvent e) {
- addButtonPressed();
- }
-
- public void mouseDown(MouseEvent e) {
-
- }
-
- public void mouseDoubleClick(MouseEvent e) {
-
- }
- });
-
- removeActionButton = new Button(actionList, SWT.NONE);
- removeActionButton.setImage(Activator.getPluginIconImage(Activator.ID, ICONS_REMOVE));
- removeActionButton.addMouseListener(new MouseListener() {
-
- /**
- * @{inheritDoc
- */
- public void mouseUp(MouseEvent e) {
- // remove the selected aspect action(s)
- ITreeSelection selection = (ITreeSelection) viewer.getSelection();
- if (selection != null && selection.size() > 0) {
- for (Object selected : selection.toList()) {
- if (selected instanceof IPostAction && selectedEntryProxy instanceof IPaletteAspectToolEntryProxy) {
- ((IPaletteAspectToolEntryProxy) selectedEntryProxy).getPostActions().remove(selected);
- } else if (selected instanceof IPreAction && selectedEntryProxy instanceof IPaletteAspectToolEntryProxy) {
- ((IPaletteAspectToolEntryProxy) selectedEntryProxy).getPreActions().remove(selected);
- }
- }
- }
- setSelectedEntryProxy(selectedEntryProxy);
- }
-
- /**
- * @{inheritDoc
- */
- public void mouseDown(MouseEvent e) {
-
- }
-
- /**
- * @{inheritDoc
- */
- public void mouseDoubleClick(MouseEvent e) {
-
- }
- });
-
- moveUpActionButton = new Button(actionList, SWT.NONE);
- moveUpActionButton.setImage(Activator.getPluginIconImage(Activator.ID, ICONS_UP));
- moveUpActionButton.addMouseListener(new MouseListener() {
-
- /**
- * @{inheritDoc
- */
- public void mouseUp(MouseEvent e) {
- IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
- if (selection != null && selection.size() > 0 && selectedEntryProxy instanceof IPaletteAspectToolEntryProxy) {
- IAspectAction action = (IAspectAction) selection.getFirstElement();
- List<IPreAction> initialPreList = ((IPaletteAspectToolEntryProxy) selectedEntryProxy).getPreActions();
- List<IPostAction> initialPostList = ((IPaletteAspectToolEntryProxy) selectedEntryProxy).getPostActions();
-
- if (action instanceof IPreAction) {
- // move from pre action list
- if (initialPreList.indexOf(action) > 0) {
- Collections.swap(initialPreList, initialPreList.indexOf(action), initialPreList.indexOf(action) - 1);
- }
- } else if (action instanceof IPostAction) {
- if (initialPostList.indexOf(action) > 0) {
- Collections.swap(initialPostList, initialPostList.indexOf(action), initialPostList.indexOf(action) - 1);
- }
- }
-
- // update content
- viewer.setInput(selectedEntryProxy);
- // restore selection
- viewer.setSelection(new StructuredSelection(action), true);
- }
-
- }
-
- /**
- * @{inheritDoc
- */
- public void mouseDown(MouseEvent e) {
-
- }
-
- /**
- * @{inheritDoc
- */
- public void mouseDoubleClick(MouseEvent e) {
-
- }
- });
-
- moveDownActionButton = new Button(actionList, SWT.NONE);
- moveDownActionButton.setImage(Activator.getPluginIconImage(Activator.ID, ICONS_DOWN));
- moveDownActionButton.addMouseListener(new MouseListener() {
-
- /**
- * @{inheritDoc
- */
- public void mouseUp(MouseEvent e) {
- IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
- if (selection != null && selection.size() > 0 && selectedEntryProxy instanceof IPaletteAspectToolEntryProxy) {
- IAspectAction action = (IAspectAction) selection.getFirstElement();
- List<IPreAction> initialPreList = ((IPaletteAspectToolEntryProxy) selectedEntryProxy).getPreActions();
- List<IPostAction> initialPostList = ((IPaletteAspectToolEntryProxy) selectedEntryProxy).getPostActions();
-
- if (action instanceof IPreAction) {
- // move from pre action list
- if (initialPreList.indexOf(action) < initialPreList.size() - 1) {
- Collections.swap(initialPreList, initialPreList.indexOf(action), initialPreList.indexOf(action) + 1);
- }
- } else if (action instanceof IPostAction) {
- if (initialPostList.indexOf(action) < initialPostList.size() - 1) {
- Collections.swap(initialPostList, initialPostList.indexOf(action), initialPostList.indexOf(action) + 1);
- }
- }
-
- // update content
- viewer.setInput(selectedEntryProxy);
- // restore selection
- viewer.setSelection(new StructuredSelection(action), true);
- }
-
- }
-
- /**
- * @{inheritDoc
- */
- public void mouseDown(MouseEvent e) {
-
- }
-
- /**
- * @{inheritDoc
- */
- public void mouseDoubleClick(MouseEvent e) {
-
- }
- });
-
- updateButtons();
-
- viewer = new TreeViewer(actionList, SWT.BORDER);
- data = new GridData(SWT.FILL, SWT.FILL, true, true);
- data.horizontalSpan = 5;
- data.heightHint = 150;
- viewer.getControl().setLayoutData(data);
- viewer.setLabelProvider(new AspectActionLabelProvider());
- viewer.setContentProvider(new AspectActionContentProvider());
- viewer.addSelectionChangedListener(new ISelectionChangedListener() {
-
- public void selectionChanged(SelectionChangedEvent event) {
- handleActionListSelectionChanged(event);
- }
-
- });
-
- actionDescriptionComposite = new PageBook(composite, SWT.NONE);
- data = new GridData(SWT.FILL, SWT.FILL, true, true);
- actionDescriptionComposite.setLayoutData(data);
-
- return composite;
- }
-
- /**
- * Action run when the button add is pressed
- */
- protected void addButtonPressed() {
- Menu menu = new Menu(addActionButton);
- for (IAspectActionProvider factory : AspectToolService.getInstance().getProviders()) {
-
- // check if action can be added (not present if one instance allowed)
- if (factory.isEnable(selectedEntryProxy)) {
- MenuItem item = new MenuItem(menu, SWT.NONE);
- item.setText(factory.getName());
- item.setImage(factory.getImage());
- item.setData(factory);
- item.addSelectionListener(new SelectionListener() {
-
- /**
- * @{inheritDoc
- */
- public void widgetSelected(SelectionEvent e) {
- IAspectActionProvider factory = (IAspectActionProvider) ((MenuItem) e.getSource()).getData();
- IAspectAction action = factory.createAction(null);
- if (selectedEntryProxy instanceof IPaletteAspectToolEntryProxy) {
- if (action instanceof IPostAction) {
- ((IPaletteAspectToolEntryProxy) selectedEntryProxy).getPostActions().add((IPostAction) action);
- } else if (action instanceof IPreAction) {
- ((IPaletteAspectToolEntryProxy) selectedEntryProxy).getPreActions().add((IPreAction) action);
- }
- setSelectedEntryProxy(selectedEntryProxy);
- }
- }
-
- /**
- * @{inheritDoc
- */
- public void widgetDefaultSelected(SelectionEvent e) {
-
- }
- });
- }
- }
- menu.setVisible(true);
-
- }
-
- /**
- * Handles the selection changed event in the tree viewer of actions
- *
- * @param event
- * the event fired by the tree viewer or <code>null</code>
- */
- protected void handleActionListSelectionChanged(SelectionChangedEvent event) {
- if (event == null) {
- actionDescriptionComposite.showPage(new Composite(actionDescriptionComposite, SWT.NONE));
- removeActionButton.setEnabled(false);
- } else {
- IStructuredSelection selection = (IStructuredSelection) event.getSelection();
- if (selection != null && selection.getFirstElement() instanceof IAspectAction) {
- // udpate the page book where parameters are handled
- actionDescriptionComposite.showPage(((IAspectAction) selection.getFirstElement()).createConfigurationComposite(actionDescriptionComposite, selectedEntryProxy, appliedProfiles));
- removeActionButton.setEnabled(true);
- } else {
- actionDescriptionComposite.showPage(new Composite(actionDescriptionComposite, SWT.NONE));
- removeActionButton.setEnabled(false);
- }
- }
- }
-
- /**
- * Sets the new Selected entry
- *
- * @param selectedConfiguration
- * the selectedConfiguration to set
- */
- public void setSelectedEntryProxy(PaletteEntryProxy selectedEntryProxy) {
- // should save the content for the previous selected entry proxy...
- this.selectedEntryProxy = selectedEntryProxy;
-
- if (viewer != null) {
- viewer.setInput(selectedEntryProxy);
-
- // select first action
- handleActionListSelectionChanged(null);
-
- // select first post action
- if (selectedEntryProxy instanceof IPaletteAspectToolEntryProxy && ((IPaletteAspectToolEntryProxy) selectedEntryProxy).getPostActions().size() > 0) {
- viewer.setSelection(new StructuredSelection(((IPaletteAspectToolEntryProxy) selectedEntryProxy).getPostActions().get(0)), true);
- }
- // select first pre action
- else if (selectedEntryProxy instanceof IPaletteAspectToolEntryProxy && ((IPaletteAspectToolEntryProxy) selectedEntryProxy).getPreActions().size() > 0) {
- viewer.setSelection(new StructuredSelection(((IPaletteAspectToolEntryProxy) selectedEntryProxy).getPreActions().get(0)), true);
- }
-
- updateButtons();
- }
- }
-
- /**
- * Call this method to update the buttons enablement.
- */
- protected void updateButtons() {
- if (selectedEntryProxy instanceof IPaletteAspectToolEntryProxy) {
- addActionButton.setEnabled(true);
- if (((IPaletteAspectToolEntryProxy) selectedEntryProxy).getPreActions().isEmpty() && !((IPaletteAspectToolEntryProxy) selectedEntryProxy).getPostActions().isEmpty()) {
- removeActionButton.setEnabled(true);
- moveUpActionButton.setEnabled(true);
- moveDownActionButton.setEnabled(true);
- } else {
- removeActionButton.setEnabled(false);
- moveUpActionButton.setEnabled(false);
- moveDownActionButton.setEnabled(false);
- }
- } else {
- addActionButton.setEnabled(false);
- removeActionButton.setEnabled(false);
- moveUpActionButton.setEnabled(false);
- moveDownActionButton.setEnabled(false);
- }
-
- }
-
- /**
- * Content provider for the aspect action list
- */
- protected class AspectActionContentProvider implements ITreeContentProvider {
-
- /**
- * @{inheritDoc
- */
- public Object[] getChildren(Object parentElement) {
- if (parentElement instanceof IPaletteAspectToolEntryProxy) {
- List<IAspectAction> actions = new ArrayList<IAspectAction>();
- actions.addAll(((IPaletteAspectToolEntryProxy) parentElement).getPostActions());
- actions.addAll(((IPaletteAspectToolEntryProxy) parentElement).getPreActions());
- return actions.toArray();
- }
- return new Object[0];
- }
-
- /**
- * @{inheritDoc
- */
- public Object getParent(Object element) {
- if (element instanceof IAspectAction) {
- return selectedEntryProxy;
- }
- return null;
- }
-
- /**
- * @{inheritDoc
- */
- public boolean hasChildren(Object element) {
- return getChildren(element) != null && getChildren(element).length > 0;
- }
-
- /**
- * @{inheritDoc
- */
- public Object[] getElements(Object inputElement) {
- return getChildren(inputElement);
- }
-
- /**
- * @{inheritDoc
- */
- public void dispose() {
-
- }
-
- /**
- * @{inheritDoc
- */
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
-
- }
-
- }
-
- /**
- * Label provider for the aspect actions viewer
- */
- protected class AspectActionLabelProvider implements ILabelProvider {
-
- /**
- * @{inheritDoc
- */
- public Image getImage(Object element) {
- if (element instanceof IAspectAction) {
- return ((IAspectAction) element).getImage();
- }
- return null;
- }
-
- /**
- * @{inheritDoc
- */
- public String getText(Object element) {
- if (element instanceof IAspectAction) {
- return ((IAspectAction) element).getLabel();
- }
- return "notAnAction";
- }
-
- /**
- * @{inheritDoc
- */
- public void addListener(ILabelProviderListener listener) {
-
- }
-
- /**
- * @{inheritDoc
- */
- public void dispose() {
-
- }
-
- /**
- * @{inheritDoc
- */
- public boolean isLabelProperty(Object element, String property) {
- return false;
- }
-
- /**
- * @{inheritDoc
- */
- public void removeListener(ILabelProviderListener listener) {
-
- }
-
- }
-
-}
+/***************************************************************************** + * Copyright (c) 2010 CEA LIST. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Remi Schnekenburger (CEA LIST) remi.schnekenburger@cea.fr - Initial API and implementation + *****************************************************************************/ +package org.eclipse.papyrus.customization.palette.dialog; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import org.eclipse.jface.viewers.ILabelProvider; +import org.eclipse.jface.viewers.ILabelProviderListener; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.ITreeContentProvider; +import org.eclipse.jface.viewers.ITreeSelection; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.papyrus.customization.palette.Messages; +import org.eclipse.papyrus.uml.diagram.common.Activator; +import org.eclipse.papyrus.uml.diagram.common.service.palette.AspectToolService; +import org.eclipse.papyrus.uml.diagram.common.service.palette.IAspectAction; +import org.eclipse.papyrus.uml.diagram.common.service.palette.IAspectActionProvider; +import org.eclipse.papyrus.uml.diagram.common.service.palette.IPaletteAspectToolEntryProxy; +import org.eclipse.papyrus.uml.diagram.common.service.palette.IPostAction; +import org.eclipse.papyrus.uml.diagram.common.service.palette.IPreAction; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.MouseEvent; +import org.eclipse.swt.events.MouseListener; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Menu; +import org.eclipse.swt.widgets.MenuItem; +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.part.PageBook; +import org.eclipse.uml2.uml.Profile; + + +/** + * Class in charge of the composite in the {@link LocalPaletteContentPage} + */ +public class AspectActionsInformationComposite { + + /** add icon path */ + private static final String ICONS_ADD = "/icons/obj16/Add_16x16.gif"; + + /** remove icon path */ + protected static final String ICONS_REMOVE = "/icons/delete.gif"; + + /** move up icon path */ + protected static final String ICONS_UP = "/icons/arrow_up.gif"; + + /** move down icon path */ + protected static final String ICONS_DOWN = "/icons/arrow_down.gif"; + + /** proxy name text */ + protected Text nameText; + + /** proxy description text */ + protected Text descriptionText; + + /** proxy icon text */ + protected Text iconText; + + /** referenced proxy text */ + protected Text referencedText; + + /** current selected action proxy */ + protected PaletteEntryProxy selectedEntryProxy; + + /** tree viewer for the list of aspect actions */ + protected TreeViewer viewer; + + /** page book where specific pages are displayed for configuration of the aspect actions */ + protected PageBook actionDescriptionComposite; + + /** list of applied profiles */ + protected List<Profile> appliedProfiles; + + /** remove aspect action button */ + protected Button removeActionButton; + + /** add aspect action button */ + protected Button addActionButton; + + /** move up aspect action button */ + protected Button moveUpActionButton; + + /** move down aspect action button */ + protected Button moveDownActionButton; + + /** + * Creates the content for this composite + * + * @param parent + * the conainer of the created content + * @return the created composite + */ + public Composite createComposite(Composite parent, List<Profile> appliedProfiles) { + this.appliedProfiles = appliedProfiles; + Composite composite = new Composite(parent, SWT.NONE); + GridLayout layout = new GridLayout(2, false); + layout.marginWidth = 0; + layout.marginHeight = 0; + composite.setLayout(layout); + GridData data = new GridData(SWT.FILL, SWT.FILL, true, true); + data.horizontalSpan = 4; + composite.setLayoutData(data); + + // composite for the list of aspect actions + Composite actionList = new Composite(composite, SWT.NONE); + layout = new GridLayout(5, false); + layout.marginWidth = 0; + layout.marginHeight = 0; + actionList.setLayout(layout); + data = new GridData(SWT.FILL, SWT.FILL, false, true); + actionList.setLayoutData(data); + + Label aspectListLabel = new Label(actionList, SWT.LEAD); + aspectListLabel.setText(Messages.Aspect_Action_Information_List_Label); + data = new GridData(SWT.FILL, SWT.CENTER, true, false); + data.horizontalIndent = 5; + aspectListLabel.setLayoutData(data); + + addActionButton = new Button(actionList, SWT.NONE); + addActionButton.setImage(Activator.getPluginIconImage(Activator.ID, ICONS_ADD)); + addActionButton.addMouseListener(new MouseListener() { + + @Override + public void mouseUp(MouseEvent e) { + addButtonPressed(); + } + + @Override + public void mouseDown(MouseEvent e) { + + } + + @Override + public void mouseDoubleClick(MouseEvent e) { + + } + }); + + removeActionButton = new Button(actionList, SWT.NONE); + removeActionButton.setImage(Activator.getPluginIconImage(Activator.ID, ICONS_REMOVE)); + removeActionButton.addMouseListener(new MouseListener() { + + /** + * @{inheritDoc + */ + @Override + public void mouseUp(MouseEvent e) { + // remove the selected aspect action(s) + ITreeSelection selection = (ITreeSelection) viewer.getSelection(); + if (selection != null && selection.size() > 0) { + for (Object selected : selection.toList()) { + if (selected instanceof IPostAction && selectedEntryProxy instanceof IPaletteAspectToolEntryProxy) { + ((IPaletteAspectToolEntryProxy) selectedEntryProxy).getPostActions().remove(selected); + } else if (selected instanceof IPreAction && selectedEntryProxy instanceof IPaletteAspectToolEntryProxy) { + ((IPaletteAspectToolEntryProxy) selectedEntryProxy).getPreActions().remove(selected); + } + } + } + setSelectedEntryProxy(selectedEntryProxy); + } + + /** + * @{inheritDoc + */ + @Override + public void mouseDown(MouseEvent e) { + + } + + /** + * @{inheritDoc + */ + @Override + public void mouseDoubleClick(MouseEvent e) { + + } + }); + + moveUpActionButton = new Button(actionList, SWT.NONE); + moveUpActionButton.setImage(Activator.getPluginIconImage(Activator.ID, ICONS_UP)); + moveUpActionButton.addMouseListener(new MouseListener() { + + /** + * @{inheritDoc + */ + @Override + public void mouseUp(MouseEvent e) { + IStructuredSelection selection = (IStructuredSelection) viewer.getSelection(); + if (selection != null && selection.size() > 0 && selectedEntryProxy instanceof IPaletteAspectToolEntryProxy) { + IAspectAction action = (IAspectAction) selection.getFirstElement(); + List<IPreAction> initialPreList = ((IPaletteAspectToolEntryProxy) selectedEntryProxy).getPreActions(); + List<IPostAction> initialPostList = ((IPaletteAspectToolEntryProxy) selectedEntryProxy).getPostActions(); + + if (action instanceof IPreAction) { + // move from pre action list + if (initialPreList.indexOf(action) > 0) { + Collections.swap(initialPreList, initialPreList.indexOf(action), initialPreList.indexOf(action) - 1); + } + } else if (action instanceof IPostAction) { + if (initialPostList.indexOf(action) > 0) { + Collections.swap(initialPostList, initialPostList.indexOf(action), initialPostList.indexOf(action) - 1); + } + } + + // update content + viewer.setInput(selectedEntryProxy); + // restore selection + viewer.setSelection(new StructuredSelection(action), true); + } + + } + + /** + * @{inheritDoc + */ + @Override + public void mouseDown(MouseEvent e) { + + } + + /** + * @{inheritDoc + */ + @Override + public void mouseDoubleClick(MouseEvent e) { + + } + }); + + moveDownActionButton = new Button(actionList, SWT.NONE); + moveDownActionButton.setImage(Activator.getPluginIconImage(Activator.ID, ICONS_DOWN)); + moveDownActionButton.addMouseListener(new MouseListener() { + + /** + * @{inheritDoc + */ + @Override + public void mouseUp(MouseEvent e) { + IStructuredSelection selection = (IStructuredSelection) viewer.getSelection(); + if (selection != null && selection.size() > 0 && selectedEntryProxy instanceof IPaletteAspectToolEntryProxy) { + IAspectAction action = (IAspectAction) selection.getFirstElement(); + List<IPreAction> initialPreList = ((IPaletteAspectToolEntryProxy) selectedEntryProxy).getPreActions(); + List<IPostAction> initialPostList = ((IPaletteAspectToolEntryProxy) selectedEntryProxy).getPostActions(); + + if (action instanceof IPreAction) { + // move from pre action list + if (initialPreList.indexOf(action) < initialPreList.size() - 1) { + Collections.swap(initialPreList, initialPreList.indexOf(action), initialPreList.indexOf(action) + 1); + } + } else if (action instanceof IPostAction) { + if (initialPostList.indexOf(action) < initialPostList.size() - 1) { + Collections.swap(initialPostList, initialPostList.indexOf(action), initialPostList.indexOf(action) + 1); + } + } + + // update content + viewer.setInput(selectedEntryProxy); + // restore selection + viewer.setSelection(new StructuredSelection(action), true); + } + + } + + /** + * @{inheritDoc + */ + @Override + public void mouseDown(MouseEvent e) { + + } + + /** + * @{inheritDoc + */ + @Override + public void mouseDoubleClick(MouseEvent e) { + + } + }); + + updateButtons(); + + viewer = new TreeViewer(actionList, SWT.BORDER); + data = new GridData(SWT.FILL, SWT.FILL, true, true); + data.horizontalSpan = 5; + data.heightHint = 150; + viewer.getControl().setLayoutData(data); + viewer.setLabelProvider(new AspectActionLabelProvider()); + viewer.setContentProvider(new AspectActionContentProvider()); + viewer.addSelectionChangedListener(new ISelectionChangedListener() { + + @Override + public void selectionChanged(SelectionChangedEvent event) { + handleActionListSelectionChanged(event); + } + + }); + + actionDescriptionComposite = new PageBook(composite, SWT.NONE); + data = new GridData(SWT.FILL, SWT.FILL, true, true); + actionDescriptionComposite.setLayoutData(data); + + return composite; + } + + /** + * Action run when the button add is pressed + */ + protected void addButtonPressed() { + Menu menu = new Menu(addActionButton); + for (IAspectActionProvider factory : AspectToolService.getInstance().getProviders()) { + + // check if action can be added (not present if one instance allowed) + if (factory.isEnable(selectedEntryProxy)) { + MenuItem item = new MenuItem(menu, SWT.NONE); + item.setText(factory.getName()); + item.setImage(factory.getImage()); + item.setData(factory); + item.addSelectionListener(new SelectionListener() { + + /** + * @{inheritDoc + */ + @Override + public void widgetSelected(SelectionEvent e) { + IAspectActionProvider factory = (IAspectActionProvider) ((MenuItem) e.getSource()).getData(); + IAspectAction action = factory.createAction(null); + if (selectedEntryProxy instanceof IPaletteAspectToolEntryProxy) { + if (action instanceof IPostAction) { + ((IPaletteAspectToolEntryProxy) selectedEntryProxy).getPostActions().add((IPostAction) action); + } else if (action instanceof IPreAction) { + ((IPaletteAspectToolEntryProxy) selectedEntryProxy).getPreActions().add((IPreAction) action); + } + setSelectedEntryProxy(selectedEntryProxy); + } + } + + /** + * @{inheritDoc + */ + @Override + public void widgetDefaultSelected(SelectionEvent e) { + + } + }); + } + } + menu.setVisible(true); + + } + + /** + * Handles the selection changed event in the tree viewer of actions + * + * @param event + * the event fired by the tree viewer or <code>null</code> + */ + protected void handleActionListSelectionChanged(SelectionChangedEvent event) { + if (event == null) { + actionDescriptionComposite.showPage(new Composite(actionDescriptionComposite, SWT.NONE)); + removeActionButton.setEnabled(false); + } else { + IStructuredSelection selection = (IStructuredSelection) event.getSelection(); + if (selection != null && selection.getFirstElement() instanceof IAspectAction) { + // udpate the page book where parameters are handled + actionDescriptionComposite.showPage(((IAspectAction) selection.getFirstElement()).createConfigurationComposite(actionDescriptionComposite, selectedEntryProxy, appliedProfiles)); + removeActionButton.setEnabled(true); + } else { + actionDescriptionComposite.showPage(new Composite(actionDescriptionComposite, SWT.NONE)); + removeActionButton.setEnabled(false); + } + } + } + + /** + * Sets the new Selected entry + * + * @param selectedConfiguration + * the selectedConfiguration to set + */ + public void setSelectedEntryProxy(PaletteEntryProxy selectedEntryProxy) { + // should save the content for the previous selected entry proxy... + this.selectedEntryProxy = selectedEntryProxy; + + if (viewer != null) { + viewer.setInput(selectedEntryProxy); + + // select first action + handleActionListSelectionChanged(null); + + // select first post action + if (selectedEntryProxy instanceof IPaletteAspectToolEntryProxy && ((IPaletteAspectToolEntryProxy) selectedEntryProxy).getPostActions().size() > 0) { + viewer.setSelection(new StructuredSelection(((IPaletteAspectToolEntryProxy) selectedEntryProxy).getPostActions().get(0)), true); + } + // select first pre action + else if (selectedEntryProxy instanceof IPaletteAspectToolEntryProxy && ((IPaletteAspectToolEntryProxy) selectedEntryProxy).getPreActions().size() > 0) { + viewer.setSelection(new StructuredSelection(((IPaletteAspectToolEntryProxy) selectedEntryProxy).getPreActions().get(0)), true); + } + + updateButtons(); + } + } + + /** + * Call this method to update the buttons enablement. + */ + protected void updateButtons() { + if (selectedEntryProxy instanceof IPaletteAspectToolEntryProxy) { + addActionButton.setEnabled(true); + if (((IPaletteAspectToolEntryProxy) selectedEntryProxy).getPreActions().isEmpty() && !((IPaletteAspectToolEntryProxy) selectedEntryProxy).getPostActions().isEmpty()) { + removeActionButton.setEnabled(true); + moveUpActionButton.setEnabled(true); + moveDownActionButton.setEnabled(true); + } else { + removeActionButton.setEnabled(false); + moveUpActionButton.setEnabled(false); + moveDownActionButton.setEnabled(false); + } + } else { + addActionButton.setEnabled(false); + removeActionButton.setEnabled(false); + moveUpActionButton.setEnabled(false); + moveDownActionButton.setEnabled(false); + } + + } + + /** + * Content provider for the aspect action list + */ + protected class AspectActionContentProvider implements ITreeContentProvider { + + /** + * @{inheritDoc + */ + @Override + public Object[] getChildren(Object parentElement) { + if (parentElement instanceof IPaletteAspectToolEntryProxy) { + List<IAspectAction> actions = new ArrayList<IAspectAction>(); + actions.addAll(((IPaletteAspectToolEntryProxy) parentElement).getPostActions()); + actions.addAll(((IPaletteAspectToolEntryProxy) parentElement).getPreActions()); + return actions.toArray(); + } + return new Object[0]; + } + + /** + * @{inheritDoc + */ + @Override + public Object getParent(Object element) { + if (element instanceof IAspectAction) { + return selectedEntryProxy; + } + return null; + } + + /** + * @{inheritDoc + */ + @Override + public boolean hasChildren(Object element) { + return getChildren(element) != null && getChildren(element).length > 0; + } + + /** + * @{inheritDoc + */ + @Override + public Object[] getElements(Object inputElement) { + return getChildren(inputElement); + } + + /** + * @{inheritDoc + */ + @Override + public void dispose() { + + } + + /** + * @{inheritDoc + */ + @Override + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + + } + + } + + /** + * Label provider for the aspect actions viewer + */ + protected class AspectActionLabelProvider implements ILabelProvider { + + /** + * @{inheritDoc + */ + @Override + public Image getImage(Object element) { + if (element instanceof IAspectAction) { + return ((IAspectAction) element).getImage(); + } + return null; + } + + /** + * @{inheritDoc + */ + @Override + public String getText(Object element) { + if (element instanceof IAspectAction) { + return ((IAspectAction) element).getLabel(); + } + return "notAnAction"; + } + + /** + * @{inheritDoc + */ + @Override + public void addListener(ILabelProviderListener listener) { + + } + + /** + * @{inheritDoc + */ + @Override + public void dispose() { + + } + + /** + * @{inheritDoc + */ + @Override + public boolean isLabelProperty(Object element, String property) { + return false; + } + + /** + * @{inheritDoc + */ + @Override + public void removeListener(ILabelProviderListener listener) { + + } + + } + +} diff --git a/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/dialog/BundleExplorerDialog.java b/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/dialog/BundleExplorerDialog.java deleted file mode 100644 index fed5f51c1c6..00000000000 --- a/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/dialog/BundleExplorerDialog.java +++ /dev/null @@ -1,190 +0,0 @@ -/*****************************************************************************
- * Copyright (c) 2010 CEA LIST.
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Remi Schnekenburger (CEA LIST) remi.schnekenburger@cea.fr - Initial API and implementation
- *****************************************************************************/
-package org.eclipse.papyrus.customization.palette.dialog;
-
-import java.util.Comparator;
-
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.jface.dialogs.IDialogSettings;
-import org.eclipse.papyrus.uml.diagram.common.Activator;
-import org.eclipse.pde.core.plugin.IPluginBase;
-import org.eclipse.pde.core.plugin.IPluginModelBase;
-import org.eclipse.pde.internal.ui.PDEPlugin;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.dialogs.FilteredItemsSelectionDialog;
-
-
-/**
- * This dialog allows user to browse the available plugins and select some
- */
-public class BundleExplorerDialog extends FilteredItemsSelectionDialog {
-
- private static final String DIALOG_SETTINGS = "org.eclipse.papyrus.infra.widgets.toolbox.BundleExplorerDialog";
-
- private IPluginModelBase[] fModels;
-
- /**
- * Creates a new BundleExplorerDialog.
- *
- * @param shell
- * the parent shell for the dialog
- * @param multi
- * <code>true</code> if multi selection is allowed
- */
- public BundleExplorerDialog(Shell shell, boolean multi, IPluginModelBase[] models) {
- super(shell, multi);
- setTitle("Plug-in Selection");
- setMessage("Select a Plug-in:");
- fModels = models;
- PDEPlugin.getDefault().getLabelProvider().connect(this);
- setListLabelProvider(PDEPlugin.getDefault().getLabelProvider());
- }
-
- /**
- * @{inheritDoc
- */
- @Override
- protected Control createExtendedContentArea(Composite parent) {
- return null;
- }
-
- /**
- * @{inheritDoc
- */
- @Override
- protected ItemsFilter createFilter() {
- return new PluginSearchItemsFilter();
- }
-
- /**
- * @{inheritDoc
- */
- @Override
- protected void fillContentProvider(AbstractContentProvider contentProvider, ItemsFilter itemsFilter, IProgressMonitor progressMonitor) throws CoreException {
- for (int i = 0; i < fModels.length; i++) {
- contentProvider.add(fModels[i], itemsFilter);
- progressMonitor.worked(1);
- }
- progressMonitor.done();
- }
-
- /**
- * @{inheritDoc
- */
- @Override
- protected IDialogSettings getDialogSettings() {
- IDialogSettings settings = Activator.getDefault().getDialogSettings().getSection(DIALOG_SETTINGS);
-
- if (settings == null) {
- settings = Activator.getDefault().getDialogSettings().addNewSection(DIALOG_SETTINGS);
- }
-
- return settings;
- }
-
- /**
- * @{inheritDoc
- */
- @Override
- public String getElementName(Object item) {
- if (item instanceof IPluginModelBase) {
- IPluginModelBase model = (IPluginModelBase) item;
- return model.getPluginBase().getId();
- }
- return null;
- }
-
- /**
- * @{inheritDoc
- */
- @Override
- protected Comparator<?> getItemsComparator() {
- return new PluginSearchComparator();
- }
-
- /**
- * @{inheritDoc
- */
- @Override
- protected IStatus validateItem(Object item) {
- return new Status(IStatus.OK, Activator.ID, 0, "", null); //$NON-NLS-1$
- }
-
- private class PluginSearchItemsFilter extends ItemsFilter {
-
- @Override
- public boolean isConsistentItem(Object item) {
- return true;
- }
-
- @Override
- public boolean matchItem(Object item) {
- String id = null;
- if (item instanceof IPluginModelBase) {
- IPluginModelBase model = (IPluginModelBase) item;
- id = model.getPluginBase().getId();
- }
-
- return (matches(id));
- }
-
- @Override
- protected boolean matches(String text) {
- String pattern = patternMatcher.getPattern();
- if (pattern.indexOf("*") != 0 && pattern.indexOf("?") != 0 && pattern.indexOf(".") != 0) {//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- pattern = "*" + pattern; //$NON-NLS-1$
- patternMatcher.setPattern(pattern);
- }
- return patternMatcher.matches(text);
- }
- }
-
- private class PluginSearchComparator implements Comparator {
-
- public int compare(Object o1, Object o2) {
- int id1 = getId(o1);
- int id2 = getId(o2);
-
- if (id1 != id2) {
- return id1 - id2;
- }
- return compareSimilarObjects(o1, o2);
- }
-
- private int getId(Object element) {
- if (element instanceof IPluginModelBase) {
- return 100;
- }
- return 0;
- }
-
- private int compareSimilarObjects(Object o1, Object o2) {
- if (o1 instanceof IPluginModelBase && o2 instanceof IPluginModelBase) {
- IPluginModelBase ipmb1 = (IPluginModelBase) o1;
- IPluginModelBase ipmb2 = (IPluginModelBase) o2;
- return comparePlugins(ipmb1.getPluginBase(), ipmb2.getPluginBase());
- }
- return 0;
- }
-
- private int comparePlugins(IPluginBase ipmb1, IPluginBase ipmb2) {
- return ipmb1.getId().compareTo(ipmb2.getId());
- }
-
- }
-
-}
diff --git a/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/dialog/BundleIconExplorerDialog.java b/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/dialog/BundleIconExplorerDialog.java deleted file mode 100644 index edaf7837c95..00000000000 --- a/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/dialog/BundleIconExplorerDialog.java +++ /dev/null @@ -1,501 +0,0 @@ -/*****************************************************************************
- * Copyright (c) 2010 CEA LIST.
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Remi Schnekenburger (CEA LIST) remi.schnekenburger@cea.fr - Initial API and implementation
- * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Bug fix
- *****************************************************************************/
-package org.eclipse.papyrus.customization.palette.dialog;
-
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Enumeration;
-import java.util.List;
-
-import org.eclipse.core.runtime.Assert;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.jface.viewers.LabelProvider;
-import org.eclipse.jface.window.Window;
-import org.eclipse.papyrus.customization.palette.Messages;
-import org.eclipse.papyrus.uml.diagram.common.Activator;
-import org.eclipse.pde.core.plugin.IPluginModel;
-import org.eclipse.pde.core.plugin.PluginRegistry;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.KeyEvent;
-import org.eclipse.swt.events.KeyListener;
-import org.eclipse.swt.events.MouseEvent;
-import org.eclipse.swt.events.MouseListener;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.graphics.Rectangle;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Event;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Listener;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.swt.widgets.Text;
-import org.eclipse.ui.dialogs.FilteredList;
-import org.eclipse.ui.dialogs.SelectionStatusDialog;
-import org.osgi.framework.Bundle;
-
-/**
- * Selection dialog for icons in bundles
- */
-public class BundleIconExplorerDialog extends SelectionStatusDialog {
-
- /** gif file extension */
- protected static final String GIF_EXTENSION = ".gif"; //$NON-NLS-1$
-
- /** length of the extension */
- public static final int GIF_EXTENSION_LENGTH = GIF_EXTENSION.length();
-
- /** protocol for platform plugin URLs */
- protected static final String PLUGIN_PROTOCOL = "platform:/plugin/"; //$NON-NLS-1$
-
- /** indicates if several icons can be selected at the same time */
- protected final boolean allowMultiple;
-
- /** list that displays icons */
- protected FilteredList filteredList;
-
- /** text where a filter can be entered for the icon names */
- protected Text filterText;
-
- /** current filter string */
- protected String filter = null;
-
- /** initial value */
- protected String initialValue;
-
- /** current displayed bundle name */
- protected String currentBundleName = "org.eclipse.uml2.uml.edit"; //$NON-NLS-1$
-
- private Text text;
-
- /**
- * Creates a new Icon Bundle Explorer Dialog
- *
- * @param parentShell
- * the parent shell for the dialog
- */
- public BundleIconExplorerDialog(Shell parentShell, boolean allowMultiple, String initialValue, String bundle) {
- super(parentShell);
- this.allowMultiple = allowMultiple;
- this.initialValue = initialValue;
- this.currentBundleName = bundle;
- setTitle(Messages.BundleIconExplorerDialog_Title);
- setMessage(Messages.BundleIconExplorerDialog_Message);
-
- }
-
- /**
- * Creates a new Icon Bundle Explorer Dialog
- *
- * @param parentShell
- * the parent shell for the dialog
- */
- public BundleIconExplorerDialog(Shell parentShell, String initialValue) {
- this(parentShell, false, initialValue, retrieveBundleId(initialValue));
- }
-
- /**
- * Retrieves the bundle from which the
- *
- * @param initialValue
- * the initial value from which the bundle has to be retrieved
- * @return the bundle id
- */
- protected static String retrieveBundleId(String initialValue) {
- if (initialValue.startsWith(PLUGIN_PROTOCOL)) {
- String tmp = initialValue.substring(PLUGIN_PROTOCOL.length());
- int bundleIdEndIndex = tmp.indexOf("/");
- return tmp.substring(0, bundleIdEndIndex);
- }
- return "org.eclipse.uml2.uml.edit";
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected Control createDialogArea(Composite parent) {
- Composite composite = (Composite) super.createDialogArea(parent);
- initializeDialogUnits(composite);
-
- // creates the message area, as defined in the super class
- createMessageArea(composite);
- createComboArea(composite);
- createFilterText(composite);
- createFilteredList(composite);
-
- refreshList();
-
- return composite;
- }
-
- /**
- * Refresh the content of the
- */
- @SuppressWarnings("unchecked")
- protected void refreshList() {
- // check selection
- currentBundleName = text.getText().trim();
- Bundle bundle = Platform.getBundle(currentBundleName);
- if (bundle == null) {
- Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.ID, "impossible to find bundle with id: " + currentBundleName));
- return;
- }
- Enumeration<URL> e = bundle.findEntries("", "*" + GIF_EXTENSION, true); //$NON-NLS-1$ //$NON-NLS-2$
- List<ImageProxy> selectedProxy = new ArrayList<ImageProxy>();
- List<ImageProxy> images = new ArrayList<ImageProxy>();
- if (e == null) {
- return;
- }
- while (e.hasMoreElements()) {
- ImageProxy proxy = new ImageProxy(e.nextElement());
- if (proxy.isDisplayed()) {
- images.add(proxy);
- // check if the proxy corresponds to the initialValue
- if (proxy.isInitial()) {
- selectedProxy.add(proxy);
- }
- }
- }
- filteredList.setElements(images.toArray());
-
- // select objects
- if (!selectedProxy.isEmpty()) {
- filteredList.setSelection(selectedProxy.toArray());
- }
-
- }
-
- /**
- * Creates an area where users can select bundles where icons should be selected
- *
- * @param composite
- * the parent composite of the controls created in this area
- */
- protected void createComboArea(Composite composite) {
- Composite parent = new Composite(composite, SWT.NONE);
- GridData data = new GridData();
- data.grabExcessVerticalSpace = false;
- data.grabExcessHorizontalSpace = true;
- data.horizontalAlignment = GridData.FILL;
- data.verticalAlignment = GridData.BEGINNING;
- parent.setLayoutData(data);
- parent.setFont(parent.getFont());
-
- GridLayout layout = new GridLayout(3, false);
- parent.setLayout(layout);
-
- Label label = new Label(parent, SWT.NONE);
- label.setText("Bundle");
-
- text = new Text(parent, SWT.READ_ONLY | SWT.BORDER);
- data = new GridData();
- data.grabExcessVerticalSpace = false;
- data.grabExcessHorizontalSpace = true;
- data.horizontalAlignment = GridData.FILL;
- data.verticalAlignment = GridData.BEGINNING;
- text.setLayoutData(data);
-
- text.setText(currentBundleName);
-
- Button selectBundleButton = new Button(parent, SWT.NONE);
- selectBundleButton.setText("...");
- selectBundleButton.addMouseListener(new MouseListener() {
-
- /**
- * @{inheritDoc
- */
- public void mouseUp(MouseEvent e) {
- handleManageBundlesButtonPressed();
- }
-
- /**
- * @{inheritDoc
- */
- public void mouseDown(MouseEvent e) {
-
- }
-
- /**
- * @{inheritDoc
- */
- public void mouseDoubleClick(MouseEvent e) {
-
- }
- });
- }
-
- /**
- * Handles action when user press the Manage bundle button in the combo area
- */
- protected void handleManageBundlesButtonPressed() {
- // open a dialog
- BundleExplorerDialog dialog = new BundleExplorerDialog(getParentShell(), false, PluginRegistry.getActiveModels(true));
- if (Window.OK == dialog.open()) {
- text.setText(((IPluginModel) dialog.getFirstResult()).getPlugin().getId());
- refreshList();
- }
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected void computeResult() {
- List<Object> proxies = Arrays.asList(getSelectedElements());
- List<String> results = new ArrayList<String>(proxies.size());
- for (Object proxy : proxies) {
- results.add(((ImageProxy) proxy).getPluginPath());
- }
- setResult(results);
- }
-
- /**
- * Returns an array of the currently selected elements.
- * To be called within or after open().
- *
- * @return returns an array of the currently selected elements.
- */
- protected Object[] getSelectedElements() {
- Assert.isNotNull(filteredList);
- return filteredList.getSelection();
- }
-
- /**
- * Creates an area where a filter can be entered. This filter will restrict the list of available icons.
- *
- * @param parent
- * the parent composite where to create the filter text
- * @return the created text area
- */
- protected Text createFilterText(Composite parent) {
- Text text = new Text(parent, SWT.BORDER);
-
- GridData data = new GridData();
- data.grabExcessVerticalSpace = false;
- data.grabExcessHorizontalSpace = true;
- data.horizontalAlignment = GridData.FILL;
- data.verticalAlignment = GridData.BEGINNING;
- text.setLayoutData(data);
- text.setFont(parent.getFont());
-
- text.setText((filter == null ? "" : filter)); //$NON-NLS-1$
-
- Listener listener = new Listener() {
-
- public void handleEvent(Event e) {
- filteredList.setFilter("*" + filterText.getText()); //$NON-NLS-1$
- }
- };
- text.addListener(SWT.Modify, listener);
-
- text.addKeyListener(new KeyListener() {
-
- public void keyPressed(KeyEvent e) {
- if (e.keyCode == SWT.ARROW_DOWN) {
- filteredList.setFocus();
- }
- }
-
- public void keyReleased(KeyEvent e) {
- }
- });
-
- filterText = text;
-
- return text;
- }
-
- /**
- * Creates a filtered list.
- *
- * @param parent
- * the parent composite.
- * @return returns the filtered list widget.
- */
- protected FilteredList createFilteredList(Composite parent) {
- int flags = SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL | (allowMultiple ? SWT.MULTI : SWT.SINGLE);
-
- FilteredList list = new FilteredList(parent, flags, new BundleIconLabelProvider(), true, true, true);
-
- GridData data = new GridData();
- data.widthHint = convertWidthInCharsToPixels(60);
- data.heightHint = convertHeightInCharsToPixels(18);
- data.grabExcessVerticalSpace = true;
- data.grabExcessHorizontalSpace = true;
- data.horizontalAlignment = GridData.FILL;
- data.verticalAlignment = GridData.FILL;
- list.setLayoutData(data);
- list.setFont(parent.getFont());
- list.setFilter((filter == null ? "" : filter)); //$NON-NLS-1$
-
- filteredList = list;
- return list;
- }
-
- /**
- * Returns the bundle identifier for the current image
- *
- * @return the bundle identifier for the current image
- */
- public String getCurrentBundleName() {
- return currentBundleName;
- }
-
- /**
- * Returns the path to the icon in the bundle
- *
- * @return the path to the icon in the bundle
- */
- public String getIconPath() {
- List<Object> proxies = Arrays.asList(getSelectedElements());
- if (proxies.size() == 1) {
- return ((ImageProxy) proxies.get(0)).getLocalPath();
- }
-
- return "";
- }
-
- /**
- * label provider for the icons in Bundle
- */
- public class BundleIconLabelProvider extends LabelProvider {
-
-
- /**
- * Creates a new BundleIconLabelProvider.
- */
- public BundleIconLabelProvider() {
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public Image getImage(Object element) {
- if (element instanceof ImageProxy) {
- // int index = ((String)element).indexOf(currentBundleName);
- // String path = ((String)element).substring(index+currentBundleName.length());
- // return Activator.getImage(currentBundleName, path);
- return ((ImageProxy) element).getImage();
- }
- return super.getImage(element);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public String getText(Object element) {
- if (element instanceof ImageProxy) {
- return ((ImageProxy) element).getText();
- }
- return super.getText(element);
- }
- }
-
- /**
- * Proxy for images
- */
- protected class ImageProxy {
-
- /** proxied image */
- private final Image image;
-
- /** full plugin path */
- private String path;
-
- /** local path inside the plugin */
- private String localPath;
-
- /** local path inside the plugin */
- private String fileName;
-
- /**
- * Creates an Image Proxy
- *
- * @param url
- * the url of the image to proxy
- */
- public ImageProxy(URL url) {
- localPath = url.getPath();
- path = PLUGIN_PROTOCOL + getCurrentBundleName() + localPath;
- image = org.eclipse.papyrus.uml.diagram.common.Activator.getImage(path, ""); //$NON-NLS-1$
- int index = localPath.lastIndexOf('/');
- if (index > 0 && index < localPath.length()) {
- fileName = localPath.substring(index + 1, localPath.length() - GIF_EXTENSION_LENGTH);
- } else {
- fileName = Messages.BundleIconExplorerDialog_UnknownFileName;
- }
- }
-
- /**
- * Checks if this proxy corresponds to the initial value
- *
- * @return <code>true</code> if this is the initial value proxy
- */
- public boolean isInitial() {
- return initialValue.equals(path);
- }
-
- /**
- * Returns the real image
- *
- * @return the real image
- */
- public Image getImage() {
- return image;
- }
-
- /**
- * Returns <code>true</code> if this image is correct
- *
- * @return <code>true</code> if this image is correct
- */
- public boolean isDisplayed() {
- Rectangle bounds = image.getBounds();
- if (bounds.height == 16 && bounds.width == 16) {
- return true;
- }
- return false;
- }
-
- /**
- * Returns the text to display
- *
- * @return the text to display
- */
- public String getText() {
- return fileName;
- }
-
- public String getPluginPath() {
- return path;
- }
-
-
- /**
- * Returns the path to the icon in the bundle
- *
- * @return the path to the icon in the bundle
- */
- public String getLocalPath() {
- return localPath;
- }
- }
-}
diff --git a/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/dialog/ConfigurationInformationComposite.java b/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/dialog/ConfigurationInformationComposite.java index a508977852f..6dce046b3d6 100644 --- a/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/dialog/ConfigurationInformationComposite.java +++ b/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/dialog/ConfigurationInformationComposite.java @@ -1,339 +1,349 @@ -/*****************************************************************************
- * Copyright (c) 2010 CEA LIST.
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Remi Schnekenburger (CEA LIST) remi.schnekenburger@cea.fr - Initial API and implementation
- *****************************************************************************/
-package org.eclipse.papyrus.customization.palette.dialog;
-
-import java.util.List;
-
-import org.eclipse.jface.window.Window;
-import org.eclipse.papyrus.uml.diagram.common.Activator;
-import org.eclipse.papyrus.uml.diagram.common.Messages;
-import org.eclipse.papyrus.uml.diagram.paletteconfiguration.Configuration;
-import org.eclipse.papyrus.uml.diagram.paletteconfiguration.IconDescriptor;
-import org.eclipse.papyrus.uml.diagram.paletteconfiguration.PaletteconfigurationFactory;
-import org.eclipse.papyrus.uml.diagram.paletteconfiguration.ToolConfiguration;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.FocusEvent;
-import org.eclipse.swt.events.FocusListener;
-import org.eclipse.swt.events.MouseEvent;
-import org.eclipse.swt.events.MouseListener;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Text;
-import org.eclipse.uml2.uml.Profile;
-
-
-/**
- * Class in charge of the composite in the {@link LocalPaletteContentPage}
- */
-public class ConfigurationInformationComposite {
-
- /** current selected entry proxy */
- protected Configuration selectedConfiguration;
-
- /** proxy name text */
- protected Text nameText;
-
- /** proxy description text */
- protected Text descriptionText;
-
- /** proxy icon text */
- protected Text iconText;
-
- /** referenced proxy text */
- protected Text referencedText;
-
- /** list of applied profiles */
- protected List<Profile> appliedProfiles;
-
- /** button for icon selection */
- protected Button iconButton;
-
- /** protocol for platform plugin URLs */
- protected static final String PLUGIN_PROTOCOL = "platform:/plugin/"; //$NON-NLS-1$
-
- /**
- * Creates the content of the information composite
- *
- * @param parent
- * the composite where to add created controls
- * @param appliedProfiles
- * the list of applied profiles
- * @return the newly created composite
- */
- public Composite createComposite(final Composite parent, List<Profile> appliedProfiles) {
- this.appliedProfiles = appliedProfiles;
- Composite composite = new Composite(parent, SWT.NONE);
- GridLayout layout = new GridLayout(3, false);
- composite.setLayout(layout);
- GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
- data.widthHint = 260;
- data.horizontalIndent = 10;
- composite.setLayoutData(data);
-
- Label entryInformationLabel = new Label(composite, SWT.NONE);
- entryInformationLabel.setText(Messages.Local_Palette_Entry_Information);
- data = new GridData(SWT.FILL, SWT.FILL, true, false);
- data.horizontalSpan = 3;
- entryInformationLabel.setLayoutData(data);
-
- Label nameLabel = new Label(composite, SWT.NONE);
- nameLabel.setText(Messages.Local_Palette_Entry_Name);
- data = new GridData(SWT.FILL, SWT.FILL, false, false);
- nameLabel.setLayoutData(data);
- nameText = new Text(composite, SWT.LEAD | SWT.BORDER);
- data = new GridData(SWT.FILL, SWT.FILL, true, false);
- nameText.setLayoutData(data);
- nameText.addFocusListener(new NameFocusListener());
- data = new GridData(SWT.FILL, SWT.FILL, true, false);
- data.horizontalSpan = 2;
- nameText.setLayoutData(data);
-
- Label referencedLabel = new Label(composite, SWT.NONE);
- referencedLabel.setText(Messages.Local_Palette_Entry_Reference);
- data = new GridData(SWT.FILL, SWT.BEGINNING, true, false);
- referencedLabel.setLayoutData(data);
- referencedText = new Text(composite, SWT.LEAD | SWT.BORDER | SWT.READ_ONLY);
- data = new GridData(SWT.FILL, SWT.FILL, true, false);
- referencedText.setLayoutData(data);
- data = new GridData(SWT.FILL, SWT.FILL, true, false);
- data.horizontalSpan = 2;
- referencedText.setLayoutData(data);
-
- Label descriptionLabel = new Label(composite, SWT.NONE);
- descriptionLabel.setText(Messages.Local_Palette_Entry_Description);
- data = new GridData(SWT.FILL, SWT.BEGINNING, true, false);
- descriptionLabel.setLayoutData(data);
- descriptionText = new Text(composite, SWT.WRAP | SWT.BORDER);
- data = new GridData(SWT.FILL, SWT.FILL, true, true);
- data.horizontalSpan = 2;
- data.widthHint = 160;
- descriptionText.setLayoutData(data);
- descriptionText.addFocusListener(new DescriptionFocusListener());
-
-
- Label iconLabel = new Label(composite, SWT.NONE);
- iconLabel.setText(Messages.Local_Palette_Entry_Icon);
- data = new GridData(SWT.FILL, SWT.BEGINNING, true, false);
- iconLabel.setLayoutData(data);
- iconText = new Text(composite, SWT.LEAD | SWT.BORDER);
- data = new GridData(SWT.FILL, SWT.FILL, true, false);
- iconText.setLayoutData(data);
- iconText.addFocusListener(new IconFocusListener());
- iconButton = new Button(composite, SWT.NONE);
- iconButton.setText("Select...");
- iconButton.addMouseListener(new MouseListener() {
-
- /**
- * @{inheritDoc
- */
- public void mouseUp(MouseEvent e) {
- BundleIconExplorerDialog dialog = new BundleIconExplorerDialog(parent.getShell(), iconText.getText());
- if (Window.OK == dialog.open()) {
- Object[] values = dialog.getResult();
- if (values.length != 1) {
- Activator.log.error("Waiting one icon path, but found " + values.length, null);
- } else {
- iconText.setText(values[0].toString());
-
- String bundleId = dialog.getCurrentBundleName();
- String iconPath = dialog.getIconPath();
- updateIconInConfiguration(bundleId, iconPath);
- }
- }
- }
-
- /**
- * @{inheritDoc
- */
- public void mouseDown(MouseEvent e) {
- }
-
- /**
- * @{inheritDoc
- */
- public void mouseDoubleClick(MouseEvent e) {
- }
- });
-
- return composite;
- }
-
-
- private void updateIconInConfiguration(String bundleId, String iconPath) {
- if (selectedConfiguration != null) {
- IconDescriptor descriptor = PaletteconfigurationFactory.eINSTANCE.createIconDescriptor();
- if (bundleId != null && iconPath != null) {
- descriptor.setPluginID(bundleId);
- descriptor.setIconPath(iconPath);
- }
- selectedConfiguration.setIcon(descriptor);
- }
- }
-
- /**
- * Updates the name field in the information area
- */
- protected void updateNameEntryField() {
- if (selectedConfiguration != null) {
- nameText.setText((selectedConfiguration.getLabel() != null) ? selectedConfiguration.getLabel() : "");
- nameText.setEnabled(true);
- } else {
- nameText.setText("");
- nameText.setEnabled(false);
- }
-
- }
-
- /**
- * Updates the reference field in the information area
- */
- protected void updateReferencedEntryField() {
- if (selectedConfiguration instanceof ToolConfiguration) {
- ToolConfiguration configuration = ((ToolConfiguration) selectedConfiguration);
- } else {
- referencedText.setText("");
- referencedText.setEnabled(false);
- }
- }
-
- /**
- * Updates the description field in the information area
- */
- protected void updateDescriptionEntryField() {
- if (selectedConfiguration != null) {
- descriptionText.setText((selectedConfiguration.getDescription() != null) ? selectedConfiguration.getDescription() : "");
- descriptionText.setEnabled(true);
- } else {
- descriptionText.setText("");
- descriptionText.setEnabled(false);
- }
- }
-
- /**
- * Updates the icon field in the information area
- */
- protected void updateIconEntryField() {
- if (selectedConfiguration != null) {
- IconDescriptor descriptor = selectedConfiguration.getIcon();
- if (descriptor != null) {
- String iconPath = descriptor.getIconPath();
- String bundleId = descriptor.getPluginID();
- if (iconPath != null && bundleId != null) {
- iconText.setText(PLUGIN_PROTOCOL + bundleId + iconPath);
- }
- }
- iconText.setEnabled(true);
- } else {
- iconText.setText("");
- iconText.setEnabled(true);
- }
- }
-
- /**
- * Sets the new Selected entry
- *
- * @param configuration
- * the selectedConfiguration to set
- */
- public void setSelectedConfiguration(Configuration configuration) {
- this.selectedConfiguration = configuration;
-
- updateNameEntryField();
- updateIconEntryField();
- updateReferencedEntryField();
- updateDescriptionEntryField();
- }
-
- /**
- * focus listener for the name text field
- */
- protected class NameFocusListener implements FocusListener {
-
- /**
- * @{inheritDoc
- */
- public void focusGained(FocusEvent e) {
- }
-
- /**
- * @{inheritDoc
- */
- public void focusLost(FocusEvent e) {
- if (selectedConfiguration != null) {
- selectedConfiguration.setLabel(nameText.getText().trim());
- }
- }
-
- }
-
- /**
- * focus listener for the name text field
- */
- protected class DescriptionFocusListener implements FocusListener {
-
- /**
- * @{inheritDoc
- */
- public void focusGained(FocusEvent e) {
- }
-
- /**
- * @{inheritDoc
- */
- public void focusLost(FocusEvent e) {
- if (selectedConfiguration != null) {
- selectedConfiguration.setDescription(descriptionText.getText().trim());
- }
- }
- }
-
- /**
- * focus listener for the name text field
- */
- protected class IconFocusListener implements FocusListener {
-
- /**
- * @{inheritDoc
- */
- public void focusGained(FocusEvent e) {
- }
-
- /**
- * @{inheritDoc
- */
- public void focusLost(FocusEvent e) {
- String text = iconText.getText();
- if (selectedConfiguration != null && text != null && !text.equals("")) {
-
- // parse the text....
- if (!text.startsWith(PLUGIN_PROTOCOL)) {
- return;
- }
-
- text = text.substring(PLUGIN_PROTOCOL.length(), text.length());
-
- int i = text.indexOf("/");
- if (i < 1) {
- return;
- }
- String bundlePath = text.substring(0, i);
- String iconPath = text.substring(bundlePath.length(), text.length());
-
- updateIconInConfiguration(bundlePath, iconPath);
- }
- }
- }
-
-}
+/***************************************************************************** + * Copyright (c) 2010 CEA LIST. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Remi Schnekenburger (CEA LIST) remi.schnekenburger@cea.fr - Initial API and implementation + *****************************************************************************/ +package org.eclipse.papyrus.customization.palette.dialog; + +import java.util.List; + +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.customization.palette.Messages; +import org.eclipse.papyrus.infra.widgets.editors.BundleIconExplorerDialog; +import org.eclipse.papyrus.uml.diagram.common.Activator; +import org.eclipse.papyrus.uml.diagram.paletteconfiguration.Configuration; +import org.eclipse.papyrus.uml.diagram.paletteconfiguration.IconDescriptor; +import org.eclipse.papyrus.uml.diagram.paletteconfiguration.PaletteconfigurationFactory; +import org.eclipse.papyrus.uml.diagram.paletteconfiguration.ToolConfiguration; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.FocusEvent; +import org.eclipse.swt.events.FocusListener; +import org.eclipse.swt.events.MouseEvent; +import org.eclipse.swt.events.MouseListener; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Text; +import org.eclipse.uml2.uml.Profile; + + +/** + * Class in charge of the composite in the {@link LocalPaletteContentPage} + */ +public class ConfigurationInformationComposite { + + /** current selected entry proxy */ + protected Configuration selectedConfiguration; + + /** proxy name text */ + protected Text nameText; + + /** proxy description text */ + protected Text descriptionText; + + /** proxy icon text */ + protected Text iconText; + + /** referenced proxy text */ + protected Text referencedText; + + /** list of applied profiles */ + protected List<Profile> appliedProfiles; + + /** button for icon selection */ + protected Button iconButton; + + /** protocol for platform plugin URLs */ + protected static final String PLUGIN_PROTOCOL = "platform:/plugin/"; //$NON-NLS-1$ + + /** + * Creates the content of the information composite + * + * @param parent + * the composite where to add created controls + * @param appliedProfiles + * the list of applied profiles + * @return the newly created composite + */ + public Composite createComposite(final Composite parent, List<Profile> appliedProfiles) { + this.appliedProfiles = appliedProfiles; + Composite composite = new Composite(parent, SWT.NONE); + GridLayout layout = new GridLayout(3, false); + composite.setLayout(layout); + GridData data = new GridData(SWT.FILL, SWT.FILL, true, true); + data.widthHint = 260; + data.horizontalIndent = 10; + composite.setLayoutData(data); + + Label entryInformationLabel = new Label(composite, SWT.NONE); + entryInformationLabel.setText(Messages.Local_Palette_Entry_Information); + data = new GridData(SWT.FILL, SWT.FILL, true, false); + data.horizontalSpan = 3; + entryInformationLabel.setLayoutData(data); + + Label nameLabel = new Label(composite, SWT.NONE); + nameLabel.setText(Messages.Local_Palette_Entry_Name); + data = new GridData(SWT.FILL, SWT.FILL, false, false); + nameLabel.setLayoutData(data); + nameText = new Text(composite, SWT.LEAD | SWT.BORDER); + data = new GridData(SWT.FILL, SWT.FILL, true, false); + nameText.setLayoutData(data); + nameText.addFocusListener(new NameFocusListener()); + data = new GridData(SWT.FILL, SWT.FILL, true, false); + data.horizontalSpan = 2; + nameText.setLayoutData(data); + + Label referencedLabel = new Label(composite, SWT.NONE); + referencedLabel.setText(Messages.Local_Palette_Entry_Reference); + data = new GridData(SWT.FILL, SWT.BEGINNING, true, false); + referencedLabel.setLayoutData(data); + referencedText = new Text(composite, SWT.LEAD | SWT.BORDER | SWT.READ_ONLY); + data = new GridData(SWT.FILL, SWT.FILL, true, false); + referencedText.setLayoutData(data); + data = new GridData(SWT.FILL, SWT.FILL, true, false); + data.horizontalSpan = 2; + referencedText.setLayoutData(data); + + Label descriptionLabel = new Label(composite, SWT.NONE); + descriptionLabel.setText(Messages.Local_Palette_Entry_Description); + data = new GridData(SWT.FILL, SWT.BEGINNING, true, false); + descriptionLabel.setLayoutData(data); + descriptionText = new Text(composite, SWT.WRAP | SWT.BORDER); + data = new GridData(SWT.FILL, SWT.FILL, true, true); + data.horizontalSpan = 2; + data.widthHint = 160; + descriptionText.setLayoutData(data); + descriptionText.addFocusListener(new DescriptionFocusListener()); + + + Label iconLabel = new Label(composite, SWT.NONE); + iconLabel.setText(Messages.Local_Palette_Entry_Icon); + data = new GridData(SWT.FILL, SWT.BEGINNING, true, false); + iconLabel.setLayoutData(data); + iconText = new Text(composite, SWT.LEAD | SWT.BORDER); + data = new GridData(SWT.FILL, SWT.FILL, true, false); + iconText.setLayoutData(data); + iconText.addFocusListener(new IconFocusListener()); + iconButton = new Button(composite, SWT.NONE); + iconButton.setText("Select..."); + iconButton.addMouseListener(new MouseListener() { + + /** + * @{inheritDoc + */ + @Override + public void mouseUp(MouseEvent e) { + BundleIconExplorerDialog dialog = new BundleIconExplorerDialog(parent.getShell(), iconText.getText()); + if (Window.OK == dialog.open()) { + Object[] values = dialog.getResult(); + if (values.length != 1) { + Activator.log.error("Waiting one icon path, but found " + values.length, null);//$NON-NLS-1$ + } else { + iconText.setText(values[0].toString()); + + String bundleId = dialog.getCurrentBundleName(); + String iconPath = dialog.getIconPath(); + updateIconInConfiguration(bundleId, iconPath); + } + } + } + + /** + * @{inheritDoc + */ + @Override + public void mouseDown(MouseEvent e) { + } + + /** + * @{inheritDoc + */ + @Override + public void mouseDoubleClick(MouseEvent e) { + } + }); + + return composite; + } + + + private void updateIconInConfiguration(String bundleId, String iconPath) { + if (selectedConfiguration != null) { + IconDescriptor descriptor = PaletteconfigurationFactory.eINSTANCE.createIconDescriptor(); + if (bundleId != null && iconPath != null) { + descriptor.setPluginID(bundleId); + descriptor.setIconPath(iconPath); + } + selectedConfiguration.setIcon(descriptor); + } + } + + /** + * Updates the name field in the information area + */ + protected void updateNameEntryField() { + if (selectedConfiguration != null) { + nameText.setText((selectedConfiguration.getLabel() != null) ? selectedConfiguration.getLabel() : ""); + nameText.setEnabled(true); + } else { + nameText.setText(""); + nameText.setEnabled(false); + } + + } + + /** + * Updates the reference field in the information area + */ + protected void updateReferencedEntryField() { + if (selectedConfiguration instanceof ToolConfiguration) { + ToolConfiguration configuration = ((ToolConfiguration) selectedConfiguration); + } else { + referencedText.setText(""); + referencedText.setEnabled(false); + } + } + + /** + * Updates the description field in the information area + */ + protected void updateDescriptionEntryField() { + if (selectedConfiguration != null) { + descriptionText.setText((selectedConfiguration.getDescription() != null) ? selectedConfiguration.getDescription() : ""); + descriptionText.setEnabled(true); + } else { + descriptionText.setText(""); + descriptionText.setEnabled(false); + } + } + + /** + * Updates the icon field in the information area + */ + protected void updateIconEntryField() { + if (selectedConfiguration != null) { + IconDescriptor descriptor = selectedConfiguration.getIcon(); + if (descriptor != null) { + String iconPath = descriptor.getIconPath(); + String bundleId = descriptor.getPluginID(); + if (iconPath != null && bundleId != null) { + iconText.setText(PLUGIN_PROTOCOL + bundleId + iconPath); + } + } + iconText.setEnabled(true); + } else { + iconText.setText(""); + iconText.setEnabled(true); + } + } + + /** + * Sets the new Selected entry + * + * @param configuration + * the selectedConfiguration to set + */ + public void setSelectedConfiguration(Configuration configuration) { + this.selectedConfiguration = configuration; + + updateNameEntryField(); + updateIconEntryField(); + updateReferencedEntryField(); + updateDescriptionEntryField(); + } + + /** + * focus listener for the name text field + */ + protected class NameFocusListener implements FocusListener { + + /** + * @{inheritDoc + */ + @Override + public void focusGained(FocusEvent e) { + } + + /** + * @{inheritDoc + */ + @Override + public void focusLost(FocusEvent e) { + if (selectedConfiguration != null) { + selectedConfiguration.setLabel(nameText.getText().trim()); + } + } + + } + + /** + * focus listener for the name text field + */ + protected class DescriptionFocusListener implements FocusListener { + + /** + * @{inheritDoc + */ + @Override + public void focusGained(FocusEvent e) { + } + + /** + * @{inheritDoc + */ + @Override + public void focusLost(FocusEvent e) { + if (selectedConfiguration != null) { + selectedConfiguration.setDescription(descriptionText.getText().trim()); + } + } + } + + /** + * focus listener for the name text field + */ + protected class IconFocusListener implements FocusListener { + + /** + * @{inheritDoc + */ + @Override + public void focusGained(FocusEvent e) { + } + + /** + * @{inheritDoc + */ + @Override + public void focusLost(FocusEvent e) { + String text = iconText.getText(); + if (selectedConfiguration != null && text != null && !text.equals("")) { + + // parse the text.... + if (!text.startsWith(PLUGIN_PROTOCOL)) { + return; + } + + text = text.substring(PLUGIN_PROTOCOL.length(), text.length()); + + int i = text.indexOf("/"); + if (i < 1) { + return; + } + String bundlePath = text.substring(0, i); + String iconPath = text.substring(bundlePath.length(), text.length()); + + updateIconInConfiguration(bundlePath, iconPath); + } + } + } + +} diff --git a/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/dialog/DrawerInformationPage.java b/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/dialog/DrawerInformationPage.java index 830640b2e5c..41cf5e622d7 100644 --- a/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/dialog/DrawerInformationPage.java +++ b/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/dialog/DrawerInformationPage.java @@ -1,419 +1,425 @@ -/*****************************************************************************
- * Copyright (c) 2009 CEA LIST.
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Remi Schnekenburger (CEA LIST) remi.schnekenburger@cea.fr - Initial API and implementation
- *
- *****************************************************************************/
-
-package org.eclipse.papyrus.customization.palette.dialog;
-
-import org.eclipse.jface.dialogs.Dialog;
-import org.eclipse.jface.window.Window;
-import org.eclipse.jface.wizard.WizardPage;
-import org.eclipse.papyrus.uml.diagram.common.Activator;
-import org.eclipse.papyrus.uml.diagram.common.Messages;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.MouseEvent;
-import org.eclipse.swt.events.MouseListener;
-import org.eclipse.swt.events.SelectionAdapter;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Event;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Listener;
-import org.eclipse.swt.widgets.Text;
-import org.eclipse.swt.widgets.Widget;
-
-/**
- * Wizard page for information about the new drawer
- */
-public class DrawerInformationPage extends WizardPage implements Listener {
-
- /** text area for the name of the palette definition */
- protected Text nameText;
-
- /** text area for the id of the palette definition */
- protected Text idText;
-
- /** parent composite for advanced fields */
- protected Composite advancedComposite;
-
- /** Button to show/hide advanced fields */
- protected Button advancedButton;
-
- /** drawer ID */
- protected String drawerID;
-
- /** palette name */
- protected String name;
-
- /** image descriptor for the drawer icon */
- protected String imageDescriptorPath;
-
- /** Text area for icon path */
- protected Text imageText;
-
- /** drawer proxy to edit, if one exists */
- protected final PaletteLocalDrawerProxy drawerProxy;
-
- /** path to the icon */
- protected static final String WIZARD_ICON = "/icons/new_drawer_wiz.gif";
-
- /**
- * Creates a new wizard page with the given name, title, and image.
- *
- * @param part
- * the editor part in which the wizard was created
- */
- public DrawerInformationPage() {
- super(Messages.Wizard_Drawer_Page_Name, Messages.Wizard_Drawer_Page_Title, Activator.getImageDescriptor(WIZARD_ICON));
- drawerProxy = null;
- }
-
- /**
- * Creates a new wizard page with the given name, title, and image.
- *
- * @param part
- * the editor part in which the wizard was created
- */
- public DrawerInformationPage(PaletteLocalDrawerProxy drawerProxy) {
- super(Messages.Wizard_Drawer_Page_Name, Messages.Wizard_Drawer_Page_Title, Activator.getImageDescriptor(WIZARD_ICON));
- this.drawerProxy = drawerProxy;
- }
-
- /**
- * {@inheritDoc}
- */
- public void createControl(Composite parent) {
-
- // initialize dialog units
- initializeDialogUnits(parent);
-
- // initialize values
- intializeValues();
-
- // Create a new composite as there is the title bar seperator
- // to deal with
- Composite control = new Composite(parent, SWT.NONE);
- GridLayout layout = new GridLayout(2, false);
- control.setLayout(layout);
- control.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
- setControl(control);
-
- createNameControl(control);
-
- createAdvancedControls(control);
-
- // end of the control creation
- Dialog.applyDialogFont(control);
-
- validatePage();
- // Show description on opening
- setErrorMessage(null);
- setMessage(null);
- setPageComplete(false);
- setControl(control);
- }
-
- /**
- * initializes fields using context information
- */
- protected void intializeValues() {
- initName();
- initDrawerID();
- initImageDescriptor();
- }
-
- /**
- * Returns the current value of palette name
- *
- * @return the current value of palette name
- */
- public String getDrawerName() {
- return name;
- }
-
- /**
- * Returns the current value of palette ID
- *
- * @return the current value of palette ID
- */
- public String getDrawerID() {
- return drawerID;
- }
-
- /**
- * Returns the current value of path for image descriptor
- *
- * @return the current value of path for image descriptor
- */
- public String getImageDescriptorPath() {
- return imageDescriptorPath;
- }
-
- /**
- * inits the name field value
- */
- protected void initName() {
- if (drawerProxy == null) {
- name = "";
- } else {
- name = drawerProxy.getLabel();
- }
-
- }
-
- /**
- * inits the palette id value
- */
- protected void initDrawerID() {
- if (drawerProxy == null) {
- drawerID = "drawer_" + System.currentTimeMillis();
- } else {
- drawerID = drawerProxy.getId();
- }
-
- }
-
- /**
- * Inits the image descriptor
- */
- protected void initImageDescriptor() {
- if (drawerProxy == null) {
- imageDescriptorPath = "/icons/drawer.gif";
- } else {
- imageDescriptorPath = drawerProxy.getImagePath();
- }
-
- }
-
- /**
- * Validates the content of the fields in this page
- */
- protected boolean validatePage() {
- boolean valid = true;
- if (advancedComposite != null && !advancedComposite.isDisposed()) {
-
- if ("".equals(getDrawerID())) {
- setErrorMessage(Messages.Wizard_Drawer_Error_Id);
- valid = false;
- } else if ("".equals(getImageDescriptorPath())) {
- setErrorMessage(Messages.Wizard_Drawer_Error_Icon);
- valid = false;
- }
- }
-
- if ("".equals(getDrawerName())) {
- setErrorMessage(Messages.Wizard_Drawer_Error_Name);
- valid = false;
- }
-
- if (valid) {
- setMessage(null);
- setErrorMessage(null);
- }
- return valid;
- }
-
- /**
- * Creates the widget for advanced options.
- *
- * @param parent
- * the parent composite
- */
- protected void createAdvancedControls(Composite parent) {
- advancedButton = new Button(parent, SWT.PUSH);
- advancedButton.setFont(parent.getFont());
- advancedButton.setText(Messages.Dialog_Advanced_Button_Closed);
- GridData data = setButtonLayoutData(advancedButton);
- data.horizontalAlignment = GridData.BEGINNING;
- data.horizontalSpan = 2;
- advancedButton.setLayoutData(data);
- advancedButton.addSelectionListener(new SelectionAdapter() {
-
- @Override
- public void widgetSelected(SelectionEvent e) {
- handleAdvancedButtonSelect();
- }
- });
- }
-
- public Composite createAdvancedComposite(Composite parent) {
- advancedComposite = new Composite(parent, SWT.NONE);
- advancedComposite.setFont(parent.getFont());
- advancedComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
- GridLayout layout = new GridLayout(3, false);
- layout.marginHeight = 0;
- layout.marginWidth = 0;
- advancedComposite.setLayout(layout);
-
- createIconControl(advancedComposite);
-
- createIDControl(advancedComposite);
-
- advancedComposite.getParent().layout();
- return advancedComposite;
- }
-
- /**
- * creates the control area for the icon path definition
- *
- * @param composite
- * the parent composite
- */
- protected void createIconControl(final Composite composite) {
- final Label iconLabel = new Label(composite, SWT.NONE);
- iconLabel.setText(Messages.Wizard_Drawer_Icon);
- iconLabel.setToolTipText(Messages.Wizard_Drawer_Icon_Tooltip);
-
- imageText = new Text(composite, SWT.BORDER | SWT.READ_ONLY);
- imageText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
- imageText.setToolTipText(Messages.Wizard_Drawer_Icon_Tooltip);
-
- // initialize, then add the listener...
- initialPopulateDrawerIconField();
-
- // imageText.addListener(SWT.Modify, this);
-
- Button button = new Button(composite, SWT.NONE);
- button.setText("...");
- button.addMouseListener(new MouseListener() {
-
- /**
- * @{inheritDoc
- */
- public void mouseUp(MouseEvent e) {
- BundleIconExplorerDialog dialog = new BundleIconExplorerDialog(composite.getShell(), imageText.getText());
- if (Window.OK == dialog.open()) {
- Object[] values = dialog.getResult();
- if (values.length != 1) {
- Activator.log.error("Waiting one icon path, but found " + values.length, null);
- } else {
- imageDescriptorPath = values[0].toString();
- imageText.setText(imageDescriptorPath);
- }
- }
- setPageComplete(validatePage());
- }
-
- /**
- * @{inheritDoc
- */
- public void mouseDown(MouseEvent e) {
- }
-
- /**
- * @{inheritDoc
- */
- public void mouseDoubleClick(MouseEvent e) {
- }
- });
-
- }
-
- /**
- * Shows/hides the advanced option widgets.
- */
- protected void handleAdvancedButtonSelect() {
- Composite composite = (Composite) getControl();
-
- if (advancedComposite != null) {
- advancedComposite.dispose();
- advancedComposite = null;
- advancedButton.setText(Messages.Dialog_Advanced_Button_Closed);
- } else {
- createAdvancedComposite(composite);
- advancedButton.setText(Messages.Dialog_Advanced_Button_Opened);
- }
- }
-
- /**
- * creates the control area for the id definition
- *
- * @param control
- * the parent composite
- */
- protected void createIDControl(Composite control) {
- final Label idLabel = new Label(control, SWT.NONE);
- idLabel.setText(Messages.Wizard_Drawer_Id);
- idLabel.setToolTipText(Messages.Wizard_Drawer_Id_Tooltip);
-
- idText = new Text(control, SWT.BORDER);
- GridData data = new GridData(SWT.FILL, SWT.CENTER, true, false);
- data.horizontalSpan = 2;
- idText.setLayoutData(data);
- idText.setToolTipText(Messages.Wizard_Drawer_Id_Tooltip);
-
- // initialize, then add the listener...
- initialPopulateDrawerIDField();
-
- idText.addListener(SWT.Modify, this);
- }
-
- /**
- * intialize the field using current value of the palette id
- */
- protected void initialPopulateDrawerIconField() {
- imageText.setText(imageDescriptorPath);
- }
-
- /**
- * intialize the field using current value of the palette id
- */
- protected void initialPopulateDrawerIDField() {
- idText.setText(drawerID);
- }
-
- /**
- * creates the control area for the name definition
- *
- * @param control
- * the parent composite
- */
- protected void createNameControl(Composite control) {
- final Label nameLabel = new Label(control, SWT.NONE);
- nameLabel.setText(Messages.Wizard_Drawer_Name);
- nameLabel.setToolTipText(Messages.Wizard_Drawer_Name_Tooltip);
-
- nameText = new Text(control, SWT.BORDER);
- nameText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
- nameText.setToolTipText(Messages.Wizard_Drawer_Name_Tooltip);
-
- // initialize, then add the listener...
- initialPopulateNameField();
-
- nameText.addListener(SWT.Modify, this);
-
- }
-
- /**
- * initialize name field
- */
- protected void initialPopulateNameField() {
- nameText.setText(name);
- }
-
- /**
- * The <code>WizardNewFileCreationPage</code> implementation of this <code>Listener</code> method handles all events and enablements for controls
- * on this page. Subclasses may extend.
- */
- public void handleEvent(Event event) {
- Widget widget = event.widget;
- if (widget.equals(nameText)) {
- name = nameText.getText();
- } else if (widget.equals(idText)) {
- drawerID = idText.getText();
- }
- setPageComplete(validatePage());
- }
-
-}
+/***************************************************************************** + * Copyright (c) 2009 CEA LIST. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Remi Schnekenburger (CEA LIST) remi.schnekenburger@cea.fr - Initial API and implementation + * + *****************************************************************************/ + +package org.eclipse.papyrus.customization.palette.dialog; + +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.window.Window; +import org.eclipse.jface.wizard.WizardPage; +import org.eclipse.papyrus.customization.palette.Messages; +import org.eclipse.papyrus.infra.widgets.editors.BundleIconExplorerDialog; +import org.eclipse.papyrus.uml.diagram.common.Activator; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.MouseEvent; +import org.eclipse.swt.events.MouseListener; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.swt.widgets.Text; +import org.eclipse.swt.widgets.Widget; + +/** + * Wizard page for information about the new drawer + */ +public class DrawerInformationPage extends WizardPage implements Listener { + + /** text area for the name of the palette definition */ + protected Text nameText; + + /** text area for the id of the palette definition */ + protected Text idText; + + /** parent composite for advanced fields */ + protected Composite advancedComposite; + + /** Button to show/hide advanced fields */ + protected Button advancedButton; + + /** drawer ID */ + protected String drawerID; + + /** palette name */ + protected String name; + + /** image descriptor for the drawer icon */ + protected String imageDescriptorPath; + + /** Text area for icon path */ + protected Text imageText; + + /** drawer proxy to edit, if one exists */ + protected final PaletteLocalDrawerProxy drawerProxy; + + /** path to the icon */ + protected static final String WIZARD_ICON = "/icons/new_drawer_wiz.gif"; + + /** + * Creates a new wizard page with the given name, title, and image. + * + * @param part + * the editor part in which the wizard was created + */ + public DrawerInformationPage() { + super(Messages.Wizard_Drawer_Page_Name, Messages.Wizard_Drawer_Page_Title, Activator.getImageDescriptor(WIZARD_ICON)); + drawerProxy = null; + } + + /** + * Creates a new wizard page with the given name, title, and image. + * + * @param part + * the editor part in which the wizard was created + */ + public DrawerInformationPage(PaletteLocalDrawerProxy drawerProxy) { + super(Messages.Wizard_Drawer_Page_Name, Messages.Wizard_Drawer_Page_Title, Activator.getImageDescriptor(WIZARD_ICON)); + this.drawerProxy = drawerProxy; + } + + /** + * {@inheritDoc} + */ + @Override + public void createControl(Composite parent) { + + // initialize dialog units + initializeDialogUnits(parent); + + // initialize values + intializeValues(); + + // Create a new composite as there is the title bar seperator + // to deal with + Composite control = new Composite(parent, SWT.NONE); + GridLayout layout = new GridLayout(2, false); + control.setLayout(layout); + control.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + setControl(control); + + createNameControl(control); + + createAdvancedControls(control); + + // end of the control creation + Dialog.applyDialogFont(control); + + validatePage(); + // Show description on opening + setErrorMessage(null); + setMessage(null); + setPageComplete(false); + setControl(control); + } + + /** + * initializes fields using context information + */ + protected void intializeValues() { + initName(); + initDrawerID(); + initImageDescriptor(); + } + + /** + * Returns the current value of palette name + * + * @return the current value of palette name + */ + public String getDrawerName() { + return name; + } + + /** + * Returns the current value of palette ID + * + * @return the current value of palette ID + */ + public String getDrawerID() { + return drawerID; + } + + /** + * Returns the current value of path for image descriptor + * + * @return the current value of path for image descriptor + */ + public String getImageDescriptorPath() { + return imageDescriptorPath; + } + + /** + * inits the name field value + */ + protected void initName() { + if (drawerProxy == null) { + name = ""; + } else { + name = drawerProxy.getLabel(); + } + + } + + /** + * inits the palette id value + */ + protected void initDrawerID() { + if (drawerProxy == null) { + drawerID = "drawer_" + System.currentTimeMillis(); + } else { + drawerID = drawerProxy.getId(); + } + + } + + /** + * Inits the image descriptor + */ + protected void initImageDescriptor() { + if (drawerProxy == null) { + imageDescriptorPath = "/icons/drawer.gif"; + } else { + imageDescriptorPath = drawerProxy.getImagePath(); + } + + } + + /** + * Validates the content of the fields in this page + */ + protected boolean validatePage() { + boolean valid = true; + if (advancedComposite != null && !advancedComposite.isDisposed()) { + + if ("".equals(getDrawerID())) { + setErrorMessage(Messages.Wizard_Drawer_Error_Id); + valid = false; + } else if ("".equals(getImageDescriptorPath())) { + setErrorMessage(Messages.Wizard_Drawer_Error_Icon); + valid = false; + } + } + + if ("".equals(getDrawerName())) { + setErrorMessage(Messages.Wizard_Drawer_Error_Name); + valid = false; + } + + if (valid) { + setMessage(null); + setErrorMessage(null); + } + return valid; + } + + /** + * Creates the widget for advanced options. + * + * @param parent + * the parent composite + */ + protected void createAdvancedControls(Composite parent) { + advancedButton = new Button(parent, SWT.PUSH); + advancedButton.setFont(parent.getFont()); + advancedButton.setText(Messages.Dialog_Advanced_Button_Closed); + GridData data = setButtonLayoutData(advancedButton); + data.horizontalAlignment = GridData.BEGINNING; + data.horizontalSpan = 2; + advancedButton.setLayoutData(data); + advancedButton.addSelectionListener(new SelectionAdapter() { + + @Override + public void widgetSelected(SelectionEvent e) { + handleAdvancedButtonSelect(); + } + }); + } + + public Composite createAdvancedComposite(Composite parent) { + advancedComposite = new Composite(parent, SWT.NONE); + advancedComposite.setFont(parent.getFont()); + advancedComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1)); + GridLayout layout = new GridLayout(3, false); + layout.marginHeight = 0; + layout.marginWidth = 0; + advancedComposite.setLayout(layout); + + createIconControl(advancedComposite); + + createIDControl(advancedComposite); + + advancedComposite.getParent().layout(); + return advancedComposite; + } + + /** + * creates the control area for the icon path definition + * + * @param composite + * the parent composite + */ + protected void createIconControl(final Composite composite) { + final Label iconLabel = new Label(composite, SWT.NONE); + iconLabel.setText(Messages.Wizard_Drawer_Icon); + iconLabel.setToolTipText(Messages.Wizard_Drawer_Icon_Tooltip); + + imageText = new Text(composite, SWT.BORDER | SWT.READ_ONLY); + imageText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + imageText.setToolTipText(Messages.Wizard_Drawer_Icon_Tooltip); + + // initialize, then add the listener... + initialPopulateDrawerIconField(); + + // imageText.addListener(SWT.Modify, this); + + Button button = new Button(composite, SWT.NONE); + button.setText("..."); + button.addMouseListener(new MouseListener() { + + /** + * @{inheritDoc + */ + @Override + public void mouseUp(MouseEvent e) { + BundleIconExplorerDialog dialog = new BundleIconExplorerDialog(composite.getShell(), imageText.getText()); + if (Window.OK == dialog.open()) { + Object[] values = dialog.getResult(); + if (values.length != 1) { + Activator.log.error("Waiting one icon path, but found " + values.length, null); + } else { + imageDescriptorPath = values[0].toString(); + imageText.setText(imageDescriptorPath); + } + } + setPageComplete(validatePage()); + } + + /** + * @{inheritDoc + */ + @Override + public void mouseDown(MouseEvent e) { + } + + /** + * @{inheritDoc + */ + @Override + public void mouseDoubleClick(MouseEvent e) { + } + }); + + } + + /** + * Shows/hides the advanced option widgets. + */ + protected void handleAdvancedButtonSelect() { + Composite composite = (Composite) getControl(); + + if (advancedComposite != null) { + advancedComposite.dispose(); + advancedComposite = null; + advancedButton.setText(Messages.Dialog_Advanced_Button_Closed); + } else { + createAdvancedComposite(composite); + advancedButton.setText(Messages.Dialog_Advanced_Button_Opened); + } + } + + /** + * creates the control area for the id definition + * + * @param control + * the parent composite + */ + protected void createIDControl(Composite control) { + final Label idLabel = new Label(control, SWT.NONE); + idLabel.setText(Messages.Wizard_Drawer_Id); + idLabel.setToolTipText(Messages.Wizard_Drawer_Id_Tooltip); + + idText = new Text(control, SWT.BORDER); + GridData data = new GridData(SWT.FILL, SWT.CENTER, true, false); + data.horizontalSpan = 2; + idText.setLayoutData(data); + idText.setToolTipText(Messages.Wizard_Drawer_Id_Tooltip); + + // initialize, then add the listener... + initialPopulateDrawerIDField(); + + idText.addListener(SWT.Modify, this); + } + + /** + * intialize the field using current value of the palette id + */ + protected void initialPopulateDrawerIconField() { + imageText.setText(imageDescriptorPath); + } + + /** + * intialize the field using current value of the palette id + */ + protected void initialPopulateDrawerIDField() { + idText.setText(drawerID); + } + + /** + * creates the control area for the name definition + * + * @param control + * the parent composite + */ + protected void createNameControl(Composite control) { + final Label nameLabel = new Label(control, SWT.NONE); + nameLabel.setText(Messages.Wizard_Drawer_Name); + nameLabel.setToolTipText(Messages.Wizard_Drawer_Name_Tooltip); + + nameText = new Text(control, SWT.BORDER); + nameText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + nameText.setToolTipText(Messages.Wizard_Drawer_Name_Tooltip); + + // initialize, then add the listener... + initialPopulateNameField(); + + nameText.addListener(SWT.Modify, this); + + } + + /** + * initialize name field + */ + protected void initialPopulateNameField() { + nameText.setText(name); + } + + /** + * The <code>WizardNewFileCreationPage</code> implementation of this <code>Listener</code> method handles all events and enablements for controls + * on this page. Subclasses may extend. + */ + @Override + public void handleEvent(Event event) { + Widget widget = event.widget; + if (widget.equals(nameText)) { + name = nameText.getText(); + } else if (widget.equals(idText)) { + drawerID = idText.getText(); + } + setPageComplete(validatePage()); + } + +} diff --git a/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/dialog/ExportPaletteConfigurationWizard.java b/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/dialog/ExportPaletteConfigurationWizard.java new file mode 100644 index 00000000000..85dce028af4 --- /dev/null +++ b/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/dialog/ExportPaletteConfigurationWizard.java @@ -0,0 +1,120 @@ +/***************************************************************************** + * Copyright (c) 2016 CEA LIST. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Mickael ADAM (ALL4TEC) mickael.adam@all4tec.net - Initial API and Implementation + * + *****************************************************************************/ + +package org.eclipse.papyrus.customization.palette.dialog; + +import java.io.IOException; + +import org.eclipse.emf.common.util.URI; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.papyrus.customization.palette.Messages; +import org.eclipse.papyrus.customization.palette.PaletteConstants; +import org.eclipse.papyrus.customization.palette.utils.PaletteUtils; +import org.eclipse.papyrus.infra.types.ElementTypeSetConfiguration; +import org.eclipse.papyrus.uml.diagram.common.Activator; +import org.eclipse.papyrus.uml.diagram.common.service.PapyrusPaletteService.ProviderDescriptor; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.dialogs.WizardNewFileCreationPage; + +/** + * Wizard to export an existing Palette Definition and its associated models files. + */ +public class ExportPaletteConfigurationWizard extends AbstractPaletteConfigurationWizard { + + /** content page */ + protected PaletteConfigurationContentPage contentPage; + + /** the new file creation page of the wizard */ + private WizardNewFileCreationPage newFileCreationPage; + + /** + * Creates a new local Palette Wizard. + * + * @param part + * the editor part where the palette is available + * @param descriptor + * the descriptor to edit + */ + public ExportPaletteConfigurationWizard(final IEditorPart part, final ProviderDescriptor descriptor) { + super(part, descriptor); + setWindowTitle(Messages.ExportPaletteConfigurationWizard_ExportWiazrdLabel); + } + + /** + * {@inheritDoc} + */ + @Override + public void addPages() { + super.addPages(); + + newFileCreationPage = new WizardNewFileCreationPage("", new StructuredSelection());//$NON-NLS-1$ + + newFileCreationPage.setTitle(Messages.ExportPaletteConfigurationWizard_export_palette); + newFileCreationPage.setDescription(Messages.ExportPaletteConfigurationWizard_Export_description); + + addPage(newFileCreationPage); + } + + + /** + * {@inheritDoc} + */ + @Override + protected void saveResources() { + + // Get the wanted location + String selectedPath = newFileCreationPage.getContainerFullPath().append(newFileCreationPage.getFileName()).toString(); + + clearStringBuilder(); + stringBuilder.append(selectedPath); + stringBuilder.append(STR_DOT); + stringBuilder.append(PaletteConstants.PALETTECONFIGURATION_EXTENSION); + // Set new path + paletteResource.setURI(URI.createFileURI(stringBuilder.toString())); + + clearStringBuilder(); + stringBuilder.append(selectedPath); + stringBuilder.append(PaletteConstants.ELEMENTTYPE_UI_IDENTIFIER_POSTFIX); + stringBuilder.append(STR_DOT); + stringBuilder.append(PaletteConstants.ELEMENTTYPE_EXTENSION); + + elementTypeUIResource.setURI(URI.createFileURI(stringBuilder.toString())); + + clearStringBuilder(); + stringBuilder.append(selectedPath); + stringBuilder.append(PaletteConstants.ELEMENTTYPE_SEMENTIC_IDENTIFIER_POSTFIX); + stringBuilder.append(STR_DOT); + stringBuilder.append(PaletteConstants.ELEMENTTYPE_EXTENSION); + elementTypeSemResource.setURI(URI.createFileURI(stringBuilder.toString())); + + // Save + try { + paletteResource.save(PaletteUtils.saveOptions); + // Checks if model are not void and are useful + if (!((ElementTypeSetConfiguration) elementTypeUIResource.getContents().get(0)).getElementTypeConfigurations().isEmpty()) { + elementTypeUIResource.save(PaletteUtils.saveOptions); + elementTypeSemResource.save(PaletteUtils.saveOptions); + } + } catch (IOException e) { + Activator.log.error(e); + } + } + + /** + * {@inheritDoc} + */ + @Override + protected void deployModels() { + // Nothings to loads + } +} diff --git a/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/dialog/ExtendedPaletteContentPage.java b/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/dialog/ExtendedPaletteContentPage.java index 886a77e2eec..3f54ff2dbdd 100644 --- a/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/dialog/ExtendedPaletteContentPage.java +++ b/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/dialog/ExtendedPaletteContentPage.java @@ -1,2413 +1,2463 @@ -/*****************************************************************************
- * Copyright (c) 2009, 2014 CEA LIST and others.
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Remi Schnekenburger (CEA LIST) remi.schnekenburger@cea.fr - Initial API and implementation
- * Christian W. Damus (CEA) - bug 422257
- *
- *****************************************************************************/
-package org.eclipse.papyrus.customization.palette.dialog;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.emf.common.notify.Notification;
-import org.eclipse.emf.ecore.EClass;
-import org.eclipse.emf.ecore.EClassifier;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.resource.Resource;
-import org.eclipse.emf.ecore.resource.ResourceSet;
-import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
-import org.eclipse.emf.ecore.util.EContentAdapter;
-import org.eclipse.emf.ecore.util.EcoreUtil;
-import org.eclipse.gef.palette.CombinedTemplateCreationEntry;
-import org.eclipse.gef.palette.PaletteContainer;
-import org.eclipse.gef.palette.PaletteDrawer;
-import org.eclipse.gef.palette.PaletteEntry;
-import org.eclipse.gef.palette.PaletteRoot;
-import org.eclipse.gef.palette.PaletteStack;
-import org.eclipse.gef.palette.PaletteToolbar;
-import org.eclipse.gef.palette.ToolEntry;
-import org.eclipse.gef.ui.palette.PaletteCustomizer;
-import org.eclipse.gmf.runtime.common.core.service.ProviderPriority;
-import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditorWithFlyOutPalette;
-import org.eclipse.jface.dialogs.Dialog;
-import org.eclipse.jface.resource.ImageDescriptor;
-import org.eclipse.jface.util.LocalSelectionTransfer;
-import org.eclipse.jface.viewers.DoubleClickEvent;
-import org.eclipse.jface.viewers.IDoubleClickListener;
-import org.eclipse.jface.viewers.ILabelProvider;
-import org.eclipse.jface.viewers.ILabelProviderListener;
-import org.eclipse.jface.viewers.ISelectionChangedListener;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.ITreeContentProvider;
-import org.eclipse.jface.viewers.SelectionChangedEvent;
-import org.eclipse.jface.viewers.TreeViewer;
-import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.jface.viewers.ViewerComparator;
-import org.eclipse.jface.viewers.ViewerFilter;
-import org.eclipse.jface.wizard.WizardPage;
-import org.eclipse.papyrus.emf.facet.custom.core.ICustomizationCatalogManagerFactory;
-import org.eclipse.papyrus.emf.facet.custom.core.ICustomizationManager;
-import org.eclipse.papyrus.emf.facet.custom.core.ICustomizationManagerFactory;
-import org.eclipse.papyrus.emf.facet.custom.core.internal.CustomizationCatalogManager;
-import org.eclipse.papyrus.emf.facet.custom.metamodel.v0_2_0.custom.Customization;
-import org.eclipse.papyrus.emf.facet.custom.ui.internal.CustomizedLabelProvider;
-import org.eclipse.papyrus.emf.facet.custom.ui.internal.CustomizedTreeContentProvider;
-import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
-import org.eclipse.papyrus.uml.diagram.common.Activator;
-import org.eclipse.papyrus.uml.diagram.common.Messages;
-import org.eclipse.papyrus.uml.diagram.common.part.PaletteUtil;
-import org.eclipse.papyrus.uml.diagram.common.part.PapyrusPalettePreferences;
-import org.eclipse.papyrus.uml.diagram.common.service.AspectCreationEntry;
-import org.eclipse.papyrus.uml.diagram.common.service.IPapyrusPaletteConstant;
-import org.eclipse.papyrus.uml.diagram.common.service.PaletteConfigurationUtils;
-import org.eclipse.papyrus.uml.diagram.common.service.PapyrusPaletteService;
-import org.eclipse.papyrus.uml.diagram.common.service.palette.StereotypeAspectActionProvider;
-import org.eclipse.papyrus.uml.diagram.paletteconfiguration.Configuration;
-import org.eclipse.papyrus.uml.diagram.paletteconfiguration.DrawerConfiguration;
-import org.eclipse.papyrus.uml.diagram.paletteconfiguration.LeafConfiguration;
-import org.eclipse.papyrus.uml.diagram.paletteconfiguration.PaletteConfiguration;
-import org.eclipse.papyrus.uml.diagram.paletteconfiguration.PaletteconfigurationPackage;
-import org.eclipse.papyrus.uml.diagram.paletteconfiguration.SeparatorConfiguration;
-import org.eclipse.papyrus.uml.diagram.paletteconfiguration.StackConfiguration;
-import org.eclipse.papyrus.uml.diagram.paletteconfiguration.ToolConfiguration;
-import org.eclipse.papyrus.uml.diagram.paletteconfiguration.util.PaletteconfigurationSwitch;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.dnd.DND;
-import org.eclipse.swt.dnd.DragSourceAdapter;
-import org.eclipse.swt.dnd.DragSourceEvent;
-import org.eclipse.swt.dnd.DragSourceListener;
-import org.eclipse.swt.dnd.DropTargetEvent;
-import org.eclipse.swt.dnd.DropTargetListener;
-import org.eclipse.swt.dnd.Transfer;
-import org.eclipse.swt.dnd.TreeDropTargetEffect;
-import org.eclipse.swt.events.ModifyEvent;
-import org.eclipse.swt.events.ModifyListener;
-import org.eclipse.swt.events.MouseEvent;
-import org.eclipse.swt.events.MouseListener;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Combo;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Event;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Listener;
-import org.eclipse.swt.widgets.ToolBar;
-import org.eclipse.swt.widgets.ToolItem;
-import org.eclipse.swt.widgets.Tree;
-import org.eclipse.swt.widgets.TreeItem;
-import org.eclipse.ui.IEditorPart;
-import org.eclipse.uml2.uml.Class;
-import org.eclipse.uml2.uml.Package;
-import org.eclipse.uml2.uml.Profile;
-import org.eclipse.uml2.uml.Stereotype;
-import org.eclipse.uml2.uml.UMLPackage;
-import org.w3c.dom.Document;
-
-/**
- * Wizard page for information about the new local palette definition
- */
-public class ExtendedPaletteContentPage extends WizardPage implements Listener {
-
- /** editor part in which the palette is created */
- protected IEditorPart editorPart;
-
- /** available tools viewer */
- protected TreeViewer availableToolsViewer;
-
- /** label provider for the tree viewer */
- protected PaletteLabelProvider paletteLabelProvider;
-
- /** icon path when tools are hidden */
- protected static final String HIDDEN_TOOLS_ICON = "/icons/tools_hidden.gif";
-
- /** icon path when tools are shown */
- protected static final String SHOWN_TOOLS_ICON = "/icons/tools_shown.gif";
-
- /** path to the icon */
- protected static final String WIZARD_ICON = "/icons/local_desc_wiz.png";
-
- /** icon path when drawers are hidden */
- protected static final String SHOWN_DRAWERS_ICON = "/icons/drawers_shown.gif";
-
- /** icon path when drawers are shown */
- protected static final String HIDDEN_DRAWERS_ICON = "/icons/drawers_hidden.gif";
-
- /** icon path for the add button */
- protected static final String ADD_ICON = "/icons/arrow_right.gif";
-
- /** icon path for the remove button */
- protected static final String REMOVE_ICON = "/icons/arrow_left.gif";
-
- /** icon path for the delete button */
- protected static final String DELETE_ICON = "/icons/delete.gif";
-
- /** icon path for the create drawer button */
- protected static final String CREATE_DRAWERS_ICON = "/icons/new_drawer.gif";
-
- /** icon path for the create separator button */
- protected String CREATE_SEPARATOR_ICON = "/icons/separator.gif";
-
- /** icon path for the create stack button */
- protected String CREATE_STACK_ICON = "/icons/stack.gif";
-
- /** icon path for the delete drawer button */
- protected static final String DELETE_DRAWERS_ICON = "/icons/delete.gif";
-
- /** icon for the content provider switch button */
- protected String SWITCH_CONTENT_PROVIDER_ICON = "/icons/switch_provider.gif";
-
- /** label for the standard tools */
- protected static final String UML_TOOLS_LABEL = "UML tools";
-
- /** icon path for the edit drawer button */
- protected static final String EDIT_ICON = "/icons/obj16/file.gif";
-
- /** instance of the filter used to show/hide drawers */
- protected final ViewerFilter drawerFilter = new DrawerFilter();
-
- /** instance of the filter used to show/hide tools */
- protected final ViewerFilter toolFilter = new ToolFilter();
-
- /** stored preferences */
- protected List<String> storedPreferences;
-
- /** add button */
- protected Button addButton;
-
- /** remove button */
- protected Button removeButton;
-
- /** tree viewer for the new palette */
- protected TreeViewer paletteTreeViewer;
-
- /** document for element creation */
- protected Document document;
-
- /** content node for the palette viewer */
- protected PaletteContainerProxy contentNode;
-
- /** combo to select which profile tools should be visible */
- protected Combo profileCombo;
-
- /** list of profiles that can provide tools */
- protected List<String> profileComboList = new ArrayList<String>();
-
- /** tool item in charge of toggling content providers in the available tool viewer */
- protected ToolItem toggleContentProvider;
-
- /** required profile by this palette */
- protected Set<String> requiredProfiles;
-
- /** palette customizer used for the palette */
- protected PaletteCustomizer customizer;
-
- /** current selected entry proxy */
- protected Configuration selectedConfiguration;
-
- /** class in charge of the information composite */
- protected ConfigurationInformationComposite informationComposite = new ConfigurationInformationComposite();
-
- /** class in charge of the aspect tool information composite */
- protected AspectActionsInformationComposite aspectActionComposite = new AspectActionsInformationComposite();
-
- /** toolbar above tools */
- protected ToolBar toolbar;
-
- /** validator key for toolbar items */
- protected final static String VALIDATOR = "validator";
-
- /** priority of the current edited palette */
- protected ProviderPriority priority;
-
- /** resource set that contains the palette configuration resource */
- private ResourceSet resourceSet;
-
- /** palette configuration resource */
- private Resource resourceToEdit;
-
- /** customization manager for the content provider */
- // TODO: EMFFACET: pb of ResourceSET
- private ICustomizationManager manager = ICustomizationManagerFactory.DEFAULT.getOrCreateICustomizationManager(new ResourceSetImpl());
-
-
- /**
- * Creates a new wizard page with the given name, title, and image.
- *
- * @param part
- * the editor part in which the wizard was created
- */
- public ExtendedPaletteContentPage(IEditorPart part, PaletteCustomizer customizer) {
- super(Messages.Local_Palette_ContentPage_Name, Messages.Local_Palette_ContentPage_Title, Activator.getImageDescriptor(WIZARD_ICON));
- this.editorPart = part;
- this.customizer = customizer;
- }
-
- @Override
- public void dispose() {
- super.dispose();
-
- if (resourceSet != null) {
- EMFHelper.unload(resourceSet);
- }
-
- if (manager != null) {
- EMFHelper.unload(manager.getResourceSet());
- }
- }
-
- /**
- * Sets the priority of the current edited palette
- *
- * @param priority
- * the priority of the current edited palette
- */
- public void setPriority(ProviderPriority priority) {
- this.priority = priority;
- }
-
- /**
- * @return the resourceSet
- */
- public ResourceSet getResourceSet() {
- return resourceSet;
- }
-
- /**
- * @return the resourceToEdit
- */
- public Resource getResourceToEdit() {
- return resourceToEdit;
- }
-
- /**
- * Returns the list of required profiles by this local palette definition
- *
- * @return the profiles required by this palette
- */
- public Set<String> getRequiredProfiles() {
- return requiredProfiles;
- }
-
- /**
- * {@inheritDoc}
- */
- public void createControl(Composite parent) {
-
- // initialize dialog units
- initializeDialogUnits(parent);
-
- // Create a new composite as there is the title bar seperator
- // to deal with
- Composite control = new Composite(parent, SWT.NONE);
- GridLayout layout = new GridLayout(4, false);
- control.setLayout(layout);
- control.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
- setControl(control);
-
- // create Available Tools Group
- createAvailableToolsGroup();
-
- // create add/remove buttons
- createAddRemoveButtons();
-
- // create Palette Group
- createPalettePreviewGroup();
-
- // create tool description group (custom name, description, and perhaphs icon.... Just under this group, another one with aspect actions)
- createToolDescriptionGroup();
-
- // just under, creates a new line of composites...
- createAspectActionComposite();
-
-
-
- // add listeners inter-groups
- ISelectionChangedListener listener = createToolsViewerSelectionChangeListener();
- availableToolsViewer.addSelectionChangedListener(listener);
- paletteTreeViewer.addSelectionChangedListener(listener);
- resourceToEdit.eAdapters().add(new EContentAdapter() {
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void notifyChanged(Notification notification) {
- super.notifyChanged(notification);
- paletteTreeViewer.refresh();
- }
- });
-
- // end of the control creation
- Dialog.applyDialogFont(control);
-
- validatePage();
- // Show description on opening
- setErrorMessage(null);
- setMessage(null);
- setControl(control);
- }
-
- /**
- * Creates the composite group that presents information about ascpect actions for aspect tools
- */
- protected void createAspectActionComposite() {
- aspectActionComposite.createComposite((Composite) getControl(), getAllAppliedProfiles());
- }
-
- /**
- * Creates the composite group that presents information about current selected tool
- */
- protected void createToolDescriptionGroup() {
- informationComposite.createComposite((Composite) getControl(), getAllAppliedProfiles());
- }
-
- /**
- * update the preferences to have all tools accessible
- */
- protected void updatePreferences() {
- // change => set to no hidden palettes
- storedPreferences = PapyrusPalettePreferences.getHiddenPalettes(editorPart);
-
- // remove all, but should only remove visible palettes
- for (String id : storedPreferences) {
- PapyrusPalettePreferences.changePaletteVisibility(id, editorPart, true);
- }
- }
-
- /**
- * Restore preferences
- */
- public void restorePreferences() {
- // remove all, but should only remove visible palettes
- for (String id : storedPreferences) {
- PapyrusPalettePreferences.changePaletteVisibility(id, editorPart, false);
- }
- }
-
- /**
- * creates the palette preview group
- */
- protected void createPalettePreviewGroup() {
- Composite parent = (Composite) getControl();
- Composite paletteComposite = new Composite(parent, SWT.NONE);
-
- GridLayout layout = new GridLayout(2, true);
- layout.marginHeight = 0;
- layout.marginWidth = 0;
- paletteComposite.setLayout(layout);
- GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
- paletteComposite.setLayoutData(data);
-
- Label label = new Label(paletteComposite, SWT.NONE);
- label.setText(Messages.Local_Palette_Palette_Preview);
- data = new GridData(SWT.LEFT, SWT.CENTER, true, false);
- label.setLayoutData(data);
-
- toolbar = new ToolBar(paletteComposite, SWT.HORIZONTAL);
- data = new GridData(SWT.RIGHT, SWT.FILL, false, false);
- toolbar.setLayoutData(data);
- populatePalettePreviewToolBar(toolbar);
-
- Tree tree = new Tree(paletteComposite, SWT.SINGLE | SWT.BORDER);
- data = new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1);
- data.widthHint = 185;
- // Make the tree this tall even when there is nothing in it. This will keep the
- // dialog from shrinking to an unusually small size.
- data.heightHint = 200;
- tree.setLayoutData(data);
- paletteTreeViewer = new TreeViewer(tree);
- paletteTreeViewer.setContentProvider(new ExtendedPaletteContentProvider());
- paletteTreeViewer.setLabelProvider(new ExtendedPaletteLabelProvider());
- paletteTreeViewer.addSelectionChangedListener(new ISelectionChangedListener() {
-
- public void selectionChanged(SelectionChangedEvent event) {
- handlePalettePreviewSelectionChanged(event);
- }
- });
-
- addPalettePreviewDropSupport();
- addPalettePreviewDragSupport();
- addPalettePreviewEditSupport();
-
- paletteTreeViewer.setInput(resourceToEdit);
- }
-
- /**
- * handle the selection change event for the palette preview
- *
- * @param event
- * the event that is thrown by the palette viewer
- */
- protected void handlePalettePreviewSelectionChanged(SelectionChangedEvent event) {
- // retrieve current selection
- Configuration configuration = getSelectedConfiguration();
- if (configuration != null) {
- selectedConfiguration = configuration;
- // update the current selected palette entry proxy
- informationComposite.setSelectedConfiguration(selectedConfiguration);
- } else {
- selectedConfiguration = null;
- informationComposite.setSelectedConfiguration(null);
- }
-
- // update toolbar
- if (toolbar != null && !toolbar.isDisposed()) {
- for (int i = 0; i < toolbar.getItemCount(); i++) {
- ToolItem item = toolbar.getItem(i);
- Object validator = item.getData(VALIDATOR);
- if (validator instanceof ToolBarItemValidator) {
- item.setEnabled(((ToolBarItemValidator) validator).isEnable());
- }
- }
- }
- }
-
- /**
- * Adds the behavior for the double click strategy
- */
- protected void addPalettePreviewEditSupport() {
- paletteTreeViewer.addDoubleClickListener(new IDoubleClickListener() {
-
- /**
- * {@inheritDoc}
- */
- public void doubleClick(DoubleClickEvent event) {
- // nothing here
- }
- });
-
- }
-
- /**
- * Add drop behavior for the palette preview
- */
- protected void addPalettePreviewDropSupport() {
- // transfer types
- Transfer[] transfers = new Transfer[] { LocalSelectionTransfer.getTransfer() };
-
- // drag listener
- DropTargetListener listener = new TreeDropTargetEffect(paletteTreeViewer.getTree()) {
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void drop(DropTargetEvent event) {
- super.drop(event);
- IStructuredSelection transferedSelection = (IStructuredSelection) LocalSelectionTransfer.getTransfer().nativeToJava(event.currentDataType);
- Object objectToTransfer = transferedSelection.getFirstElement();
- if (!(objectToTransfer instanceof IAdaptable)) {
- return;
- }
- final EObject eobjectToTransfer = EMFHelper.getEObject(objectToTransfer);
-
- Object targetObject = ((TreeItem) event.item).getData();
- if (!(targetObject instanceof IAdaptable)) {
- return;
- }
-
- final EObject targetEObject = EMFHelper.getEObject(targetObject);
- if (targetEObject == null) {
- return;
- }
-
- new PaletteconfigurationSwitch<Object>() {
-
- /**
- * {@inheritDoc}
- */
- @Override
- public Object caseDrawerConfiguration(DrawerConfiguration drawerConfigurationToMove) {
- if (targetEObject instanceof DrawerConfiguration) {
- // move the drawer before the target drawer configuration
- PaletteConfiguration paletteConfiguration = (PaletteConfiguration) ((DrawerConfiguration) targetEObject).eContainer();
- PaletteConfigurationUtils.moveDrawerConfiguration(paletteConfiguration, drawerConfigurationToMove, (DrawerConfiguration) targetEObject);
-
- }
- return super.caseDrawerConfiguration(drawerConfigurationToMove);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public Object caseSeparatorConfiguration(SeparatorConfiguration separatorConfigurationToMove) {
- if (targetEObject instanceof DrawerConfiguration) {
- PaletteConfigurationUtils.moveSeparatorConfiguration(((DrawerConfiguration) targetEObject), separatorConfigurationToMove);
- } else if (targetEObject instanceof StackConfiguration) {
- PaletteConfigurationUtils.moveSeparatorConfiguration(((StackConfiguration) targetEObject), separatorConfigurationToMove);
- } else if (targetEObject instanceof ToolConfiguration) {
- PaletteConfigurationUtils.moveSeparatorConfiguration(((ToolConfiguration) targetEObject), separatorConfigurationToMove);
- } else if (targetEObject instanceof SeparatorConfiguration) {
- PaletteConfigurationUtils.moveSeparatorConfiguration(((SeparatorConfiguration) targetEObject), separatorConfigurationToMove);
- }
-
- return super.caseSeparatorConfiguration(separatorConfigurationToMove);
- };
-
- /**
- * {@inheritDoc}
- */
- @Override
- public Object caseStackConfiguration(StackConfiguration stackConfigurationToMove) {
- if (targetEObject instanceof DrawerConfiguration) {
- PaletteConfigurationUtils.moveStackConfiguration(((DrawerConfiguration) targetEObject), stackConfigurationToMove);
- } else if (targetEObject instanceof StackConfiguration) {
- PaletteConfigurationUtils.moveStackConfiguration(((StackConfiguration) targetEObject), stackConfigurationToMove);
- } else if (targetEObject instanceof ToolConfiguration) {
- PaletteConfigurationUtils.moveStackConfiguration(((ToolConfiguration) targetEObject), stackConfigurationToMove);
- } else if (targetEObject instanceof SeparatorConfiguration) {
- PaletteConfigurationUtils.moveStackConfiguration(((SeparatorConfiguration) targetEObject), stackConfigurationToMove);
- }
-
- return super.caseStackConfiguration(stackConfigurationToMove);
- };
-
- /**
- * {@inheritDoc}
- */
- @Override
- public Object caseToolConfiguration(ToolConfiguration toolConfigurationToMove) {
- if (targetEObject instanceof DrawerConfiguration) {
- PaletteConfigurationUtils.moveToolConfiguration(((DrawerConfiguration) targetEObject), toolConfigurationToMove);
- } else if (targetEObject instanceof StackConfiguration) {
- PaletteConfigurationUtils.moveToolConfiguration(((StackConfiguration) targetEObject), toolConfigurationToMove);
- } else if (targetEObject instanceof ToolConfiguration) {
- PaletteConfigurationUtils.moveToolConfiguration(((ToolConfiguration) targetEObject), toolConfigurationToMove);
- } else if (targetEObject instanceof SeparatorConfiguration) {
- PaletteConfigurationUtils.moveToolConfiguration(((SeparatorConfiguration) targetEObject), toolConfigurationToMove);
- }
-
- return super.caseToolConfiguration(toolConfigurationToMove);
- };
-
-
- }.doSwitch(eobjectToTransfer);
-
- setPageComplete(validatePage());
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void dragOver(DropTargetEvent event) {
- super.dragOver(event);
-
- IStructuredSelection transferedSelection = (IStructuredSelection) LocalSelectionTransfer.getTransfer().nativeToJava(event.currentDataType);
- // check selection is compatible for drop target
-
- TreeItem item = paletteTreeViewer.getTree().getItem(paletteTreeViewer.getTree().toControl(new Point(event.x, event.y)));
-
- checkSelectionForDrop(transferedSelection, item, event);
- }
- };
-
- paletteTreeViewer.addDropSupport(DND.DROP_LINK | DND.DROP_MOVE, transfers, listener);
- }
-
- /**
- * Adds drag ability to the palette preview composite
- */
- protected void addPalettePreviewDragSupport() {
-
- // transfer types
- Transfer[] transfers = new Transfer[] { LocalSelectionTransfer.getTransfer() };
-
- // drag listener
- DragSourceListener listener = new DragSourceAdapter() {
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void dragStart(DragSourceEvent event) {
- super.dragStart(event);
- event.data = paletteTreeViewer.getSelection();
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void dragSetData(DragSourceEvent event) {
- super.dragSetData(event);
- LocalSelectionTransfer.getTransfer().setSelection(paletteTreeViewer.getSelection());
- }
-
- };
-
- paletteTreeViewer.addDragSupport(DND.DROP_MOVE, transfers, listener);
- }
-
- /**
- * Checks if the selection can be added to the target widget
- *
- * @param transferedSelection
- * the selection to be dropped
- * @param widget
- * the widget where to drop
- */
- protected void checkSelectionForDrop(IStructuredSelection transferedSelection, TreeItem item, final DropTargetEvent event) {
- event.detail = DND.DROP_NONE;
- final Object objectToTransfer = transferedSelection.getFirstElement();
- if (!(objectToTransfer instanceof IAdaptable)) {
- return;
- }
- final EObject eobjectToTransfer = EMFHelper.getEObject(objectToTransfer);
- // handle only first selected element
- if (item == null) {
- // adding to the root, should only be a drawer
- if (eobjectToTransfer instanceof DrawerConfiguration) {
- event.detail = DND.DROP_LINK;
- }
- } else {
- Object targetObject = item.getData();
- if (!(targetObject instanceof IAdaptable)) {
- event.detail = DND.DROP_NONE;
- return;
- }
- final EObject targetEObject = EMFHelper.getEObject(targetObject);
- if (targetEObject == null) {
- event.detail = DND.DROP_NONE;
- return;
- }
-
- new PaletteconfigurationSwitch<Object>() {
-
- /**
- * {@inheritDoc}
- */
- @Override
- public Object caseDrawerConfiguration(DrawerConfiguration object) {
- if (targetEObject instanceof DrawerConfiguration) {
- event.detail = DND.DROP_MOVE;
- event.feedback = DND.FEEDBACK_INSERT_BEFORE;
- }
- return object;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public Object caseSeparatorConfiguration(SeparatorConfiguration object) {
- if (targetEObject instanceof DrawerConfiguration) {
- event.detail = DND.DROP_MOVE;
- } else if (targetEObject instanceof StackConfiguration) {
- event.detail = DND.DROP_MOVE;
- event.feedback = DND.FEEDBACK_INSERT_BEFORE;
- } else if (targetEObject instanceof ToolConfiguration) {
- event.detail = DND.DROP_MOVE;
- event.feedback = DND.FEEDBACK_INSERT_BEFORE;
- } else if (targetEObject instanceof SeparatorConfiguration) {
- event.detail = DND.DROP_MOVE;
- event.feedback = DND.FEEDBACK_INSERT_BEFORE;
- }
-
- return object;
- };
-
- /**
- * {@inheritDoc}
- */
- @Override
- public Object caseStackConfiguration(StackConfiguration object) {
- if (targetEObject instanceof DrawerConfiguration) {
- event.detail = DND.DROP_MOVE;
- } else if (targetEObject instanceof StackConfiguration) {
- event.detail = DND.DROP_MOVE;
- event.feedback = DND.FEEDBACK_INSERT_BEFORE;
- } else if (targetEObject instanceof ToolConfiguration) {
- event.detail = DND.DROP_MOVE;
- event.feedback = DND.FEEDBACK_INSERT_BEFORE;
- } else if (targetEObject instanceof SeparatorConfiguration) {
- event.detail = DND.DROP_MOVE;
- event.feedback = DND.FEEDBACK_INSERT_BEFORE;
- }
- return object;
- };
-
- /**
- * {@inheritDoc}
- */
- @Override
- public Object caseToolConfiguration(ToolConfiguration object) {
- if (targetEObject instanceof DrawerConfiguration) {
- event.detail = DND.DROP_MOVE;
- } else if (targetEObject instanceof StackConfiguration) {
- event.detail = DND.DROP_MOVE;
- } else if (targetEObject instanceof ToolConfiguration) {
- event.detail = DND.DROP_MOVE;
- event.feedback = DND.FEEDBACK_INSERT_BEFORE;
- } else if (targetEObject instanceof SeparatorConfiguration) {
- event.detail = DND.DROP_MOVE;
- event.feedback = DND.FEEDBACK_INSERT_BEFORE;
- }
- return object;
- };
-
-
- }.doSwitch(eobjectToTransfer);
-
- }
- }
-
- /**
- * Sets an empty content for the palette preview
- */
- public void initializeContent() {
- contentNode = new PaletteContainerProxy(null);
-
- // adds a default local drawer
- PaletteLocalDrawerProxy proxy = new PaletteLocalDrawerProxy("Default", generateID("Drawer_"), "/icons/drawer.gif", "Default Drawer");
- contentNode.addChild(proxy);
-
- setPageComplete(false);
- }
-
- /**
- * Sets the initial content for the palette preview
- *
- * @param descriptor
- * the descriptor that contains the configuration file to load
- */
- public void initializeContent(PapyrusPaletteService.ExtendedProviderDescriptor descriptor) {
- resourceSet = createResourceSet();
- resourceToEdit = getResourceSet().createResource(descriptor.getRedefinitionFileURI());
-
- // check resource is not null;
- if (resourceToEdit == null) {
- Activator.log.error("No resource has been created for uri :" + descriptor.getRedefinitionFileURI(), null);
- }
- try {
- resourceToEdit.load(Collections.emptyMap());
- } catch (IOException e) {
- Activator.log.error("Impossible to load configuration file", e);
- }
-
- }
-
- /**
- * Creates and returns the resource set used to modidy the content of the palette configuration
- *
- * @return the newly created ResourceSet.
- */
- protected ResourceSet createResourceSet() {
- return new ResourceSetImpl();
- }
-
- /**
- * populates the preview palette toolbar
- *
- * @param toolbar
- * the toolbar to populate
- */
- protected void populatePalettePreviewToolBar(ToolBar toolbar) {
- ConfigurationSelectedValidator validator = new ConfigurationSelectedValidator();
- DrawerConfigurationSelectedValidator drawerConfigurationSelectedValidator = new DrawerConfigurationSelectedValidator();
- createToolBarItem(toolbar, DELETE_ICON, Messages.PapyrusPaletteCustomizerDialog_RemoveButtonTooltip, createRemoveElementListener(), validator);
- createToolBarItem(toolbar, CREATE_DRAWERS_ICON, Messages.Local_Palette_Create_Drawer_Tooltip, createNewDrawerListener(), null);
- createToolBarItem(toolbar, CREATE_SEPARATOR_ICON, Messages.Local_Palette_Create_Separator_Tooltip, createNewSeparatorListener(), validator);
- createToolBarItem(toolbar, CREATE_STACK_ICON, Messages.Local_Palette_Create_Stack_Tooltip, createNewStackListener(), drawerConfigurationSelectedValidator);
- }
-
- /**
- * Creates the listener for the remove item(s) button
- *
- * @return the listener for the remove button
- */
- protected Listener createRemoveElementListener() {
- return new Listener() {
-
- /**
- * {@inheritDoc}
- */
- public void handleEvent(Event event) {
- IStructuredSelection selection = (IStructuredSelection) paletteTreeViewer.getSelection();
- if (selection == null || selection.size() < 1) {
- return;
- }
-
- Iterator<?> it = selection.iterator();
- while (it.hasNext()) {
- Object o = it.next();
- if (o instanceof IAdaptable) {
- EObject eobject = EMFHelper.getEObject(o);
- if (eobject instanceof Configuration) {
- PaletteConfigurationUtils.removeConfiguration((Configuration) eobject);
- }
- }
- }
- }
- };
- }
-
- /**
- * Creates the listener for the new drawer tool item
- *
- * @return the listener created
- */
- protected Listener createNewDrawerListener() {
- return new Listener() {
-
- /**
- * {@inheritDoc}
- */
- public void handleEvent(Event event) {
- PaletteConfiguration paletteConfiguration = (PaletteConfiguration) EcoreUtil.getObjectByType(resourceToEdit.getContents(), PaletteconfigurationPackage.eINSTANCE.getPaletteConfiguration());
- if (paletteConfiguration != null) {
- PaletteConfigurationUtils.createDrawer(paletteConfiguration);
- } else {
- Activator.log.error("Impossible to find the palette configuration", null);
- }
-
- setPageComplete(validatePage());
- }
- };
- }
-
- /**
- * Creates the listener for the new stack tool item
- *
- * @return the listener created
- */
- protected Listener createNewStackListener() {
- return new Listener() {
-
- /**
- * {@inheritDoc}
- */
- public void handleEvent(Event event) {
- Configuration selectedConfiguration = getSelectedConfiguration();
- if (selectedConfiguration instanceof DrawerConfiguration) {
- PaletteConfigurationUtils.createStack(((DrawerConfiguration) selectedConfiguration));
- } else if (selectedConfiguration instanceof LeafConfiguration) {
- PaletteConfigurationUtils.createStack(((LeafConfiguration) selectedConfiguration));
- } else {
- Activator.log.error("Invalid selection to create a Stack: " + selectedConfiguration, null);
- }
-
- // paletteTreeViewer.refresh();
- setPageComplete(validatePage());
- }
- };
- }
-
- /**
- * Generates the ID for a local element
- *
- * @param base
- * the begining of the id
- * @return the separator id
- */
- protected String generateID(String base) {
- StringBuffer id = new StringBuffer();
- id.append(base);
- id.append("_");
- id.append(System.currentTimeMillis());
-
- return id.toString();
- }
-
- /**
- * Creates the listener for the new separator tool item
- *
- * @return the listener created
- */
- protected Listener createNewSeparatorListener() {
- return new Listener() {
-
- /**
- * {@inheritDoc}
- */
- public void handleEvent(Event event) {
- Configuration selectedConfiguration = getSelectedConfiguration();
- if (selectedConfiguration instanceof DrawerConfiguration) {
- PaletteConfigurationUtils.createSeparator(((DrawerConfiguration) selectedConfiguration));
- } else if (selectedConfiguration instanceof LeafConfiguration) {
- PaletteConfigurationUtils.createSeparator(((LeafConfiguration) selectedConfiguration));
- } else {
- Activator.log.error("Invalid selection to create a separator: " + selectedConfiguration, null);
- }
-
- setPageComplete(validatePage());
- }
- };
- }
-
- /**
- * Returns the current selected configuration
- *
- * @return the current selected configuration or <code>null</code> if the element is not translatable into a {@link Configuration}
- */
- protected Configuration getSelectedConfiguration() {
- // retrieve selection
- if (paletteTreeViewer != null && !paletteTreeViewer.getControl().isDisposed()) {
- // retrieve selection. first element should be a drawer
- IStructuredSelection selection = (IStructuredSelection) paletteTreeViewer.getSelection();
- if (selection == null) {
- return null;
- } else {
- Object object = selection.getFirstElement();
- if (object instanceof IAdaptable) {
- EObject eobject = EMFHelper.getEObject(object);
- if (eobject instanceof Configuration) {
- return (Configuration) eobject;
- }
- }
- }
- }
- return null;
- }
-
- /**
- * Creates a toolbar item.
- *
- * @param toolbar
- * the parent toolbar
- * @param itemIcon
- * path for icon
- * @param tooltip
- * tooltip text for the toolbar item
- * @param listener
- * listener for tool bar item
- */
- protected void createToolBarItem(ToolBar toolbar, String itemIcon, String tooltip, Listener listener, ToolBarItemValidator validator) {
- ToolItem item = new ToolItem(toolbar, SWT.BORDER);
- item.setImage(Activator.getPluginIconImage(Activator.ID, itemIcon));
- item.setToolTipText(tooltip);
- item.addListener(SWT.Selection, listener);
- item.setData(VALIDATOR, validator);
- }
-
- /**
- * creates the buttons to add/remove entries
- */
- protected void createAddRemoveButtons() {
- Composite composite = new Composite((Composite) getControl(), SWT.NONE);
- GridLayout layout = new GridLayout(1, true);
- composite.setLayout(layout);
-
- GridData data = new GridData(SWT.CENTER, SWT.CENTER, false, true);
- composite.setLayoutData(data);
-
- addButton = new Button(composite, SWT.NONE);
- addButton.setImage(Activator.getPluginIconImage(Activator.ID, ADD_ICON));
- addButton.setToolTipText(Messages.PapyrusPaletteCustomizerDialog_AddButtonTooltip);
- addButton.addMouseListener(createAddButtonListener());
- addButton.setEnabled(false);
- addButton.addListener(SWT.MouseUp, this);
-
- removeButton = new Button(composite, SWT.NONE);
- removeButton.setImage(Activator.getPluginIconImage(Activator.ID, REMOVE_ICON));
- removeButton.setToolTipText(Messages.PapyrusPaletteCustomizerDialog_RemoveButtonTooltip);
- removeButton.addMouseListener(createRemoveButtonListener());
- removeButton.setEnabled(false);
- removeButton.addListener(SWT.MouseUp, this);
- }
-
- /**
- * selection listener for the tools viewer , to update the state of the add button
- *
- * @return the new created selection listener
- */
- protected ISelectionChangedListener createToolsViewerSelectionChangeListener() {
- return new ISelectionChangedListener() {
-
- /**
- * {@inheritDoc}
- */
- public void selectionChanged(SelectionChangedEvent event) {
-
- // get source and target selection
- // check source entry can be added to target entry
- Object source = ((IStructuredSelection) availableToolsViewer.getSelection()).getFirstElement();
- Object target = ((IStructuredSelection) paletteTreeViewer.getSelection()).getFirstElement();
-
- // manage add button
- if (isAddValidTarget(source, target)) {
- addButton.setEnabled(true);
- } else {
- addButton.setEnabled(false);
- }
-
- // manage remove button
- if (isRemoveValidSource(target)) {
- removeButton.setEnabled(true);
- } else {
- removeButton.setEnabled(false);
- }
-
- }
-
- /**
- * Returns true if the source can be added to the target
- *
- * @param source
- * the source object
- * @param target
- * the target object
- * @return <code>true</code> if the source can be added to the target
- */
- protected boolean isAddValidTarget(Object source, Object target) {
- if (!(source instanceof PaletteEntry)) {
- return false;
- }
-
- // case1: source is a drawer.
- // it can only be added to the root element (no selection)
- // case2: source is a palette tool
- // it can't be added to the root element
- // it can only be added to a container element (drawer or stack)
- if (source instanceof PaletteDrawer) {
- if (target == null) {
- return true;
- }
- return false;
- } else if (source instanceof ToolEntry) {
- if (target instanceof PaletteEntryProxy) {
- // EntryType type = ((PaletteEntryProxy)target).getType();
- // switch(type) {
- // case DRAWER:
- // case STACK:
- // return true;
- // default:
- // return false;
- // }
- }
- return false;
- }
- return false;
- }
-
- /**
- * Returns true if the source can be added to the target
- *
- * @param source
- * the source object
- * @return <code>true</code> if the source can be removed (not null and instanceof
- * PaletteEntryProxy)
- */
- protected boolean isRemoveValidSource(Object source) {
- if (source instanceof PaletteEntryProxy) {
- return true;
- }
- return false;
- }
- };
-
- }
-
- /**
- * Creates the add button listener
- */
- protected MouseListener createAddButtonListener() {
- return new MouseListener() {
-
- public void mouseUp(MouseEvent e) {
- // // add the element selected on the left to the right tree
- // // check the selection.
- // IStructuredSelection selection = (IStructuredSelection)availableToolsViewer.getSelection();
- // if(selection == null || selection.size() < 1) {
- // return;
- // }
- // PaletteEntry entry = (PaletteEntry)selection.getFirstElement();
- // if(entry == null) {
- // return;
- // }
- //
- // // find the selection on the right
- // selection = (IStructuredSelection)paletteTreeViewer.getSelection();
- //
- // PaletteEntryProxy parentNode = (PaletteEntryProxy)selection.getFirstElement();
- // // Bugfix: only drawers can be added to root element
- // if(parentNode == null && entry instanceof PaletteDrawer) {
- // parentNode = (PaletteContainerProxy)paletteTreeViewer.getInput();
- // }
- //
- // // check we have a containe here
- // if(!(parentNode instanceof PaletteContainerProxy)) {
- // return;
- // }
- //
- // // create a new entry in the document
- // PaletteEntryProxy proxy = createNodeFromEntry(entry);
- // ((PaletteContainerProxy)parentNode).addChild(proxy);
- //
- // paletteTreeViewer.expandToLevel(parentNode, 1);
- }
-
- /**
- * {@inheritDoc}
- */
- public void mouseDown(MouseEvent e) {
- // do nothing
- }
-
- /**
- * {@inheritDoc}
- */
- public void mouseDoubleClick(MouseEvent e) {
- // do nothing
- }
- };
- }
-
- // /**
- // * Creates a node in the xml document from the given entry
- // *
- // * @param entry
- // * the palette entry from which to create the node
- // * @param parentNode
- // * the parent node for the newly created node
- // * @return the created entry proxy or <code>null</code>
- // */
- // protected PaletteEntryProxy createNodeFromEntry(Object entry) {
- // PaletteEntryProxy entryProxy = null;
- //
- // if(entry instanceof AspectCreationEntry) {
- // // should modify id of the element here, otherwise, different elements would have the same id...
- // entryProxy = new PaletteAspectToolEntryProxy(((AspectCreationEntry)entry).clone());
- // } else if(entry instanceof CombinedTemplateCreationEntry) {
- // CombinedTemplateCreationEntry originalEntry = (CombinedTemplateCreationEntry)entry;
- // // create a new Aspect entry proxy
- // AspectCreationEntry aspectEntry = new AspectCreationEntry(originalEntry.getLabel(), originalEntry.getDescription(), originalEntry.getId() + "_" + System.currentTimeMillis(), originalEntry.getSmallIcon(), originalEntry, new HashMap<Object, Object>());
- // entryProxy = new PaletteAspectToolEntryProxy(aspectEntry);
- // } else if(entry instanceof PaletteContainer) {
- // entryProxy = new PaletteContainerProxy((PaletteContainer)entry);
- // } else if(entry instanceof PaletteEntryProxy) {
- // entryProxy = ((PaletteEntryProxy)entry);
- // }
- // return entryProxy;
- // }
-
- /**
- * Creates the add button listener
- */
- protected MouseListener createRemoveButtonListener() {
- return new MouseListener() {
-
- public void mouseUp(MouseEvent e) {
- // remove the element selected on the right
- // add the element selected on the left to the right tree
- // check the selection.
- IStructuredSelection selection = (IStructuredSelection) paletteTreeViewer.getSelection();
- if (selection == null || selection.size() < 1) {
- return;
- }
- PaletteEntryProxy proxyToDelete = (PaletteEntryProxy) selection.getFirstElement();
- if (proxyToDelete == null) {
- return;
- }
-
- // create a new entry in the document
- // get container of the proxy to be deleted
- PaletteContainerProxy parentProxy = proxyToDelete.getParent();
- parentProxy.removeChild(proxyToDelete);
- }
-
- /**
- * {@inheritDoc}
- */
- public void mouseDown(MouseEvent e) {
- // do nothing
- }
-
- /**
- * {@inheritDoc}
- */
- public void mouseDoubleClick(MouseEvent e) {
- // do nothing
- }
- };
- }
-
- /**
- * creates the available entries group
- */
- protected void createAvailableToolsGroup() {
- Composite parent = (Composite) getControl();
- Composite availableToolsComposite = new Composite(parent, SWT.NONE);
- GridLayout layout = new GridLayout(2, true);
- layout.marginHeight = 0;
- layout.marginWidth = 0;
- availableToolsComposite.setLayout(layout);
- GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
- availableToolsComposite.setLayoutData(data);
-
- Label label = new Label(availableToolsComposite, SWT.NONE);
- label.setText(Messages.Local_Palette_Available_Tools);
- data = new GridData(SWT.LEFT, SWT.CENTER, true, false);
- label.setLayoutData(data);
-
- ToolBar toolbar = new ToolBar(availableToolsComposite, SWT.HORIZONTAL);
- data = new GridData(SWT.RIGHT, SWT.FILL, false, false);
- toolbar.setLayoutData(data);
- populateAvailableToolsToolBar(toolbar);
-
- createProfileCombo(availableToolsComposite);
-
- Tree tree = new Tree(availableToolsComposite, SWT.SINGLE | SWT.BORDER);
- data = new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1);
- data.widthHint = 185;
- // Make the tree this tall even when there is nothing in it. This will keep the
- // dialog from shrinking to an unusually small size.
- data.heightHint = 200;
- tree.setLayoutData(data);
- availableToolsViewer = new TreeViewer(tree);
- availableToolsViewer.setContentProvider(new UMLToolsTreeContentProvider());
- paletteLabelProvider = new PaletteLabelProvider();
- availableToolsViewer.setLabelProvider(paletteLabelProvider);
- ViewerComparator labelComparator = new LabelViewerComparator();
- availableToolsViewer.setComparator(labelComparator);
- // remove the note stack and standard group
- availableToolsViewer.addFilter(new ViewerFilter() {
-
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean select(Viewer viewer, Object parentElement, Object element) {
- if (element instanceof PaletteStack && "noteStack".equals(((PaletteStack) element).getId())) {
- return false;
- } else if (element instanceof PaletteToolbar && "standardGroup".equals(((PaletteToolbar) element).getId())) {
- return false;
- }
- return true;
- }
- });
- availableToolsViewer.addFilter(new DrawerFilter());
- // add drag support
- addAvailableToolsDragSupport();
- // availableToolsViewer.setInput(getAllVisibleStandardEntries());
- }
-
- /**
- * Creates the profile combo
- *
- * @param availableToolsComposite
- * the available tools composite
- * @return the created combo
- */
- protected Combo createProfileCombo(Composite availableToolsComposite) {
- // retrieve top package, to know which profiles are available
- // creates the combo
- profileCombo = new Combo(availableToolsComposite, SWT.BORDER | SWT.READ_ONLY);
- GridData data = new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1);
- profileCombo.setLayoutData(data);
-
- // retrieve all applied profiles
- List<Profile> profiles = getAllAppliedProfiles();
-
- int profileNumber = profiles.size();
- for (int i = 0; i < profileNumber; i++) {
- profileComboList.add(i, profiles.get(i).getName());
- }
- profileComboList.add(UML_TOOLS_LABEL);
- profileCombo.setItems(profileComboList.toArray(new String[] {}));
-
- // add selection listener for the combo. selects the "UML tools" item
- ProfileComboSelectionListener listener = new ProfileComboSelectionListener();
- profileCombo.addSelectionListener(listener);
- profileCombo.addModifyListener(listener);
- // profileCombo.select(profileNumber);
-
- return profileCombo;
- }
-
- /**
- * returns the list of applied profile for the nearest package of the top element
- *
- * @return the list of applied profile for the nearest package of the top element or an empty
- * list
- */
- protected List<Profile> getAllAppliedProfiles() {
- Package topPackage = null;
- if (editorPart instanceof DiagramEditorWithFlyOutPalette) {
- EObject element = ((DiagramEditorWithFlyOutPalette) editorPart).getDiagram().getElement();
- if (element instanceof org.eclipse.uml2.uml.Element) {
- topPackage = ((org.eclipse.uml2.uml.Element) element).getNearestPackage();
- }
- }
- if (topPackage != null) {
- return topPackage.getAllAppliedProfiles();
- }
- return Collections.emptyList();
- }
-
- /**
- * Add drag support from the available tools viewer
- */
- protected void addAvailableToolsDragSupport() {
- // transfer types
- Transfer[] transfers = new Transfer[] { LocalSelectionTransfer.getTransfer() };
-
- // drag listener
- DragSourceListener listener = new DragSourceAdapter() {
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void dragStart(DragSourceEvent event) {
- super.dragStart(event);
- event.data = availableToolsViewer.getSelection();
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void dragSetData(DragSourceEvent event) {
- super.dragSetData(event);
- LocalSelectionTransfer.getTransfer().setSelection(availableToolsViewer.getSelection());
- }
-
- };
-
- availableToolsViewer.addDragSupport(DND.DROP_LINK, transfers, listener);
- }
-
- /**
- * Adds elements to the tool bar for available tools viewer
- *
- * @param toolbar
- * the toolbar to populate
- */
- protected void populateAvailableToolsToolBar(ToolBar toolbar) {
- toggleContentProvider = createCheckToolBarItem(toolbar, SWITCH_CONTENT_PROVIDER_ICON, Messages.Local_Palette_SwitchToolsContentProvider_Tooltip, createSwitchToolsContentProviderListener());
- toggleContentProvider.setSelection(true);
- toggleContentProvider.setEnabled(false);
- createCheckToolBarItem(toolbar, SHOWN_TOOLS_ICON, Messages.Local_Palette_ShowTools_Tooltip, createsShowToolListener());
- }
-
- /**
- * Creates the listener for the available tools content provider
- *
- * @return the listener created
- */
- protected Listener createSwitchToolsContentProviderListener() {
- return new Listener() {
-
- /**
- * {@inheritDoc}
- */
- public void handleEvent(Event event) {
- if (!(event.widget instanceof ToolItem)) {
- return;
- }
- ToolItem item = ((ToolItem) event.widget);
- // retrieve current profile selected in the combo profile
- int index = profileCombo.getSelectionIndex();
- Collection<PaletteEntry> standardEntries = getAllVisibleStandardEntries();
- Profile profile = getAllAppliedProfiles().get(index);
-
- if (item.getSelection()) {
- availableToolsViewer.setContentProvider(new ProfileToolsStereotypeMetaclassTreeContentProvider(profile, standardEntries));
- item.setSelection(true);
- } else {
-
- availableToolsViewer.setContentProvider(new ProfileToolsMetaclassStereotypeTreeContentProvider(profile, standardEntries));
- item.setSelection(false);
- }
-
- // generate tools for given profile
- availableToolsViewer.setInput(profile);
- }
- };
- }
-
- /**
- * creates the tool item for drawers visibility listener
- *
- * @return the listener for the tool button
- */
- protected Listener createShowDrawerListener() {
- return new Listener() {
-
- /**
- * {@inheritDoc}
- */
- public void handleEvent(Event event) {
- if (!(event.widget instanceof ToolItem)) {
- return;
- }
- ToolItem item = ((ToolItem) event.widget);
- if (item.getSelection()) {
- // elements should be hidden
- availableToolsViewer.addFilter(drawerFilter);
- item.setSelection(true);
- } else {
- availableToolsViewer.removeFilter(drawerFilter);
- item.setSelection(false);
- }
- }
- };
- }
-
- /**
- * creates the tool item for tools visibility listener
- *
- * @return the listener for the tool button
- */
- protected Listener createsShowToolListener() {
- return new Listener() {
-
- /**
- * {@inheritDoc}
- */
- public void handleEvent(Event event) {
- if (!(event.widget instanceof ToolItem)) {
- return;
- }
- ToolItem item = ((ToolItem) event.widget);
- if (item.getSelection()) {
- // elements should be hidden
- availableToolsViewer.addFilter(toolFilter);
- item.setSelection(true);
- } else {
- availableToolsViewer.removeFilter(toolFilter);
- item.setSelection(false);
- }
- }
- };
- }
-
- /**
- * Creates a toolbar item which can be checked.
- *
- * @param toolbar
- * the parent toolbar
- * @param shownElementsIcon
- * path for shown elements icon
- * @param listener
- * listener for button action
- * @param tooltip
- * tooltip text for the toolbar item
- */
- protected ToolItem createCheckToolBarItem(ToolBar toolbar, String shownElementsIcon, String tooltip, Listener listener) {
- ToolItem item = new ToolItem(toolbar, SWT.CHECK | SWT.BORDER);
- item.setImage(Activator.getPluginIconImage(Activator.ID, shownElementsIcon));
- item.setToolTipText(tooltip);
- item.addListener(SWT.Selection, listener);
- return item;
- }
-
- /**
- * Validates the content of the fields in this page
- */
- protected boolean validatePage() {
- boolean valid = true;
-
- if (valid) {
- setMessage(null);
- setErrorMessage(null);
- }
- return valid;
- }
-
- /**
- * The <code>WizardNewFileCreationPage</code> implementation of this <code>Listener</code> method handles all events and enablements for controls
- * on this page. Subclasses may extend.
- */
- public void handleEvent(Event event) {
- setPageComplete(validatePage());
- }
-
- /**
- * Content provider for available tools viewer
- */
- public class UMLToolsTreeContentProvider implements ITreeContentProvider {
-
- /**
- * Constructor
- *
- * @param viewer
- * The viewer whose ContentProvider this content provider is
- */
- public UMLToolsTreeContentProvider() {
- }
-
- /**
- * {@inheritDoc}
- */
- public Object[] getElements(Object inputElement) {
- Object[] elements = null;
-
- if (inputElement instanceof Collection<?>) {
- elements = ((Collection<?>) inputElement).toArray();
- } else if (inputElement instanceof PaletteRoot) {
- // paletteUil.getAllEntries(...) to add drawers
- // if so, uncomment the addFilterbutton for drawers in populate tool bar
- elements = PaletteUtil.getAllToolEntries(((PaletteRoot) inputElement)).toArray();
- }
-
- if (elements == null) {
- elements = new Object[0];
- }
- return elements;
- }
-
- /**
- * {@inheritDoc}
- */
- public void dispose() {
- }
-
- /**
- * {@inheritDoc}
- */
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
-
- }
-
- /**
- * {@inheritDoc}
- */
- public Object[] getChildren(Object parentElement) {
- Object[] elements = null;
-
- if (parentElement instanceof Collection<?>) {
- elements = ((Collection<?>) parentElement).toArray();
- } else if (parentElement instanceof PaletteRoot) {
- // paletteUil.getAllEntries(...) to add drawers
- // if so, uncomment the addFilterbutton for drawers in populate tool bar
- elements = PaletteUtil.getAllToolEntries(((PaletteRoot) parentElement)).toArray();
- }
-
- return elements;
- }
-
- /**
- * {@inheritDoc}
- */
- public Object getParent(Object element) {
- return null;
- }
-
- /**
- * {@inheritDoc}
- */
- public boolean hasChildren(Object element) {
- return getChildren(element) != null && getChildren(element).length > 0;
- }
- }
-
- /**
- * Label provider for palette tools.
- * <P>
- * We should be using the Palette label provider from GEF, if it was not with visibility "package"...
- *
- * @see org.eclipse.gef.ui.palette.customize.PaletteLabelProvider </P>
- *
- */
- public class PaletteLabelProvider implements ILabelProvider {
-
- /**
- * {@inheritDoc}
- */
- public Image getImage(Object element) {
- if (element instanceof PaletteEntry) {
- ImageDescriptor descriptor = ((PaletteEntry) element).getSmallIcon();
- if (descriptor == null) {
- return null;
- }
- return Activator.getPluginIconImage(Activator.ID, descriptor);
- } else if (element instanceof Stereotype) {
- return Activator.getPluginIconImage(Activator.ID, "/icons/stereotype.gif");
- }
- return null;
- }
-
- /**
- * {@inheritDoc}
- */
- public String getText(Object element) {
- if (element instanceof PaletteEntry) {
- return ((PaletteEntry) element).getLabel();
- } else if (element instanceof Stereotype) {
- return ((Stereotype) element).getName();
- }
- return "unknown element";
- }
-
- /**
- * {@inheritDoc}
- */
- public void addListener(ILabelProviderListener listener) {
-
- }
-
- /**
- * {@inheritDoc}
- */
- public void dispose() {
-
- }
-
- /**
- * {@inheritDoc}
- */
- public boolean isLabelProperty(Object element, String property) {
- return false;
- }
-
- /**
- * {@inheritDoc}
- */
- public void removeListener(ILabelProviderListener listener) {
-
- }
-
- }
-
- /**
- * Label provider for palette tools.
- * <P>
- * We should be using the Palette label provider from GEF, if it was not with visibility "package"...
- *
- * @see org.eclipse.gef.ui.palette.customize.PaletteLabelProvider </P>
- *
- */
- public class ExtendedPaletteLabelProvider extends CustomizedLabelProvider {
-
- /**
- * Constructor.
- */
- public ExtendedPaletteLabelProvider() {
- super(manager);
- }
- }
-
- /**
- * Filter for the viewer. Hide/show Drawers
- */
- public class DrawerFilter extends ViewerFilter {
-
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean select(Viewer viewer, Object parentElement, Object element) {
- if (element instanceof PaletteDrawer) {
- return false;
- }
- return true;
- }
-
- }
-
- /**
- * Filter for the viewer. Hide/show Drawers
- */
- public class ToolFilter extends ViewerFilter {
-
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean select(Viewer viewer, Object parentElement, Object element) {
- if (element instanceof ToolEntry) {
- return false;
- }
- return true;
- }
-
- }
-
- /**
- * Content Provider for the palette preview
- */
- public class ExtendedPaletteContentProvider extends CustomizedTreeContentProvider {
-
- private CustomizationCatalogManager catalogManager;
- private ResourceSet catalogManagerResourceSet;
-
- /**
- * Constructor.
- */
- public ExtendedPaletteContentProvider() {
- super(manager);
- // TODO: EMFFACET refactor this code
- catalogManagerResourceSet = new ResourceSetImpl();
- catalogManager = (CustomizationCatalogManager) ICustomizationCatalogManagerFactory.DEFAULT.getOrCreateCustomizationCatalogManager(catalogManagerResourceSet);
- List<Customization> paletteCustomizations = catalogManager.getCustomizationsByName("PaletteConfiguration");
- if (paletteCustomizations.size() > 0) {
- // manager.setShowTypeOfLinks(false);
- // manager.registerCustomization(paletteCustomization);
- // manager.loadCustomizations();
- }
- }
-
- @Override
- public void dispose() {
- super.dispose();
-
- if (catalogManagerResourceSet != null) {
- EMFHelper.unload(catalogManagerResourceSet);
- catalogManagerResourceSet = null;
- }
-
- catalogManager = null;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public Object[] getRootElements(Object inputElement) {
- if (inputElement instanceof PaletteConfiguration) {
- return ((PaletteConfiguration) inputElement).getDrawerConfigurations().toArray();
- } else if (inputElement instanceof Resource) {
- List<EObject> roots = ((Resource) inputElement).getContents();
- if (roots != null && !roots.isEmpty()) {
- EObject rootObject = roots.get(0);
- if (rootObject instanceof PaletteConfiguration) {
- return ((PaletteConfiguration) rootObject).getDrawerConfigurations().toArray();
- }
- }
- }
- return new Object[0];
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean hasChildren(Object element) {
- Object[] children = getChildren(element);
- if (children == null) {
- return false;
- }
- if (children.length == 0) {
- return false;
- }
- return true;
- }
- }
-
-
- /**
- * Performs all action on finish
- *
- * @param id
- * the path for the file
- */
- public void performFinish(String path) {
- if (resourceToEdit != null) {
- try {
- resourceToEdit.save(Collections.emptyMap());
- } catch (IOException e) {
- Activator.log.error(e);
- }
- }
-
- // // creates the document
- // Document document = createXMLDocumentFromPalettePreview();
- // saveDocument(document, path);
- // requiredProfiles = collectRequiredProfiles();
- }
-
- // /**
- // * collect the required profiles from all tool provided by the local palette definition
- // */
- // protected Set<String> collectRequiredProfiles() {
- // Set<String> profiles = new HashSet<String>();
- // PaletteContainerProxy rootProxy = (PaletteContainerProxy)paletteTreeViewer.getInput();
- // collectRequiredProfiles(rootProxy.getChildren(), profiles);
- // return profiles;
- // }
- //
- // /**
- // * collect the required profiles from all tool provided by the local palette definition
- // */
- // protected void collectRequiredProfiles(List<PaletteEntryProxy> proxies, Set<String> requiredProfiles) {
- // for(PaletteEntryProxy proxy : proxies) {
- // // add profile(s) if relevant, check for children
- //
- // if(proxy instanceof PaletteAspectToolEntryProxy) {
- // // list of profiles
- // for(String stereotypeQN : ((PaletteAspectToolEntryProxy)proxy).getStereotypesQNList()) {
- // // retrieve list of profiles from the stereotype QN (only remove last segment
- // // ?!)
- // String profileName = PaletteUtil.findProfileNameFromStereotypeName(stereotypeQN);
- // requiredProfiles.add(profileName);
- // }
- // }
- //
- // if(proxy.getChildren() != null) {
- // collectRequiredProfiles(proxy.getChildren(), requiredProfiles);
- // }
- // }
- // }
- //
- // /**
- // * Saves the xml document into file
- // *
- // * @param document
- // * the document to save
- // * @param path
- // * name of the file
- // * @return the file created or updated
- // */
- // protected File saveDocument(Document document, String path) {
- // File file = null;
- // try {
- // // create the file that stores the XML configuration
- // file = Activator.getDefault().getStateLocation().append(path).toFile();
- // TransformerFactory tranFactory = TransformerFactory.newInstance();
- // Transformer aTransformer;
- //
- // aTransformer = tranFactory.newTransformer();
- //
- // Source src = new DOMSource(document);
- // Result dest = new StreamResult(file);
- // aTransformer.transform(src, dest);
- // } catch (TransformerConfigurationException e) {
- // Activator.log.error(e);
- // } catch (TransformerException e) {
- // Activator.log.error(e);
- // }
- // return file;
- //
- // }
- //
- // /**
- // * Creates the document from the palette preview
- // *
- // * @return the dom structure of the document
- // */
- // protected Document createXMLDocumentFromPalettePreview() {
- // DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
- // documentBuilderFactory.setNamespaceAware(true);
- // DocumentBuilder documentBuilder;
- // try {
- // documentBuilder = documentBuilderFactory.newDocumentBuilder();
- // document = documentBuilder.newDocument();
- // Element paletteDefElement = document.createElement(IPapyrusPaletteConstant.PALETTE_DEFINITION);
- // document.appendChild(paletteDefElement);
- // Element contentElement = document.createElement(IPapyrusPaletteConstant.CONTENT);
- // paletteDefElement.appendChild(contentElement);
- //
- // generateXMLPaletteContent(document, contentElement);
- // return document;
- // } catch (ParserConfigurationException e) {
- // Activator.getDefault().logError("impossible to create the palette tree viewer content", e);
- // }
- // return null;
- // }
- //
- // /**
- // * Generates the xml content for the palette
- // *
- // * @param document
- // * the document to fill
- // * @param contentElement
- // * the root for the xml content
- // */
- // protected void generateXMLPaletteContent(Document document, Element contentElement) {
- // PaletteContainerProxy rootProxy = (PaletteContainerProxy)paletteTreeViewer.getInput();
- // for(PaletteEntryProxy proxy : rootProxy.getChildren()) {
- // generateXMLPaletteContainerProxy(document, contentElement, proxy);
- // }
- // }
- //
- // /**
- // * Generates the xml content for the given container
- // *
- // * @param document
- // * the document to fill
- // * @param containerProxy
- // * the entry proxy
- // */
- // protected void generateXMLPaletteContainerProxy(Document document, Element contentElement, PaletteEntryProxy containerProxy) {
- //
- // Element element = null;
- // List<PaletteEntryProxy> children = containerProxy.getChildren();
- // // generate the element
- // switch(containerProxy.getType()) {
- // case DRAWER:
- // element = document.createElement(IPapyrusPaletteConstant.DRAWER);
- // element.setAttribute(IPapyrusPaletteConstant.NAME, containerProxy.getLabel());
- // if(containerProxy instanceof PaletteLocalDrawerProxy) {
- // element.setAttribute(IPapyrusPaletteConstant.ICON_PATH, ((PaletteLocalDrawerProxy)containerProxy).getImagePath());
- // }
- // break;
- // case TOOL:
- // element = document.createElement(IPapyrusPaletteConstant.TOOL);
- // break;
- // case SEPARATOR:
- // element = document.createElement(IPapyrusPaletteConstant.SEPARATOR);
- // break;
- // case STACK:
- // element = document.createElement(IPapyrusPaletteConstant.STACK);
- // break;
- // case ASPECT_TOOL:
- // element = document.createElement(IPapyrusPaletteConstant.ASPECT_TOOL);
- // // try to cast the element into PaletteAspectToolEntryProxy
- // if(containerProxy instanceof PaletteAspectToolEntryProxy) {
- // PaletteAspectToolEntryProxy aspectEntryProxy = (PaletteAspectToolEntryProxy)containerProxy;
- // // element.setAttribute(IPapyrusPaletteConstant.ID, aspectEntryProxy.getId());
- // element.setAttribute(IPapyrusPaletteConstant.NAME, aspectEntryProxy.getLabel());
- // element.setAttribute(IPapyrusPaletteConstant.DESCRIPTION, aspectEntryProxy.getEntry().getDescription());
- // element.setAttribute(IPapyrusPaletteConstant.REF_TOOL_ID, aspectEntryProxy.getReferencedPaletteID());
- //
- // if(aspectEntryProxy.getImagePath() != null && !aspectEntryProxy.getImagePath().equals("")) {
- // element.setAttribute(IPapyrusPaletteConstant.ICON_PATH, aspectEntryProxy.getImagePath());
- // }
- //
- //
- // // add post action, stereotype list
- // for(IAspectAction action : ((PaletteAspectToolEntryProxy)containerProxy).getPostActions()) {
- // Element postActionNode = document.createElement(IPapyrusPaletteConstant.POST_ACTION);
- // postActionNode.setAttribute(IPapyrusPaletteConstant.ID, action.getFactoryId());
- // action.save(postActionNode);
- // element.appendChild(postActionNode);
- // }
- // }
- // default:
- // break;
- // }
- //
- // element.setAttribute(IPapyrusPaletteConstant.ID, containerProxy.getId());
- // contentElement.appendChild(element);
- //
- // if(children != null) {
- // for(PaletteEntryProxy proxy : children) {
- // generateXMLPaletteContainerProxy(document, element, proxy);
- // }
- // }
- // }
-
- // public enum EntryType {
- // DRAWER, TOOL, STACK, SEPARATOR, ASPECT_TOOL
- // }
-
-
- /**
- * Comparator for the label viewers
- */
- public class LabelViewerComparator extends ViewerComparator {
-
- /**
- * Creates a new LabelViewerComparator.
- */
- public LabelViewerComparator() {
- super();
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public int compare(Viewer testViewer, Object e1, Object e2) {
- String label1 = "";
- String label2 = "";
-
- if (e1 instanceof PaletteEntry) {
- label1 = ((PaletteEntry) e1).getLabel();
- } else if (e1 instanceof Stereotype) {
- label1 = ((Stereotype) e1).getName();
- }
- if (e2 instanceof PaletteEntry) {
- label2 = ((PaletteEntry) e2).getLabel();
- } else if (e2 instanceof Stereotype) {
- label2 = ((Stereotype) e2).getName();
- }
-
- if (label1 == null) {
- return 1;
- }
- if (label2 == null) {
- return -1;
- }
-
- return label1.compareTo(label2);
- }
- }
-
- /**
- * Listener for the profile combo. It changes the input of the following viewer.
- */
- public class ProfileComboSelectionListener implements SelectionListener, ModifyListener {
-
- /**
- * {@inheritDoc}
- */
- public void widgetDefaultSelected(SelectionEvent e) {
- // nothing to do
- }
-
- /**
- * {@inheritDoc}
- */
- public void widgetSelected(SelectionEvent e) {
- handleSelectionChanged();
- }
-
- /**
- * {@inheritDoc}
- */
- public void modifyText(ModifyEvent e) {
- handleSelectionChanged();
- }
-
- /**
- * handles the change selection for the combo
- */
- protected void handleSelectionChanged() {
- int index = profileCombo.getSelectionIndex();
- if (index < 0 || index >= profileCombo.getItems().length) {
- return;
- }
- String name = profileComboList.get(index);
-
- Collection<PaletteEntry> standardEntries = getAllVisibleStandardEntries();
- // retrieve the profile or uml standards tools to display
- if (UML_TOOLS_LABEL.equals(name)) {
- // change content provider
- availableToolsViewer.setContentProvider(new UMLToolsTreeContentProvider());
- availableToolsViewer.setInput(standardEntries);
- toggleContentProvider.setEnabled(false);
- } else {
- if (toggleContentProvider != null && !toggleContentProvider.isDisposed()) {
- toggleContentProvider.setEnabled(true);
- }
- // switch content provider
- // this is a profile in case of uml2 tools
- Profile profile = getAllAppliedProfiles().get(index);
- if (toggleContentProvider.getSelection()) {
- availableToolsViewer.setContentProvider(new ProfileToolsStereotypeMetaclassTreeContentProvider(profile, standardEntries));
- } else {
- availableToolsViewer.setContentProvider(new ProfileToolsMetaclassStereotypeTreeContentProvider(profile, standardEntries));
- }
-
- // generate tools for given profile
- availableToolsViewer.setInput(profile);
- }
- }
- }
-
- /**
- * Content provider for the available tools viewer, when the tools to see are coming from a
- * profile
- */
- public class ProfileToolsStereotypeMetaclassTreeContentProvider implements ITreeContentProvider {
-
- /** standard uml tools palette entries */
- final protected Collection<PaletteEntry> standardEntries;
-
- /**
- * Creates a new ProfileToolsStereotypeMetaclassTreeContentProvider.
- *
- * @param profile
- * the profile for which tools are built
- * @param standardEntries
- * list of standard uml tools palette entries
- */
- public ProfileToolsStereotypeMetaclassTreeContentProvider(Profile profile, Collection<PaletteEntry> standardEntries) {
- this.standardEntries = standardEntries;
- }
-
- /**
- * {@inheritDoc}
- */
- public Object[] getChildren(Object parentElement) {
- if (parentElement instanceof Profile) {
- return ((Profile) parentElement).getOwnedStereotypes().toArray();
- } else if (parentElement instanceof Stereotype) {
- List<PaletteEntry> entries = new ArrayList<PaletteEntry>();
- Stereotype stereotype = (Stereotype) parentElement;
-
- for (PaletteEntry entry : standardEntries) {
- // retrieve the element type created by the tool.
- if (entry instanceof CombinedTemplateCreationEntry) {
-
- EClass toolMetaclass = PaletteUtil.getToolMetaclass((CombinedTemplateCreationEntry) entry);
- if (toolMetaclass != null) {
- List<Class> metaclasses = stereotype.getAllExtendedMetaclasses();
- for (Class stMetaclass : metaclasses) {
- // get Eclass
- java.lang.Class<?> metaclassClass = stMetaclass.getClass();
- if (metaclassClass != null) {
- EClassifier metaClassifier = UMLPackage.eINSTANCE.getEClassifier(stMetaclass.getName());
- if (((EClass) metaClassifier).isSuperTypeOf(toolMetaclass)) {
- // should create the palette entry
- Map<Object, Object> properties = new HashMap<Object, Object>();
- properties.put(IPapyrusPaletteConstant.ASPECT_ACTION_KEY, StereotypeAspectActionProvider.createConfigurationNode(stereotype.getQualifiedName()));
- AspectCreationEntry aspectEntry = new AspectCreationEntry(stereotype.getName() + " (" + entry.getLabel() + ")", "Create an element with a stereotype", entry.getId() + "_" + System.currentTimeMillis(),
- entry.getSmallIcon(), (CombinedTemplateCreationEntry) entry, properties);
- entries.add(aspectEntry);
- }
- }
-
- }
- }
- }
- }
- return entries.toArray();
- } else {
- return new Object[0];
- }
- }
-
- /**
- * {@inheritDoc}
- */
- public Object getParent(Object element) {
- if (element instanceof Stereotype) {
- return ((Stereotype) element).getProfile();
- }
- return null;
- }
-
- /**
- * {@inheritDoc}
- */
- public boolean hasChildren(Object element) {
- if (element instanceof Profile) {
- return true;
- } else if (element instanceof Stereotype) {
- return true;
- }
- return false;
- }
-
- /**
- * {@inheritDoc}
- */
- public Object[] getElements(Object inputElement) {
- if (inputElement instanceof Profile) {
- List<Stereotype> stereotypes = ((Profile) inputElement).getOwnedStereotypes();
- return stereotypes.toArray();
- }
- return new Object[0];
- }
-
- /**
- * {@inheritDoc}
- */
- public void dispose() {
- // nothing to do here
- }
-
- /**
- * {@inheritDoc}
- */
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
- // nothing to do here
- }
-
- }
-
- /**
- * Content provider for the available tools viewer, when the
- */
- public class ProfileToolsMetaclassStereotypeTreeContentProvider implements ITreeContentProvider {
-
- /** standard uml tools palette entries */
- final protected Collection<PaletteEntry> standardEntries;
-
- /** profile to display */
- final protected Profile profile;
-
- /**
- * Creates a new ProfileToolsMetaclassStereotypeTreeContentProvider.
- *
- * @param profile
- * the profile for which tools are built
- * @param standardEntries
- * list of standard uml tools palette entries
- */
- public ProfileToolsMetaclassStereotypeTreeContentProvider(Profile profile, Collection<PaletteEntry> standardEntries) {
- this.profile = profile;
- this.standardEntries = standardEntries;
- }
-
- /**
- * {@inheritDoc}
- */
- public Object[] getChildren(Object parentElement) {
- if (parentElement instanceof Profile) {
- return standardEntries.toArray();
- } else if (parentElement instanceof AspectCreationEntry) {
- return new Object[0];
- } else if (parentElement instanceof PaletteEntry) {
- List<AspectCreationEntry> entries = new ArrayList<AspectCreationEntry>();
- // display all stereotypes applicable to the type of element created by this tool
- if (parentElement instanceof CombinedTemplateCreationEntry) {
- CombinedTemplateCreationEntry entry = (CombinedTemplateCreationEntry) parentElement;
- EClass toolMetaclass = PaletteUtil.getToolMetaclass(entry);
- if (toolMetaclass != null) {
- for (Stereotype stereotype : profile.getOwnedStereotypes()) {
- List<Class> metaclasses = stereotype.getAllExtendedMetaclasses();
- for (Class stMetaclass : metaclasses) {
- // get Eclass
- EClassifier metaClassifier = UMLPackage.eINSTANCE.getEClassifier(stMetaclass.getName());
- if (((EClass) metaClassifier).isSuperTypeOf(toolMetaclass)) {
- // should create the palette entry
- Map<Object, Object> properties = new HashMap<Object, Object>();
- // ArrayList<String> stereotypesQNToApply = new ArrayList<String>();
- properties.put(IPapyrusPaletteConstant.ASPECT_ACTION_KEY, StereotypeAspectActionProvider.createConfigurationNode(stereotype.getQualifiedName()));
- AspectCreationEntry aspectEntry = new AspectCreationEntry(stereotype.getName() + " (" + entry.getLabel() + ")", "Create an element with a stereotype", entry.getId() + "_" + System.currentTimeMillis(), entry.getSmallIcon(),
- entry, properties);
- entries.add(aspectEntry);
- }
- }
- }
- }
- }
- return entries.toArray();
- } else {
- return new Object[0];
- }
- }
-
- /**
- * {@inheritDoc}
- */
- public Object getParent(Object element) {
- if (element instanceof Stereotype) {
- return ((Stereotype) element).getProfile();
- }
- return null;
- }
-
- /**
- * {@inheritDoc}
- */
- public boolean hasChildren(Object element) {
- if (element instanceof Profile) {
- return true;
- } else if (element instanceof AspectCreationEntry) {
- return false;
- } else if (element instanceof PaletteEntry) {
- return true;
- }
- return false;
- }
-
- /**
- * {@inheritDoc}
- */
- public Object[] getElements(Object inputElement) {
- if (inputElement instanceof Profile) {
- return standardEntries.toArray();
- }
- return new Object[0];
- }
-
- /**
- * {@inheritDoc}
- */
- public void dispose() {
- // nothing to do here
- }
-
- /**
- * {@inheritDoc}
- */
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
- // nothing to do here
- }
-
- }
-
- /**
- * Returns the list of all visible palette entries
- *
- * @return the list of all visible palette entries
- */
- protected Collection<PaletteEntry> getAllVisibleStandardEntries() {
- HashSet<PaletteEntry> result = new HashSet<PaletteEntry>();
- for (PaletteEntry entry : PaletteUtil.getAvailableEntriesSet(editorPart, priority).values()) {
- // the entry is not just a defineOnly entry but a visible one
- if (getRootParent(entry) != null) {
- result.add(entry);
- }
- }
- return result;
- }
-
- /**
- * Returns the Root element for the palette entry. It searches recursively from parent to parent, until it find the root element
- *
- * @param entry
- * the palette entry for which root element is searched
- * @return the root element or <code>null</code> if none was found
- */
- protected PaletteRoot getRootParent(PaletteEntry entry) {
- PaletteContainer parent = entry.getParent();
- if (parent instanceof PaletteRoot) {
- return (PaletteRoot) parent;
- } else if (parent != null) {
- return getRootParent(parent);
- } else {
- return null;
- }
- }
-
- /**
- * Item validator
- */
- protected abstract class ToolBarItemValidator {
-
- /**
- * Checks if the button should be enable or not
- *
- * @return <code>true</code> if the button should be enable
- */
- public abstract boolean isEnable();
- }
-
- /**
- * validator for the create separator or stack tool item. Only valid when selection is a {@link Configuration}
- */
- protected class ConfigurationSelectedValidator extends ToolBarItemValidator {
-
- /**
- * @{inheritDoc
- */
- @Override
- public boolean isEnable() {
- return getSelectedConfiguration() != null;
- }
- }
-
- /**
- * validator for the create stack tool item. Only valid when selection is a {@link DrawerConfiguration}
- */
- protected class DrawerConfigurationSelectedValidator extends ToolBarItemValidator {
-
- /**
- * @{inheritDoc
- */
- @Override
- public boolean isEnable() {
- return getSelectedConfiguration() instanceof DrawerConfiguration;
- }
-
- }
-}
+/***************************************************************************** + * Copyright (c) 2009, 2014 CEA LIST and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Remi Schnekenburger (CEA LIST) remi.schnekenburger@cea.fr - Initial API and implementation + * Christian W. Damus (CEA) - bug 422257 + * Mickael ADAM (ALL4TEC) mickael.adam@all4tec.net - adaptation to use paletteConfiguration model instead of eclipse palette xml file + * + *****************************************************************************/ +package org.eclipse.papyrus.customization.palette.dialog; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.emf.common.notify.Notification; +import org.eclipse.emf.common.util.URI; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EClassifier; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.ecore.resource.ResourceSet; +import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; +import org.eclipse.emf.ecore.util.EContentAdapter; +import org.eclipse.emf.ecore.util.EcoreUtil; +import org.eclipse.gef.palette.CombinedTemplateCreationEntry; +import org.eclipse.gef.palette.PaletteContainer; +import org.eclipse.gef.palette.PaletteDrawer; +import org.eclipse.gef.palette.PaletteEntry; +import org.eclipse.gef.palette.PaletteRoot; +import org.eclipse.gef.palette.PaletteStack; +import org.eclipse.gef.palette.PaletteToolbar; +import org.eclipse.gef.palette.ToolEntry; +import org.eclipse.gef.ui.palette.PaletteCustomizer; +import org.eclipse.gmf.runtime.common.core.service.ProviderPriority; +import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditorWithFlyOutPalette; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.util.LocalSelectionTransfer; +import org.eclipse.jface.viewers.DoubleClickEvent; +import org.eclipse.jface.viewers.IDoubleClickListener; +import org.eclipse.jface.viewers.ILabelProvider; +import org.eclipse.jface.viewers.ILabelProviderListener; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.ITreeContentProvider; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.jface.viewers.ViewerComparator; +import org.eclipse.jface.viewers.ViewerFilter; +import org.eclipse.jface.wizard.WizardPage; +import org.eclipse.papyrus.customization.palette.Messages; +import org.eclipse.papyrus.emf.facet.custom.core.ICustomizationCatalogManagerFactory; +import org.eclipse.papyrus.emf.facet.custom.core.ICustomizationManager; +import org.eclipse.papyrus.emf.facet.custom.core.ICustomizationManagerFactory; +import org.eclipse.papyrus.emf.facet.custom.core.internal.CustomizationCatalogManager; +import org.eclipse.papyrus.emf.facet.custom.metamodel.v0_2_0.custom.Customization; +import org.eclipse.papyrus.emf.facet.custom.ui.internal.CustomizedLabelProvider; +import org.eclipse.papyrus.emf.facet.custom.ui.internal.CustomizedTreeContentProvider; +import org.eclipse.papyrus.infra.emf.utils.EMFHelper; +import org.eclipse.papyrus.uml.diagram.common.Activator; +import org.eclipse.papyrus.uml.diagram.common.part.PaletteUtil; +import org.eclipse.papyrus.uml.diagram.common.part.PapyrusPalettePreferences; +import org.eclipse.papyrus.uml.diagram.common.service.AspectCreationEntry; +import org.eclipse.papyrus.uml.diagram.common.service.IPapyrusPaletteConstant; +import org.eclipse.papyrus.uml.diagram.common.service.PaletteConfigurationUtils; +import org.eclipse.papyrus.uml.diagram.common.service.PapyrusPaletteService; +import org.eclipse.papyrus.uml.diagram.common.service.palette.StereotypeAspectActionProvider; +import org.eclipse.papyrus.uml.diagram.paletteconfiguration.Configuration; +import org.eclipse.papyrus.uml.diagram.paletteconfiguration.DrawerConfiguration; +import org.eclipse.papyrus.uml.diagram.paletteconfiguration.LeafConfiguration; +import org.eclipse.papyrus.uml.diagram.paletteconfiguration.PaletteConfiguration; +import org.eclipse.papyrus.uml.diagram.paletteconfiguration.PaletteconfigurationPackage; +import org.eclipse.papyrus.uml.diagram.paletteconfiguration.SeparatorConfiguration; +import org.eclipse.papyrus.uml.diagram.paletteconfiguration.StackConfiguration; +import org.eclipse.papyrus.uml.diagram.paletteconfiguration.ToolConfiguration; +import org.eclipse.papyrus.uml.diagram.paletteconfiguration.util.PaletteconfigurationSwitch; +import org.eclipse.swt.SWT; +import org.eclipse.swt.dnd.DND; +import org.eclipse.swt.dnd.DragSourceAdapter; +import org.eclipse.swt.dnd.DragSourceEvent; +import org.eclipse.swt.dnd.DragSourceListener; +import org.eclipse.swt.dnd.DropTargetEvent; +import org.eclipse.swt.dnd.DropTargetListener; +import org.eclipse.swt.dnd.Transfer; +import org.eclipse.swt.dnd.TreeDropTargetEffect; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.events.MouseEvent; +import org.eclipse.swt.events.MouseListener; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Combo; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.swt.widgets.ToolBar; +import org.eclipse.swt.widgets.ToolItem; +import org.eclipse.swt.widgets.Tree; +import org.eclipse.swt.widgets.TreeItem; +import org.eclipse.ui.IEditorPart; +import org.eclipse.uml2.uml.Class; +import org.eclipse.uml2.uml.Package; +import org.eclipse.uml2.uml.Profile; +import org.eclipse.uml2.uml.Stereotype; +import org.eclipse.uml2.uml.UMLPackage; +import org.w3c.dom.Document; + +/** + * Wizard page for information about the new local palette definition + */ +public class ExtendedPaletteContentPage extends WizardPage implements Listener { + + /** editor part in which the palette is created */ + protected IEditorPart editorPart; + + /** available tools viewer */ + protected TreeViewer availableToolsViewer; + + /** label provider for the tree viewer */ + protected PaletteLabelProvider paletteLabelProvider; + + /** icon path when tools are hidden */ + protected static final String HIDDEN_TOOLS_ICON = "/icons/tools_hidden.gif"; + + /** icon path when tools are shown */ + protected static final String SHOWN_TOOLS_ICON = "/icons/tools_shown.gif"; + + /** path to the icon */ + protected static final String WIZARD_ICON = "/icons/local_desc_wiz.png"; + + /** icon path when drawers are hidden */ + protected static final String SHOWN_DRAWERS_ICON = "/icons/drawers_shown.gif"; + + /** icon path when drawers are shown */ + protected static final String HIDDEN_DRAWERS_ICON = "/icons/drawers_hidden.gif"; + + /** icon path for the add button */ + protected static final String ADD_ICON = "/icons/arrow_right.gif"; + + /** icon path for the remove button */ + protected static final String REMOVE_ICON = "/icons/arrow_left.gif"; + + /** icon path for the delete button */ + protected static final String DELETE_ICON = "/icons/delete.gif"; + + /** icon path for the create drawer button */ + protected static final String CREATE_DRAWERS_ICON = "/icons/new_drawer.gif"; + + /** icon path for the create separator button */ + protected String CREATE_SEPARATOR_ICON = "/icons/separator.gif"; + + /** icon path for the create stack button */ + protected String CREATE_STACK_ICON = "/icons/stack.gif"; + + /** icon path for the delete drawer button */ + protected static final String DELETE_DRAWERS_ICON = "/icons/delete.gif"; + + /** icon for the content provider switch button */ + protected String SWITCH_CONTENT_PROVIDER_ICON = "/icons/switch_provider.gif"; + + /** label for the standard tools */ + protected static final String UML_TOOLS_LABEL = "UML tools"; + + /** icon path for the edit drawer button */ + protected static final String EDIT_ICON = "/icons/obj16/file.gif"; + + /** instance of the filter used to show/hide drawers */ + protected final ViewerFilter drawerFilter = new DrawerFilter(); + + /** instance of the filter used to show/hide tools */ + protected final ViewerFilter toolFilter = new ToolFilter(); + + /** stored preferences */ + protected List<String> storedPreferences; + + /** add button */ + protected Button addButton; + + /** remove button */ + protected Button removeButton; + + /** tree viewer for the new palette */ + protected TreeViewer paletteTreeViewer; + + /** document for element creation */ + protected Document document; + + /** content node for the palette viewer */ + protected PaletteContainerProxy contentNode; + + /** combo to select which profile tools should be visible */ + protected Combo profileCombo; + + /** list of profiles that can provide tools */ + protected List<String> profileComboList = new ArrayList<String>(); + + /** tool item in charge of toggling content providers in the available tool viewer */ + protected ToolItem toggleContentProvider; + + /** required profile by this palette */ + protected Set<String> requiredProfiles; + + /** palette customizer used for the palette */ + protected PaletteCustomizer customizer; + + /** current selected entry proxy */ + protected Configuration selectedConfiguration; + + /** class in charge of the information composite */ + protected ConfigurationInformationComposite informationComposite = new ConfigurationInformationComposite(); + + /** class in charge of the aspect tool information composite */ + protected AspectActionsInformationComposite aspectActionComposite = new AspectActionsInformationComposite(); + + /** toolbar above tools */ + protected ToolBar toolbar; + + /** validator key for toolbar items */ + protected final static String VALIDATOR = "validator"; + + /** priority of the current edited palette */ + protected ProviderPriority priority; + + /** resource set that contains the palette configuration resource */ + private ResourceSet resourceSet; + + /** palette configuration resource */ + private Resource resourceToEdit; + + /** customization manager for the content provider */ + // TODO: EMFFACET: pb of ResourceSET + private ICustomizationManager manager = ICustomizationManagerFactory.DEFAULT.getOrCreateICustomizationManager(new ResourceSetImpl()); + + + /** + * Creates a new wizard page with the given name, title, and image. + * + * @param part + * the editor part in which the wizard was created + */ + public ExtendedPaletteContentPage(IEditorPart part, PaletteCustomizer customizer) { + super(Messages.Local_Palette_ContentPage_Name, Messages.Local_Palette_ContentPage_Title, Activator.getImageDescriptor(WIZARD_ICON)); + this.editorPart = part; + this.customizer = customizer; + } + + @Override + public void dispose() { + super.dispose(); + + if (resourceSet != null) { + EMFHelper.unload(resourceSet); + } + + if (manager != null) { + EMFHelper.unload(manager.getResourceSet()); + } + } + + /** + * Sets the priority of the current edited palette + * + * @param priority + * the priority of the current edited palette + */ + public void setPriority(ProviderPriority priority) { + this.priority = priority; + } + + /** + * @return the resourceSet + */ + public ResourceSet getResourceSet() { + return resourceSet; + } + + /** + * @return the resourceToEdit + */ + public Resource getResourceToEdit() { + return resourceToEdit; + } + + /** + * Returns the list of required profiles by this local palette definition + * + * @return the profiles required by this palette + */ + public Set<String> getRequiredProfiles() { + return requiredProfiles; + } + + /** + * {@inheritDoc} + */ + @Override + public void createControl(Composite parent) { + + // initialize dialog units + initializeDialogUnits(parent); + + // Create a new composite as there is the title bar seperator + // to deal with + Composite control = new Composite(parent, SWT.NONE); + GridLayout layout = new GridLayout(4, false); + control.setLayout(layout); + control.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + setControl(control); + + // create Available Tools Group + createAvailableToolsGroup(); + + // create add/remove buttons + createAddRemoveButtons(); + + // create Palette Group + createPalettePreviewGroup(); + + // create tool description group (custom name, description, and perhaphs icon.... Just under this group, another one with aspect actions) + createToolDescriptionGroup(); + + // just under, creates a new line of composites... + createAspectActionComposite(); + + + + // add listeners inter-groups + ISelectionChangedListener listener = createToolsViewerSelectionChangeListener(); + availableToolsViewer.addSelectionChangedListener(listener); + paletteTreeViewer.addSelectionChangedListener(listener); + resourceToEdit.eAdapters().add(new EContentAdapter() { + + /** + * {@inheritDoc} + */ + @Override + public void notifyChanged(Notification notification) { + super.notifyChanged(notification); + paletteTreeViewer.refresh(); + } + }); + + // end of the control creation + Dialog.applyDialogFont(control); + + validatePage(); + // Show description on opening + setErrorMessage(null); + setMessage(null); + setControl(control); + } + + /** + * Creates the composite group that presents information about ascpect actions for aspect tools + */ + protected void createAspectActionComposite() { + aspectActionComposite.createComposite((Composite) getControl(), getAllAppliedProfiles()); + } + + /** + * Creates the composite group that presents information about current selected tool + */ + protected void createToolDescriptionGroup() { + informationComposite.createComposite((Composite) getControl(), getAllAppliedProfiles()); + } + + /** + * update the preferences to have all tools accessible + */ + protected void updatePreferences() { + // change => set to no hidden palettes + storedPreferences = PapyrusPalettePreferences.getHiddenPalettes(editorPart); + + // remove all, but should only remove visible palettes + for (String id : storedPreferences) { + PapyrusPalettePreferences.changePaletteVisibility(id, editorPart, true); + } + } + + /** + * Restore preferences + */ + public void restorePreferences() { + // remove all, but should only remove visible palettes + for (String id : storedPreferences) { + PapyrusPalettePreferences.changePaletteVisibility(id, editorPart, false); + } + } + + /** + * creates the palette preview group + */ + protected void createPalettePreviewGroup() { + Composite parent = (Composite) getControl(); + Composite paletteComposite = new Composite(parent, SWT.NONE); + + GridLayout layout = new GridLayout(2, true); + layout.marginHeight = 0; + layout.marginWidth = 0; + paletteComposite.setLayout(layout); + GridData data = new GridData(SWT.FILL, SWT.FILL, true, true); + paletteComposite.setLayoutData(data); + + Label label = new Label(paletteComposite, SWT.NONE); + label.setText(Messages.Local_Palette_Palette_Preview); + data = new GridData(SWT.LEFT, SWT.CENTER, true, false); + label.setLayoutData(data); + + toolbar = new ToolBar(paletteComposite, SWT.HORIZONTAL); + data = new GridData(SWT.RIGHT, SWT.FILL, false, false); + toolbar.setLayoutData(data); + populatePalettePreviewToolBar(toolbar); + + Tree tree = new Tree(paletteComposite, SWT.SINGLE | SWT.BORDER); + data = new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1); + data.widthHint = 185; + // Make the tree this tall even when there is nothing in it. This will keep the + // dialog from shrinking to an unusually small size. + data.heightHint = 200; + tree.setLayoutData(data); + paletteTreeViewer = new TreeViewer(tree); + paletteTreeViewer.setContentProvider(new ExtendedPaletteContentProvider()); + paletteTreeViewer.setLabelProvider(new ExtendedPaletteLabelProvider()); + paletteTreeViewer.addSelectionChangedListener(new ISelectionChangedListener() { + + @Override + public void selectionChanged(SelectionChangedEvent event) { + handlePalettePreviewSelectionChanged(event); + } + }); + + addPalettePreviewDropSupport(); + addPalettePreviewDragSupport(); + addPalettePreviewEditSupport(); + + paletteTreeViewer.setInput(resourceToEdit); + } + + /** + * handle the selection change event for the palette preview + * + * @param event + * the event that is thrown by the palette viewer + */ + protected void handlePalettePreviewSelectionChanged(SelectionChangedEvent event) { + // retrieve current selection + Configuration configuration = getSelectedConfiguration(); + if (configuration != null) { + selectedConfiguration = configuration; + // update the current selected palette entry proxy + informationComposite.setSelectedConfiguration(selectedConfiguration); + } else { + selectedConfiguration = null; + informationComposite.setSelectedConfiguration(null); + } + + // update toolbar + if (toolbar != null && !toolbar.isDisposed()) { + for (int i = 0; i < toolbar.getItemCount(); i++) { + ToolItem item = toolbar.getItem(i); + Object validator = item.getData(VALIDATOR); + if (validator instanceof ToolBarItemValidator) { + item.setEnabled(((ToolBarItemValidator) validator).isEnable()); + } + } + } + } + + /** + * Adds the behavior for the double click strategy + */ + protected void addPalettePreviewEditSupport() { + paletteTreeViewer.addDoubleClickListener(new IDoubleClickListener() { + + /** + * {@inheritDoc} + */ + @Override + public void doubleClick(DoubleClickEvent event) { + // nothing here + } + }); + + } + + /** + * Add drop behavior for the palette preview + */ + protected void addPalettePreviewDropSupport() { + // transfer types + Transfer[] transfers = new Transfer[] { LocalSelectionTransfer.getTransfer() }; + + // drag listener + DropTargetListener listener = new TreeDropTargetEffect(paletteTreeViewer.getTree()) { + + /** + * {@inheritDoc} + */ + @Override + public void drop(DropTargetEvent event) { + super.drop(event); + IStructuredSelection transferedSelection = (IStructuredSelection) LocalSelectionTransfer.getTransfer().nativeToJava(event.currentDataType); + Object objectToTransfer = transferedSelection.getFirstElement(); + if (!(objectToTransfer instanceof IAdaptable)) { + return; + } + final EObject eobjectToTransfer = EMFHelper.getEObject(objectToTransfer); + + Object targetObject = ((TreeItem) event.item).getData(); + if (!(targetObject instanceof IAdaptable)) { + return; + } + + final EObject targetEObject = EMFHelper.getEObject(targetObject); + if (targetEObject == null) { + return; + } + + new PaletteconfigurationSwitch<Object>() { + + /** + * {@inheritDoc} + */ + @Override + public Object caseDrawerConfiguration(DrawerConfiguration drawerConfigurationToMove) { + if (targetEObject instanceof DrawerConfiguration) { + // move the drawer before the target drawer configuration + PaletteConfiguration paletteConfiguration = (PaletteConfiguration) ((DrawerConfiguration) targetEObject).eContainer(); + PaletteConfigurationUtils.moveDrawerConfiguration(paletteConfiguration, drawerConfigurationToMove, (DrawerConfiguration) targetEObject); + + } + return super.caseDrawerConfiguration(drawerConfigurationToMove); + } + + /** + * {@inheritDoc} + */ + @Override + public Object caseSeparatorConfiguration(SeparatorConfiguration separatorConfigurationToMove) { + if (targetEObject instanceof DrawerConfiguration) { + PaletteConfigurationUtils.moveSeparatorConfiguration(((DrawerConfiguration) targetEObject), separatorConfigurationToMove); + } else if (targetEObject instanceof StackConfiguration) { + PaletteConfigurationUtils.moveSeparatorConfiguration(((StackConfiguration) targetEObject), separatorConfigurationToMove); + } else if (targetEObject instanceof ToolConfiguration) { + PaletteConfigurationUtils.moveSeparatorConfiguration(((ToolConfiguration) targetEObject), separatorConfigurationToMove); + } else if (targetEObject instanceof SeparatorConfiguration) { + PaletteConfigurationUtils.moveSeparatorConfiguration(((SeparatorConfiguration) targetEObject), separatorConfigurationToMove); + } + + return super.caseSeparatorConfiguration(separatorConfigurationToMove); + }; + + /** + * {@inheritDoc} + */ + @Override + public Object caseStackConfiguration(StackConfiguration stackConfigurationToMove) { + if (targetEObject instanceof DrawerConfiguration) { + PaletteConfigurationUtils.moveStackConfiguration(((DrawerConfiguration) targetEObject), stackConfigurationToMove); + } else if (targetEObject instanceof StackConfiguration) { + PaletteConfigurationUtils.moveStackConfiguration(((StackConfiguration) targetEObject), stackConfigurationToMove); + } else if (targetEObject instanceof ToolConfiguration) { + PaletteConfigurationUtils.moveStackConfiguration(((ToolConfiguration) targetEObject), stackConfigurationToMove); + } else if (targetEObject instanceof SeparatorConfiguration) { + PaletteConfigurationUtils.moveStackConfiguration(((SeparatorConfiguration) targetEObject), stackConfigurationToMove); + } + + return super.caseStackConfiguration(stackConfigurationToMove); + }; + + /** + * {@inheritDoc} + */ + @Override + public Object caseToolConfiguration(ToolConfiguration toolConfigurationToMove) { + if (targetEObject instanceof DrawerConfiguration) { + PaletteConfigurationUtils.moveToolConfiguration(((DrawerConfiguration) targetEObject), toolConfigurationToMove); + } else if (targetEObject instanceof StackConfiguration) { + PaletteConfigurationUtils.moveToolConfiguration(((StackConfiguration) targetEObject), toolConfigurationToMove); + } else if (targetEObject instanceof ToolConfiguration) { + PaletteConfigurationUtils.moveToolConfiguration(((ToolConfiguration) targetEObject), toolConfigurationToMove); + } else if (targetEObject instanceof SeparatorConfiguration) { + PaletteConfigurationUtils.moveToolConfiguration(((SeparatorConfiguration) targetEObject), toolConfigurationToMove); + } + + return super.caseToolConfiguration(toolConfigurationToMove); + }; + + + }.doSwitch(eobjectToTransfer); + + setPageComplete(validatePage()); + } + + /** + * {@inheritDoc} + */ + @Override + public void dragOver(DropTargetEvent event) { + super.dragOver(event); + + IStructuredSelection transferedSelection = (IStructuredSelection) LocalSelectionTransfer.getTransfer().nativeToJava(event.currentDataType); + // check selection is compatible for drop target + + TreeItem item = paletteTreeViewer.getTree().getItem(paletteTreeViewer.getTree().toControl(new Point(event.x, event.y))); + + checkSelectionForDrop(transferedSelection, item, event); + } + }; + + paletteTreeViewer.addDropSupport(DND.DROP_LINK | DND.DROP_MOVE, transfers, listener); + } + + /** + * Adds drag ability to the palette preview composite + */ + protected void addPalettePreviewDragSupport() { + + // transfer types + Transfer[] transfers = new Transfer[] { LocalSelectionTransfer.getTransfer() }; + + // drag listener + DragSourceListener listener = new DragSourceAdapter() { + + /** + * {@inheritDoc} + */ + @Override + public void dragStart(DragSourceEvent event) { + super.dragStart(event); + event.data = paletteTreeViewer.getSelection(); + } + + /** + * {@inheritDoc} + */ + @Override + public void dragSetData(DragSourceEvent event) { + super.dragSetData(event); + LocalSelectionTransfer.getTransfer().setSelection(paletteTreeViewer.getSelection()); + } + + }; + + paletteTreeViewer.addDragSupport(DND.DROP_MOVE, transfers, listener); + } + + /** + * Checks if the selection can be added to the target widget + * + * @param transferedSelection + * the selection to be dropped + * @param widget + * the widget where to drop + */ + protected void checkSelectionForDrop(IStructuredSelection transferedSelection, TreeItem item, final DropTargetEvent event) { + event.detail = DND.DROP_NONE; + final Object objectToTransfer = transferedSelection.getFirstElement(); + if (!(objectToTransfer instanceof IAdaptable)) { + return; + } + final EObject eobjectToTransfer = EMFHelper.getEObject(objectToTransfer); + // handle only first selected element + if (item == null) { + // adding to the root, should only be a drawer + if (eobjectToTransfer instanceof DrawerConfiguration) { + event.detail = DND.DROP_LINK; + } + } else { + Object targetObject = item.getData(); + if (!(targetObject instanceof IAdaptable)) { + event.detail = DND.DROP_NONE; + return; + } + final EObject targetEObject = EMFHelper.getEObject(targetObject); + if (targetEObject == null) { + event.detail = DND.DROP_NONE; + return; + } + + new PaletteconfigurationSwitch<Object>() { + + /** + * {@inheritDoc} + */ + @Override + public Object caseDrawerConfiguration(DrawerConfiguration object) { + if (targetEObject instanceof DrawerConfiguration) { + event.detail = DND.DROP_MOVE; + event.feedback = DND.FEEDBACK_INSERT_BEFORE; + } + return object; + } + + /** + * {@inheritDoc} + */ + @Override + public Object caseSeparatorConfiguration(SeparatorConfiguration object) { + if (targetEObject instanceof DrawerConfiguration) { + event.detail = DND.DROP_MOVE; + } else if (targetEObject instanceof StackConfiguration) { + event.detail = DND.DROP_MOVE; + event.feedback = DND.FEEDBACK_INSERT_BEFORE; + } else if (targetEObject instanceof ToolConfiguration) { + event.detail = DND.DROP_MOVE; + event.feedback = DND.FEEDBACK_INSERT_BEFORE; + } else if (targetEObject instanceof SeparatorConfiguration) { + event.detail = DND.DROP_MOVE; + event.feedback = DND.FEEDBACK_INSERT_BEFORE; + } + + return object; + }; + + /** + * {@inheritDoc} + */ + @Override + public Object caseStackConfiguration(StackConfiguration object) { + if (targetEObject instanceof DrawerConfiguration) { + event.detail = DND.DROP_MOVE; + } else if (targetEObject instanceof StackConfiguration) { + event.detail = DND.DROP_MOVE; + event.feedback = DND.FEEDBACK_INSERT_BEFORE; + } else if (targetEObject instanceof ToolConfiguration) { + event.detail = DND.DROP_MOVE; + event.feedback = DND.FEEDBACK_INSERT_BEFORE; + } else if (targetEObject instanceof SeparatorConfiguration) { + event.detail = DND.DROP_MOVE; + event.feedback = DND.FEEDBACK_INSERT_BEFORE; + } + return object; + }; + + /** + * {@inheritDoc} + */ + @Override + public Object caseToolConfiguration(ToolConfiguration object) { + if (targetEObject instanceof DrawerConfiguration) { + event.detail = DND.DROP_MOVE; + } else if (targetEObject instanceof StackConfiguration) { + event.detail = DND.DROP_MOVE; + } else if (targetEObject instanceof ToolConfiguration) { + event.detail = DND.DROP_MOVE; + event.feedback = DND.FEEDBACK_INSERT_BEFORE; + } else if (targetEObject instanceof SeparatorConfiguration) { + event.detail = DND.DROP_MOVE; + event.feedback = DND.FEEDBACK_INSERT_BEFORE; + } + return object; + }; + + + }.doSwitch(eobjectToTransfer); + + } + } + + /** + * Sets an empty content for the palette preview + */ + public void initializeContent() { + contentNode = new PaletteContainerProxy(null); + + // adds a default local drawer + PaletteLocalDrawerProxy proxy = new PaletteLocalDrawerProxy("Default", generateID("Drawer_"), "/icons/drawer.gif", "Default Drawer"); + contentNode.addChild(proxy); + + setPageComplete(false); + } + + /** + * Sets the initial content for the palette preview + * + * @param descriptor + * the descriptor that contains the configuration file to load + */ + public void initializeContent(PapyrusPaletteService.ExtendedProviderDescriptor descriptor) { + resourceSet = createResourceSet(); + URI redefinitionFileURI = PaletteUtil.getRedefinitionFileURI(descriptor.getContributionID()); + resourceToEdit = getResourceSet().createResource(redefinitionFileURI); + + // check resource is not null; + if (resourceToEdit == null) { + Activator.log.error("No resource has been created for uri :" + redefinitionFileURI, null); + } + try { + resourceToEdit.load(Collections.emptyMap()); + } catch (IOException e) { + Activator.log.error("Impossible to load configuration file", e); + } + + } + + /** + * Creates and returns the resource set used to modidy the content of the palette configuration + * + * @return the newly created ResourceSet. + */ + protected ResourceSet createResourceSet() { + return new ResourceSetImpl(); + } + + /** + * populates the preview palette toolbar + * + * @param toolbar + * the toolbar to populate + */ + protected void populatePalettePreviewToolBar(ToolBar toolbar) { + ConfigurationSelectedValidator validator = new ConfigurationSelectedValidator(); + DrawerConfigurationSelectedValidator drawerConfigurationSelectedValidator = new DrawerConfigurationSelectedValidator(); + createToolBarItem(toolbar, DELETE_ICON, Messages.PapyrusPaletteCustomizerDialog_RemoveButtonTooltip, createRemoveElementListener(), validator); + createToolBarItem(toolbar, CREATE_DRAWERS_ICON, Messages.Local_Palette_Create_Drawer_Tooltip, createNewDrawerListener(), null); + createToolBarItem(toolbar, CREATE_SEPARATOR_ICON, Messages.Local_Palette_Create_Separator_Tooltip, createNewSeparatorListener(), validator); + createToolBarItem(toolbar, CREATE_STACK_ICON, Messages.Local_Palette_Create_Stack_Tooltip, createNewStackListener(), drawerConfigurationSelectedValidator); + } + + /** + * Creates the listener for the remove item(s) button + * + * @return the listener for the remove button + */ + protected Listener createRemoveElementListener() { + return new Listener() { + + /** + * {@inheritDoc} + */ + @Override + public void handleEvent(Event event) { + IStructuredSelection selection = (IStructuredSelection) paletteTreeViewer.getSelection(); + if (selection == null || selection.size() < 1) { + return; + } + + Iterator<?> it = selection.iterator(); + while (it.hasNext()) { + Object o = it.next(); + if (o instanceof IAdaptable) { + EObject eobject = EMFHelper.getEObject(o); + if (eobject instanceof Configuration) { + PaletteConfigurationUtils.removeConfiguration((Configuration) eobject); + } + } + } + } + }; + } + + /** + * Creates the listener for the new drawer tool item + * + * @return the listener created + */ + protected Listener createNewDrawerListener() { + return new Listener() { + + /** + * {@inheritDoc} + */ + @Override + public void handleEvent(Event event) { + PaletteConfiguration paletteConfiguration = (PaletteConfiguration) EcoreUtil.getObjectByType(resourceToEdit.getContents(), PaletteconfigurationPackage.eINSTANCE.getPaletteConfiguration()); + if (paletteConfiguration != null) { + PaletteConfigurationUtils.createDrawer(paletteConfiguration); + } else { + Activator.log.error("Impossible to find the palette configuration", null); + } + + setPageComplete(validatePage()); + } + }; + } + + /** + * Creates the listener for the new stack tool item + * + * @return the listener created + */ + protected Listener createNewStackListener() { + return new Listener() { + + /** + * {@inheritDoc} + */ + @Override + public void handleEvent(Event event) { + Configuration selectedConfiguration = getSelectedConfiguration(); + if (selectedConfiguration instanceof DrawerConfiguration) { + PaletteConfigurationUtils.createStack(((DrawerConfiguration) selectedConfiguration)); + } else if (selectedConfiguration instanceof LeafConfiguration) { + PaletteConfigurationUtils.createStack(((LeafConfiguration) selectedConfiguration)); + } else { + Activator.log.error("Invalid selection to create a Stack: " + selectedConfiguration, null); + } + + // paletteTreeViewer.refresh(); + setPageComplete(validatePage()); + } + }; + } + + /** + * Generates the ID for a local element + * + * @param base + * the begining of the id + * @return the separator id + */ + protected String generateID(String base) { + StringBuffer id = new StringBuffer(); + id.append(base); + id.append("_"); + id.append(System.currentTimeMillis()); + + return id.toString(); + } + + /** + * Creates the listener for the new separator tool item + * + * @return the listener created + */ + protected Listener createNewSeparatorListener() { + return new Listener() { + + /** + * {@inheritDoc} + */ + @Override + public void handleEvent(Event event) { + Configuration selectedConfiguration = getSelectedConfiguration(); + if (selectedConfiguration instanceof DrawerConfiguration) { + PaletteConfigurationUtils.createSeparator(((DrawerConfiguration) selectedConfiguration)); + } else if (selectedConfiguration instanceof LeafConfiguration) { + PaletteConfigurationUtils.createSeparator(((LeafConfiguration) selectedConfiguration)); + } else { + Activator.log.error("Invalid selection to create a separator: " + selectedConfiguration, null); + } + + setPageComplete(validatePage()); + } + }; + } + + /** + * Returns the current selected configuration + * + * @return the current selected configuration or <code>null</code> if the element is not translatable into a {@link Configuration} + */ + protected Configuration getSelectedConfiguration() { + // retrieve selection + if (paletteTreeViewer != null && !paletteTreeViewer.getControl().isDisposed()) { + // retrieve selection. first element should be a drawer + IStructuredSelection selection = (IStructuredSelection) paletteTreeViewer.getSelection(); + if (selection == null) { + return null; + } else { + Object object = selection.getFirstElement(); + if (object instanceof IAdaptable) { + EObject eobject = EMFHelper.getEObject(object); + if (eobject instanceof Configuration) { + return (Configuration) eobject; + } + } + } + } + return null; + } + + /** + * Creates a toolbar item. + * + * @param toolbar + * the parent toolbar + * @param itemIcon + * path for icon + * @param tooltip + * tooltip text for the toolbar item + * @param listener + * listener for tool bar item + */ + protected void createToolBarItem(ToolBar toolbar, String itemIcon, String tooltip, Listener listener, ToolBarItemValidator validator) { + ToolItem item = new ToolItem(toolbar, SWT.BORDER); + item.setImage(Activator.getPluginIconImage(Activator.ID, itemIcon)); + item.setToolTipText(tooltip); + item.addListener(SWT.Selection, listener); + item.setData(VALIDATOR, validator); + } + + /** + * creates the buttons to add/remove entries + */ + protected void createAddRemoveButtons() { + Composite composite = new Composite((Composite) getControl(), SWT.NONE); + GridLayout layout = new GridLayout(1, true); + composite.setLayout(layout); + + GridData data = new GridData(SWT.CENTER, SWT.CENTER, false, true); + composite.setLayoutData(data); + + addButton = new Button(composite, SWT.NONE); + addButton.setImage(Activator.getPluginIconImage(Activator.ID, ADD_ICON)); + addButton.setToolTipText(Messages.PapyrusPaletteCustomizerDialog_AddButtonTooltip); + addButton.addMouseListener(createAddButtonListener()); + addButton.setEnabled(false); + addButton.addListener(SWT.MouseUp, this); + + removeButton = new Button(composite, SWT.NONE); + removeButton.setImage(Activator.getPluginIconImage(Activator.ID, REMOVE_ICON)); + removeButton.setToolTipText(Messages.PapyrusPaletteCustomizerDialog_RemoveButtonTooltip); + removeButton.addMouseListener(createRemoveButtonListener()); + removeButton.setEnabled(false); + removeButton.addListener(SWT.MouseUp, this); + } + + /** + * selection listener for the tools viewer , to update the state of the add button + * + * @return the new created selection listener + */ + protected ISelectionChangedListener createToolsViewerSelectionChangeListener() { + return new ISelectionChangedListener() { + + /** + * {@inheritDoc} + */ + @Override + public void selectionChanged(SelectionChangedEvent event) { + + // get source and target selection + // check source entry can be added to target entry + Object source = ((IStructuredSelection) availableToolsViewer.getSelection()).getFirstElement(); + Object target = ((IStructuredSelection) paletteTreeViewer.getSelection()).getFirstElement(); + + // manage add button + if (isAddValidTarget(source, target)) { + addButton.setEnabled(true); + } else { + addButton.setEnabled(false); + } + + // manage remove button + if (isRemoveValidSource(target)) { + removeButton.setEnabled(true); + } else { + removeButton.setEnabled(false); + } + + } + + /** + * Returns true if the source can be added to the target + * + * @param source + * the source object + * @param target + * the target object + * @return <code>true</code> if the source can be added to the target + */ + protected boolean isAddValidTarget(Object source, Object target) { + if (!(source instanceof PaletteEntry)) { + return false; + } + + // case1: source is a drawer. + // it can only be added to the root element (no selection) + // case2: source is a palette tool + // it can't be added to the root element + // it can only be added to a container element (drawer or stack) + if (source instanceof PaletteDrawer) { + if (target == null) { + return true; + } + return false; + } else if (source instanceof ToolEntry) { + if (target instanceof PaletteEntryProxy) { + // EntryType type = ((PaletteEntryProxy)target).getType(); + // switch(type) { + // case DRAWER: + // case STACK: + // return true; + // default: + // return false; + // } + } + return false; + } + return false; + } + + /** + * Returns true if the source can be added to the target + * + * @param source + * the source object + * @return <code>true</code> if the source can be removed (not null and instanceof + * PaletteEntryProxy) + */ + protected boolean isRemoveValidSource(Object source) { + if (source instanceof PaletteEntryProxy) { + return true; + } + return false; + } + }; + + } + + /** + * Creates the add button listener + */ + protected MouseListener createAddButtonListener() { + return new MouseListener() { + + @Override + public void mouseUp(MouseEvent e) { + // // add the element selected on the left to the right tree + // // check the selection. + // IStructuredSelection selection = (IStructuredSelection)availableToolsViewer.getSelection(); + // if(selection == null || selection.size() < 1) { + // return; + // } + // PaletteEntry entry = (PaletteEntry)selection.getFirstElement(); + // if(entry == null) { + // return; + // } + // + // // find the selection on the right + // selection = (IStructuredSelection)paletteTreeViewer.getSelection(); + // + // PaletteEntryProxy parentNode = (PaletteEntryProxy)selection.getFirstElement(); + // // Bugfix: only drawers can be added to root element + // if(parentNode == null && entry instanceof PaletteDrawer) { + // parentNode = (PaletteContainerProxy)paletteTreeViewer.getInput(); + // } + // + // // check we have a containe here + // if(!(parentNode instanceof PaletteContainerProxy)) { + // return; + // } + // + // // create a new entry in the document + // PaletteEntryProxy proxy = createNodeFromEntry(entry); + // ((PaletteContainerProxy)parentNode).addChild(proxy); + // + // paletteTreeViewer.expandToLevel(parentNode, 1); + } + + /** + * {@inheritDoc} + */ + @Override + public void mouseDown(MouseEvent e) { + // do nothing + } + + /** + * {@inheritDoc} + */ + @Override + public void mouseDoubleClick(MouseEvent e) { + // do nothing + } + }; + } + + // /** + // * Creates a node in the xml document from the given entry + // * + // * @param entry + // * the palette entry from which to create the node + // * @param parentNode + // * the parent node for the newly created node + // * @return the created entry proxy or <code>null</code> + // */ + // protected PaletteEntryProxy createNodeFromEntry(Object entry) { + // PaletteEntryProxy entryProxy = null; + // + // if(entry instanceof AspectCreationEntry) { + // // should modify id of the element here, otherwise, different elements would have the same id... + // entryProxy = new PaletteAspectToolEntryProxy(((AspectCreationEntry)entry).clone()); + // } else if(entry instanceof CombinedTemplateCreationEntry) { + // CombinedTemplateCreationEntry originalEntry = (CombinedTemplateCreationEntry)entry; + // // create a new Aspect entry proxy + // AspectCreationEntry aspectEntry = new AspectCreationEntry(originalEntry.getLabel(), originalEntry.getDescription(), originalEntry.getId() + "_" + System.currentTimeMillis(), originalEntry.getSmallIcon(), originalEntry, new HashMap<Object, Object>()); + // entryProxy = new PaletteAspectToolEntryProxy(aspectEntry); + // } else if(entry instanceof PaletteContainer) { + // entryProxy = new PaletteContainerProxy((PaletteContainer)entry); + // } else if(entry instanceof PaletteEntryProxy) { + // entryProxy = ((PaletteEntryProxy)entry); + // } + // return entryProxy; + // } + + /** + * Creates the add button listener + */ + protected MouseListener createRemoveButtonListener() { + return new MouseListener() { + + @Override + public void mouseUp(MouseEvent e) { + // remove the element selected on the right + // add the element selected on the left to the right tree + // check the selection. + IStructuredSelection selection = (IStructuredSelection) paletteTreeViewer.getSelection(); + if (selection == null || selection.size() < 1) { + return; + } + PaletteEntryProxy proxyToDelete = (PaletteEntryProxy) selection.getFirstElement(); + if (proxyToDelete == null) { + return; + } + + // create a new entry in the document + // get container of the proxy to be deleted + PaletteContainerProxy parentProxy = proxyToDelete.getParent(); + parentProxy.removeChild(proxyToDelete); + } + + /** + * {@inheritDoc} + */ + @Override + public void mouseDown(MouseEvent e) { + // do nothing + } + + /** + * {@inheritDoc} + */ + @Override + public void mouseDoubleClick(MouseEvent e) { + // do nothing + } + }; + } + + /** + * creates the available entries group + */ + protected void createAvailableToolsGroup() { + Composite parent = (Composite) getControl(); + Composite availableToolsComposite = new Composite(parent, SWT.NONE); + GridLayout layout = new GridLayout(2, true); + layout.marginHeight = 0; + layout.marginWidth = 0; + availableToolsComposite.setLayout(layout); + GridData data = new GridData(SWT.FILL, SWT.FILL, true, true); + availableToolsComposite.setLayoutData(data); + + Label label = new Label(availableToolsComposite, SWT.NONE); + label.setText(Messages.Local_Palette_Available_Tools); + data = new GridData(SWT.LEFT, SWT.CENTER, true, false); + label.setLayoutData(data); + + ToolBar toolbar = new ToolBar(availableToolsComposite, SWT.HORIZONTAL); + data = new GridData(SWT.RIGHT, SWT.FILL, false, false); + toolbar.setLayoutData(data); + populateAvailableToolsToolBar(toolbar); + + createProfileCombo(availableToolsComposite); + + Tree tree = new Tree(availableToolsComposite, SWT.SINGLE | SWT.BORDER); + data = new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1); + data.widthHint = 185; + // Make the tree this tall even when there is nothing in it. This will keep the + // dialog from shrinking to an unusually small size. + data.heightHint = 200; + tree.setLayoutData(data); + availableToolsViewer = new TreeViewer(tree); + availableToolsViewer.setContentProvider(new UMLToolsTreeContentProvider()); + paletteLabelProvider = new PaletteLabelProvider(); + availableToolsViewer.setLabelProvider(paletteLabelProvider); + ViewerComparator labelComparator = new LabelViewerComparator(); + availableToolsViewer.setComparator(labelComparator); + // remove the note stack and standard group + availableToolsViewer.addFilter(new ViewerFilter() { + + /** + * {@inheritDoc} + */ + @Override + public boolean select(Viewer viewer, Object parentElement, Object element) { + if (element instanceof PaletteStack && "noteStack".equals(((PaletteStack) element).getId())) { + return false; + } else if (element instanceof PaletteToolbar && "standardGroup".equals(((PaletteToolbar) element).getId())) { + return false; + } + return true; + } + }); + availableToolsViewer.addFilter(new DrawerFilter()); + // add drag support + addAvailableToolsDragSupport(); + // availableToolsViewer.setInput(getAllVisibleStandardEntries()); + } + + /** + * Creates the profile combo + * + * @param availableToolsComposite + * the available tools composite + * @return the created combo + */ + protected Combo createProfileCombo(Composite availableToolsComposite) { + // retrieve top package, to know which profiles are available + // creates the combo + profileCombo = new Combo(availableToolsComposite, SWT.BORDER | SWT.READ_ONLY); + GridData data = new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1); + profileCombo.setLayoutData(data); + + // retrieve all applied profiles + List<Profile> profiles = getAllAppliedProfiles(); + + int profileNumber = profiles.size(); + for (int i = 0; i < profileNumber; i++) { + profileComboList.add(i, profiles.get(i).getName()); + } + profileComboList.add(UML_TOOLS_LABEL); + profileCombo.setItems(profileComboList.toArray(new String[] {})); + + // add selection listener for the combo. selects the "UML tools" item + ProfileComboSelectionListener listener = new ProfileComboSelectionListener(); + profileCombo.addSelectionListener(listener); + profileCombo.addModifyListener(listener); + // profileCombo.select(profileNumber); + + return profileCombo; + } + + /** + * returns the list of applied profile for the nearest package of the top element + * + * @return the list of applied profile for the nearest package of the top element or an empty + * list + */ + protected List<Profile> getAllAppliedProfiles() { + Package topPackage = null; + if (editorPart instanceof DiagramEditorWithFlyOutPalette) { + EObject element = ((DiagramEditorWithFlyOutPalette) editorPart).getDiagram().getElement(); + if (element instanceof org.eclipse.uml2.uml.Element) { + topPackage = ((org.eclipse.uml2.uml.Element) element).getNearestPackage(); + } + } + if (topPackage != null) { + return topPackage.getAllAppliedProfiles(); + } + return Collections.emptyList(); + } + + /** + * Add drag support from the available tools viewer + */ + protected void addAvailableToolsDragSupport() { + // transfer types + Transfer[] transfers = new Transfer[] { LocalSelectionTransfer.getTransfer() }; + + // drag listener + DragSourceListener listener = new DragSourceAdapter() { + + /** + * {@inheritDoc} + */ + @Override + public void dragStart(DragSourceEvent event) { + super.dragStart(event); + event.data = availableToolsViewer.getSelection(); + } + + /** + * {@inheritDoc} + */ + @Override + public void dragSetData(DragSourceEvent event) { + super.dragSetData(event); + LocalSelectionTransfer.getTransfer().setSelection(availableToolsViewer.getSelection()); + } + + }; + + availableToolsViewer.addDragSupport(DND.DROP_LINK, transfers, listener); + } + + /** + * Adds elements to the tool bar for available tools viewer + * + * @param toolbar + * the toolbar to populate + */ + protected void populateAvailableToolsToolBar(ToolBar toolbar) { + toggleContentProvider = createCheckToolBarItem(toolbar, SWITCH_CONTENT_PROVIDER_ICON, Messages.Local_Palette_SwitchToolsContentProvider_Tooltip, createSwitchToolsContentProviderListener()); + toggleContentProvider.setSelection(true); + toggleContentProvider.setEnabled(false); + createCheckToolBarItem(toolbar, SHOWN_TOOLS_ICON, Messages.Local_Palette_ShowTools_Tooltip, createsShowToolListener()); + } + + /** + * Creates the listener for the available tools content provider + * + * @return the listener created + */ + protected Listener createSwitchToolsContentProviderListener() { + return new Listener() { + + /** + * {@inheritDoc} + */ + @Override + public void handleEvent(Event event) { + if (!(event.widget instanceof ToolItem)) { + return; + } + ToolItem item = ((ToolItem) event.widget); + // retrieve current profile selected in the combo profile + int index = profileCombo.getSelectionIndex(); + Collection<PaletteEntry> standardEntries = getAllVisibleStandardEntries(); + Profile profile = getAllAppliedProfiles().get(index); + + if (item.getSelection()) { + availableToolsViewer.setContentProvider(new ProfileToolsStereotypeMetaclassTreeContentProvider(profile, standardEntries)); + item.setSelection(true); + } else { + + availableToolsViewer.setContentProvider(new ProfileToolsMetaclassStereotypeTreeContentProvider(profile, standardEntries)); + item.setSelection(false); + } + + // generate tools for given profile + availableToolsViewer.setInput(profile); + } + }; + } + + /** + * creates the tool item for drawers visibility listener + * + * @return the listener for the tool button + */ + protected Listener createShowDrawerListener() { + return new Listener() { + + /** + * {@inheritDoc} + */ + @Override + public void handleEvent(Event event) { + if (!(event.widget instanceof ToolItem)) { + return; + } + ToolItem item = ((ToolItem) event.widget); + if (item.getSelection()) { + // elements should be hidden + availableToolsViewer.addFilter(drawerFilter); + item.setSelection(true); + } else { + availableToolsViewer.removeFilter(drawerFilter); + item.setSelection(false); + } + } + }; + } + + /** + * creates the tool item for tools visibility listener + * + * @return the listener for the tool button + */ + protected Listener createsShowToolListener() { + return new Listener() { + + /** + * {@inheritDoc} + */ + @Override + public void handleEvent(Event event) { + if (!(event.widget instanceof ToolItem)) { + return; + } + ToolItem item = ((ToolItem) event.widget); + if (item.getSelection()) { + // elements should be hidden + availableToolsViewer.addFilter(toolFilter); + item.setSelection(true); + } else { + availableToolsViewer.removeFilter(toolFilter); + item.setSelection(false); + } + } + }; + } + + /** + * Creates a toolbar item which can be checked. + * + * @param toolbar + * the parent toolbar + * @param shownElementsIcon + * path for shown elements icon + * @param listener + * listener for button action + * @param tooltip + * tooltip text for the toolbar item + */ + protected ToolItem createCheckToolBarItem(ToolBar toolbar, String shownElementsIcon, String tooltip, Listener listener) { + ToolItem item = new ToolItem(toolbar, SWT.CHECK | SWT.BORDER); + item.setImage(Activator.getPluginIconImage(Activator.ID, shownElementsIcon)); + item.setToolTipText(tooltip); + item.addListener(SWT.Selection, listener); + return item; + } + + /** + * Validates the content of the fields in this page + */ + protected boolean validatePage() { + boolean valid = true; + + if (valid) { + setMessage(null); + setErrorMessage(null); + } + return valid; + } + + /** + * The <code>WizardNewFileCreationPage</code> implementation of this <code>Listener</code> method handles all events and enablements for controls + * on this page. Subclasses may extend. + */ + @Override + public void handleEvent(Event event) { + setPageComplete(validatePage()); + } + + /** + * Content provider for available tools viewer + */ + public class UMLToolsTreeContentProvider implements ITreeContentProvider { + + /** + * Constructor + * + * @param viewer + * The viewer whose ContentProvider this content provider is + */ + public UMLToolsTreeContentProvider() { + } + + /** + * {@inheritDoc} + */ + @Override + public Object[] getElements(Object inputElement) { + Object[] elements = null; + + if (inputElement instanceof Collection<?>) { + elements = ((Collection<?>) inputElement).toArray(); + } else if (inputElement instanceof PaletteRoot) { + // paletteUil.getAllEntries(...) to add drawers + // if so, uncomment the addFilterbutton for drawers in populate tool bar + elements = PaletteUtil.getAllToolEntries(((PaletteRoot) inputElement)).toArray(); + } + + if (elements == null) { + elements = new Object[0]; + } + return elements; + } + + /** + * {@inheritDoc} + */ + @Override + public void dispose() { + } + + /** + * {@inheritDoc} + */ + @Override + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + + } + + /** + * {@inheritDoc} + */ + @Override + public Object[] getChildren(Object parentElement) { + Object[] elements = null; + + if (parentElement instanceof Collection<?>) { + elements = ((Collection<?>) parentElement).toArray(); + } else if (parentElement instanceof PaletteRoot) { + // paletteUil.getAllEntries(...) to add drawers + // if so, uncomment the addFilterbutton for drawers in populate tool bar + elements = PaletteUtil.getAllToolEntries(((PaletteRoot) parentElement)).toArray(); + } + + return elements; + } + + /** + * {@inheritDoc} + */ + @Override + public Object getParent(Object element) { + return null; + } + + /** + * {@inheritDoc} + */ + @Override + public boolean hasChildren(Object element) { + return getChildren(element) != null && getChildren(element).length > 0; + } + } + + /** + * Label provider for palette tools. + * <P> + * We should be using the Palette label provider from GEF, if it was not with visibility "package"... + * + * @see org.eclipse.gef.ui.palette.customize.PaletteLabelProvider + * </P> + * + */ + public class PaletteLabelProvider implements ILabelProvider { + + /** + * {@inheritDoc} + */ + @Override + public Image getImage(Object element) { + if (element instanceof PaletteEntry) { + ImageDescriptor descriptor = ((PaletteEntry) element).getSmallIcon(); + if (descriptor == null) { + return null; + } + return Activator.getPluginIconImage(Activator.ID, descriptor); + } else if (element instanceof Stereotype) { + return Activator.getPluginIconImage(Activator.ID, "/icons/stereotype.gif"); + } + return null; + } + + /** + * {@inheritDoc} + */ + @Override + public String getText(Object element) { + if (element instanceof PaletteEntry) { + return ((PaletteEntry) element).getLabel(); + } else if (element instanceof Stereotype) { + return ((Stereotype) element).getName(); + } + return "unknown element"; + } + + /** + * {@inheritDoc} + */ + @Override + public void addListener(ILabelProviderListener listener) { + + } + + /** + * {@inheritDoc} + */ + @Override + public void dispose() { + + } + + /** + * {@inheritDoc} + */ + @Override + public boolean isLabelProperty(Object element, String property) { + return false; + } + + /** + * {@inheritDoc} + */ + @Override + public void removeListener(ILabelProviderListener listener) { + + } + + } + + /** + * Label provider for palette tools. + * <P> + * We should be using the Palette label provider from GEF, if it was not with visibility "package"... + * + * @see org.eclipse.gef.ui.palette.customize.PaletteLabelProvider + * </P> + * + */ + public class ExtendedPaletteLabelProvider extends CustomizedLabelProvider { + + /** + * Constructor. + */ + public ExtendedPaletteLabelProvider() { + super(manager); + } + } + + /** + * Filter for the viewer. Hide/show Drawers + */ + public class DrawerFilter extends ViewerFilter { + + /** + * {@inheritDoc} + */ + @Override + public boolean select(Viewer viewer, Object parentElement, Object element) { + if (element instanceof PaletteDrawer) { + return false; + } + return true; + } + + } + + /** + * Filter for the viewer. Hide/show Drawers + */ + public class ToolFilter extends ViewerFilter { + + /** + * {@inheritDoc} + */ + @Override + public boolean select(Viewer viewer, Object parentElement, Object element) { + if (element instanceof ToolEntry) { + return false; + } + return true; + } + + } + + /** + * Content Provider for the palette preview + */ + public class ExtendedPaletteContentProvider extends CustomizedTreeContentProvider { + + private CustomizationCatalogManager catalogManager; + private ResourceSet catalogManagerResourceSet; + + /** + * Constructor. + */ + public ExtendedPaletteContentProvider() { + super(manager); + // TODO: EMFFACET refactor this code + catalogManagerResourceSet = new ResourceSetImpl(); + catalogManager = (CustomizationCatalogManager) ICustomizationCatalogManagerFactory.DEFAULT.getOrCreateCustomizationCatalogManager(catalogManagerResourceSet); + List<Customization> paletteCustomizations = catalogManager.getCustomizationsByName("PaletteConfiguration"); + if (paletteCustomizations.size() > 0) { + // manager.setShowTypeOfLinks(false); + // manager.registerCustomization(paletteCustomization); + // manager.loadCustomizations(); + } + } + + @Override + public void dispose() { + super.dispose(); + + if (catalogManagerResourceSet != null) { + EMFHelper.unload(catalogManagerResourceSet); + catalogManagerResourceSet = null; + } + + catalogManager = null; + } + + /** + * {@inheritDoc} + */ + @Override + public Object[] getRootElements(Object inputElement) { + if (inputElement instanceof PaletteConfiguration) { + return ((PaletteConfiguration) inputElement).getDrawerConfigurations().toArray(); + } else if (inputElement instanceof Resource) { + List<EObject> roots = ((Resource) inputElement).getContents(); + if (roots != null && !roots.isEmpty()) { + EObject rootObject = roots.get(0); + if (rootObject instanceof PaletteConfiguration) { + return ((PaletteConfiguration) rootObject).getDrawerConfigurations().toArray(); + } + } + } + return new Object[0]; + } + + /** + * {@inheritDoc} + */ + @Override + public boolean hasChildren(Object element) { + Object[] children = getChildren(element); + if (children == null) { + return false; + } + if (children.length == 0) { + return false; + } + return true; + } + } + + + /** + * Performs all action on finish + * + * @param id + * the path for the file + */ + public void performFinish(String path) { + if (resourceToEdit != null) { + try { + resourceToEdit.save(Collections.emptyMap()); + } catch (IOException e) { + Activator.log.error(e); + } + } + + // // creates the document + // Document document = createXMLDocumentFromPalettePreview(); + // saveDocument(document, path); + // requiredProfiles = collectRequiredProfiles(); + } + + // /** + // * collect the required profiles from all tool provided by the local palette definition + // */ + // protected Set<String> collectRequiredProfiles() { + // Set<String> profiles = new HashSet<String>(); + // PaletteContainerProxy rootProxy = (PaletteContainerProxy)paletteTreeViewer.getInput(); + // collectRequiredProfiles(rootProxy.getChildren(), profiles); + // return profiles; + // } + // + // /** + // * collect the required profiles from all tool provided by the local palette definition + // */ + // protected void collectRequiredProfiles(List<PaletteEntryProxy> proxies, Set<String> requiredProfiles) { + // for(PaletteEntryProxy proxy : proxies) { + // // add profile(s) if relevant, check for children + // + // if(proxy instanceof PaletteAspectToolEntryProxy) { + // // list of profiles + // for(String stereotypeQN : ((PaletteAspectToolEntryProxy)proxy).getStereotypesQNList()) { + // // retrieve list of profiles from the stereotype QN (only remove last segment + // // ?!) + // String profileName = PaletteUtil.findProfileNameFromStereotypeName(stereotypeQN); + // requiredProfiles.add(profileName); + // } + // } + // + // if(proxy.getChildren() != null) { + // collectRequiredProfiles(proxy.getChildren(), requiredProfiles); + // } + // } + // } + // + // /** + // * Saves the xml document into file + // * + // * @param document + // * the document to save + // * @param path + // * name of the file + // * @return the file created or updated + // */ + // protected File saveDocument(Document document, String path) { + // File file = null; + // try { + // // create the file that stores the XML configuration + // file = Activator.getDefault().getStateLocation().append(path).toFile(); + // TransformerFactory tranFactory = TransformerFactory.newInstance(); + // Transformer aTransformer; + // + // aTransformer = tranFactory.newTransformer(); + // + // Source src = new DOMSource(document); + // Result dest = new StreamResult(file); + // aTransformer.transform(src, dest); + // } catch (TransformerConfigurationException e) { + // Activator.log.error(e); + // } catch (TransformerException e) { + // Activator.log.error(e); + // } + // return file; + // + // } + // + // /** + // * Creates the document from the palette preview + // * + // * @return the dom structure of the document + // */ + // protected Document createXMLDocumentFromPalettePreview() { + // DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); + // documentBuilderFactory.setNamespaceAware(true); + // DocumentBuilder documentBuilder; + // try { + // documentBuilder = documentBuilderFactory.newDocumentBuilder(); + // document = documentBuilder.newDocument(); + // Element paletteDefElement = document.createElement(IPapyrusPaletteConstant.PALETTE_DEFINITION); + // document.appendChild(paletteDefElement); + // Element contentElement = document.createElement(IPapyrusPaletteConstant.CONTENT); + // paletteDefElement.appendChild(contentElement); + // + // generateXMLPaletteContent(document, contentElement); + // return document; + // } catch (ParserConfigurationException e) { + // Activator.getDefault().logError("impossible to create the palette tree viewer content", e); + // } + // return null; + // } + // + // /** + // * Generates the xml content for the palette + // * + // * @param document + // * the document to fill + // * @param contentElement + // * the root for the xml content + // */ + // protected void generateXMLPaletteContent(Document document, Element contentElement) { + // PaletteContainerProxy rootProxy = (PaletteContainerProxy)paletteTreeViewer.getInput(); + // for(PaletteEntryProxy proxy : rootProxy.getChildren()) { + // generateXMLPaletteContainerProxy(document, contentElement, proxy); + // } + // } + // + // /** + // * Generates the xml content for the given container + // * + // * @param document + // * the document to fill + // * @param containerProxy + // * the entry proxy + // */ + // protected void generateXMLPaletteContainerProxy(Document document, Element contentElement, PaletteEntryProxy containerProxy) { + // + // Element element = null; + // List<PaletteEntryProxy> children = containerProxy.getChildren(); + // // generate the element + // switch(containerProxy.getType()) { + // case DRAWER: + // element = document.createElement(IPapyrusPaletteConstant.DRAWER); + // element.setAttribute(IPapyrusPaletteConstant.NAME, containerProxy.getLabel()); + // if(containerProxy instanceof PaletteLocalDrawerProxy) { + // element.setAttribute(IPapyrusPaletteConstant.ICON_PATH, ((PaletteLocalDrawerProxy)containerProxy).getImagePath()); + // } + // break; + // case TOOL: + // element = document.createElement(IPapyrusPaletteConstant.TOOL); + // break; + // case SEPARATOR: + // element = document.createElement(IPapyrusPaletteConstant.SEPARATOR); + // break; + // case STACK: + // element = document.createElement(IPapyrusPaletteConstant.STACK); + // break; + // case ASPECT_TOOL: + // element = document.createElement(IPapyrusPaletteConstant.ASPECT_TOOL); + // // try to cast the element into PaletteAspectToolEntryProxy + // if(containerProxy instanceof PaletteAspectToolEntryProxy) { + // PaletteAspectToolEntryProxy aspectEntryProxy = (PaletteAspectToolEntryProxy)containerProxy; + // // element.setAttribute(IPapyrusPaletteConstant.ID, aspectEntryProxy.getId()); + // element.setAttribute(IPapyrusPaletteConstant.NAME, aspectEntryProxy.getLabel()); + // element.setAttribute(IPapyrusPaletteConstant.DESCRIPTION, aspectEntryProxy.getEntry().getDescription()); + // element.setAttribute(IPapyrusPaletteConstant.REF_TOOL_ID, aspectEntryProxy.getReferencedPaletteID()); + // + // if(aspectEntryProxy.getImagePath() != null && !aspectEntryProxy.getImagePath().equals("")) { + // element.setAttribute(IPapyrusPaletteConstant.ICON_PATH, aspectEntryProxy.getImagePath()); + // } + // + // + // // add post action, stereotype list + // for(IAspectAction action : ((PaletteAspectToolEntryProxy)containerProxy).getPostActions()) { + // Element postActionNode = document.createElement(IPapyrusPaletteConstant.POST_ACTION); + // postActionNode.setAttribute(IPapyrusPaletteConstant.ID, action.getFactoryId()); + // action.save(postActionNode); + // element.appendChild(postActionNode); + // } + // } + // default: + // break; + // } + // + // element.setAttribute(IPapyrusPaletteConstant.ID, containerProxy.getId()); + // contentElement.appendChild(element); + // + // if(children != null) { + // for(PaletteEntryProxy proxy : children) { + // generateXMLPaletteContainerProxy(document, element, proxy); + // } + // } + // } + + // public enum EntryType { + // DRAWER, TOOL, STACK, SEPARATOR, ASPECT_TOOL + // } + + + /** + * Comparator for the label viewers + */ + public class LabelViewerComparator extends ViewerComparator { + + /** + * Creates a new LabelViewerComparator. + */ + public LabelViewerComparator() { + super(); + } + + /** + * {@inheritDoc} + */ + @Override + public int compare(Viewer testViewer, Object e1, Object e2) { + String label1 = ""; + String label2 = ""; + + if (e1 instanceof PaletteEntry) { + label1 = ((PaletteEntry) e1).getLabel(); + } else if (e1 instanceof Stereotype) { + label1 = ((Stereotype) e1).getName(); + } + if (e2 instanceof PaletteEntry) { + label2 = ((PaletteEntry) e2).getLabel(); + } else if (e2 instanceof Stereotype) { + label2 = ((Stereotype) e2).getName(); + } + + if (label1 == null) { + return 1; + } + if (label2 == null) { + return -1; + } + + return label1.compareTo(label2); + } + } + + /** + * Listener for the profile combo. It changes the input of the following viewer. + */ + public class ProfileComboSelectionListener implements SelectionListener, ModifyListener { + + /** + * {@inheritDoc} + */ + @Override + public void widgetDefaultSelected(SelectionEvent e) { + // nothing to do + } + + /** + * {@inheritDoc} + */ + @Override + public void widgetSelected(SelectionEvent e) { + handleSelectionChanged(); + } + + /** + * {@inheritDoc} + */ + @Override + public void modifyText(ModifyEvent e) { + handleSelectionChanged(); + } + + /** + * handles the change selection for the combo + */ + protected void handleSelectionChanged() { + int index = profileCombo.getSelectionIndex(); + if (index < 0 || index >= profileCombo.getItems().length) { + return; + } + String name = profileComboList.get(index); + + Collection<PaletteEntry> standardEntries = getAllVisibleStandardEntries(); + // retrieve the profile or uml standards tools to display + if (UML_TOOLS_LABEL.equals(name)) { + // change content provider + availableToolsViewer.setContentProvider(new UMLToolsTreeContentProvider()); + availableToolsViewer.setInput(standardEntries); + toggleContentProvider.setEnabled(false); + } else { + if (toggleContentProvider != null && !toggleContentProvider.isDisposed()) { + toggleContentProvider.setEnabled(true); + } + // switch content provider + // this is a profile in case of uml2 tools + Profile profile = getAllAppliedProfiles().get(index); + if (toggleContentProvider.getSelection()) { + availableToolsViewer.setContentProvider(new ProfileToolsStereotypeMetaclassTreeContentProvider(profile, standardEntries)); + } else { + availableToolsViewer.setContentProvider(new ProfileToolsMetaclassStereotypeTreeContentProvider(profile, standardEntries)); + } + + // generate tools for given profile + availableToolsViewer.setInput(profile); + } + } + } + + /** + * Content provider for the available tools viewer, when the tools to see are coming from a + * profile + */ + public class ProfileToolsStereotypeMetaclassTreeContentProvider implements ITreeContentProvider { + + /** standard uml tools palette entries */ + final protected Collection<PaletteEntry> standardEntries; + + /** + * Creates a new ProfileToolsStereotypeMetaclassTreeContentProvider. + * + * @param profile + * the profile for which tools are built + * @param standardEntries + * list of standard uml tools palette entries + */ + public ProfileToolsStereotypeMetaclassTreeContentProvider(Profile profile, Collection<PaletteEntry> standardEntries) { + this.standardEntries = standardEntries; + } + + /** + * {@inheritDoc} + */ + @Override + public Object[] getChildren(Object parentElement) { + if (parentElement instanceof Profile) { + return ((Profile) parentElement).getOwnedStereotypes().toArray(); + } else if (parentElement instanceof Stereotype) { + List<PaletteEntry> entries = new ArrayList<PaletteEntry>(); + Stereotype stereotype = (Stereotype) parentElement; + + for (PaletteEntry entry : standardEntries) { + // retrieve the element type created by the tool. + if (entry instanceof CombinedTemplateCreationEntry) { + + EClass toolMetaclass = PaletteUtil.getToolMetaclass((CombinedTemplateCreationEntry) entry); + if (toolMetaclass != null) { + List<Class> metaclasses = stereotype.getAllExtendedMetaclasses(); + for (Class stMetaclass : metaclasses) { + // get Eclass + java.lang.Class<?> metaclassClass = stMetaclass.getClass(); + if (metaclassClass != null) { + EClassifier metaClassifier = UMLPackage.eINSTANCE.getEClassifier(stMetaclass.getName()); + if (((EClass) metaClassifier).isSuperTypeOf(toolMetaclass)) { + // should create the palette entry + Map<Object, Object> properties = new HashMap<Object, Object>(); + properties.put(IPapyrusPaletteConstant.ASPECT_ACTION_KEY, StereotypeAspectActionProvider.createConfigurationNode(stereotype.getQualifiedName())); + AspectCreationEntry aspectEntry = new AspectCreationEntry(stereotype.getName() + " (" + entry.getLabel() + ")", "Create an element with a stereotype", entry.getId() + "_" + System.currentTimeMillis(), + entry.getSmallIcon(), (CombinedTemplateCreationEntry) entry, properties); + entries.add(aspectEntry); + } + } + + } + } + } + } + return entries.toArray(); + } else { + return new Object[0]; + } + } + + /** + * {@inheritDoc} + */ + @Override + public Object getParent(Object element) { + if (element instanceof Stereotype) { + return ((Stereotype) element).getProfile(); + } + return null; + } + + /** + * {@inheritDoc} + */ + @Override + public boolean hasChildren(Object element) { + if (element instanceof Profile) { + return true; + } else if (element instanceof Stereotype) { + return true; + } + return false; + } + + /** + * {@inheritDoc} + */ + @Override + public Object[] getElements(Object inputElement) { + if (inputElement instanceof Profile) { + List<Stereotype> stereotypes = ((Profile) inputElement).getOwnedStereotypes(); + return stereotypes.toArray(); + } + return new Object[0]; + } + + /** + * {@inheritDoc} + */ + @Override + public void dispose() { + // nothing to do here + } + + /** + * {@inheritDoc} + */ + @Override + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + // nothing to do here + } + + } + + /** + * Content provider for the available tools viewer, when the + */ + public class ProfileToolsMetaclassStereotypeTreeContentProvider implements ITreeContentProvider { + + /** standard uml tools palette entries */ + final protected Collection<PaletteEntry> standardEntries; + + /** profile to display */ + final protected Profile profile; + + /** + * Creates a new ProfileToolsMetaclassStereotypeTreeContentProvider. + * + * @param profile + * the profile for which tools are built + * @param standardEntries + * list of standard uml tools palette entries + */ + public ProfileToolsMetaclassStereotypeTreeContentProvider(Profile profile, Collection<PaletteEntry> standardEntries) { + this.profile = profile; + this.standardEntries = standardEntries; + } + + /** + * {@inheritDoc} + */ + @Override + public Object[] getChildren(Object parentElement) { + if (parentElement instanceof Profile) { + return standardEntries.toArray(); + } else if (parentElement instanceof AspectCreationEntry) { + return new Object[0]; + } else if (parentElement instanceof PaletteEntry) { + List<AspectCreationEntry> entries = new ArrayList<AspectCreationEntry>(); + // display all stereotypes applicable to the type of element created by this tool + if (parentElement instanceof CombinedTemplateCreationEntry) { + CombinedTemplateCreationEntry entry = (CombinedTemplateCreationEntry) parentElement; + EClass toolMetaclass = PaletteUtil.getToolMetaclass(entry); + if (toolMetaclass != null) { + for (Stereotype stereotype : profile.getOwnedStereotypes()) { + List<Class> metaclasses = stereotype.getAllExtendedMetaclasses(); + for (Class stMetaclass : metaclasses) { + // get Eclass + EClassifier metaClassifier = UMLPackage.eINSTANCE.getEClassifier(stMetaclass.getName()); + if (((EClass) metaClassifier).isSuperTypeOf(toolMetaclass)) { + // should create the palette entry + Map<Object, Object> properties = new HashMap<Object, Object>(); + // ArrayList<String> stereotypesQNToApply = new ArrayList<String>(); + properties.put(IPapyrusPaletteConstant.ASPECT_ACTION_KEY, StereotypeAspectActionProvider.createConfigurationNode(stereotype.getQualifiedName())); + AspectCreationEntry aspectEntry = new AspectCreationEntry(stereotype.getName() + " (" + entry.getLabel() + ")", "Create an element with a stereotype", entry.getId() + "_" + System.currentTimeMillis(), entry.getSmallIcon(), + entry, properties); + entries.add(aspectEntry); + } + } + } + } + } + return entries.toArray(); + } else { + return new Object[0]; + } + } + + /** + * {@inheritDoc} + */ + @Override + public Object getParent(Object element) { + if (element instanceof Stereotype) { + return ((Stereotype) element).getProfile(); + } + return null; + } + + /** + * {@inheritDoc} + */ + @Override + public boolean hasChildren(Object element) { + if (element instanceof Profile) { + return true; + } else if (element instanceof AspectCreationEntry) { + return false; + } else if (element instanceof PaletteEntry) { + return true; + } + return false; + } + + /** + * {@inheritDoc} + */ + @Override + public Object[] getElements(Object inputElement) { + if (inputElement instanceof Profile) { + return standardEntries.toArray(); + } + return new Object[0]; + } + + /** + * {@inheritDoc} + */ + @Override + public void dispose() { + // nothing to do here + } + + /** + * {@inheritDoc} + */ + @Override + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + // nothing to do here + } + + } + + /** + * Returns the list of all visible palette entries + * + * @return the list of all visible palette entries + */ + protected Collection<PaletteEntry> getAllVisibleStandardEntries() { + HashSet<PaletteEntry> result = new HashSet<PaletteEntry>(); + for (PaletteEntry entry : PaletteUtil.getAvailableEntriesSet(editorPart, priority).values()) { + // the entry is not just a defineOnly entry but a visible one + if (getRootParent(entry) != null) { + result.add(entry); + } + } + return result; + } + + /** + * Returns the Root element for the palette entry. It searches recursively from parent to parent, until it find the root element + * + * @param entry + * the palette entry for which root element is searched + * @return the root element or <code>null</code> if none was found + */ + protected PaletteRoot getRootParent(PaletteEntry entry) { + PaletteContainer parent = entry.getParent(); + if (parent instanceof PaletteRoot) { + return (PaletteRoot) parent; + } else if (parent != null) { + return getRootParent(parent); + } else { + return null; + } + } + + /** + * Item validator + */ + protected abstract class ToolBarItemValidator { + + /** + * Checks if the button should be enable or not + * + * @return <code>true</code> if the button should be enable + */ + public abstract boolean isEnable(); + } + + /** + * validator for the create separator or stack tool item. Only valid when selection is a {@link Configuration} + */ + protected class ConfigurationSelectedValidator extends ToolBarItemValidator { + + /** + * @{inheritDoc + */ + @Override + public boolean isEnable() { + return getSelectedConfiguration() != null; + } + } + + /** + * validator for the create stack tool item. Only valid when selection is a {@link DrawerConfiguration} + */ + protected class DrawerConfigurationSelectedValidator extends ToolBarItemValidator { + + /** + * @{inheritDoc + */ + @Override + public boolean isEnable() { + return getSelectedConfiguration() instanceof DrawerConfiguration; + } + + } +} diff --git a/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/dialog/ExtendedPaletteInformationPage.java b/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/dialog/ExtendedPaletteInformationPage.java index a8e766aec7f..97161d322fc 100644 --- a/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/dialog/ExtendedPaletteInformationPage.java +++ b/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/dialog/ExtendedPaletteInformationPage.java @@ -1,460 +1,462 @@ -/*****************************************************************************
- * Copyright (c) 2009 CEA LIST.
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Remi Schnekenburger (CEA LIST) remi.schnekenburger@cea.fr - Initial API and implementation
- *
- *****************************************************************************/
-
-package org.eclipse.papyrus.customization.palette.dialog;
-
-import org.eclipse.gmf.runtime.common.core.service.ProviderPriority;
-import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditorWithFlyOutPalette;
-import org.eclipse.jface.dialogs.Dialog;
-import org.eclipse.jface.wizard.IWizardPage;
-import org.eclipse.jface.wizard.WizardPage;
-import org.eclipse.papyrus.uml.diagram.common.Activator;
-import org.eclipse.papyrus.uml.diagram.common.Messages;
-import org.eclipse.papyrus.uml.diagram.common.service.PapyrusPaletteService;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.SelectionAdapter;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Event;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Listener;
-import org.eclipse.swt.widgets.Text;
-import org.eclipse.swt.widgets.Widget;
-import org.eclipse.ui.IEditorPart;
-
-/**
- * Wizard page for information about the new local palette definition
- */
-public class ExtendedPaletteInformationPage extends WizardPage implements Listener {
-
- /** array list of priorities */
- private static String[] priorityList;
-
- /** text area for the name of the palette definition */
- protected Text nameText;
-
- /** text area for the id of the palette definition */
- protected Text idText;
-
- /** text area for the editor id of the palette definition */
- protected Text editorText;
-
- /** text for the priority of the provider */
- private Text priorityText;
-
- /** parent composite for advanced fields */
- protected Composite advancedComposite;
-
- /** Button to show/hide advanced fields */
- protected Button advancedButton;
-
- /** editor part in which the palette is created */
- protected IEditorPart editorPart;
-
- /** priority value */
- protected ProviderPriority priority;
-
- /** editor ID value */
- protected String editorID;
-
- /** palette ID */
- protected String paletteID;
-
- /** palette name */
- protected String name;
-
- /** path to the icon */
- protected static final String WIZARD_ICON = "/icons/local_desc_wiz.png";
-
- /** validate on opening */
- protected boolean validateOnLaunch = false;
-
- static {
- priorityList = new String[] { ProviderPriority.LOWEST.getName(), ProviderPriority.LOW.getName(), ProviderPriority.MEDIUM.getName(), ProviderPriority.HIGH.getName(), ProviderPriority.HIGHEST.getName() };
- }
-
- /**
- * Creates a new wizard page with the given name, title, and image.
- *
- * @param part
- * the editor part in which the wizard was created
- */
- public ExtendedPaletteInformationPage(IEditorPart part) {
- super(Messages.Local_Palette_InfoPage_Name, Messages.Local_Palette_InfoPage_Title, Activator.getImageDescriptor(WIZARD_ICON));
- this.editorPart = part;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public IWizardPage getNextPage() {
- ExtendedPaletteContentPage contentPage = (ExtendedPaletteContentPage) super.getNextPage();
- if (priority != null) {
- contentPage.setPriority(priority);
- contentPage.profileCombo.deselectAll();
- contentPage.profileCombo.select(contentPage.profileCombo.getItems().length - 1); // select the last one (UML)
- }
- return contentPage;
- }
-
- /**
- * {@inheritDoc}
- */
- public void createControl(Composite parent) {
-
- // initialize dialog units
- initializeDialogUnits(parent);
-
- // Create a new composite as there is the title bar seperator
- // to deal with
- Composite control = new Composite(parent, SWT.NONE);
- GridLayout layout = new GridLayout(2, false);
- control.setLayout(layout);
- control.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
- setControl(control);
-
- createNameControl(control);
-
- createAdvancedControls(control);
-
- // end of the control creation
- Dialog.applyDialogFont(control);
-
- // Show description on opening
- setErrorMessage(null);
- setMessage(null);
- if (validateOnLaunch) {
- setPageComplete(validatePage());
- }
- setControl(control);
- }
-
- /**
- * initializes fields using context information
- */
- public void intializeValues() {
- initName("");
- String editorIDValue = "";
- if (editorPart instanceof DiagramEditorWithFlyOutPalette) {
- editorIDValue = ((DiagramEditorWithFlyOutPalette) editorPart).getContributorId();
- }
- initEditorID(editorIDValue);
- initPaletteID(System.getProperty("user.name") + "_" + System.currentTimeMillis());
- initPriority(ProviderPriority.LOWEST);
- }
-
- /**
- * initializes fields using existing descriptor
- */
- public void intializeValues(PapyrusPaletteService.ExtendedProviderDescriptor descriptor) {
- initName(descriptor.getContributionName());
- String editorIDValue = "";
- if (editorPart instanceof DiagramEditorWithFlyOutPalette) {
- editorIDValue = ((DiagramEditorWithFlyOutPalette) editorPart).getContributorId();
- }
- initEditorID(editorIDValue);
- initPaletteID(descriptor.getContributionID());
- initPriority(descriptor.getPriority());
- validateOnLaunch = true;
- }
-
- /**
- * Returns the current value of palette name
- *
- * @return the current value of palette name
- */
- public String getPaletteName() {
- return name;
- }
-
- /**
- * Returns the current value of palette ID
- *
- * @return the current value of palette ID
- */
- public String getPaletteID() {
- return paletteID;
- }
-
- /**
- * Returns the current value of editor ID
- *
- * @return the current value of editor ID
- */
- public String getEditorID() {
- return editorID;
- }
-
- /**
- * Returns the current value of editor ID
- *
- * @return the current value of editor ID
- */
- public ProviderPriority getPalettePriority() {
- return priority;
- }
-
- /**
- * inits the name field value
- *
- * @param value
- * value to set
- */
- protected void initName(String value) {
- name = value;
- }
-
- /**
- * inits the priority value
- *
- * @param value
- * value to set
- */
- protected void initPriority(ProviderPriority value) {
- this.priority = value; // by default, Medium
- }
-
- /**
- * inits the palette id value
- *
- * @param value
- * value to set
- */
- protected void initPaletteID(String value) {
- paletteID = value;
-
- }
-
- /**
- * inits the editor id value
- *
- * @param value
- * value to set
- */
- protected void initEditorID(String value) {
- editorID = value;
- }
-
- /**
- * Validates the content of the fields in this page
- */
- protected boolean validatePage() {
- boolean valid = true;
- if (advancedComposite != null && !advancedComposite.isDisposed()) {
- if ("".equals(getPaletteID())) {
- setErrorMessage(Messages.Local_Palette_Error_PaletteId);
- valid = false;
- }
- }
-
- if ("".equals(getPaletteName())) {
- setErrorMessage(Messages.Local_Palette_Error_Name);
- valid = false;
- }
-
- if (valid) {
- setMessage(null);
- setErrorMessage(null);
- }
- return valid;
- }
-
- /**
- * Creates the widget for advanced options.
- *
- * @param parent
- * the parent composite
- */
- protected void createAdvancedControls(Composite parent) {
- advancedButton = new Button(parent, SWT.PUSH);
- advancedButton.setFont(parent.getFont());
- advancedButton.setText(Messages.Dialog_Advanced_Button_Closed);
- GridData data = setButtonLayoutData(advancedButton);
- data.horizontalAlignment = GridData.BEGINNING;
- data.horizontalSpan = 2;
- advancedButton.setLayoutData(data);
- advancedButton.addSelectionListener(new SelectionAdapter() {
-
- @Override
- public void widgetSelected(SelectionEvent e) {
- handleAdvancedButtonSelect();
- }
- });
- }
-
- public Composite createAdvancedComposite(Composite parent) {
- advancedComposite = new Composite(parent, SWT.NONE);
- advancedComposite.setFont(parent.getFont());
- advancedComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
- GridLayout layout = new GridLayout(2, false);
- layout.marginHeight = 0;
- layout.marginWidth = 0;
- advancedComposite.setLayout(layout);
-
- createIDControl(advancedComposite);
-
- createEditorIDControl(advancedComposite);
-
- createPriorityControl(advancedComposite);
-
- advancedComposite.getParent().layout();
- return advancedComposite;
- }
-
- /**
- * Shows/hides the advanced option widgets.
- */
- protected void handleAdvancedButtonSelect() {
- Composite composite = (Composite) getControl();
-
- if (advancedComposite != null) {
- advancedComposite.dispose();
- advancedComposite = null;
- advancedButton.setText(Messages.Dialog_Advanced_Button_Closed);
- } else {
- createAdvancedComposite(composite);
- advancedButton.setText(Messages.Dialog_Advanced_Button_Opened);
- }
- }
-
- /**
- * creates the control area for the priority
- *
- * @param control
- * the parent composite
- */
- protected void createPriorityControl(Composite control) {
- final Label priorityLabel = new Label(control, SWT.NONE);
- priorityLabel.setText(Messages.Local_Palette_Priority);
- priorityLabel.setToolTipText(Messages.Local_Palette_Priority_Tooltip);
-
- // choice widget among priority values
- priorityText = new Text(control, SWT.READ_ONLY | SWT.BORDER);
- priorityText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
- // initialize
- initialPopulatePriorityField();
-
- }
-
- /**
- * intialize the field using current value of the palette id
- */
- protected void initialPopulatePriorityField() {
- priorityText.setText(this.getPalettePriority().toString());
- }
-
- /**
- * creates the control area for the id definition
- *
- * @param control
- * the parent composite
- */
- protected void createIDControl(Composite control) {
- final Label idLabel = new Label(control, SWT.NONE);
- idLabel.setText(Messages.Local_Palette_Id);
- idLabel.setToolTipText(Messages.Local_Palette_Id_Tooltip);
-
- idText = new Text(control, SWT.BORDER);
- idText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
- idText.setToolTipText(Messages.Local_Palette_Id_Tooltip);
-
- // initialize, then add the listener...
- initialPopulatePaletteIDField();
-
- idText.addListener(SWT.Modify, this);
- }
-
- /**
- * intialize the field using current value of the palette id
- */
- protected void initialPopulatePaletteIDField() {
- idText.setText(paletteID);
- }
-
- /**
- * creates the control area for the name definition
- *
- * @param control
- * the parent composite
- */
- protected void createNameControl(Composite control) {
- final Label nameLabel = new Label(control, SWT.NONE);
- nameLabel.setText(Messages.Local_Palette_Name);
- nameLabel.setToolTipText(Messages.Local_Palette_Name_Tooltip);
-
- nameText = new Text(control, SWT.BORDER);
- nameText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
- nameText.setToolTipText(Messages.Local_Palette_Name_Tooltip);
-
- // initialize, then add the listener...
- initialPopulateNameField();
-
- nameText.addListener(SWT.Modify, this);
-
- }
-
- /**
- * creates the control area for the name definition
- *
- * @param control
- * the parent composite
- */
- protected void createEditorIDControl(Composite control) {
- final Label editorLabel = new Label(control, SWT.NONE);
- editorLabel.setText(Messages.Local_Palette_Editor_Id);
- editorLabel.setToolTipText(Messages.Local_Palette_Editor_Id_Tooltip);
-
- editorText = new Text(control, SWT.BORDER | SWT.READ_ONLY);
- editorText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
- editorText.setToolTipText(Messages.Local_Palette_Editor_Id_Tooltip);
-
- // initialize, then add the listener...
- initialPopulateEditorIDField();
-
- }
-
- /**
- * intialize the field using current value of the editor id
- */
- protected void initialPopulateEditorIDField() {
- editorText.setText(editorID);
- }
-
- /**
- * initialize name field
- */
- protected void initialPopulateNameField() {
- nameText.setText(name);
- }
-
- /**
- * The <code>WizardNewFileCreationPage</code> implementation of this <code>Listener</code> method handles all events and enablements for controls
- * on this page. Subclasses may extend.
- */
- public void handleEvent(Event event) {
- Widget widget = event.widget;
- if (widget.equals(nameText)) {
- name = nameText.getText();
- } else if (widget.equals(idText)) {
- paletteID = idText.getText();
- } else if (widget.equals(editorText)) {
- editorID = editorText.getText();
- }
- setPageComplete(validatePage());
- }
-
-}
+/***************************************************************************** + * Copyright (c) 2009 CEA LIST. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Remi Schnekenburger (CEA LIST) remi.schnekenburger@cea.fr - Initial API and implementation + * + *****************************************************************************/ + +package org.eclipse.papyrus.customization.palette.dialog; + +import org.eclipse.gmf.runtime.common.core.service.ProviderPriority; +import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditorWithFlyOutPalette; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.wizard.IWizardPage; +import org.eclipse.jface.wizard.WizardPage; +import org.eclipse.papyrus.customization.palette.Messages; +import org.eclipse.papyrus.uml.diagram.common.Activator; +import org.eclipse.papyrus.uml.diagram.common.service.PapyrusPaletteService; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.swt.widgets.Text; +import org.eclipse.swt.widgets.Widget; +import org.eclipse.ui.IEditorPart; + +/** + * Wizard page for information about the new local palette definition + */ +public class ExtendedPaletteInformationPage extends WizardPage implements Listener { + + /** array list of priorities */ + private static String[] priorityList; + + /** text area for the name of the palette definition */ + protected Text nameText; + + /** text area for the id of the palette definition */ + protected Text idText; + + /** text area for the editor id of the palette definition */ + protected Text editorText; + + /** text for the priority of the provider */ + private Text priorityText; + + /** parent composite for advanced fields */ + protected Composite advancedComposite; + + /** Button to show/hide advanced fields */ + protected Button advancedButton; + + /** editor part in which the palette is created */ + protected IEditorPart editorPart; + + /** priority value */ + protected ProviderPriority priority; + + /** editor ID value */ + protected String editorID; + + /** palette ID */ + protected String paletteID; + + /** palette name */ + protected String name; + + /** path to the icon */ + protected static final String WIZARD_ICON = "/icons/local_desc_wiz.png"; + + /** validate on opening */ + protected boolean validateOnLaunch = false; + + static { + priorityList = new String[] { ProviderPriority.LOWEST.getName(), ProviderPriority.LOW.getName(), ProviderPriority.MEDIUM.getName(), ProviderPriority.HIGH.getName(), ProviderPriority.HIGHEST.getName() }; + } + + /** + * Creates a new wizard page with the given name, title, and image. + * + * @param part + * the editor part in which the wizard was created + */ + public ExtendedPaletteInformationPage(IEditorPart part) { + super(Messages.Local_Palette_InfoPage_Name, Messages.Local_Palette_InfoPage_Title, Activator.getImageDescriptor(WIZARD_ICON)); + this.editorPart = part; + } + + /** + * {@inheritDoc} + */ + @Override + public IWizardPage getNextPage() { + ExtendedPaletteContentPage contentPage = (ExtendedPaletteContentPage) super.getNextPage(); + if (priority != null) { + contentPage.setPriority(priority); + contentPage.profileCombo.deselectAll(); + contentPage.profileCombo.select(contentPage.profileCombo.getItems().length - 1); // select the last one (UML) + } + return contentPage; + } + + /** + * {@inheritDoc} + */ + @Override + public void createControl(Composite parent) { + + // initialize dialog units + initializeDialogUnits(parent); + + // Create a new composite as there is the title bar seperator + // to deal with + Composite control = new Composite(parent, SWT.NONE); + GridLayout layout = new GridLayout(2, false); + control.setLayout(layout); + control.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + setControl(control); + + createNameControl(control); + + createAdvancedControls(control); + + // end of the control creation + Dialog.applyDialogFont(control); + + // Show description on opening + setErrorMessage(null); + setMessage(null); + if (validateOnLaunch) { + setPageComplete(validatePage()); + } + setControl(control); + } + + /** + * initializes fields using context information + */ + public void intializeValues() { + initName(""); + String editorIDValue = ""; + if (editorPart instanceof DiagramEditorWithFlyOutPalette) { + editorIDValue = ((DiagramEditorWithFlyOutPalette) editorPart).getContributorId(); + } + initEditorID(editorIDValue); + initPaletteID(System.getProperty("user.name") + "_" + System.currentTimeMillis()); + initPriority(ProviderPriority.LOWEST); + } + + /** + * initializes fields using existing descriptor + */ + public void intializeValues(PapyrusPaletteService.ExtendedProviderDescriptor descriptor) { + initName(descriptor.getContributionName()); + String editorIDValue = ""; + if (editorPart instanceof DiagramEditorWithFlyOutPalette) { + editorIDValue = ((DiagramEditorWithFlyOutPalette) editorPart).getContributorId(); + } + initEditorID(editorIDValue); + initPaletteID(descriptor.getContributionID()); + initPriority(descriptor.getPriority()); + validateOnLaunch = true; + } + + /** + * Returns the current value of palette name + * + * @return the current value of palette name + */ + public String getPaletteName() { + return name; + } + + /** + * Returns the current value of palette ID + * + * @return the current value of palette ID + */ + public String getPaletteID() { + return paletteID; + } + + /** + * Returns the current value of editor ID + * + * @return the current value of editor ID + */ + public String getEditorID() { + return editorID; + } + + /** + * Returns the current value of editor ID + * + * @return the current value of editor ID + */ + public ProviderPriority getPalettePriority() { + return priority; + } + + /** + * inits the name field value + * + * @param value + * value to set + */ + protected void initName(String value) { + name = value; + } + + /** + * inits the priority value + * + * @param value + * value to set + */ + protected void initPriority(ProviderPriority value) { + this.priority = value; // by default, Medium + } + + /** + * inits the palette id value + * + * @param value + * value to set + */ + protected void initPaletteID(String value) { + paletteID = value; + + } + + /** + * inits the editor id value + * + * @param value + * value to set + */ + protected void initEditorID(String value) { + editorID = value; + } + + /** + * Validates the content of the fields in this page + */ + protected boolean validatePage() { + boolean valid = true; + if (advancedComposite != null && !advancedComposite.isDisposed()) { + if ("".equals(getPaletteID())) { + setErrorMessage(Messages.Local_Palette_Error_PaletteId); + valid = false; + } + } + + if ("".equals(getPaletteName())) { + setErrorMessage(Messages.Local_Palette_Error_Name); + valid = false; + } + + if (valid) { + setMessage(null); + setErrorMessage(null); + } + return valid; + } + + /** + * Creates the widget for advanced options. + * + * @param parent + * the parent composite + */ + protected void createAdvancedControls(Composite parent) { + advancedButton = new Button(parent, SWT.PUSH); + advancedButton.setFont(parent.getFont()); + advancedButton.setText(Messages.Dialog_Advanced_Button_Closed); + GridData data = setButtonLayoutData(advancedButton); + data.horizontalAlignment = GridData.BEGINNING; + data.horizontalSpan = 2; + advancedButton.setLayoutData(data); + advancedButton.addSelectionListener(new SelectionAdapter() { + + @Override + public void widgetSelected(SelectionEvent e) { + handleAdvancedButtonSelect(); + } + }); + } + + public Composite createAdvancedComposite(Composite parent) { + advancedComposite = new Composite(parent, SWT.NONE); + advancedComposite.setFont(parent.getFont()); + advancedComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1)); + GridLayout layout = new GridLayout(2, false); + layout.marginHeight = 0; + layout.marginWidth = 0; + advancedComposite.setLayout(layout); + + createIDControl(advancedComposite); + + createEditorIDControl(advancedComposite); + + createPriorityControl(advancedComposite); + + advancedComposite.getParent().layout(); + return advancedComposite; + } + + /** + * Shows/hides the advanced option widgets. + */ + protected void handleAdvancedButtonSelect() { + Composite composite = (Composite) getControl(); + + if (advancedComposite != null) { + advancedComposite.dispose(); + advancedComposite = null; + advancedButton.setText(Messages.Dialog_Advanced_Button_Closed); + } else { + createAdvancedComposite(composite); + advancedButton.setText(Messages.Dialog_Advanced_Button_Opened); + } + } + + /** + * creates the control area for the priority + * + * @param control + * the parent composite + */ + protected void createPriorityControl(Composite control) { + final Label priorityLabel = new Label(control, SWT.NONE); + priorityLabel.setText(Messages.Local_Palette_Priority); + priorityLabel.setToolTipText(Messages.Local_Palette_Priority_Tooltip); + + // choice widget among priority values + priorityText = new Text(control, SWT.READ_ONLY | SWT.BORDER); + priorityText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + // initialize + initialPopulatePriorityField(); + + } + + /** + * intialize the field using current value of the palette id + */ + protected void initialPopulatePriorityField() { + priorityText.setText(this.getPalettePriority().toString()); + } + + /** + * creates the control area for the id definition + * + * @param control + * the parent composite + */ + protected void createIDControl(Composite control) { + final Label idLabel = new Label(control, SWT.NONE); + idLabel.setText(Messages.Local_Palette_Id); + idLabel.setToolTipText(Messages.Local_Palette_Id_Tooltip); + + idText = new Text(control, SWT.BORDER); + idText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + idText.setToolTipText(Messages.Local_Palette_Id_Tooltip); + + // initialize, then add the listener... + initialPopulatePaletteIDField(); + + idText.addListener(SWT.Modify, this); + } + + /** + * intialize the field using current value of the palette id + */ + protected void initialPopulatePaletteIDField() { + idText.setText(paletteID); + } + + /** + * creates the control area for the name definition + * + * @param control + * the parent composite + */ + protected void createNameControl(Composite control) { + final Label nameLabel = new Label(control, SWT.NONE); + nameLabel.setText(Messages.Local_Palette_Name); + nameLabel.setToolTipText(Messages.Local_Palette_Name_Tooltip); + + nameText = new Text(control, SWT.BORDER); + nameText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + nameText.setToolTipText(Messages.Local_Palette_Name_Tooltip); + + // initialize, then add the listener... + initialPopulateNameField(); + + nameText.addListener(SWT.Modify, this); + + } + + /** + * creates the control area for the name definition + * + * @param control + * the parent composite + */ + protected void createEditorIDControl(Composite control) { + final Label editorLabel = new Label(control, SWT.NONE); + editorLabel.setText(Messages.Local_Palette_Editor_Id); + editorLabel.setToolTipText(Messages.Local_Palette_Editor_Id_Tooltip); + + editorText = new Text(control, SWT.BORDER | SWT.READ_ONLY); + editorText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + editorText.setToolTipText(Messages.Local_Palette_Editor_Id_Tooltip); + + // initialize, then add the listener... + initialPopulateEditorIDField(); + + } + + /** + * intialize the field using current value of the editor id + */ + protected void initialPopulateEditorIDField() { + editorText.setText(editorID); + } + + /** + * initialize name field + */ + protected void initialPopulateNameField() { + nameText.setText(name); + } + + /** + * The <code>WizardNewFileCreationPage</code> implementation of this <code>Listener</code> method handles all events and enablements for controls + * on this page. Subclasses may extend. + */ + @Override + public void handleEvent(Event event) { + Widget widget = event.widget; + if (widget.equals(nameText)) { + name = nameText.getText(); + } else if (widget.equals(idText)) { + paletteID = idText.getText(); + } else if (widget.equals(editorText)) { + editorID = editorText.getText(); + } + setPageComplete(validatePage()); + } + +} diff --git a/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/dialog/LocalPaletteContentPage.java b/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/dialog/LocalPaletteContentPage.java index be95152f88b..0a54c6f1bc7 100644 --- a/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/dialog/LocalPaletteContentPage.java +++ b/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/dialog/LocalPaletteContentPage.java @@ -1,2487 +1,2548 @@ -/*****************************************************************************
- * Copyright (c) 2009, 2014 CEA LIST, Christian W. Damus, and others.
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Remi Schnekenburger (CEA LIST) remi.schnekenburger@cea.fr - Initial API and implementation
- * Christian W. Damus - bug 454578
- *
- *****************************************************************************/
-package org.eclipse.papyrus.customization.palette.dialog;
-
-import java.beans.PropertyChangeEvent;
-import java.beans.PropertyChangeListener;
-import java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.transform.Result;
-import javax.xml.transform.Source;
-import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerConfigurationException;
-import javax.xml.transform.TransformerException;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.dom.DOMSource;
-import javax.xml.transform.stream.StreamResult;
-
-import org.eclipse.emf.common.util.URI;
-import org.eclipse.emf.ecore.EClass;
-import org.eclipse.emf.ecore.EClassifier;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.util.EcoreUtil;
-import org.eclipse.gef.palette.CombinedTemplateCreationEntry;
-import org.eclipse.gef.palette.PaletteContainer;
-import org.eclipse.gef.palette.PaletteDrawer;
-import org.eclipse.gef.palette.PaletteEntry;
-import org.eclipse.gef.palette.PaletteRoot;
-import org.eclipse.gef.palette.PaletteStack;
-import org.eclipse.gef.palette.PaletteToolbar;
-import org.eclipse.gef.palette.ToolEntry;
-import org.eclipse.gef.ui.palette.PaletteCustomizer;
-import org.eclipse.gmf.runtime.common.core.service.ProviderPriority;
-import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditorWithFlyOutPalette;
-import org.eclipse.jface.dialogs.Dialog;
-import org.eclipse.jface.resource.ImageDescriptor;
-import org.eclipse.jface.util.LocalSelectionTransfer;
-import org.eclipse.jface.viewers.AbstractTreeViewer;
-import org.eclipse.jface.viewers.DoubleClickEvent;
-import org.eclipse.jface.viewers.IDoubleClickListener;
-import org.eclipse.jface.viewers.ILabelProvider;
-import org.eclipse.jface.viewers.ILabelProviderListener;
-import org.eclipse.jface.viewers.ISelectionChangedListener;
-import org.eclipse.jface.viewers.ISelectionProvider;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.ITreeContentProvider;
-import org.eclipse.jface.viewers.ITreeSelection;
-import org.eclipse.jface.viewers.SelectionChangedEvent;
-import org.eclipse.jface.viewers.TreeSelection;
-import org.eclipse.jface.viewers.TreeViewer;
-import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.jface.viewers.ViewerComparator;
-import org.eclipse.jface.viewers.ViewerFilter;
-import org.eclipse.jface.wizard.WizardDialog;
-import org.eclipse.jface.wizard.WizardPage;
-import org.eclipse.osgi.util.NLS;
-import org.eclipse.papyrus.customization.palette.proxies.XMLPaletteDefinitionProxyFactory;
-import org.eclipse.papyrus.uml.diagram.common.Activator;
-import org.eclipse.papyrus.uml.diagram.common.Messages;
-import org.eclipse.papyrus.uml.diagram.common.part.PaletteUtil;
-import org.eclipse.papyrus.uml.diagram.common.part.PapyrusPalettePreferences;
-import org.eclipse.papyrus.uml.diagram.common.service.AspectCreationEntry;
-import org.eclipse.papyrus.uml.diagram.common.service.IPapyrusPaletteConstant;
-import org.eclipse.papyrus.uml.diagram.common.service.PapyrusPaletteService;
-import org.eclipse.papyrus.uml.diagram.common.service.XMLPaletteDefinitionWalker;
-import org.eclipse.papyrus.uml.diagram.common.service.palette.IAspectAction;
-import org.eclipse.papyrus.uml.diagram.common.service.palette.StereotypeAspectActionProvider;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.dnd.DND;
-import org.eclipse.swt.dnd.DragSourceAdapter;
-import org.eclipse.swt.dnd.DragSourceEvent;
-import org.eclipse.swt.dnd.DragSourceListener;
-import org.eclipse.swt.dnd.DropTargetEvent;
-import org.eclipse.swt.dnd.DropTargetListener;
-import org.eclipse.swt.dnd.Transfer;
-import org.eclipse.swt.dnd.TreeDropTargetEffect;
-import org.eclipse.swt.events.ModifyEvent;
-import org.eclipse.swt.events.ModifyListener;
-import org.eclipse.swt.events.MouseEvent;
-import org.eclipse.swt.events.MouseListener;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Combo;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Event;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Listener;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.swt.widgets.ToolBar;
-import org.eclipse.swt.widgets.ToolItem;
-import org.eclipse.swt.widgets.Tree;
-import org.eclipse.swt.widgets.TreeItem;
-import org.eclipse.ui.IEditorPart;
-import org.eclipse.uml2.uml.Class;
-import org.eclipse.uml2.uml.Package;
-import org.eclipse.uml2.uml.Profile;
-import org.eclipse.uml2.uml.Stereotype;
-import org.eclipse.uml2.uml.UMLPackage;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.xml.sax.SAXException;
-
-/**
- * Wizard page for information about the new local palette definition
- */
-public class LocalPaletteContentPage extends WizardPage implements Listener {
-
- /** editor part in which the palette is created */
- protected IEditorPart editorPart;
-
- /** available tools viewer */
- protected TreeViewer availableToolsViewer;
-
- /** label provider for the tree viewer */
- protected PaletteLabelProvider paletteLabelProvider;
-
- /** icon path when tools are hidden */
- protected static final String HIDDEN_TOOLS_ICON = "/icons/tools_hidden.gif";
-
- /** icon path when tools are shown */
- protected static final String SHOWN_TOOLS_ICON = "/icons/tools_shown.gif";
-
- /** path to the icon */
- protected static final String WIZARD_ICON = "/icons/local_desc_wiz.png";
-
- /** icon path when drawers are hidden */
- protected static final String SHOWN_DRAWERS_ICON = "/icons/drawers_shown.gif";
-
- /** icon path when drawers are shown */
- protected static final String HIDDEN_DRAWERS_ICON = "/icons/drawers_hidden.gif";
-
- /** icon path for the add button */
- protected static final String ADD_ICON = "/icons/arrow_right.gif";
-
- /** icon path for the remove button */
- protected static final String REMOVE_ICON = "/icons/arrow_left.gif";
-
- /** icon path for the delete button */
- protected static final String DELETE_ICON = "/icons/delete.gif";
-
- /** icon path for the create drawer button */
- protected static final String CREATE_DRAWERS_ICON = "/icons/new_drawer.gif";
-
- /** icon path for the create separator button */
- protected String CREATE_SEPARATOR_ICON = "/icons/separator.gif";
-
- /** icon path for the create stack button */
- protected String CREATE_STACK_ICON = "/icons/stack.gif";
-
- /** icon path for the delete drawer button */
- protected static final String DELETE_DRAWERS_ICON = "/icons/delete.gif";
-
- /** icon for the content provider switch button */
- protected String SWITCH_CONTENT_PROVIDER_ICON = "/icons/switch_provider.gif";
-
- /** label for the standard tools */
- protected static final String UML_TOOLS_LABEL = "UML tools";
-
- /** icon path for the edit drawer button */
- protected static final String EDIT_ICON = "/icons/obj16/file.gif";
-
- /** instance of the filter used to show/hide drawers */
- protected final ViewerFilter drawerFilter = new DrawerFilter();
-
- /** instance of the filter used to show/hide tools */
- protected final ViewerFilter toolFilter = new ToolFilter();
-
- /** stored preferences */
- protected List<String> storedPreferences;
-
- /** add button */
- protected Button addButton;
-
- /** remove button */
- protected Button removeButton;
-
- /** tree viewer for the new palette */
- protected TreeViewer paletteTreeViewer;
-
- /** document for element creation */
- protected Document document;
-
- /** content node for the palette viewer */
- protected PaletteContainerProxy contentNode;
-
- /** combo to select which profile tools should be visible */
- protected Combo profileCombo;
-
- /** list of profiles that can provide tools */
- protected List<String> profileComboList = new ArrayList<String>();
-
- /** tool item in charge of toggling content providers in the available tool viewer */
- protected ToolItem toggleContentProvider;
-
- /** required profile by this palette */
- protected Set<String> requiredProfiles;
-
- /** palette customizer used for the palette */
- protected PaletteCustomizer customizer;
-
- /** current selected entry proxy */
- protected PaletteEntryProxy selectedEntryProxy;
-
- /** class in charge of the information composite */
- protected PaletteEntryProxyInformationComposite informationComposite = new PaletteEntryProxyInformationComposite();
-
- /** class in charge of the aspect tool information composite */
- protected AspectActionsInformationComposite aspectActionComposite = new AspectActionsInformationComposite();
-
- protected ToolBar toolbar;
-
- /** validator key for toolbar items */
- protected final static String VALIDATOR = "validator";
-
- /** priority of the current edited palette */
- protected ProviderPriority priority;
-
-
- /**
- * Creates a new wizard page with the given name, title, and image.
- *
- * @param part
- * the editor part in which the wizard was created
- */
- public LocalPaletteContentPage(IEditorPart part, PaletteCustomizer customizer) {
- super(Messages.Local_Palette_ContentPage_Name, Messages.Local_Palette_ContentPage_Title, Activator.getImageDescriptor(WIZARD_ICON));
- this.editorPart = part;
- this.customizer = customizer;
- }
-
- /**
- * {@inheritDoc}
- */
- public void createControl(Composite parent) {
-
- // initialize dialog units
- initializeDialogUnits(parent);
-
- // Create a new composite as there is the title bar seperator
- // to deal with
- Composite control = new Composite(parent, SWT.NONE);
- GridLayout layout = new GridLayout(4, false);
- control.setLayout(layout);
- control.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
- setControl(control);
-
- // create Available Tools Group
- createAvailableToolsGroup();
-
- // create add/remove buttons
- createAddRemoveButtons();
-
- // create Palette Group
- createPalettePreviewGroup();
-
- // create tool description group (custom name, description, and perhaphs icon.... Just under this group, another one with aspect actions)
- createToolDescriptionGroup();
-
- // just under, creates a new line of composites...
- createAspectActionComposite();
-
-
-
- // add listeners inter-groups
- ISelectionChangedListener listener = createToolsViewerSelectionChangeListener();
- availableToolsViewer.addSelectionChangedListener(listener);
- paletteTreeViewer.addSelectionChangedListener(listener);
-
- // end of the control creation
- Dialog.applyDialogFont(control);
-
- validatePage();
- // Show description on opening
- setErrorMessage(null);
- setMessage(null);
- setControl(control);
- }
-
- /**
- * Creates the composite group that presents information about ascpect actions for aspect tools
- */
- protected void createAspectActionComposite() {
- aspectActionComposite.createComposite((Composite) getControl(), getAllAppliedProfiles());
- }
-
- /**
- * Creates the composite group that presents information about current selected tool
- */
- protected void createToolDescriptionGroup() {
- informationComposite.createComposite((Composite) getControl(), getAllAppliedProfiles());
- }
-
- /**
- * update the preferences to have all tools accessible
- */
- protected void updatePreferences() {
- // change => set to no hidden palettes
- storedPreferences = PapyrusPalettePreferences.getHiddenPalettes(editorPart);
-
- // remove all, but should only remove visible palettes
- for (String id : storedPreferences) {
- PapyrusPalettePreferences.changePaletteVisibility(id, editorPart, true);
- }
- }
-
- /**
- * Restore preferences
- */
- public void restorePreferences() {
- // remove all, but should only remove visible palettes
- for (String id : storedPreferences) {
- PapyrusPalettePreferences.changePaletteVisibility(id, editorPart, false);
- }
- }
-
- /**
- * creates the palette preview group
- */
- protected void createPalettePreviewGroup() {
- Composite parent = (Composite) getControl();
- Composite paletteComposite = new Composite(parent, SWT.NONE);
-
- GridLayout layout = new GridLayout(2, true);
- layout.marginHeight = 0;
- layout.marginWidth = 0;
- paletteComposite.setLayout(layout);
- GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
- paletteComposite.setLayoutData(data);
-
- Label label = new Label(paletteComposite, SWT.NONE);
- label.setText(Messages.Local_Palette_Palette_Preview);
- data = new GridData(SWT.LEFT, SWT.CENTER, true, false);
- label.setLayoutData(data);
-
- toolbar = new ToolBar(paletteComposite, SWT.HORIZONTAL);
- data = new GridData(SWT.RIGHT, SWT.FILL, false, false);
- toolbar.setLayoutData(data);
- populatePalettePreviewToolBar(toolbar);
-
- Tree tree = new Tree(paletteComposite, SWT.SINGLE | SWT.BORDER);
- data = new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1);
- data.widthHint = 185;
- // Make the tree this tall even when there is nothing in it. This will keep the
- // dialog from shrinking to an unusually small size.
- data.heightHint = 200;
- tree.setLayoutData(data);
- paletteTreeViewer = new TreeViewer(tree);
- paletteTreeViewer.setContentProvider(new PaletteContentProvider(paletteTreeViewer));
- paletteTreeViewer.setLabelProvider(new PaletteProxyLabelProvider());
- paletteTreeViewer.addSelectionChangedListener(new ISelectionChangedListener() {
-
- public void selectionChanged(SelectionChangedEvent event) {
- handlePalettePreviewSelectionChanged(event);
- }
- });
-
- addPalettePreviewDropSupport();
- addPalettePreviewDragSupport();
- addPalettePreviewEditSupport();
-
- paletteTreeViewer.setInput(contentNode);
- }
-
- /**
- * handle the selection change event for the palette preview
- *
- * @param event
- * the event that is thrown by the palette viewer
- */
- protected void handlePalettePreviewSelectionChanged(SelectionChangedEvent event) {
- // retrieve current selection
- ITreeSelection selection = (TreeSelection) event.getSelection();
- Object firstSelected = selection.getFirstElement();
- if (firstSelected instanceof PaletteEntryProxy) {
- // update the current selected palette entry proxy
- selectedEntryProxy = ((PaletteEntryProxy) firstSelected);
- informationComposite.setSelectedEntryProxy(selectedEntryProxy);
- aspectActionComposite.setSelectedEntryProxy(selectedEntryProxy);
- }
-
- // update toolbar
- if (toolbar != null && !toolbar.isDisposed()) {
- for (int i = 0; i < toolbar.getItemCount(); i++) {
- ToolItem item = toolbar.getItem(i);
- Object validator = item.getData(VALIDATOR);
- if (validator instanceof ToolBarItemValidator) {
- item.setEnabled(((ToolBarItemValidator) validator).isEnable());
- }
- }
- }
-
- }
-
- /**
- * @{inheritDoc
- */
- @Override
- public void dispose() {
- super.dispose();
- }
-
- /**
- * Adds the behavior for the double click strategy
- */
- protected void addPalettePreviewEditSupport() {
- paletteTreeViewer.addDoubleClickListener(new IDoubleClickListener() {
-
- /**
- * {@inheritDoc}
- */
- public void doubleClick(DoubleClickEvent event) {
- // retrieve current item double clicked...
- ITreeSelection selection = (TreeSelection) event.getSelection();
- Object firstSelected = selection.getFirstElement();
- if (firstSelected instanceof PaletteLocalDrawerProxy) {
- UpdateLocalDrawerWizard wizard = new UpdateLocalDrawerWizard(((PaletteLocalDrawerProxy) firstSelected).getParent(), (PaletteLocalDrawerProxy) firstSelected);
- WizardDialog dialog = new WizardDialog(getShell(), wizard);
- dialog.open();
- // paletteTreeViewer.refresh();
- }
- }
- });
-
- }
-
- /**
- * Add drop behavior for the palette preview
- */
- protected void addPalettePreviewDropSupport() {
- // transfer types
- Transfer[] transfers = new Transfer[] { LocalSelectionTransfer.getTransfer() };
-
- // drag listener
- DropTargetListener listener = new TreeDropTargetEffect(paletteTreeViewer.getTree()) {
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void drop(DropTargetEvent event) {
- super.drop(event);
-
- // create proxy and adds it to its target parent
- PaletteEntryProxy target = (PaletteEntryProxy) ((TreeItem) event.item).getData();
- if (target == null) {
- target = (PaletteContainerProxy) paletteTreeViewer.getInput();
- }
-
- // get the elements from the drag listener (either a palette entry or a palette
- // entry proxy)
- IStructuredSelection transferedSelection = (IStructuredSelection) LocalSelectionTransfer.getTransfer().getSelection();
- Object entry = transferedSelection.getFirstElement();
-
- // creates the proxy for the element to be dropped
- PaletteEntryProxy entryProxy = createNodeFromEntry(entry);
-
- if (entryProxy == null) {
- return;
- }
- if (target instanceof PaletteContainerProxy) {
- // tries to remove from its parent if possible
- if (entryProxy.getParent() != null) {
- entryProxy.getParent().removeChild(entryProxy);
- }
- ((PaletteContainerProxy) target).addChild(entryProxy);
- paletteTreeViewer.expandToLevel(target, 1);
- } else if (target instanceof PaletteEntryProxy) {
- // tries to remove from its parent if possible
- if (entryProxy.getParent() != null) {
- entryProxy.getParent().removeChild(entryProxy);
- }
- target.getParent().addChild(entryProxy, target);
- paletteTreeViewer.expandToLevel(target.getParent(), 1);
- } else {
- // add to parent...
- target.getParent().addChild(entryProxy);
- paletteTreeViewer.expandToLevel(target.getParent(), AbstractTreeViewer.ALL_LEVELS);
- }
- setPageComplete(validatePage());
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void dragOver(DropTargetEvent event) {
- super.dragOver(event);
-
- LocalSelectionTransfer localTransfer = LocalSelectionTransfer.getTransfer();
- IStructuredSelection transferedSelection = null;
- if (localTransfer.isSupportedType(event.currentDataType)) {
- transferedSelection = (IStructuredSelection) localTransfer.getSelection();
- }
-
- // check selection is compatible for drop target
-
- TreeItem item = paletteTreeViewer.getTree().getItem(paletteTreeViewer.getTree().toControl(new Point(event.x, event.y)));
-
- checkSelectionForDrop(transferedSelection, item, event);
- }
- };
-
- paletteTreeViewer.addDropSupport(DND.DROP_LINK | DND.DROP_MOVE, transfers, listener);
- }
-
- /**
- * Adds drag ability to the palette preview composite
- */
- protected void addPalettePreviewDragSupport() {
-
- // transfer types
- Transfer[] transfers = new Transfer[] { LocalSelectionTransfer.getTransfer() };
-
- // drag listener
- DragSourceListener listener = new LocalSelectionDragSource(paletteTreeViewer);
-
- paletteTreeViewer.addDragSupport(DND.DROP_MOVE, transfers, listener);
- }
-
- /**
- * Checks if the selection can be added to the target widget
- *
- * @param transferedSelection
- * the selection to be dropped
- * @param widget
- * the widget where to drop
- * @return <code>true</code> if element can be dropped
- */
- protected void checkSelectionForDrop(IStructuredSelection transferedSelection, TreeItem item, DropTargetEvent event) {
- event.detail = DND.DROP_NONE;
-
- if (transferedSelection == null) {
- return;
- }
-
- Object entry = transferedSelection.getFirstElement();
- // handle only first selected element
- if (item == null) {
- // adding to the root, should only be a drawer
- if (entry instanceof PaletteDrawer) {
- event.detail = DND.DROP_LINK;
- }
- } else {
- PaletteEntryProxy targetProxy = (PaletteEntryProxy) item.getData();
- switch (targetProxy.getType()) {
- case DRAWER:
- if (entry instanceof ToolEntry) {
- event.detail = DND.DROP_LINK;
- } else if (entry instanceof PaletteEntryProxy) {
- event.detail = DND.DROP_MOVE;
- }
- break;
- case STACK:
- if (entry instanceof ToolEntry) {
- event.detail = DND.DROP_LINK;
- } else if (entry instanceof PaletteEntryProxy && !(entry instanceof PaletteLocalStackProxy)) {
- event.detail = DND.DROP_MOVE;
- }
- break;
- case TOOL:
- if (entry instanceof ToolEntry) {
- event.detail = DND.DROP_LINK; // add the selected tool before the destination
- // tool
- } else if (entry instanceof PaletteEntryProxy) {
- event.detail = DND.DROP_MOVE; // moves the element before the entry
- }
- break;
- case SEPARATOR:
- if (entry instanceof PaletteEntryProxy) {
- event.detail = DND.DROP_MOVE;
- }
- break;
- default:
- break;
- }
- }
- }
-
- /**
- * Sets an empty content for the palette preview
- */
- public void initializeContent() {
- contentNode = new PaletteContainerProxy(null);
-
- // adds a default local drawer
- PaletteLocalDrawerProxy proxy = new PaletteLocalDrawerProxy("Default", generateID("Drawer_"), "/icons/drawer.gif", "Default Drawer");
- contentNode.addChild(proxy);
-
- setPageComplete(false);
- }
-
- /**
- * Sets the initial content for the palette preview
- */
- public void initializeContent(PapyrusPaletteService.LocalProviderDescriptor descriptor) {
- // retrieve the xml definition file
- String xmlPath = PapyrusPalettePreferences.getPalettePathFromID(descriptor.getContributionID());
-
- // parse the content file
- DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
- documentBuilderFactory.setNamespaceAware(true);
- try {
- DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
-
- // Bundle bundle = Platform.getBundle(pluginID);
- // URL url = bundle.getEntry(path);
-
- File file = Activator.getDefault().getStateLocation().append(xmlPath).toFile();
- if (!file.exists()) {
- Activator.log.error("Impossible to load file: " + file, null);
- } else {
- Document document = documentBuilder.parse(file);
- Map<String, PaletteEntry> entries = PaletteUtil.getAvailableEntriesSet(editorPart, ProviderPriority.HIGHEST);
-
- XMLPaletteDefinitionProxyFactory factory = new XMLPaletteDefinitionProxyFactory(entries);
- XMLPaletteDefinitionWalker walker = new XMLPaletteDefinitionWalker(factory);
-
- for (int i = 0; i < document.getChildNodes().getLength(); i++) {
- Node node = document.getChildNodes().item(i);
- if (IPapyrusPaletteConstant.PALETTE_DEFINITION.equals(node.getNodeName())) {
- walker.walk(node);
- }
- }
- contentNode = factory.getRootProxy();
-
- // tells that the page can be closed directly without modifying the palette
- setPageComplete(true);
- return;
- }
- } catch (ParserConfigurationException e) {
- Activator.log.error(e);
- } catch (IOException e) {
- Activator.log.error(e);
- } catch (SAXException e) {
- Activator.log.error(e);
- }
-
- // paletteTreeViewer.setInput(contentNode);
- contentNode = new PaletteContainerProxy(null);
- }
-
- /**
- * Saves the xml document into file
- *
- * @param document
- * the document to save
- * @param path
- * name of the file
- * @return the file created or updated
- */
- protected File loadDocument(Document document, String path) {
- File file = null;
- try {
- // create the file that stores the XML configuration
- file = Activator.getDefault().getStateLocation().append(path).toFile();
- Transformer aTransformer = TransformerFactory.newInstance().newTransformer();
-
- Source src = new DOMSource(document);
- Result dest = new StreamResult(file);
- aTransformer.transform(src, dest);
- } catch (TransformerConfigurationException e) {
- Activator.log.error(e);
- } catch (TransformerException e) {
- Activator.log.error(e);
- }
- return file;
-
- }
-
- /**
- * populates the preview palette toolbar
- *
- * @param toolbar
- * the toolbar to populate
- */
- protected void populatePalettePreviewToolBar(ToolBar toolbar) {
- PaletteEntryProxySelectedValidator validator = new PaletteEntryProxySelectedValidator();
- createToolBarItem(toolbar, DELETE_ICON, Messages.PapyrusPaletteCustomizerDialog_RemoveButtonTooltip, createRemoveElementListener(), validator);
- createToolBarItem(toolbar, EDIT_ICON, Messages.PapyrusPaletteCustomizerDialog_EditButtonTooltip, createEditElementListener(), new EditElementToolBarItemValidator());
- createToolBarItem(toolbar, CREATE_DRAWERS_ICON, Messages.Local_Palette_Create_Drawer_Tooltip, createNewDrawerListener(), null);
- createToolBarItem(toolbar, CREATE_SEPARATOR_ICON, Messages.Local_Palette_Create_Separator_Tooltip, createNewSeparatorListener(), validator);
- createToolBarItem(toolbar, CREATE_STACK_ICON, Messages.Local_Palette_Create_Stack_Tooltip, createNewStackListener(), validator);
- }
-
- /**
- * Edits the current selected elements. This works for drawers, should work on more elements
- *
- * @return the listener for the edit button
- */
- protected Listener createEditElementListener() {
- return new Listener() {
-
- /**
- * {@inheritDoc}
- */
- public void handleEvent(Event event) {
- IStructuredSelection selection = (IStructuredSelection) paletteTreeViewer.getSelection();
- if (selection == null || selection.size() < 1) {
- return;
- }
-
- Object selected = selection.getFirstElement();
- if (selected instanceof PaletteLocalDrawerProxy) {
- UpdateLocalDrawerWizard wizard = new UpdateLocalDrawerWizard(((PaletteLocalDrawerProxy) selected).getParent(), (PaletteLocalDrawerProxy) selected);
- WizardDialog dialog = new WizardDialog(getShell(), wizard);
- dialog.open();
- }
-
- // paletteTreeViewer.refresh();
- }
- };
- }
-
- /**
- * Creates the listener for the remove item(s) button
- *
- * @return the listener for the remove button
- */
- protected Listener createRemoveElementListener() {
- return new Listener() {
-
- /**
- * {@inheritDoc}
- */
- public void handleEvent(Event event) {
- IStructuredSelection selection = (IStructuredSelection) paletteTreeViewer.getSelection();
- if (selection == null || selection.size() < 1) {
- return;
- }
-
- Iterator<?> it = selection.iterator();
- while (it.hasNext()) {
- Object o = it.next();
- if (o instanceof PaletteEntryProxy) {
- PaletteEntryProxy proxyToDelete = (PaletteEntryProxy) o;
- // create a new entry in the document
- // get container of the proxy to be deleted
- PaletteContainerProxy parentProxy = proxyToDelete.getParent();
- if (parentProxy != null) {
- parentProxy.removeChild(proxyToDelete);
- }
- }
- }
- // paletteTreeViewer.refresh();
- }
- };
- }
-
- /**
- * Creates the listener for the new drawer tool item
- *
- * @return the listener created
- */
- protected Listener createNewDrawerListener() {
- return new Listener() {
-
- /**
- * {@inheritDoc}
- */
- public void handleEvent(Event event) {
- // retrieve selected container
- PaletteContainerProxy containerProxy;
- containerProxy = (PaletteContainerProxy) paletteTreeViewer.getInput();
- NewDrawerWizard wizard = new NewDrawerWizard(containerProxy);
- WizardDialog wizardDialog = new WizardDialog(new Shell(), wizard);
- wizardDialog.open();
- // paletteTreeViewer.refresh();
- setPageComplete(validatePage());
- }
- };
- }
-
- /**
- * Creates the listener for the new stack tool item
- *
- * @return the listener created
- */
- protected Listener createNewStackListener() {
- return new Listener() {
-
- /**
- * {@inheritDoc}
- */
- public void handleEvent(Event event) {
- // retrieve selected element
- Object object = ((IStructuredSelection) paletteTreeViewer.getSelection()).getFirstElement();
-
- // if element = drawer => the new stack must be created at the end of the drawer's
- // children list
- // if element = tool => must be placed before this tool
- // else : nothinng to do
- if (object instanceof PaletteLocalDrawerProxy) {
- String id = generateID("Stack");
- PaletteLocalStackProxy proxy = new PaletteLocalStackProxy(id);
- ((PaletteLocalDrawerProxy) object).addChild(proxy);
- } else if (object instanceof PaletteEntryProxy) {
- String id = generateID("Stack");
- PaletteLocalStackProxy proxy = new PaletteLocalStackProxy(id);
- // retrieve parent
- PaletteEntryProxy childProxy = (PaletteEntryProxy) object;
- PaletteContainerProxy parentProxy = childProxy.getParent();
- parentProxy.addChild(proxy, childProxy);
- }
-
- // paletteTreeViewer.refresh();
- setPageComplete(validatePage());
- }
- };
- }
-
- /**
- * Generates the ID for a local element
- *
- * @param base
- * the begining of the id
- * @return the separator id
- */
- protected String generateID(String base) {
- StringBuffer id = new StringBuffer();
- id.append(base);
- id.append("_");
- id.append(System.currentTimeMillis());
-
- return id.toString();
- }
-
- /**
- * Creates the listener for the new separator tool item
- *
- * @return the listener created
- */
- protected Listener createNewSeparatorListener() {
- return new Listener() {
-
- /**
- * {@inheritDoc}
- */
- public void handleEvent(Event event) {
- // retrieve selected element
- Object object = ((IStructuredSelection) paletteTreeViewer.getSelection()).getFirstElement();
-
- // if element = drawer => the new stack must be created at the end of the drawer's
- // children list
- // if element = tool => must be placed before this tool
- // else : nothinng to do
- if (object instanceof PaletteLocalDrawerProxy) {
- String id = generateID("Separator");
- PaletteLocalSeparatorProxy proxy = new PaletteLocalSeparatorProxy(id);
- ((PaletteLocalDrawerProxy) object).addChild(proxy);
- } else if (object instanceof PaletteEntryProxy) {
- String id = generateID("Separator");
- PaletteLocalSeparatorProxy proxy = new PaletteLocalSeparatorProxy(id);
- // retrieve parent
- PaletteEntryProxy childProxy = (PaletteEntryProxy) object;
- PaletteContainerProxy parentProxy = childProxy.getParent();
- parentProxy.addChild(proxy, childProxy);
- }
-
- setPageComplete(validatePage());
- }
- };
- }
-
- /**
- * Creates a toolbar item.
- *
- * @param toolbar
- * the parent toolbar
- * @param itemIcon
- * path for icon
- * @param tooltip
- * tooltip text for the toolbar item
- * @param listener
- * listener for tool bar item
- */
- protected void createToolBarItem(ToolBar toolbar, String itemIcon, String tooltip, Listener listener, ToolBarItemValidator validator) {
- ToolItem item = new ToolItem(toolbar, SWT.BORDER);
- item.setImage(Activator.getPluginIconImage(Activator.ID, itemIcon));
- item.setToolTipText(tooltip);
- item.addListener(SWT.Selection, listener);
- item.setData(VALIDATOR, validator);
- }
-
- /**
- * creates the buttons to add/remove entries
- */
- protected void createAddRemoveButtons() {
- Composite composite = new Composite((Composite) getControl(), SWT.NONE);
- GridLayout layout = new GridLayout(1, true);
- composite.setLayout(layout);
-
- GridData data = new GridData(SWT.CENTER, SWT.CENTER, false, true);
- composite.setLayoutData(data);
-
- addButton = new Button(composite, SWT.NONE);
- addButton.setImage(Activator.getPluginIconImage(Activator.ID, ADD_ICON));
- addButton.setToolTipText(Messages.PapyrusPaletteCustomizerDialog_AddButtonTooltip);
- addButton.addMouseListener(createAddButtonListener());
- addButton.setEnabled(false);
- addButton.addListener(SWT.MouseUp, this);
-
- removeButton = new Button(composite, SWT.NONE);
- removeButton.setImage(Activator.getPluginIconImage(Activator.ID, REMOVE_ICON));
- removeButton.setToolTipText(Messages.PapyrusPaletteCustomizerDialog_RemoveButtonTooltip);
- removeButton.addMouseListener(createRemoveButtonListener());
- removeButton.setEnabled(false);
- removeButton.addListener(SWT.MouseUp, this);
- }
-
- /**
- * selection listener for the tools viewer , to update the state of the add button
- *
- * @return the new created selection listener
- */
- protected ISelectionChangedListener createToolsViewerSelectionChangeListener() {
- return new ISelectionChangedListener() {
-
- /**
- * {@inheritDoc}
- */
- public void selectionChanged(SelectionChangedEvent event) {
-
- // get source and target selection
- // check source entry can be added to target entry
- Object source = ((IStructuredSelection) availableToolsViewer.getSelection()).getFirstElement();
- Object target = ((IStructuredSelection) paletteTreeViewer.getSelection()).getFirstElement();
-
- // manage add button
- if (isAddValidTarget(source, target)) {
- addButton.setEnabled(true);
- } else {
- addButton.setEnabled(false);
- }
-
- // manage remove button
- if (isRemoveValidSource(target)) {
- removeButton.setEnabled(true);
- } else {
- removeButton.setEnabled(false);
- }
-
- }
-
- /**
- * Returns true if the source can be added to the target
- *
- * @param source
- * the source object
- * @param target
- * the target object
- * @return <code>true</code> if the source can be added to the target
- */
- protected boolean isAddValidTarget(Object source, Object target) {
- if (!(source instanceof PaletteEntry)) {
- return false;
- }
-
- // case1: source is a drawer.
- // it can only be added to the root element (no selection)
- // case2: source is a palette tool
- // it can't be added to the root element
- // it can only be added to a container element (drawer or stack)
- if (source instanceof PaletteDrawer) {
- if (target == null) {
- return true;
- }
- return false;
- } else if (source instanceof ToolEntry) {
- if (target instanceof PaletteEntryProxy) {
- EntryType type = ((PaletteEntryProxy) target).getType();
- switch (type) {
- case DRAWER:
- case STACK:
- return true;
- default:
- return false;
- }
- }
- return false;
- }
- return false;
- }
-
- /**
- * Returns true if the source can be added to the target
- *
- * @param source
- * the source object
- * @return <code>true</code> if the source can be removed (not null and instanceof
- * PaletteEntryProxy)
- */
- protected boolean isRemoveValidSource(Object source) {
- if (source instanceof PaletteEntryProxy) {
- return true;
- }
- return false;
- }
- };
-
- }
-
- /**
- * Creates the add button listener
- */
- protected MouseListener createAddButtonListener() {
- return new MouseListener() {
-
- public void mouseUp(MouseEvent e) {
- // add the element selected on the left to the right tree
- // check the selection.
- IStructuredSelection selection = (IStructuredSelection) availableToolsViewer.getSelection();
- if (selection == null || selection.size() < 1) {
- return;
- }
- PaletteEntry entry = (PaletteEntry) selection.getFirstElement();
- if (entry == null) {
- return;
- }
-
- // find the selection on the right
- selection = (IStructuredSelection) paletteTreeViewer.getSelection();
-
- PaletteEntryProxy parentNode = (PaletteEntryProxy) selection.getFirstElement();
- // Bugfix: only drawers can be added to root element
- if (parentNode == null && entry instanceof PaletteDrawer) {
- parentNode = (PaletteContainerProxy) paletteTreeViewer.getInput();
- }
-
- // check we have a containe here
- if (!(parentNode instanceof PaletteContainerProxy)) {
- return;
- }
-
- // create a new entry in the document
- PaletteEntryProxy proxy = createNodeFromEntry(entry);
- ((PaletteContainerProxy) parentNode).addChild(proxy);
-
- paletteTreeViewer.expandToLevel(parentNode, 1);
- }
-
- /**
- * {@inheritDoc}
- */
- public void mouseDown(MouseEvent e) {
- // do nothing
- }
-
- /**
- * {@inheritDoc}
- */
- public void mouseDoubleClick(MouseEvent e) {
- // do nothing
- }
- };
- }
-
- /**
- * Creates a node in the xml document from the given entry
- *
- * @param entry
- * the palette entry from which to create the node
- * @param parentNode
- * the parent node for the newly created node
- * @return the created entry proxy or <code>null</code>
- */
- protected PaletteEntryProxy createNodeFromEntry(Object entry) {
- PaletteEntryProxy entryProxy = null;
-
- if (entry instanceof AspectCreationEntry) {
- // should modify id of the element here, otherwise, different elements would have the same id...
- entryProxy = new PaletteAspectToolEntryProxy(((AspectCreationEntry) entry).clone());
- } else if (entry instanceof CombinedTemplateCreationEntry) {
- CombinedTemplateCreationEntry originalEntry = (CombinedTemplateCreationEntry) entry;
- // create a new Aspect entry proxy
- AspectCreationEntry aspectEntry = new AspectCreationEntry(originalEntry.getLabel(), originalEntry.getDescription(), originalEntry.getId() + "_" + System.currentTimeMillis(), originalEntry.getSmallIcon(), originalEntry,
- new HashMap<Object, Object>());
- entryProxy = new PaletteAspectToolEntryProxy(aspectEntry);
- } else if (entry instanceof PaletteContainer) {
- entryProxy = new PaletteContainerProxy((PaletteContainer) entry);
- } else if (entry instanceof PaletteEntryProxy) {
- entryProxy = ((PaletteEntryProxy) entry);
- }
- return entryProxy;
- }
-
- /**
- * Creates the add button listener
- */
- protected MouseListener createRemoveButtonListener() {
- return new MouseListener() {
-
- public void mouseUp(MouseEvent e) {
- // remove the element selected on the right
- // add the element selected on the left to the right tree
- // check the selection.
- IStructuredSelection selection = (IStructuredSelection) paletteTreeViewer.getSelection();
- if (selection == null || selection.size() < 1) {
- return;
- }
- PaletteEntryProxy proxyToDelete = (PaletteEntryProxy) selection.getFirstElement();
- if (proxyToDelete == null) {
- return;
- }
-
- // create a new entry in the document
- // get container of the proxy to be deleted
- PaletteContainerProxy parentProxy = proxyToDelete.getParent();
- parentProxy.removeChild(proxyToDelete);
- }
-
- /**
- * {@inheritDoc}
- */
- public void mouseDown(MouseEvent e) {
- // do nothing
- }
-
- /**
- * {@inheritDoc}
- */
- public void mouseDoubleClick(MouseEvent e) {
- // do nothing
- }
- };
- }
-
- /**
- * creates the available entries group
- */
- protected void createAvailableToolsGroup() {
- Composite parent = (Composite) getControl();
- Composite availableToolsComposite = new Composite(parent, SWT.NONE);
- GridLayout layout = new GridLayout(2, true);
- layout.marginHeight = 0;
- layout.marginWidth = 0;
- availableToolsComposite.setLayout(layout);
- GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
- availableToolsComposite.setLayoutData(data);
-
- Label label = new Label(availableToolsComposite, SWT.NONE);
- label.setText(Messages.Local_Palette_Available_Tools);
- data = new GridData(SWT.LEFT, SWT.CENTER, true, false);
- label.setLayoutData(data);
-
- ToolBar toolbar = new ToolBar(availableToolsComposite, SWT.HORIZONTAL);
- data = new GridData(SWT.RIGHT, SWT.FILL, false, false);
- toolbar.setLayoutData(data);
- populateAvailableToolsToolBar(toolbar);
-
- createProfileCombo(availableToolsComposite);
-
- Tree tree = new Tree(availableToolsComposite, SWT.SINGLE | SWT.BORDER);
- data = new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1);
- data.widthHint = 185;
- // Make the tree this tall even when there is nothing in it. This will keep the
- // dialog from shrinking to an unusually small size.
- data.heightHint = 200;
- tree.setLayoutData(data);
- availableToolsViewer = new TreeViewer(tree);
- availableToolsViewer.setContentProvider(new UMLToolsTreeContentProvider());
- paletteLabelProvider = new PaletteLabelProvider();
- availableToolsViewer.setLabelProvider(paletteLabelProvider);
- ViewerComparator labelComparator = new LabelViewerComparator();
- availableToolsViewer.setComparator(labelComparator);
- // remove the note stack and standard group
- availableToolsViewer.addFilter(new ViewerFilter() {
-
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean select(Viewer viewer, Object parentElement, Object element) {
- if (element instanceof PaletteStack && "noteStack".equals(((PaletteStack) element).getId())) {
- return false;
- } else if (element instanceof PaletteToolbar && "standardGroup".equals(((PaletteToolbar) element).getId())) {
- return false;
- }
- return true;
- }
- });
- availableToolsViewer.addFilter(new DrawerFilter());
- // add drag support
- addAvailableToolsDragSupport();
- // availableToolsViewer.setInput(getAllVisibleStandardEntries());
- }
-
- /**
- * Creates the profile combo
- *
- * @param availableToolsComposite
- * the available tools composite
- * @return the created combo
- */
- protected Combo createProfileCombo(Composite availableToolsComposite) {
- // retrieve top package, to know which profiles are available
- // creates the combo
- profileCombo = new Combo(availableToolsComposite, SWT.BORDER | SWT.READ_ONLY);
- GridData data = new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1);
- profileCombo.setLayoutData(data);
-
- // retrieve all applied profiles
- List<Profile> profiles = getAllAppliedProfiles();
-
- int profileNumber = profiles.size();
- for (int i = 0; i < profileNumber; i++) {
- String name;
- if (profiles.get(i).eIsProxy()) {
- name = NLS.bind("<unresolved: {0}>", URI.decode(EcoreUtil.getURI(profiles.get(i)).lastSegment()));
- } else {
- name = profiles.get(i).getName();
- if (name == null) {
- name = NLS.bind("<unnamed: {0}>", URI.decode(EcoreUtil.getURI(profiles.get(i)).lastSegment()));
- }
- }
- profileComboList.add(i, name);
- }
- profileComboList.add(UML_TOOLS_LABEL);
- profileCombo.setItems(profileComboList.toArray(new String[] {}));
-
- // add selection listener for the combo. selects the "UML tools" item
- ProfileComboSelectionListener listener = new ProfileComboSelectionListener();
- profileCombo.addSelectionListener(listener);
- profileCombo.addModifyListener(listener);
- // profileCombo.select(profileNumber);
-
- return profileCombo;
- }
-
- /**
- * returns the list of applied profile for the nearest package of the top element
- *
- * @return the list of applied profile for the nearest package of the top element or an empty
- * list
- */
- protected List<Profile> getAllAppliedProfiles() {
- Package topPackage = null;
- if (editorPart instanceof DiagramEditorWithFlyOutPalette) {
- EObject element = ((DiagramEditorWithFlyOutPalette) editorPart).getDiagram().getElement();
- if (element instanceof org.eclipse.uml2.uml.Element) {
- topPackage = ((org.eclipse.uml2.uml.Element) element).getNearestPackage();
- }
- }
- if (topPackage != null) {
- return topPackage.getAllAppliedProfiles();
- }
- return Collections.emptyList();
- }
-
- /**
- * Add drag support from the available tools viewer
- */
- protected void addAvailableToolsDragSupport() {
- // transfer types
- Transfer[] transfers = new Transfer[] { LocalSelectionTransfer.getTransfer() };
-
- // drag listener
- DragSourceListener listener = new LocalSelectionDragSource(availableToolsViewer);
-
- availableToolsViewer.addDragSupport(DND.DROP_LINK, transfers, listener);
- }
-
- /**
- * Adds elements to the tool bar for available tools viewer
- *
- * @param toolbar
- * the toolbar to populate
- */
- protected void populateAvailableToolsToolBar(ToolBar toolbar) {
- toggleContentProvider = createCheckToolBarItem(toolbar, SWITCH_CONTENT_PROVIDER_ICON, Messages.Local_Palette_SwitchToolsContentProvider_Tooltip, createSwitchToolsContentProviderListener());
- toggleContentProvider.setSelection(true);
- toggleContentProvider.setEnabled(false);
- createCheckToolBarItem(toolbar, SHOWN_TOOLS_ICON, Messages.Local_Palette_ShowTools_Tooltip, createsShowToolListener());
- }
-
- /**
- * Creates the listener for the available tools content provider
- *
- * @return the listener created
- */
- protected Listener createSwitchToolsContentProviderListener() {
- return new Listener() {
-
- /**
- * {@inheritDoc}
- */
- public void handleEvent(Event event) {
- if (!(event.widget instanceof ToolItem)) {
- return;
- }
- ToolItem item = ((ToolItem) event.widget);
- // retrieve current profile selected in the combo profile
- int index = profileCombo.getSelectionIndex();
- Collection<PaletteEntry> standardEntries = getAllVisibleStandardEntries();
- Profile profile = getAllAppliedProfiles().get(index);
-
- if (item.getSelection()) {
- availableToolsViewer.setContentProvider(new ProfileToolsStereotypeMetaclassTreeContentProvider(profile, standardEntries));
- item.setSelection(true);
- } else {
-
- availableToolsViewer.setContentProvider(new ProfileToolsMetaclassStereotypeTreeContentProvider(profile, standardEntries));
- item.setSelection(false);
- }
-
- // generate tools for given profile
- availableToolsViewer.setInput(profile);
- }
- };
- }
-
- /**
- * creates the tool item for drawers visibility listener
- *
- * @return the listener for the tool button
- */
- protected Listener createShowDrawerListener() {
- return new Listener() {
-
- /**
- * {@inheritDoc}
- */
- public void handleEvent(Event event) {
- if (!(event.widget instanceof ToolItem)) {
- return;
- }
- ToolItem item = ((ToolItem) event.widget);
- if (item.getSelection()) {
- // elements should be hidden
- availableToolsViewer.addFilter(drawerFilter);
- item.setSelection(true);
- } else {
- availableToolsViewer.removeFilter(drawerFilter);
- item.setSelection(false);
- }
- }
- };
- }
-
- /**
- * creates the tool item for tools visibility listener
- *
- * @return the listener for the tool button
- */
- protected Listener createsShowToolListener() {
- return new Listener() {
-
- /**
- * {@inheritDoc}
- */
- public void handleEvent(Event event) {
- if (!(event.widget instanceof ToolItem)) {
- return;
- }
- ToolItem item = ((ToolItem) event.widget);
- if (item.getSelection()) {
- // elements should be hidden
- availableToolsViewer.addFilter(toolFilter);
- item.setSelection(true);
- } else {
- availableToolsViewer.removeFilter(toolFilter);
- item.setSelection(false);
- }
- }
- };
- }
-
- /**
- * Creates a toolbar item which can be checked.
- *
- * @param toolbar
- * the parent toolbar
- * @param shownElementsIcon
- * path for shown elements icon
- * @param listener
- * listener for button action
- * @param tooltip
- * tooltip text for the toolbar item
- */
- protected ToolItem createCheckToolBarItem(ToolBar toolbar, String shownElementsIcon, String tooltip, Listener listener) {
- ToolItem item = new ToolItem(toolbar, SWT.CHECK | SWT.BORDER);
- item.setImage(Activator.getPluginIconImage(Activator.ID, shownElementsIcon));
- item.setToolTipText(tooltip);
- item.addListener(SWT.Selection, listener);
- return item;
- }
-
- /**
- * Validates the content of the fields in this page
- */
- protected boolean validatePage() {
- boolean valid = true;
-
- if (valid) {
- setMessage(null);
- setErrorMessage(null);
- }
- return valid;
- }
-
- /**
- * The <code>WizardNewFileCreationPage</code> implementation of this <code>Listener</code> method handles all events and enablements for controls
- * on this page. Subclasses may extend.
- */
- public void handleEvent(Event event) {
- setPageComplete(validatePage());
- }
-
- /**
- * Content provider for available tools viewer
- */
- public class UMLToolsTreeContentProvider implements ITreeContentProvider {
-
- /**
- * Constructor
- *
- * @param viewer
- * The viewer whose ContentProvider this content provider is
- */
- public UMLToolsTreeContentProvider() {
- }
-
- /**
- * {@inheritDoc}
- */
- public Object[] getElements(Object inputElement) {
- Object[] elements = null;
-
- if (inputElement instanceof Collection<?>) {
- elements = ((Collection<?>) inputElement).toArray();
- } else if (inputElement instanceof PaletteRoot) {
- // paletteUil.getAllEntries(...) to add drawers
- // if so, uncomment the addFilterbutton for drawers in populate tool bar
- elements = PaletteUtil.getAllToolEntries(((PaletteRoot) inputElement)).toArray();
- }
-
- if (elements == null) {
- elements = new Object[0];
- }
- return elements;
- }
-
- /**
- * {@inheritDoc}
- */
- public void dispose() {
- }
-
- /**
- * {@inheritDoc}
- */
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
-
- }
-
- /**
- * {@inheritDoc}
- */
- public Object[] getChildren(Object parentElement) {
- Object[] elements = null;
-
- if (parentElement instanceof Collection<?>) {
- elements = ((Collection<?>) parentElement).toArray();
- } else if (parentElement instanceof PaletteRoot) {
- // paletteUil.getAllEntries(...) to add drawers
- // if so, uncomment the addFilterbutton for drawers in populate tool bar
- elements = PaletteUtil.getAllToolEntries(((PaletteRoot) parentElement)).toArray();
- }
-
- return elements;
- }
-
- /**
- * {@inheritDoc}
- */
- public Object getParent(Object element) {
- return null;
- }
-
- /**
- * {@inheritDoc}
- */
- public boolean hasChildren(Object element) {
- return getChildren(element) != null && getChildren(element).length > 0;
- }
- }
-
- /**
- * Label provider for palette tools.
- * <P>
- * We should be using the Palette label provider from GEF, if it was not with visibility "package"...
- *
- * @see org.eclipse.gef.ui.palette.customize.PaletteLabelProvider </P>
- *
- */
- public class PaletteLabelProvider implements ILabelProvider {
-
- /**
- * {@inheritDoc}
- */
- public Image getImage(Object element) {
- if (element instanceof PaletteEntry) {
- ImageDescriptor descriptor = ((PaletteEntry) element).getSmallIcon();
- if (descriptor == null) {
- return null;
- }
- return Activator.getPluginIconImage(Activator.ID, descriptor);
- } else if (element instanceof Stereotype) {
- return Activator.getPluginIconImage(Activator.ID, "/icons/stereotype.gif");
- }
- return null;
- }
-
- /**
- * {@inheritDoc}
- */
- public String getText(Object element) {
- if (element instanceof PaletteEntry) {
- return ((PaletteEntry) element).getLabel();
- } else if (element instanceof Stereotype) {
- return ((Stereotype) element).getName();
- }
- return "unknown element";
- }
-
- /**
- * {@inheritDoc}
- */
- public void addListener(ILabelProviderListener listener) {
-
- }
-
- /**
- * {@inheritDoc}
- */
- public void dispose() {
-
- }
-
- /**
- * {@inheritDoc}
- */
- public boolean isLabelProperty(Object element, String property) {
- return false;
- }
-
- /**
- * {@inheritDoc}
- */
- public void removeListener(ILabelProviderListener listener) {
-
- }
-
- }
-
- /**
- * Label provider for palette tools.
- * <P>
- * We should be using the Palette label provider from GEF, if it was not with visibility "package"...
- *
- * @see org.eclipse.gef.ui.palette.customize.PaletteLabelProvider </P>
- *
- */
- public class PaletteProxyLabelProvider implements ILabelProvider {
-
- /**
- * {@inheritDoc}
- */
- public Image getImage(Object element) {
- if (element instanceof PaletteEntryProxy) {
- return ((PaletteEntryProxy) element).getImage();
- }
- return null;
- }
-
- /**
- * {@inheritDoc}
- */
- public String getText(Object element) {
- if (element instanceof PaletteEntryProxy) {
- return ((PaletteEntryProxy) element).getLabel();
- }
- return "unknown element";
- }
-
- /**
- * {@inheritDoc}
- */
- public void addListener(ILabelProviderListener listener) {
-
- }
-
- /**
- * {@inheritDoc}
- */
- public void dispose() {
-
- }
-
- /**
- * {@inheritDoc}
- */
- public boolean isLabelProperty(Object element, String property) {
- return false;
- }
-
- /**
- * {@inheritDoc}
- */
- public void removeListener(ILabelProviderListener listener) {
-
- }
-
- }
-
- /**
- * Filter for the viewer. Hide/show Drawers
- */
- public class DrawerFilter extends ViewerFilter {
-
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean select(Viewer viewer, Object parentElement, Object element) {
- if (element instanceof PaletteDrawer) {
- return false;
- }
- return true;
- }
-
- }
-
- /**
- * Filter for the viewer. Hide/show Drawers
- */
- public class ToolFilter extends ViewerFilter {
-
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean select(Viewer viewer, Object parentElement, Object element) {
- if (element instanceof ToolEntry) {
- return false;
- }
- return true;
- }
-
- }
-
- /**
- * Content provider for the palette
- */
- public class PaletteContentProvider implements ITreeContentProvider {
-
- /** tree viewer this provider provides content */
- protected final TreeViewer viewer;
-
- /** the document root where to build the palette */
- protected PaletteContainerProxy rootProxy;
-
- /** model listener that will listens for all modifications in the entries */
- protected PropertyChangeListener modelListener = new PropertyChangeListener() {
-
- public void propertyChange(PropertyChangeEvent evt) {
- handlePropertyChanged(evt);
- }
- };
-
- /**
- * Creates a new PaletteContentProvider.
- *
- * @param treeviewer
- * tree viewer this provider provides content
- */
- public PaletteContentProvider(TreeViewer treeviewer) {
- this.viewer = treeviewer;
- }
-
- /**
- * {@inheritDoc}
- */
- public void dispose() {
- // remove all listeners
- traverseModel(rootProxy, false);
- }
-
- /**
- * {@inheritDoc}
- */
- public Object[] getChildren(Object parentElement) {
- if (parentElement instanceof PaletteEntryProxy) {
- List<PaletteEntryProxy> children = ((PaletteEntryProxy) parentElement).getChildren();
- return (children != null) ? children.toArray() : new Object[0];
- }
- return null;
- }
-
- /**
- * {@inheritDoc}
- */
- public boolean hasChildren(Object element) {
- if (element instanceof PaletteEntryProxy) {
- return ((PaletteEntryProxy) element).getChildren() != null && !((PaletteEntryProxy) element).getChildren().isEmpty();
- }
- return false;
- }
-
- /**
- * {@inheritDoc}
- */
- public Object[] getElements(Object inputElement) {
- Object[] elements = getChildren(inputElement);
- if (elements == null) {
- elements = new Object[0];
- }
- return elements;
- }
-
- /**
- * {@inheritDoc}
- */
- public Object getParent(Object element) {
- if (element instanceof PaletteEntryProxy) {
- return ((PaletteEntryProxy) element).getParent();
- }
- return null;
- }
-
- /**
- * {@inheritDoc}
- */
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
- if (rootProxy != null) {
- // warning.. the root has no entry, this is a virtual node
- traverseModel(rootProxy, false);
- }
-
- if (newInput != null) {
- rootProxy = ((PaletteContainerProxy) newInput);
- traverseModel(rootProxy, true);
- }
- }
-
- /**
- * This method is invoked whenever there is any change in the model. It updates the
- * viewer with the changes that were made to the model. Sub-classes may override this
- * method to change or extend its functionality.
- *
- * @param evt
- * The {@link PropertyChangeEvent} that was fired from the model
- */
- protected void handlePropertyChanged(PropertyChangeEvent evt) {
- PaletteEntryProxy entry = ((PaletteEntryProxy) evt.getSource());
- String property = evt.getPropertyName();
- if (property.equals(PaletteEntry.PROPERTY_LABEL) || property.equals(PaletteEntry.PROPERTY_SMALL_ICON) || property.equals(PaletteEntryProxy.PROPERTY_ICON_PATH)) {
- viewer.update(entry, null);
- } else if (property.equals(PaletteEntryProxy.PROPERTY_ADD_CHILDREN)) {
- viewer.refresh(entry.getParent());
- // add the listeners to the child
- traverseModel(((PaletteEntryProxy) evt.getNewValue()), true);
- } else if (property.equals(PaletteEntryProxy.PROPERTY_REMOVE_CHILDREN)) {
- viewer.refresh(entry.getParent());
- // add the listeners to the child
- traverseModel(((PaletteEntryProxy) evt.getOldValue()), false);
- }
-
- }
-
- protected void traverseModel(PaletteEntryProxy entryProxy, boolean isHook) {
- if (entryProxy != null) {
- if (isHook) {
- entryProxy.addPropertyChangeListener(modelListener);
- } else {
- entryProxy.removePropertyChangeListener(modelListener);
- }
- }
-
- if (entryProxy.getChildren() != null && !entryProxy.getChildren().isEmpty()) {
- for (PaletteEntryProxy proxy : entryProxy.getChildren()) {
- traverseModel(proxy, isHook);
- }
- }
- }
- }
-
- /**
- * Performs all action on finish
- *
- * @param id
- * the path for the file
- */
- public void performFinish(String path) {
- // creates the document
- Document document = createXMLDocumentFromPalettePreview();
- saveDocument(document, path);
- requiredProfiles = collectRequiredProfiles();
- }
-
- /**
- * collect the required profiles from all tool provided by the local palette definition
- */
- protected Set<String> collectRequiredProfiles() {
- Set<String> profiles = new HashSet<String>();
- PaletteContainerProxy rootProxy = (PaletteContainerProxy) paletteTreeViewer.getInput();
- collectRequiredProfiles(rootProxy.getChildren(), profiles);
- return profiles;
- }
-
- /**
- * collect the required profiles from all tool provided by the local palette definition
- */
- protected void collectRequiredProfiles(List<PaletteEntryProxy> proxies, Set<String> requiredProfiles) {
- for (PaletteEntryProxy proxy : proxies) {
- // add profile(s) if relevant, check for children
-
- if (proxy instanceof PaletteAspectToolEntryProxy) {
- // list of profiles
- for (String stereotypeQN : ((PaletteAspectToolEntryProxy) proxy).getStereotypesQNList()) {
- // retrieve list of profiles from the stereotype QN (only remove last segment
- // ?!)
- String profileName = PaletteUtil.findProfileNameFromStereotypeName(stereotypeQN);
- requiredProfiles.add(profileName);
- }
- }
-
- if (proxy.getChildren() != null) {
- collectRequiredProfiles(proxy.getChildren(), requiredProfiles);
- }
- }
- }
-
- /**
- * Saves the xml document into file
- *
- * @param document
- * the document to save
- * @param path
- * name of the file
- * @return the file created or updated
- */
- protected File saveDocument(Document document, String path) {
- File file = null;
- try {
- // create the file that stores the XML configuration
- file = Activator.getDefault().getStateLocation().append(path).toFile();
- TransformerFactory tranFactory = TransformerFactory.newInstance();
- Transformer aTransformer;
-
- aTransformer = tranFactory.newTransformer();
-
- Source src = new DOMSource(document);
- Result dest = new StreamResult(file);
- aTransformer.transform(src, dest);
- } catch (TransformerConfigurationException e) {
- Activator.log.error(e);
- } catch (TransformerException e) {
- Activator.log.error(e);
- }
- return file;
-
- }
-
- /**
- * Creates the document from the palette preview
- *
- * @return the dom structure of the document
- */
- protected Document createXMLDocumentFromPalettePreview() {
- DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
- documentBuilderFactory.setNamespaceAware(true);
- DocumentBuilder documentBuilder;
- try {
- documentBuilder = documentBuilderFactory.newDocumentBuilder();
- document = documentBuilder.newDocument();
- Element paletteDefElement = document.createElement(IPapyrusPaletteConstant.PALETTE_DEFINITION);
- document.appendChild(paletteDefElement);
- Element contentElement = document.createElement(IPapyrusPaletteConstant.CONTENT);
- paletteDefElement.appendChild(contentElement);
-
- generateXMLPaletteContent(document, contentElement);
- return document;
- } catch (ParserConfigurationException e) {
- Activator.getDefault().logError("impossible to create the palette tree viewer content", e);
- }
- return null;
- }
-
- /**
- * Generates the xml content for the palette
- *
- * @param document
- * the document to fill
- * @param contentElement
- * the root for the xml content
- */
- protected void generateXMLPaletteContent(Document document, Element contentElement) {
- PaletteContainerProxy rootProxy = (PaletteContainerProxy) paletteTreeViewer.getInput();
- for (PaletteEntryProxy proxy : rootProxy.getChildren()) {
- generateXMLPaletteContainerProxy(document, contentElement, proxy);
- }
- }
-
- /**
- * Generates the xml content for the given container
- *
- * @param document
- * the document to fill
- * @param containerProxy
- * the entry proxy
- */
- protected void generateXMLPaletteContainerProxy(Document document, Element contentElement, PaletteEntryProxy containerProxy) {
-
- Element element = null;
- List<PaletteEntryProxy> children = containerProxy.getChildren();
- // generate the element
- switch (containerProxy.getType()) {
- case DRAWER:
- element = document.createElement(IPapyrusPaletteConstant.DRAWER);
- element.setAttribute(IPapyrusPaletteConstant.NAME, containerProxy.getLabel());
- if (containerProxy instanceof PaletteLocalDrawerProxy) {
- element.setAttribute(IPapyrusPaletteConstant.ICON_PATH, ((PaletteLocalDrawerProxy) containerProxy).getImagePath());
- }
- break;
- case TOOL:
- element = document.createElement(IPapyrusPaletteConstant.TOOL);
- break;
- case SEPARATOR:
- element = document.createElement(IPapyrusPaletteConstant.SEPARATOR);
- break;
- case STACK:
- element = document.createElement(IPapyrusPaletteConstant.STACK);
- break;
- case ASPECT_TOOL:
- element = document.createElement(IPapyrusPaletteConstant.ASPECT_TOOL);
- // try to cast the element into PaletteAspectToolEntryProxy
- if (containerProxy instanceof PaletteAspectToolEntryProxy) {
- PaletteAspectToolEntryProxy aspectEntryProxy = (PaletteAspectToolEntryProxy) containerProxy;
- // element.setAttribute(IPapyrusPaletteConstant.ID, aspectEntryProxy.getId());
- element.setAttribute(IPapyrusPaletteConstant.NAME, aspectEntryProxy.getLabel());
- element.setAttribute(IPapyrusPaletteConstant.DESCRIPTION, aspectEntryProxy.getEntry().getDescription());
- element.setAttribute(IPapyrusPaletteConstant.REF_TOOL_ID, aspectEntryProxy.getReferencedPaletteID());
-
- if (aspectEntryProxy.getImagePath() != null && !aspectEntryProxy.getImagePath().equals("")) {
- element.setAttribute(IPapyrusPaletteConstant.ICON_PATH, aspectEntryProxy.getImagePath());
- }
-
-
- // add post action, stereotype list
- for (IAspectAction action : ((PaletteAspectToolEntryProxy) containerProxy).getPostActions()) {
- Element postActionNode = document.createElement(IPapyrusPaletteConstant.POST_ACTION);
- postActionNode.setAttribute(IPapyrusPaletteConstant.ID, action.getFactoryId());
- action.save(postActionNode);
- element.appendChild(postActionNode);
- }
- for (IAspectAction action : ((PaletteAspectToolEntryProxy) containerProxy).getPreActions()) {
- Element preActionNode = document.createElement(IPapyrusPaletteConstant.PRE_ACTION);
- preActionNode.setAttribute(IPapyrusPaletteConstant.ID, action.getFactoryId());
- action.save(preActionNode);
- element.appendChild(preActionNode);
- }
- }
- default:
- break;
- }
-
- element.setAttribute(IPapyrusPaletteConstant.ID, containerProxy.getId());
- contentElement.appendChild(element);
-
- if (children != null) {
- for (PaletteEntryProxy proxy : children) {
- generateXMLPaletteContainerProxy(document, element, proxy);
- }
- }
- }
-
- public enum EntryType {
- DRAWER, TOOL, STACK, SEPARATOR, ASPECT_TOOL
- }
-
- public class LabelViewerComparator extends ViewerComparator {
-
- /**
- * Creates a new LabelViewerComparator.
- */
- public LabelViewerComparator() {
- super();
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public int compare(Viewer testViewer, Object e1, Object e2) {
- String label1 = "";
- String label2 = "";
-
- if (e1 instanceof PaletteEntry) {
- label1 = ((PaletteEntry) e1).getLabel();
- } else if (e1 instanceof Stereotype) {
- label1 = ((Stereotype) e1).getName();
- }
- if (e2 instanceof PaletteEntry) {
- label2 = ((PaletteEntry) e2).getLabel();
- } else if (e2 instanceof Stereotype) {
- label2 = ((Stereotype) e2).getName();
- }
-
- if (label1 == null) {
- return 1;
- }
- if (label2 == null) {
- return -1;
- }
-
- return label1.compareTo(label2);
- }
- }
-
- /**
- * Listener for the profile combo. It changes the input of the following viewer.
- */
- public class ProfileComboSelectionListener implements SelectionListener, ModifyListener {
-
- /**
- * {@inheritDoc}
- */
- public void widgetDefaultSelected(SelectionEvent e) {
- // nothing to do
- }
-
- /**
- * {@inheritDoc}
- */
- public void widgetSelected(SelectionEvent e) {
- handleSelectionChanged();
- }
-
- /**
- * {@inheritDoc}
- */
- public void modifyText(ModifyEvent e) {
- handleSelectionChanged();
- }
-
- /**
- * handles the change selection for the combo
- */
- protected void handleSelectionChanged() {
- int index = profileCombo.getSelectionIndex();
- if (index < 0 || index >= profileCombo.getItems().length) {
- return;
- }
- String name = profileComboList.get(index);
-
- Collection<PaletteEntry> standardEntries = getAllVisibleStandardEntries();
- // retrieve the profile or uml standards tools to display
- if (UML_TOOLS_LABEL.equals(name)) {
- // change content provider
- availableToolsViewer.setContentProvider(new UMLToolsTreeContentProvider());
- availableToolsViewer.setInput(standardEntries);
- toggleContentProvider.setEnabled(false);
- } else {
- if (toggleContentProvider != null && !toggleContentProvider.isDisposed()) {
- toggleContentProvider.setEnabled(true);
- }
- // switch content provider
- // this is a profile in case of uml2 tools
- Profile profile = getAllAppliedProfiles().get(index);
- if (toggleContentProvider.getSelection()) {
- availableToolsViewer.setContentProvider(new ProfileToolsStereotypeMetaclassTreeContentProvider(profile, standardEntries));
- } else {
- availableToolsViewer.setContentProvider(new ProfileToolsMetaclassStereotypeTreeContentProvider(profile, standardEntries));
- }
-
- // generate tools for given profile
- availableToolsViewer.setInput(profile);
- }
- }
- }
-
- /**
- * Content provider for the available tools viewer, when the tools to see are coming from a
- * profile
- */
- public class ProfileToolsStereotypeMetaclassTreeContentProvider implements ITreeContentProvider {
-
- /** standard uml tools palette entries */
- final protected Collection<PaletteEntry> standardEntries;
-
- /**
- * Creates a new ProfileToolsStereotypeMetaclassTreeContentProvider.
- *
- * @param profile
- * the profile for which tools are built
- * @param standardEntries
- * list of standard uml tools palette entries
- */
- public ProfileToolsStereotypeMetaclassTreeContentProvider(Profile profile, Collection<PaletteEntry> standardEntries) {
- this.standardEntries = standardEntries;
- }
-
- /**
- * {@inheritDoc}
- */
- public Object[] getChildren(Object parentElement) {
- if (parentElement instanceof Profile) {
- return ((Profile) parentElement).getOwnedStereotypes().toArray();
- } else if (parentElement instanceof Stereotype) {
- List<PaletteEntry> entries = new ArrayList<PaletteEntry>();
- Stereotype stereotype = (Stereotype) parentElement;
-
- for (PaletteEntry entry : standardEntries) {
- // retrieve the element type created by the tool.
- if (entry instanceof CombinedTemplateCreationEntry) {
-
- EClass toolMetaclass = PaletteUtil.getToolMetaclass((CombinedTemplateCreationEntry) entry);
- if (toolMetaclass != null) {
- List<Class> metaclasses = stereotype.getAllExtendedMetaclasses();
- for (Class stMetaclass : metaclasses) {
- // get Eclass
- java.lang.Class<?> metaclassClass = stMetaclass.getClass();
- if (metaclassClass != null) {
- EClassifier metaClassifier = UMLPackage.eINSTANCE.getEClassifier(stMetaclass.getName());
- if (((EClass) metaClassifier).isSuperTypeOf(toolMetaclass)) {
- // should create the palette entry
- Map<String, Object> properties = new HashMap<String, Object>();
- properties.put(IPapyrusPaletteConstant.ASPECT_ACTION_KEY, StereotypeAspectActionProvider.createConfigurationNode(stereotype.getQualifiedName()));
- AspectCreationEntry aspectEntry = new AspectCreationEntry(stereotype.getName() + " (" + entry.getLabel() + ")", "Create an element with a stereotype", entry.getId() + "_" + System.currentTimeMillis(),
- entry.getSmallIcon(), (CombinedTemplateCreationEntry) entry, properties);
- entries.add(aspectEntry);
- }
- }
-
- }
- }
- }
- }
- return entries.toArray();
- } else {
- return new Object[0];
- }
- }
-
- /**
- * {@inheritDoc}
- */
- public Object getParent(Object element) {
- if (element instanceof Stereotype) {
- return ((Stereotype) element).getProfile();
- }
- return null;
- }
-
- /**
- * {@inheritDoc}
- */
- public boolean hasChildren(Object element) {
- if (element instanceof Profile) {
- return true;
- } else if (element instanceof Stereotype) {
- return true;
- }
- return false;
- }
-
- /**
- * {@inheritDoc}
- */
- public Object[] getElements(Object inputElement) {
- if (inputElement instanceof Profile) {
- List<Stereotype> stereotypes = ((Profile) inputElement).getOwnedStereotypes();
- return stereotypes.toArray();
- }
- return new Object[0];
- }
-
- /**
- * {@inheritDoc}
- */
- public void dispose() {
- // nothing to do here
- }
-
- /**
- * {@inheritDoc}
- */
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
- // nothing to do here
- }
-
- }
-
- /**
- * Content provider for the available tools viewer, when the
- */
- public class ProfileToolsMetaclassStereotypeTreeContentProvider implements ITreeContentProvider {
-
- /** standard uml tools palette entries */
- final protected Collection<PaletteEntry> standardEntries;
-
- /** profile to display */
- final protected Profile profile;
-
- /**
- * Creates a new ProfileToolsMetaclassStereotypeTreeContentProvider.
- *
- * @param profile
- * the profile for which tools are built
- * @param standardEntries
- * list of standard uml tools palette entries
- */
- public ProfileToolsMetaclassStereotypeTreeContentProvider(Profile profile, Collection<PaletteEntry> standardEntries) {
- this.profile = profile;
- this.standardEntries = standardEntries;
- }
-
- /**
- * {@inheritDoc}
- */
- public Object[] getChildren(Object parentElement) {
- if (parentElement instanceof Profile) {
- return standardEntries.toArray();
- } else if (parentElement instanceof AspectCreationEntry) {
- return new Object[0];
- } else if (parentElement instanceof PaletteEntry) {
- List<AspectCreationEntry> entries = new ArrayList<AspectCreationEntry>();
- // display all stereotypes applicable to the type of element created by this tool
- if (parentElement instanceof CombinedTemplateCreationEntry) {
- CombinedTemplateCreationEntry entry = (CombinedTemplateCreationEntry) parentElement;
- EClass toolMetaclass = PaletteUtil.getToolMetaclass(entry);
- if (toolMetaclass != null) {
- for (Stereotype stereotype : profile.getOwnedStereotypes()) {
- List<Class> metaclasses = stereotype.getAllExtendedMetaclasses();
- for (Class stMetaclass : metaclasses) {
- // get Eclass
- java.lang.Class<?> metaclassClass = stMetaclass.getClass();
- if (metaclassClass != null) {
- EClassifier metaClassifier = UMLPackage.eINSTANCE.getEClassifier(stMetaclass.getName());
- if (((EClass) metaClassifier).isSuperTypeOf(toolMetaclass)) {
- // should create the palette entry
- Map<String, Object> properties = new HashMap<String, Object>();
- properties.put(IPapyrusPaletteConstant.ASPECT_ACTION_KEY, StereotypeAspectActionProvider.createConfigurationNode(stereotype.getQualifiedName()));
- AspectCreationEntry aspectEntry = new AspectCreationEntry(stereotype.getName() + " (" + entry.getLabel() + ")", "Create an element with a stereotype", entry.getId() + "_" + System.currentTimeMillis(),
- entry.getSmallIcon(), entry, properties);
- entries.add(aspectEntry);
- }
- }
-
- }
- }
- }
- }
- return entries.toArray();
- } else {
- return new Object[0];
- }
- }
-
- /**
- * {@inheritDoc}
- */
- public Object getParent(Object element) {
- if (element instanceof Stereotype) {
- return ((Stereotype) element).getProfile();
- }
- return null;
- }
-
- /**
- * {@inheritDoc}
- */
- public boolean hasChildren(Object element) {
- if (element instanceof Profile) {
- return true;
- } else if (element instanceof AspectCreationEntry) {
- return false;
- } else if (element instanceof PaletteEntry) {
- return true;
- }
- return false;
- }
-
- /**
- * {@inheritDoc}
- */
- public Object[] getElements(Object inputElement) {
- if (inputElement instanceof Profile) {
- return standardEntries.toArray();
- }
- return new Object[0];
- }
-
- /**
- * {@inheritDoc}
- */
- public void dispose() {
- // nothing to do here
- }
-
- /**
- * {@inheritDoc}
- */
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
- // nothing to do here
- }
-
- }
-
- /**
- * Returns the list of all visible palette entries
- *
- * @return the list of all visible palette entries
- */
- protected Collection<PaletteEntry> getAllVisibleStandardEntries() {
- HashSet<PaletteEntry> result = new HashSet<PaletteEntry>();
- for (PaletteEntry entry : PaletteUtil.getAvailableEntriesSet(editorPart, priority).values()) {
- // the entry is not just a defineOnly entry but a visible one
- if (getRootParent(entry) != null) {
- result.add(entry);
- }
- }
- return result;
- }
-
- /**
- * Returns the Root element for the palette entry. It searches recursively from parent to parent, until it find the root element
- *
- * @param entry
- * the palette entry for which root element is searched
- * @return the root element or <code>null</code> if none was found
- */
- protected PaletteRoot getRootParent(PaletteEntry entry) {
- PaletteContainer parent = entry.getParent();
- if (parent instanceof PaletteRoot) {
- return (PaletteRoot) parent;
- } else if (parent != null) {
- return getRootParent(parent);
- } else {
- return null;
- }
- }
-
- /**
- * Returns the list of required profiles by this local palette definition
- *
- * @return the profiles required by this palette
- */
- public Set<String> getRequiredProfiles() {
- return requiredProfiles;
- }
-
- /**
- * Item validator
- */
- protected abstract class ToolBarItemValidator {
-
- /**
- * Checks if the button should be enable or not
- *
- * @return <code>true</code> if the button should be enable
- */
- public abstract boolean isEnable();
- }
-
- /**
- * validator for the edit element tool item. It does not remove
- */
- protected class EditElementToolBarItemValidator extends ToolBarItemValidator {
-
- /**
- * @{inheritDoc
- */
- @Override
- public boolean isEnable() {
- // retrieve selection
- if (paletteTreeViewer != null && !paletteTreeViewer.getControl().isDisposed()) {
- // retrieve selection. first element should be a drawer
- IStructuredSelection selection = (IStructuredSelection) paletteTreeViewer.getSelection();
- if (selection == null) {
- return false;
- } else {
- // look for first element. should be an instance of drawer
- return (selection.getFirstElement() instanceof PaletteLocalDrawerProxy);
- }
- }
- return false;
- }
- }
-
- /**
- * validator for the create separator or stack tool item. Only valid when selection is a {@link PaletteEntryProxy} or a {@link PaletteLocalDrawerProxy}
- */
- protected class PaletteEntryProxySelectedValidator extends ToolBarItemValidator {
-
- /**
- * @{inheritDoc
- */
- @Override
- public boolean isEnable() {
- // retrieve selection
- if (paletteTreeViewer != null && !paletteTreeViewer.getControl().isDisposed()) {
- // retrieve selection. first element should be a drawer
- IStructuredSelection selection = (IStructuredSelection) paletteTreeViewer.getSelection();
- if (selection == null) {
- return false;
- } else {
- Object object = selection.getFirstElement();
- return (object instanceof PaletteEntryProxy);
- }
- }
- return false;
- }
- }
-
- /**
- * Sets the priority of the current edited palette
- *
- * @param priority
- * the priority of the current edited palette
- */
- public void setPriority(ProviderPriority priority) {
- this.priority = priority;
- }
-
- protected static class LocalSelectionDragSource extends DragSourceAdapter {
- private ISelectionProvider selectionSource;
-
- public LocalSelectionDragSource(ISelectionProvider selectionProvider) {
- selectionSource = selectionProvider;
- }
-
- @Override
- public void dragStart(DragSourceEvent event) {
- super.dragStart(event);
- LocalSelectionTransfer.getTransfer().setSelection(selectionSource.getSelection());
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void dragSetData(DragSourceEvent event) {
- super.dragSetData(event);
- LocalSelectionTransfer.getTransfer().setSelection(selectionSource.getSelection());
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void dragFinished(DragSourceEvent event) {
- LocalSelectionTransfer.getTransfer().setSelection(null);
- super.dragFinished(event);
- }
-
- }
-}
+/***************************************************************************** + * Copyright (c) 2009, 2014 CEA LIST, Christian W. Damus, and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Remi Schnekenburger (CEA LIST) remi.schnekenburger@cea.fr - Initial API and implementation + * Christian W. Damus - bug 454578 + * + *****************************************************************************/ +package org.eclipse.papyrus.customization.palette.dialog; + +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.transform.Result; +import javax.xml.transform.Source; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerConfigurationException; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; + +import org.eclipse.emf.common.util.URI; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EClassifier; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.util.EcoreUtil; +import org.eclipse.gef.palette.CombinedTemplateCreationEntry; +import org.eclipse.gef.palette.PaletteContainer; +import org.eclipse.gef.palette.PaletteDrawer; +import org.eclipse.gef.palette.PaletteEntry; +import org.eclipse.gef.palette.PaletteRoot; +import org.eclipse.gef.palette.PaletteStack; +import org.eclipse.gef.palette.PaletteToolbar; +import org.eclipse.gef.palette.ToolEntry; +import org.eclipse.gef.ui.palette.PaletteCustomizer; +import org.eclipse.gmf.runtime.common.core.service.ProviderPriority; +import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditorWithFlyOutPalette; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.util.LocalSelectionTransfer; +import org.eclipse.jface.viewers.AbstractTreeViewer; +import org.eclipse.jface.viewers.DoubleClickEvent; +import org.eclipse.jface.viewers.IDoubleClickListener; +import org.eclipse.jface.viewers.ILabelProvider; +import org.eclipse.jface.viewers.ILabelProviderListener; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.ISelectionProvider; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.ITreeContentProvider; +import org.eclipse.jface.viewers.ITreeSelection; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.jface.viewers.TreeSelection; +import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.jface.viewers.ViewerComparator; +import org.eclipse.jface.viewers.ViewerFilter; +import org.eclipse.jface.wizard.WizardDialog; +import org.eclipse.jface.wizard.WizardPage; +import org.eclipse.osgi.util.NLS; +import org.eclipse.papyrus.customization.palette.Messages; +import org.eclipse.papyrus.customization.palette.proxies.XMLPaletteDefinitionProxyFactory; +import org.eclipse.papyrus.uml.diagram.common.Activator; +import org.eclipse.papyrus.uml.diagram.common.part.PaletteUtil; +import org.eclipse.papyrus.uml.diagram.common.part.PapyrusPalettePreferences; +import org.eclipse.papyrus.uml.diagram.common.service.AspectCreationEntry; +import org.eclipse.papyrus.uml.diagram.common.service.IPapyrusPaletteConstant; +import org.eclipse.papyrus.uml.diagram.common.service.PapyrusPaletteService; +import org.eclipse.papyrus.uml.diagram.common.service.XMLPaletteDefinitionWalker; +import org.eclipse.papyrus.uml.diagram.common.service.palette.IAspectAction; +import org.eclipse.papyrus.uml.diagram.common.service.palette.StereotypeAspectActionProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.dnd.DND; +import org.eclipse.swt.dnd.DragSourceAdapter; +import org.eclipse.swt.dnd.DragSourceEvent; +import org.eclipse.swt.dnd.DragSourceListener; +import org.eclipse.swt.dnd.DropTargetEvent; +import org.eclipse.swt.dnd.DropTargetListener; +import org.eclipse.swt.dnd.Transfer; +import org.eclipse.swt.dnd.TreeDropTargetEffect; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.events.MouseEvent; +import org.eclipse.swt.events.MouseListener; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Combo; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.ToolBar; +import org.eclipse.swt.widgets.ToolItem; +import org.eclipse.swt.widgets.Tree; +import org.eclipse.swt.widgets.TreeItem; +import org.eclipse.ui.IEditorPart; +import org.eclipse.uml2.uml.Class; +import org.eclipse.uml2.uml.Package; +import org.eclipse.uml2.uml.Profile; +import org.eclipse.uml2.uml.Stereotype; +import org.eclipse.uml2.uml.UMLPackage; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.xml.sax.SAXException; + +/** + * Wizard page for information about the new local palette definition + */ +public class LocalPaletteContentPage extends WizardPage implements Listener { + + /** editor part in which the palette is created */ + protected IEditorPart editorPart; + + /** available tools viewer */ + protected TreeViewer availableToolsViewer; + + /** label provider for the tree viewer */ + protected PaletteLabelProvider paletteLabelProvider; + + /** icon path when tools are hidden */ + protected static final String HIDDEN_TOOLS_ICON = "/icons/tools_hidden.gif"; + + /** icon path when tools are shown */ + protected static final String SHOWN_TOOLS_ICON = "/icons/tools_shown.gif"; + + /** path to the icon */ + protected static final String WIZARD_ICON = "/icons/local_desc_wiz.png"; + + /** icon path when drawers are hidden */ + protected static final String SHOWN_DRAWERS_ICON = "/icons/drawers_shown.gif"; + + /** icon path when drawers are shown */ + protected static final String HIDDEN_DRAWERS_ICON = "/icons/drawers_hidden.gif"; + + /** icon path for the add button */ + protected static final String ADD_ICON = "/icons/arrow_right.gif"; + + /** icon path for the remove button */ + protected static final String REMOVE_ICON = "/icons/arrow_left.gif"; + + /** icon path for the delete button */ + protected static final String DELETE_ICON = "/icons/delete.gif"; + + /** icon path for the create drawer button */ + protected static final String CREATE_DRAWERS_ICON = "/icons/new_drawer.gif"; + + /** icon path for the create separator button */ + protected String CREATE_SEPARATOR_ICON = "/icons/separator.gif"; + + /** icon path for the create stack button */ + protected String CREATE_STACK_ICON = "/icons/stack.gif"; + + /** icon path for the delete drawer button */ + protected static final String DELETE_DRAWERS_ICON = "/icons/delete.gif"; + + /** icon for the content provider switch button */ + protected String SWITCH_CONTENT_PROVIDER_ICON = "/icons/switch_provider.gif"; + + /** label for the standard tools */ + protected static final String UML_TOOLS_LABEL = "UML tools"; + + /** icon path for the edit drawer button */ + protected static final String EDIT_ICON = "/icons/obj16/file.gif"; + + /** instance of the filter used to show/hide drawers */ + protected final ViewerFilter drawerFilter = new DrawerFilter(); + + /** instance of the filter used to show/hide tools */ + protected final ViewerFilter toolFilter = new ToolFilter(); + + /** stored preferences */ + protected List<String> storedPreferences; + + /** add button */ + protected Button addButton; + + /** remove button */ + protected Button removeButton; + + /** tree viewer for the new palette */ + protected TreeViewer paletteTreeViewer; + + /** document for element creation */ + protected Document document; + + /** content node for the palette viewer */ + protected PaletteContainerProxy contentNode; + + /** combo to select which profile tools should be visible */ + protected Combo profileCombo; + + /** list of profiles that can provide tools */ + protected List<String> profileComboList = new ArrayList<String>(); + + /** tool item in charge of toggling content providers in the available tool viewer */ + protected ToolItem toggleContentProvider; + + /** required profile by this palette */ + protected Set<String> requiredProfiles; + + /** palette customizer used for the palette */ + protected PaletteCustomizer customizer; + + /** current selected entry proxy */ + protected PaletteEntryProxy selectedEntryProxy; + + /** class in charge of the information composite */ + protected PaletteEntryProxyInformationComposite informationComposite = new PaletteEntryProxyInformationComposite(); + + /** class in charge of the aspect tool information composite */ + protected AspectActionsInformationComposite aspectActionComposite = new AspectActionsInformationComposite(); + + protected ToolBar toolbar; + + /** validator key for toolbar items */ + protected final static String VALIDATOR = "validator"; + + /** priority of the current edited palette */ + protected ProviderPriority priority; + + + /** + * Creates a new wizard page with the given name, title, and image. + * + * @param part + * the editor part in which the wizard was created + */ + public LocalPaletteContentPage(IEditorPart part, PaletteCustomizer customizer) { + super(Messages.Local_Palette_ContentPage_Name, Messages.Local_Palette_ContentPage_Title, Activator.getImageDescriptor(WIZARD_ICON)); + this.editorPart = part; + this.customizer = customizer; + } + + /** + * {@inheritDoc} + */ + @Override + public void createControl(Composite parent) { + + // initialize dialog units + initializeDialogUnits(parent); + + // Create a new composite as there is the title bar seperator + // to deal with + Composite control = new Composite(parent, SWT.NONE); + GridLayout layout = new GridLayout(4, false); + control.setLayout(layout); + control.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + setControl(control); + + // create Available Tools Group + createAvailableToolsGroup(); + + // create add/remove buttons + createAddRemoveButtons(); + + // create Palette Group + createPalettePreviewGroup(); + + // create tool description group (custom name, description, and perhaphs icon.... Just under this group, another one with aspect actions) + createToolDescriptionGroup(); + + // just under, creates a new line of composites... + createAspectActionComposite(); + + + + // add listeners inter-groups + ISelectionChangedListener listener = createToolsViewerSelectionChangeListener(); + availableToolsViewer.addSelectionChangedListener(listener); + paletteTreeViewer.addSelectionChangedListener(listener); + + // end of the control creation + Dialog.applyDialogFont(control); + + validatePage(); + // Show description on opening + setErrorMessage(null); + setMessage(null); + setControl(control); + } + + /** + * Creates the composite group that presents information about ascpect actions for aspect tools + */ + protected void createAspectActionComposite() { + aspectActionComposite.createComposite((Composite) getControl(), getAllAppliedProfiles()); + } + + /** + * Creates the composite group that presents information about current selected tool + */ + protected void createToolDescriptionGroup() { + informationComposite.createComposite((Composite) getControl(), getAllAppliedProfiles()); + } + + /** + * update the preferences to have all tools accessible + */ + protected void updatePreferences() { + // change => set to no hidden palettes + storedPreferences = PapyrusPalettePreferences.getHiddenPalettes(editorPart); + + // remove all, but should only remove visible palettes + for (String id : storedPreferences) { + PapyrusPalettePreferences.changePaletteVisibility(id, editorPart, true); + } + } + + /** + * Restore preferences + */ + public void restorePreferences() { + // remove all, but should only remove visible palettes + for (String id : storedPreferences) { + PapyrusPalettePreferences.changePaletteVisibility(id, editorPart, false); + } + } + + /** + * creates the palette preview group + */ + protected void createPalettePreviewGroup() { + Composite parent = (Composite) getControl(); + Composite paletteComposite = new Composite(parent, SWT.NONE); + + GridLayout layout = new GridLayout(2, true); + layout.marginHeight = 0; + layout.marginWidth = 0; + paletteComposite.setLayout(layout); + GridData data = new GridData(SWT.FILL, SWT.FILL, true, true); + paletteComposite.setLayoutData(data); + + Label label = new Label(paletteComposite, SWT.NONE); + label.setText(Messages.Local_Palette_Palette_Preview); + data = new GridData(SWT.LEFT, SWT.CENTER, true, false); + label.setLayoutData(data); + + toolbar = new ToolBar(paletteComposite, SWT.HORIZONTAL); + data = new GridData(SWT.RIGHT, SWT.FILL, false, false); + toolbar.setLayoutData(data); + populatePalettePreviewToolBar(toolbar); + + Tree tree = new Tree(paletteComposite, SWT.SINGLE | SWT.BORDER); + data = new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1); + data.widthHint = 185; + // Make the tree this tall even when there is nothing in it. This will keep the + // dialog from shrinking to an unusually small size. + data.heightHint = 200; + tree.setLayoutData(data); + paletteTreeViewer = new TreeViewer(tree); + paletteTreeViewer.setContentProvider(new PaletteContentProvider(paletteTreeViewer)); + paletteTreeViewer.setLabelProvider(new PaletteProxyLabelProvider()); + paletteTreeViewer.addSelectionChangedListener(new ISelectionChangedListener() { + + @Override + public void selectionChanged(SelectionChangedEvent event) { + handlePalettePreviewSelectionChanged(event); + } + }); + + addPalettePreviewDropSupport(); + addPalettePreviewDragSupport(); + addPalettePreviewEditSupport(); + + paletteTreeViewer.setInput(contentNode); + } + + /** + * handle the selection change event for the palette preview + * + * @param event + * the event that is thrown by the palette viewer + */ + protected void handlePalettePreviewSelectionChanged(SelectionChangedEvent event) { + // retrieve current selection + ITreeSelection selection = (TreeSelection) event.getSelection(); + Object firstSelected = selection.getFirstElement(); + if (firstSelected instanceof PaletteEntryProxy) { + // update the current selected palette entry proxy + selectedEntryProxy = ((PaletteEntryProxy) firstSelected); + informationComposite.setSelectedEntryProxy(selectedEntryProxy); + aspectActionComposite.setSelectedEntryProxy(selectedEntryProxy); + } + + // update toolbar + if (toolbar != null && !toolbar.isDisposed()) { + for (int i = 0; i < toolbar.getItemCount(); i++) { + ToolItem item = toolbar.getItem(i); + Object validator = item.getData(VALIDATOR); + if (validator instanceof ToolBarItemValidator) { + item.setEnabled(((ToolBarItemValidator) validator).isEnable()); + } + } + } + + } + + /** + * @{inheritDoc + */ + @Override + public void dispose() { + super.dispose(); + } + + /** + * Adds the behavior for the double click strategy + */ + protected void addPalettePreviewEditSupport() { + paletteTreeViewer.addDoubleClickListener(new IDoubleClickListener() { + + /** + * {@inheritDoc} + */ + @Override + public void doubleClick(DoubleClickEvent event) { + // retrieve current item double clicked... + ITreeSelection selection = (TreeSelection) event.getSelection(); + Object firstSelected = selection.getFirstElement(); + if (firstSelected instanceof PaletteLocalDrawerProxy) { + UpdateLocalDrawerWizard wizard = new UpdateLocalDrawerWizard(((PaletteLocalDrawerProxy) firstSelected).getParent(), (PaletteLocalDrawerProxy) firstSelected); + WizardDialog dialog = new WizardDialog(getShell(), wizard); + dialog.open(); + // paletteTreeViewer.refresh(); + } + } + }); + + } + + /** + * Add drop behavior for the palette preview + */ + protected void addPalettePreviewDropSupport() { + // transfer types + Transfer[] transfers = new Transfer[] { LocalSelectionTransfer.getTransfer() }; + + // drag listener + DropTargetListener listener = new TreeDropTargetEffect(paletteTreeViewer.getTree()) { + + /** + * {@inheritDoc} + */ + @Override + public void drop(DropTargetEvent event) { + super.drop(event); + + // create proxy and adds it to its target parent + PaletteEntryProxy target = (PaletteEntryProxy) ((TreeItem) event.item).getData(); + if (target == null) { + target = (PaletteContainerProxy) paletteTreeViewer.getInput(); + } + + // get the elements from the drag listener (either a palette entry or a palette + // entry proxy) + IStructuredSelection transferedSelection = (IStructuredSelection) LocalSelectionTransfer.getTransfer().getSelection(); + Object entry = transferedSelection.getFirstElement(); + + // creates the proxy for the element to be dropped + PaletteEntryProxy entryProxy = createNodeFromEntry(entry); + + if (entryProxy == null) { + return; + } + if (target instanceof PaletteContainerProxy) { + // tries to remove from its parent if possible + if (entryProxy.getParent() != null) { + entryProxy.getParent().removeChild(entryProxy); + } + ((PaletteContainerProxy) target).addChild(entryProxy); + paletteTreeViewer.expandToLevel(target, 1); + } else if (target instanceof PaletteEntryProxy) { + // tries to remove from its parent if possible + if (entryProxy.getParent() != null) { + entryProxy.getParent().removeChild(entryProxy); + } + target.getParent().addChild(entryProxy, target); + paletteTreeViewer.expandToLevel(target.getParent(), 1); + } else { + // add to parent... + target.getParent().addChild(entryProxy); + paletteTreeViewer.expandToLevel(target.getParent(), AbstractTreeViewer.ALL_LEVELS); + } + setPageComplete(validatePage()); + } + + /** + * {@inheritDoc} + */ + @Override + public void dragOver(DropTargetEvent event) { + super.dragOver(event); + + LocalSelectionTransfer localTransfer = LocalSelectionTransfer.getTransfer(); + IStructuredSelection transferedSelection = null; + if (localTransfer.isSupportedType(event.currentDataType)) { + transferedSelection = (IStructuredSelection) localTransfer.getSelection(); + } + + // check selection is compatible for drop target + + TreeItem item = paletteTreeViewer.getTree().getItem(paletteTreeViewer.getTree().toControl(new Point(event.x, event.y))); + + checkSelectionForDrop(transferedSelection, item, event); + } + }; + + paletteTreeViewer.addDropSupport(DND.DROP_LINK | DND.DROP_MOVE, transfers, listener); + } + + /** + * Adds drag ability to the palette preview composite + */ + protected void addPalettePreviewDragSupport() { + + // transfer types + Transfer[] transfers = new Transfer[] { LocalSelectionTransfer.getTransfer() }; + + // drag listener + DragSourceListener listener = new LocalSelectionDragSource(paletteTreeViewer); + + paletteTreeViewer.addDragSupport(DND.DROP_MOVE, transfers, listener); + } + + /** + * Checks if the selection can be added to the target widget + * + * @param transferedSelection + * the selection to be dropped + * @param widget + * the widget where to drop + * @return <code>true</code> if element can be dropped + */ + protected void checkSelectionForDrop(IStructuredSelection transferedSelection, TreeItem item, DropTargetEvent event) { + event.detail = DND.DROP_NONE; + + if (transferedSelection == null) { + return; + } + + Object entry = transferedSelection.getFirstElement(); + // handle only first selected element + if (item == null) { + // adding to the root, should only be a drawer + if (entry instanceof PaletteDrawer) { + event.detail = DND.DROP_LINK; + } + } else { + PaletteEntryProxy targetProxy = (PaletteEntryProxy) item.getData(); + switch (targetProxy.getType()) { + case DRAWER: + if (entry instanceof ToolEntry) { + event.detail = DND.DROP_LINK; + } else if (entry instanceof PaletteEntryProxy) { + event.detail = DND.DROP_MOVE; + } + break; + case STACK: + if (entry instanceof ToolEntry) { + event.detail = DND.DROP_LINK; + } else if (entry instanceof PaletteEntryProxy && !(entry instanceof PaletteLocalStackProxy)) { + event.detail = DND.DROP_MOVE; + } + break; + case TOOL: + if (entry instanceof ToolEntry) { + event.detail = DND.DROP_LINK; // add the selected tool before the destination + // tool + } else if (entry instanceof PaletteEntryProxy) { + event.detail = DND.DROP_MOVE; // moves the element before the entry + } + break; + case SEPARATOR: + if (entry instanceof PaletteEntryProxy) { + event.detail = DND.DROP_MOVE; + } + break; + default: + break; + } + } + } + + /** + * Sets an empty content for the palette preview + */ + public void initializeContent() { + contentNode = new PaletteContainerProxy(null); + + // adds a default local drawer + PaletteLocalDrawerProxy proxy = new PaletteLocalDrawerProxy("Default", generateID("Drawer_"), "/icons/drawer.gif", "Default Drawer"); + contentNode.addChild(proxy); + + setPageComplete(false); + } + + /** + * Sets the initial content for the palette preview + */ + public void initializeContent(PapyrusPaletteService.LocalProviderDescriptor descriptor) { + // retrieve the xml definition file + String xmlPath = PapyrusPalettePreferences.getPalettePathFromID(descriptor.getContributionID()); + + // parse the content file + DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); + documentBuilderFactory.setNamespaceAware(true); + try { + DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); + + // Bundle bundle = Platform.getBundle(pluginID); + // URL url = bundle.getEntry(path); + + File file = Activator.getDefault().getStateLocation().append(xmlPath).toFile(); + if (!file.exists()) { + Activator.log.error("Impossible to load file: " + file, null); + } else { + Document document = documentBuilder.parse(file); + Map<String, PaletteEntry> entries = PaletteUtil.getAvailableEntriesSet(editorPart, ProviderPriority.HIGHEST); + + XMLPaletteDefinitionProxyFactory factory = new XMLPaletteDefinitionProxyFactory(entries); + XMLPaletteDefinitionWalker walker = new XMLPaletteDefinitionWalker(factory); + + for (int i = 0; i < document.getChildNodes().getLength(); i++) { + Node node = document.getChildNodes().item(i); + if (IPapyrusPaletteConstant.PALETTE_DEFINITION.equals(node.getNodeName())) { + walker.walk(node); + } + } + contentNode = factory.getRootProxy(); + + // tells that the page can be closed directly without modifying the palette + setPageComplete(true); + return; + } + } catch (ParserConfigurationException e) { + Activator.log.error(e); + } catch (IOException e) { + Activator.log.error(e); + } catch (SAXException e) { + Activator.log.error(e); + } + + // paletteTreeViewer.setInput(contentNode); + contentNode = new PaletteContainerProxy(null); + } + + /** + * Saves the xml document into file + * + * @param document + * the document to save + * @param path + * name of the file + * @return the file created or updated + */ + protected File loadDocument(Document document, String path) { + File file = null; + try { + // create the file that stores the XML configuration + file = Activator.getDefault().getStateLocation().append(path).toFile(); + Transformer aTransformer = TransformerFactory.newInstance().newTransformer(); + + Source src = new DOMSource(document); + Result dest = new StreamResult(file); + aTransformer.transform(src, dest); + } catch (TransformerConfigurationException e) { + Activator.log.error(e); + } catch (TransformerException e) { + Activator.log.error(e); + } + return file; + + } + + /** + * populates the preview palette toolbar + * + * @param toolbar + * the toolbar to populate + */ + protected void populatePalettePreviewToolBar(ToolBar toolbar) { + PaletteEntryProxySelectedValidator validator = new PaletteEntryProxySelectedValidator(); + createToolBarItem(toolbar, DELETE_ICON, Messages.PapyrusPaletteCustomizerDialog_RemoveButtonTooltip, createRemoveElementListener(), validator); + createToolBarItem(toolbar, EDIT_ICON, Messages.PapyrusPaletteCustomizerDialog_EditButtonTooltip, createEditElementListener(), new EditElementToolBarItemValidator()); + createToolBarItem(toolbar, CREATE_DRAWERS_ICON, Messages.Local_Palette_Create_Drawer_Tooltip, createNewDrawerListener(), null); + createToolBarItem(toolbar, CREATE_SEPARATOR_ICON, Messages.Local_Palette_Create_Separator_Tooltip, createNewSeparatorListener(), validator); + createToolBarItem(toolbar, CREATE_STACK_ICON, Messages.Local_Palette_Create_Stack_Tooltip, createNewStackListener(), validator); + } + + /** + * Edits the current selected elements. This works for drawers, should work on more elements + * + * @return the listener for the edit button + */ + protected Listener createEditElementListener() { + return new Listener() { + + /** + * {@inheritDoc} + */ + @Override + public void handleEvent(Event event) { + IStructuredSelection selection = (IStructuredSelection) paletteTreeViewer.getSelection(); + if (selection == null || selection.size() < 1) { + return; + } + + Object selected = selection.getFirstElement(); + if (selected instanceof PaletteLocalDrawerProxy) { + UpdateLocalDrawerWizard wizard = new UpdateLocalDrawerWizard(((PaletteLocalDrawerProxy) selected).getParent(), (PaletteLocalDrawerProxy) selected); + WizardDialog dialog = new WizardDialog(getShell(), wizard); + dialog.open(); + } + + // paletteTreeViewer.refresh(); + } + }; + } + + /** + * Creates the listener for the remove item(s) button + * + * @return the listener for the remove button + */ + protected Listener createRemoveElementListener() { + return new Listener() { + + /** + * {@inheritDoc} + */ + @Override + public void handleEvent(Event event) { + IStructuredSelection selection = (IStructuredSelection) paletteTreeViewer.getSelection(); + if (selection == null || selection.size() < 1) { + return; + } + + Iterator<?> it = selection.iterator(); + while (it.hasNext()) { + Object o = it.next(); + if (o instanceof PaletteEntryProxy) { + PaletteEntryProxy proxyToDelete = (PaletteEntryProxy) o; + // create a new entry in the document + // get container of the proxy to be deleted + PaletteContainerProxy parentProxy = proxyToDelete.getParent(); + if (parentProxy != null) { + parentProxy.removeChild(proxyToDelete); + } + } + } + // paletteTreeViewer.refresh(); + } + }; + } + + /** + * Creates the listener for the new drawer tool item + * + * @return the listener created + */ + protected Listener createNewDrawerListener() { + return new Listener() { + + /** + * {@inheritDoc} + */ + @Override + public void handleEvent(Event event) { + // retrieve selected container + PaletteContainerProxy containerProxy; + containerProxy = (PaletteContainerProxy) paletteTreeViewer.getInput(); + NewDrawerWizard wizard = new NewDrawerWizard(containerProxy); + WizardDialog wizardDialog = new WizardDialog(new Shell(), wizard); + wizardDialog.open(); + // paletteTreeViewer.refresh(); + setPageComplete(validatePage()); + } + }; + } + + /** + * Creates the listener for the new stack tool item + * + * @return the listener created + */ + protected Listener createNewStackListener() { + return new Listener() { + + /** + * {@inheritDoc} + */ + @Override + public void handleEvent(Event event) { + // retrieve selected element + Object object = ((IStructuredSelection) paletteTreeViewer.getSelection()).getFirstElement(); + + // if element = drawer => the new stack must be created at the end of the drawer's + // children list + // if element = tool => must be placed before this tool + // else : nothinng to do + if (object instanceof PaletteLocalDrawerProxy) { + String id = generateID("Stack"); + PaletteLocalStackProxy proxy = new PaletteLocalStackProxy(id); + ((PaletteLocalDrawerProxy) object).addChild(proxy); + } else if (object instanceof PaletteEntryProxy) { + String id = generateID("Stack"); + PaletteLocalStackProxy proxy = new PaletteLocalStackProxy(id); + // retrieve parent + PaletteEntryProxy childProxy = (PaletteEntryProxy) object; + PaletteContainerProxy parentProxy = childProxy.getParent(); + parentProxy.addChild(proxy, childProxy); + } + + // paletteTreeViewer.refresh(); + setPageComplete(validatePage()); + } + }; + } + + /** + * Generates the ID for a local element + * + * @param base + * the begining of the id + * @return the separator id + */ + protected String generateID(String base) { + StringBuffer id = new StringBuffer(); + id.append(base); + id.append("_"); + id.append(System.currentTimeMillis()); + + return id.toString(); + } + + /** + * Creates the listener for the new separator tool item + * + * @return the listener created + */ + protected Listener createNewSeparatorListener() { + return new Listener() { + + /** + * {@inheritDoc} + */ + @Override + public void handleEvent(Event event) { + // retrieve selected element + Object object = ((IStructuredSelection) paletteTreeViewer.getSelection()).getFirstElement(); + + // if element = drawer => the new stack must be created at the end of the drawer's + // children list + // if element = tool => must be placed before this tool + // else : nothinng to do + if (object instanceof PaletteLocalDrawerProxy) { + String id = generateID("Separator"); + PaletteLocalSeparatorProxy proxy = new PaletteLocalSeparatorProxy(id); + ((PaletteLocalDrawerProxy) object).addChild(proxy); + } else if (object instanceof PaletteEntryProxy) { + String id = generateID("Separator"); + PaletteLocalSeparatorProxy proxy = new PaletteLocalSeparatorProxy(id); + // retrieve parent + PaletteEntryProxy childProxy = (PaletteEntryProxy) object; + PaletteContainerProxy parentProxy = childProxy.getParent(); + parentProxy.addChild(proxy, childProxy); + } + + setPageComplete(validatePage()); + } + }; + } + + /** + * Creates a toolbar item. + * + * @param toolbar + * the parent toolbar + * @param itemIcon + * path for icon + * @param tooltip + * tooltip text for the toolbar item + * @param listener + * listener for tool bar item + */ + protected void createToolBarItem(ToolBar toolbar, String itemIcon, String tooltip, Listener listener, ToolBarItemValidator validator) { + ToolItem item = new ToolItem(toolbar, SWT.BORDER); + item.setImage(Activator.getPluginIconImage(Activator.ID, itemIcon)); + item.setToolTipText(tooltip); + item.addListener(SWT.Selection, listener); + item.setData(VALIDATOR, validator); + } + + /** + * creates the buttons to add/remove entries + */ + protected void createAddRemoveButtons() { + Composite composite = new Composite((Composite) getControl(), SWT.NONE); + GridLayout layout = new GridLayout(1, true); + composite.setLayout(layout); + + GridData data = new GridData(SWT.CENTER, SWT.CENTER, false, true); + composite.setLayoutData(data); + + addButton = new Button(composite, SWT.NONE); + addButton.setImage(Activator.getPluginIconImage(Activator.ID, ADD_ICON)); + addButton.setToolTipText(Messages.PapyrusPaletteCustomizerDialog_AddButtonTooltip); + addButton.addMouseListener(createAddButtonListener()); + addButton.setEnabled(false); + addButton.addListener(SWT.MouseUp, this); + + removeButton = new Button(composite, SWT.NONE); + removeButton.setImage(Activator.getPluginIconImage(Activator.ID, REMOVE_ICON)); + removeButton.setToolTipText(Messages.PapyrusPaletteCustomizerDialog_RemoveButtonTooltip); + removeButton.addMouseListener(createRemoveButtonListener()); + removeButton.setEnabled(false); + removeButton.addListener(SWT.MouseUp, this); + } + + /** + * selection listener for the tools viewer , to update the state of the add button + * + * @return the new created selection listener + */ + protected ISelectionChangedListener createToolsViewerSelectionChangeListener() { + return new ISelectionChangedListener() { + + /** + * {@inheritDoc} + */ + @Override + public void selectionChanged(SelectionChangedEvent event) { + + // get source and target selection + // check source entry can be added to target entry + Object source = ((IStructuredSelection) availableToolsViewer.getSelection()).getFirstElement(); + Object target = ((IStructuredSelection) paletteTreeViewer.getSelection()).getFirstElement(); + + // manage add button + if (isAddValidTarget(source, target)) { + addButton.setEnabled(true); + } else { + addButton.setEnabled(false); + } + + // manage remove button + if (isRemoveValidSource(target)) { + removeButton.setEnabled(true); + } else { + removeButton.setEnabled(false); + } + + } + + /** + * Returns true if the source can be added to the target + * + * @param source + * the source object + * @param target + * the target object + * @return <code>true</code> if the source can be added to the target + */ + protected boolean isAddValidTarget(Object source, Object target) { + if (!(source instanceof PaletteEntry)) { + return false; + } + + // case1: source is a drawer. + // it can only be added to the root element (no selection) + // case2: source is a palette tool + // it can't be added to the root element + // it can only be added to a container element (drawer or stack) + if (source instanceof PaletteDrawer) { + if (target == null) { + return true; + } + return false; + } else if (source instanceof ToolEntry) { + if (target instanceof PaletteEntryProxy) { + EntryType type = ((PaletteEntryProxy) target).getType(); + switch (type) { + case DRAWER: + case STACK: + return true; + default: + return false; + } + } + return false; + } + return false; + } + + /** + * Returns true if the source can be added to the target + * + * @param source + * the source object + * @return <code>true</code> if the source can be removed (not null and instanceof + * PaletteEntryProxy) + */ + protected boolean isRemoveValidSource(Object source) { + if (source instanceof PaletteEntryProxy) { + return true; + } + return false; + } + }; + + } + + /** + * Creates the add button listener + */ + protected MouseListener createAddButtonListener() { + return new MouseListener() { + + @Override + public void mouseUp(MouseEvent e) { + // add the element selected on the left to the right tree + // check the selection. + IStructuredSelection selection = (IStructuredSelection) availableToolsViewer.getSelection(); + if (selection == null || selection.size() < 1) { + return; + } + PaletteEntry entry = (PaletteEntry) selection.getFirstElement(); + if (entry == null) { + return; + } + + // find the selection on the right + selection = (IStructuredSelection) paletteTreeViewer.getSelection(); + + PaletteEntryProxy parentNode = (PaletteEntryProxy) selection.getFirstElement(); + // Bugfix: only drawers can be added to root element + if (parentNode == null && entry instanceof PaletteDrawer) { + parentNode = (PaletteContainerProxy) paletteTreeViewer.getInput(); + } + + // check we have a containe here + if (!(parentNode instanceof PaletteContainerProxy)) { + return; + } + + // create a new entry in the document + PaletteEntryProxy proxy = createNodeFromEntry(entry); + ((PaletteContainerProxy) parentNode).addChild(proxy); + + paletteTreeViewer.expandToLevel(parentNode, 1); + } + + /** + * {@inheritDoc} + */ + @Override + public void mouseDown(MouseEvent e) { + // do nothing + } + + /** + * {@inheritDoc} + */ + @Override + public void mouseDoubleClick(MouseEvent e) { + // do nothing + } + }; + } + + /** + * Creates a node in the xml document from the given entry + * + * @param entry + * the palette entry from which to create the node + * @param parentNode + * the parent node for the newly created node + * @return the created entry proxy or <code>null</code> + */ + protected PaletteEntryProxy createNodeFromEntry(Object entry) { + PaletteEntryProxy entryProxy = null; + + if (entry instanceof AspectCreationEntry) { + // should modify id of the element here, otherwise, different elements would have the same id... + entryProxy = new PaletteAspectToolEntryProxy(((AspectCreationEntry) entry).clone()); + } else if (entry instanceof CombinedTemplateCreationEntry) { + CombinedTemplateCreationEntry originalEntry = (CombinedTemplateCreationEntry) entry; + // create a new Aspect entry proxy + AspectCreationEntry aspectEntry = new AspectCreationEntry(originalEntry.getLabel(), originalEntry.getDescription(), originalEntry.getId() + "_" + System.currentTimeMillis(), originalEntry.getSmallIcon(), originalEntry, + new HashMap<Object, Object>()); + entryProxy = new PaletteAspectToolEntryProxy(aspectEntry); + } else if (entry instanceof PaletteContainer) { + entryProxy = new PaletteContainerProxy((PaletteContainer) entry); + } else if (entry instanceof PaletteEntryProxy) { + entryProxy = ((PaletteEntryProxy) entry); + } + return entryProxy; + } + + /** + * Creates the add button listener + */ + protected MouseListener createRemoveButtonListener() { + return new MouseListener() { + + @Override + public void mouseUp(MouseEvent e) { + // remove the element selected on the right + // add the element selected on the left to the right tree + // check the selection. + IStructuredSelection selection = (IStructuredSelection) paletteTreeViewer.getSelection(); + if (selection == null || selection.size() < 1) { + return; + } + PaletteEntryProxy proxyToDelete = (PaletteEntryProxy) selection.getFirstElement(); + if (proxyToDelete == null) { + return; + } + + // create a new entry in the document + // get container of the proxy to be deleted + PaletteContainerProxy parentProxy = proxyToDelete.getParent(); + parentProxy.removeChild(proxyToDelete); + } + + /** + * {@inheritDoc} + */ + @Override + public void mouseDown(MouseEvent e) { + // do nothing + } + + /** + * {@inheritDoc} + */ + @Override + public void mouseDoubleClick(MouseEvent e) { + // do nothing + } + }; + } + + /** + * creates the available entries group + */ + protected void createAvailableToolsGroup() { + Composite parent = (Composite) getControl(); + Composite availableToolsComposite = new Composite(parent, SWT.NONE); + GridLayout layout = new GridLayout(2, true); + layout.marginHeight = 0; + layout.marginWidth = 0; + availableToolsComposite.setLayout(layout); + GridData data = new GridData(SWT.FILL, SWT.FILL, true, true); + availableToolsComposite.setLayoutData(data); + + Label label = new Label(availableToolsComposite, SWT.NONE); + label.setText(Messages.Local_Palette_Available_Tools); + data = new GridData(SWT.LEFT, SWT.CENTER, true, false); + label.setLayoutData(data); + + ToolBar toolbar = new ToolBar(availableToolsComposite, SWT.HORIZONTAL); + data = new GridData(SWT.RIGHT, SWT.FILL, false, false); + toolbar.setLayoutData(data); + populateAvailableToolsToolBar(toolbar); + + createProfileCombo(availableToolsComposite); + + Tree tree = new Tree(availableToolsComposite, SWT.SINGLE | SWT.BORDER); + data = new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1); + data.widthHint = 185; + // Make the tree this tall even when there is nothing in it. This will keep the + // dialog from shrinking to an unusually small size. + data.heightHint = 200; + tree.setLayoutData(data); + availableToolsViewer = new TreeViewer(tree); + availableToolsViewer.setContentProvider(new UMLToolsTreeContentProvider()); + paletteLabelProvider = new PaletteLabelProvider(); + availableToolsViewer.setLabelProvider(paletteLabelProvider); + ViewerComparator labelComparator = new LabelViewerComparator(); + availableToolsViewer.setComparator(labelComparator); + // remove the note stack and standard group + availableToolsViewer.addFilter(new ViewerFilter() { + + /** + * {@inheritDoc} + */ + @Override + public boolean select(Viewer viewer, Object parentElement, Object element) { + if (element instanceof PaletteStack && "noteStack".equals(((PaletteStack) element).getId())) { + return false; + } else if (element instanceof PaletteToolbar && "standardGroup".equals(((PaletteToolbar) element).getId())) { + return false; + } + return true; + } + }); + availableToolsViewer.addFilter(new DrawerFilter()); + // add drag support + addAvailableToolsDragSupport(); + // availableToolsViewer.setInput(getAllVisibleStandardEntries()); + } + + /** + * Creates the profile combo + * + * @param availableToolsComposite + * the available tools composite + * @return the created combo + */ + protected Combo createProfileCombo(Composite availableToolsComposite) { + // retrieve top package, to know which profiles are available + // creates the combo + profileCombo = new Combo(availableToolsComposite, SWT.BORDER | SWT.READ_ONLY); + GridData data = new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1); + profileCombo.setLayoutData(data); + + // retrieve all applied profiles + List<Profile> profiles = getAllAppliedProfiles(); + + int profileNumber = profiles.size(); + for (int i = 0; i < profileNumber; i++) { + String name; + if (profiles.get(i).eIsProxy()) { + name = NLS.bind("<unresolved: {0}>", URI.decode(EcoreUtil.getURI(profiles.get(i)).lastSegment())); + } else { + name = profiles.get(i).getName(); + if (name == null) { + name = NLS.bind("<unnamed: {0}>", URI.decode(EcoreUtil.getURI(profiles.get(i)).lastSegment())); + } + } + profileComboList.add(i, name); + } + profileComboList.add(UML_TOOLS_LABEL); + profileCombo.setItems(profileComboList.toArray(new String[] {})); + + // add selection listener for the combo. selects the "UML tools" item + ProfileComboSelectionListener listener = new ProfileComboSelectionListener(); + profileCombo.addSelectionListener(listener); + profileCombo.addModifyListener(listener); + // profileCombo.select(profileNumber); + + return profileCombo; + } + + /** + * returns the list of applied profile for the nearest package of the top element + * + * @return the list of applied profile for the nearest package of the top element or an empty + * list + */ + protected List<Profile> getAllAppliedProfiles() { + Package topPackage = null; + if (editorPart instanceof DiagramEditorWithFlyOutPalette) { + EObject element = ((DiagramEditorWithFlyOutPalette) editorPart).getDiagram().getElement(); + if (element instanceof org.eclipse.uml2.uml.Element) { + topPackage = ((org.eclipse.uml2.uml.Element) element).getNearestPackage(); + } + } + if (topPackage != null) { + return topPackage.getAllAppliedProfiles(); + } + return Collections.emptyList(); + } + + /** + * Add drag support from the available tools viewer + */ + protected void addAvailableToolsDragSupport() { + // transfer types + Transfer[] transfers = new Transfer[] { LocalSelectionTransfer.getTransfer() }; + + // drag listener + DragSourceListener listener = new LocalSelectionDragSource(availableToolsViewer); + + availableToolsViewer.addDragSupport(DND.DROP_LINK, transfers, listener); + } + + /** + * Adds elements to the tool bar for available tools viewer + * + * @param toolbar + * the toolbar to populate + */ + protected void populateAvailableToolsToolBar(ToolBar toolbar) { + toggleContentProvider = createCheckToolBarItem(toolbar, SWITCH_CONTENT_PROVIDER_ICON, Messages.Local_Palette_SwitchToolsContentProvider_Tooltip, createSwitchToolsContentProviderListener()); + toggleContentProvider.setSelection(true); + toggleContentProvider.setEnabled(false); + createCheckToolBarItem(toolbar, SHOWN_TOOLS_ICON, Messages.Local_Palette_ShowTools_Tooltip, createsShowToolListener()); + } + + /** + * Creates the listener for the available tools content provider + * + * @return the listener created + */ + protected Listener createSwitchToolsContentProviderListener() { + return new Listener() { + + /** + * {@inheritDoc} + */ + @Override + public void handleEvent(Event event) { + if (!(event.widget instanceof ToolItem)) { + return; + } + ToolItem item = ((ToolItem) event.widget); + // retrieve current profile selected in the combo profile + int index = profileCombo.getSelectionIndex(); + Collection<PaletteEntry> standardEntries = getAllVisibleStandardEntries(); + Profile profile = getAllAppliedProfiles().get(index); + + if (item.getSelection()) { + availableToolsViewer.setContentProvider(new ProfileToolsStereotypeMetaclassTreeContentProvider(profile, standardEntries)); + item.setSelection(true); + } else { + + availableToolsViewer.setContentProvider(new ProfileToolsMetaclassStereotypeTreeContentProvider(profile, standardEntries)); + item.setSelection(false); + } + + // generate tools for given profile + availableToolsViewer.setInput(profile); + } + }; + } + + /** + * creates the tool item for drawers visibility listener + * + * @return the listener for the tool button + */ + protected Listener createShowDrawerListener() { + return new Listener() { + + /** + * {@inheritDoc} + */ + @Override + public void handleEvent(Event event) { + if (!(event.widget instanceof ToolItem)) { + return; + } + ToolItem item = ((ToolItem) event.widget); + if (item.getSelection()) { + // elements should be hidden + availableToolsViewer.addFilter(drawerFilter); + item.setSelection(true); + } else { + availableToolsViewer.removeFilter(drawerFilter); + item.setSelection(false); + } + } + }; + } + + /** + * creates the tool item for tools visibility listener + * + * @return the listener for the tool button + */ + protected Listener createsShowToolListener() { + return new Listener() { + + /** + * {@inheritDoc} + */ + @Override + public void handleEvent(Event event) { + if (!(event.widget instanceof ToolItem)) { + return; + } + ToolItem item = ((ToolItem) event.widget); + if (item.getSelection()) { + // elements should be hidden + availableToolsViewer.addFilter(toolFilter); + item.setSelection(true); + } else { + availableToolsViewer.removeFilter(toolFilter); + item.setSelection(false); + } + } + }; + } + + /** + * Creates a toolbar item which can be checked. + * + * @param toolbar + * the parent toolbar + * @param shownElementsIcon + * path for shown elements icon + * @param listener + * listener for button action + * @param tooltip + * tooltip text for the toolbar item + */ + protected ToolItem createCheckToolBarItem(ToolBar toolbar, String shownElementsIcon, String tooltip, Listener listener) { + ToolItem item = new ToolItem(toolbar, SWT.CHECK | SWT.BORDER); + item.setImage(Activator.getPluginIconImage(Activator.ID, shownElementsIcon)); + item.setToolTipText(tooltip); + item.addListener(SWT.Selection, listener); + return item; + } + + /** + * Validates the content of the fields in this page + */ + protected boolean validatePage() { + boolean valid = true; + + if (valid) { + setMessage(null); + setErrorMessage(null); + } + return valid; + } + + /** + * The <code>WizardNewFileCreationPage</code> implementation of this <code>Listener</code> method handles all events and enablements for controls + * on this page. Subclasses may extend. + */ + @Override + public void handleEvent(Event event) { + setPageComplete(validatePage()); + } + + /** + * Content provider for available tools viewer + */ + public class UMLToolsTreeContentProvider implements ITreeContentProvider { + + /** + * Constructor + * + * @param viewer + * The viewer whose ContentProvider this content provider is + */ + public UMLToolsTreeContentProvider() { + } + + /** + * {@inheritDoc} + */ + @Override + public Object[] getElements(Object inputElement) { + Object[] elements = null; + + if (inputElement instanceof Collection<?>) { + elements = ((Collection<?>) inputElement).toArray(); + } else if (inputElement instanceof PaletteRoot) { + // paletteUil.getAllEntries(...) to add drawers + // if so, uncomment the addFilterbutton for drawers in populate tool bar + elements = PaletteUtil.getAllToolEntries(((PaletteRoot) inputElement)).toArray(); + } + + if (elements == null) { + elements = new Object[0]; + } + return elements; + } + + /** + * {@inheritDoc} + */ + @Override + public void dispose() { + } + + /** + * {@inheritDoc} + */ + @Override + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + + } + + /** + * {@inheritDoc} + */ + @Override + public Object[] getChildren(Object parentElement) { + Object[] elements = null; + + if (parentElement instanceof Collection<?>) { + elements = ((Collection<?>) parentElement).toArray(); + } else if (parentElement instanceof PaletteRoot) { + // paletteUil.getAllEntries(...) to add drawers + // if so, uncomment the addFilterbutton for drawers in populate tool bar + elements = PaletteUtil.getAllToolEntries(((PaletteRoot) parentElement)).toArray(); + } + + return elements; + } + + /** + * {@inheritDoc} + */ + @Override + public Object getParent(Object element) { + return null; + } + + /** + * {@inheritDoc} + */ + @Override + public boolean hasChildren(Object element) { + return getChildren(element) != null && getChildren(element).length > 0; + } + } + + /** + * Label provider for palette tools. + * <P> + * We should be using the Palette label provider from GEF, if it was not with visibility "package"... + * + * @see org.eclipse.gef.ui.palette.customize.PaletteLabelProvider + * </P> + * + */ + public class PaletteLabelProvider implements ILabelProvider { + + /** + * {@inheritDoc} + */ + @Override + public Image getImage(Object element) { + if (element instanceof PaletteEntry) { + ImageDescriptor descriptor = ((PaletteEntry) element).getSmallIcon(); + if (descriptor == null) { + return null; + } + return Activator.getPluginIconImage(Activator.ID, descriptor); + } else if (element instanceof Stereotype) { + return Activator.getPluginIconImage(Activator.ID, "/icons/stereotype.gif"); + } + return null; + } + + /** + * {@inheritDoc} + */ + @Override + public String getText(Object element) { + if (element instanceof PaletteEntry) { + return ((PaletteEntry) element).getLabel(); + } else if (element instanceof Stereotype) { + return ((Stereotype) element).getName(); + } + return "unknown element"; + } + + /** + * {@inheritDoc} + */ + @Override + public void addListener(ILabelProviderListener listener) { + + } + + /** + * {@inheritDoc} + */ + @Override + public void dispose() { + + } + + /** + * {@inheritDoc} + */ + @Override + public boolean isLabelProperty(Object element, String property) { + return false; + } + + /** + * {@inheritDoc} + */ + @Override + public void removeListener(ILabelProviderListener listener) { + + } + + } + + /** + * Label provider for palette tools. + * <P> + * We should be using the Palette label provider from GEF, if it was not with visibility "package"... + * + * @see org.eclipse.gef.ui.palette.customize.PaletteLabelProvider + * </P> + * + */ + public class PaletteProxyLabelProvider implements ILabelProvider { + + /** + * {@inheritDoc} + */ + @Override + public Image getImage(Object element) { + if (element instanceof PaletteEntryProxy) { + return ((PaletteEntryProxy) element).getImage(); + } + return null; + } + + /** + * {@inheritDoc} + */ + @Override + public String getText(Object element) { + if (element instanceof PaletteEntryProxy) { + return ((PaletteEntryProxy) element).getLabel(); + } + return "unknown element"; + } + + /** + * {@inheritDoc} + */ + @Override + public void addListener(ILabelProviderListener listener) { + + } + + /** + * {@inheritDoc} + */ + @Override + public void dispose() { + + } + + /** + * {@inheritDoc} + */ + @Override + public boolean isLabelProperty(Object element, String property) { + return false; + } + + /** + * {@inheritDoc} + */ + @Override + public void removeListener(ILabelProviderListener listener) { + + } + + } + + /** + * Filter for the viewer. Hide/show Drawers + */ + public class DrawerFilter extends ViewerFilter { + + /** + * {@inheritDoc} + */ + @Override + public boolean select(Viewer viewer, Object parentElement, Object element) { + if (element instanceof PaletteDrawer) { + return false; + } + return true; + } + + } + + /** + * Filter for the viewer. Hide/show Drawers + */ + public class ToolFilter extends ViewerFilter { + + /** + * {@inheritDoc} + */ + @Override + public boolean select(Viewer viewer, Object parentElement, Object element) { + if (element instanceof ToolEntry) { + return false; + } + return true; + } + + } + + /** + * Content provider for the palette + */ + public class PaletteContentProvider implements ITreeContentProvider { + + /** tree viewer this provider provides content */ + protected final TreeViewer viewer; + + /** the document root where to build the palette */ + protected PaletteContainerProxy rootProxy; + + /** model listener that will listens for all modifications in the entries */ + protected PropertyChangeListener modelListener = new PropertyChangeListener() { + + @Override + public void propertyChange(PropertyChangeEvent evt) { + handlePropertyChanged(evt); + } + }; + + /** + * Creates a new PaletteContentProvider. + * + * @param treeviewer + * tree viewer this provider provides content + */ + public PaletteContentProvider(TreeViewer treeviewer) { + this.viewer = treeviewer; + } + + /** + * {@inheritDoc} + */ + @Override + public void dispose() { + // remove all listeners + traverseModel(rootProxy, false); + } + + /** + * {@inheritDoc} + */ + @Override + public Object[] getChildren(Object parentElement) { + if (parentElement instanceof PaletteEntryProxy) { + List<PaletteEntryProxy> children = ((PaletteEntryProxy) parentElement).getChildren(); + return (children != null) ? children.toArray() : new Object[0]; + } + return null; + } + + /** + * {@inheritDoc} + */ + @Override + public boolean hasChildren(Object element) { + if (element instanceof PaletteEntryProxy) { + return ((PaletteEntryProxy) element).getChildren() != null && !((PaletteEntryProxy) element).getChildren().isEmpty(); + } + return false; + } + + /** + * {@inheritDoc} + */ + @Override + public Object[] getElements(Object inputElement) { + Object[] elements = getChildren(inputElement); + if (elements == null) { + elements = new Object[0]; + } + return elements; + } + + /** + * {@inheritDoc} + */ + @Override + public Object getParent(Object element) { + if (element instanceof PaletteEntryProxy) { + return ((PaletteEntryProxy) element).getParent(); + } + return null; + } + + /** + * {@inheritDoc} + */ + @Override + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + if (rootProxy != null) { + // warning.. the root has no entry, this is a virtual node + traverseModel(rootProxy, false); + } + + if (newInput != null) { + rootProxy = ((PaletteContainerProxy) newInput); + traverseModel(rootProxy, true); + } + } + + /** + * This method is invoked whenever there is any change in the model. It updates the + * viewer with the changes that were made to the model. Sub-classes may override this + * method to change or extend its functionality. + * + * @param evt + * The {@link PropertyChangeEvent} that was fired from the model + */ + protected void handlePropertyChanged(PropertyChangeEvent evt) { + PaletteEntryProxy entry = ((PaletteEntryProxy) evt.getSource()); + String property = evt.getPropertyName(); + if (property.equals(PaletteEntry.PROPERTY_LABEL) || property.equals(PaletteEntry.PROPERTY_SMALL_ICON) || property.equals(PaletteEntryProxy.PROPERTY_ICON_PATH)) { + viewer.update(entry, null); + } else if (property.equals(PaletteEntryProxy.PROPERTY_ADD_CHILDREN)) { + viewer.refresh(entry.getParent()); + // add the listeners to the child + traverseModel(((PaletteEntryProxy) evt.getNewValue()), true); + } else if (property.equals(PaletteEntryProxy.PROPERTY_REMOVE_CHILDREN)) { + viewer.refresh(entry.getParent()); + // add the listeners to the child + traverseModel(((PaletteEntryProxy) evt.getOldValue()), false); + } + + } + + protected void traverseModel(PaletteEntryProxy entryProxy, boolean isHook) { + if (entryProxy != null) { + if (isHook) { + entryProxy.addPropertyChangeListener(modelListener); + } else { + entryProxy.removePropertyChangeListener(modelListener); + } + } + + if (entryProxy.getChildren() != null && !entryProxy.getChildren().isEmpty()) { + for (PaletteEntryProxy proxy : entryProxy.getChildren()) { + traverseModel(proxy, isHook); + } + } + } + } + + /** + * Performs all action on finish + * + * @param id + * the path for the file + */ + public void performFinish(String path) { + // creates the document + Document document = createXMLDocumentFromPalettePreview(); + saveDocument(document, path); + requiredProfiles = collectRequiredProfiles(); + } + + /** + * collect the required profiles from all tool provided by the local palette definition + */ + protected Set<String> collectRequiredProfiles() { + Set<String> profiles = new HashSet<String>(); + PaletteContainerProxy rootProxy = (PaletteContainerProxy) paletteTreeViewer.getInput(); + collectRequiredProfiles(rootProxy.getChildren(), profiles); + return profiles; + } + + /** + * collect the required profiles from all tool provided by the local palette definition + */ + protected void collectRequiredProfiles(List<PaletteEntryProxy> proxies, Set<String> requiredProfiles) { + for (PaletteEntryProxy proxy : proxies) { + // add profile(s) if relevant, check for children + + if (proxy instanceof PaletteAspectToolEntryProxy) { + // list of profiles + for (String stereotypeQN : ((PaletteAspectToolEntryProxy) proxy).getStereotypesQNList()) { + // retrieve list of profiles from the stereotype QN (only remove last segment + // ?!) + String profileName = PaletteUtil.findProfileNameFromStereotypeName(stereotypeQN); + requiredProfiles.add(profileName); + } + } + + if (proxy.getChildren() != null) { + collectRequiredProfiles(proxy.getChildren(), requiredProfiles); + } + } + } + + /** + * Saves the xml document into file + * + * @param document + * the document to save + * @param path + * name of the file + * @return the file created or updated + */ + protected File saveDocument(Document document, String path) { + File file = null; + try { + // create the file that stores the XML configuration + file = Activator.getDefault().getStateLocation().append(path).toFile(); + TransformerFactory tranFactory = TransformerFactory.newInstance(); + Transformer aTransformer; + + aTransformer = tranFactory.newTransformer(); + + Source src = new DOMSource(document); + Result dest = new StreamResult(file); + aTransformer.transform(src, dest); + } catch (TransformerConfigurationException e) { + Activator.log.error(e); + } catch (TransformerException e) { + Activator.log.error(e); + } + return file; + + } + + /** + * Creates the document from the palette preview + * + * @return the dom structure of the document + */ + protected Document createXMLDocumentFromPalettePreview() { + DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); + documentBuilderFactory.setNamespaceAware(true); + DocumentBuilder documentBuilder; + try { + documentBuilder = documentBuilderFactory.newDocumentBuilder(); + document = documentBuilder.newDocument(); + Element paletteDefElement = document.createElement(IPapyrusPaletteConstant.PALETTE_DEFINITION); + document.appendChild(paletteDefElement); + Element contentElement = document.createElement(IPapyrusPaletteConstant.CONTENT); + paletteDefElement.appendChild(contentElement); + + generateXMLPaletteContent(document, contentElement); + return document; + } catch (ParserConfigurationException e) { + Activator.getDefault().logError("impossible to create the palette tree viewer content", e); + } + return null; + } + + /** + * Generates the xml content for the palette + * + * @param document + * the document to fill + * @param contentElement + * the root for the xml content + */ + protected void generateXMLPaletteContent(Document document, Element contentElement) { + PaletteContainerProxy rootProxy = (PaletteContainerProxy) paletteTreeViewer.getInput(); + for (PaletteEntryProxy proxy : rootProxy.getChildren()) { + generateXMLPaletteContainerProxy(document, contentElement, proxy); + } + } + + /** + * Generates the xml content for the given container + * + * @param document + * the document to fill + * @param containerProxy + * the entry proxy + */ + protected void generateXMLPaletteContainerProxy(Document document, Element contentElement, PaletteEntryProxy containerProxy) { + + Element element = null; + List<PaletteEntryProxy> children = containerProxy.getChildren(); + // generate the element + switch (containerProxy.getType()) { + case DRAWER: + element = document.createElement(IPapyrusPaletteConstant.DRAWER); + element.setAttribute(IPapyrusPaletteConstant.NAME, containerProxy.getLabel()); + if (containerProxy instanceof PaletteLocalDrawerProxy) { + element.setAttribute(IPapyrusPaletteConstant.ICON_PATH, ((PaletteLocalDrawerProxy) containerProxy).getImagePath()); + } + break; + case TOOL: + element = document.createElement(IPapyrusPaletteConstant.TOOL); + break; + case SEPARATOR: + element = document.createElement(IPapyrusPaletteConstant.SEPARATOR); + break; + case STACK: + element = document.createElement(IPapyrusPaletteConstant.STACK); + break; + case ASPECT_TOOL: + element = document.createElement(IPapyrusPaletteConstant.ASPECT_TOOL); + // try to cast the element into PaletteAspectToolEntryProxy + if (containerProxy instanceof PaletteAspectToolEntryProxy) { + PaletteAspectToolEntryProxy aspectEntryProxy = (PaletteAspectToolEntryProxy) containerProxy; + // element.setAttribute(IPapyrusPaletteConstant.ID, aspectEntryProxy.getId()); + element.setAttribute(IPapyrusPaletteConstant.NAME, aspectEntryProxy.getLabel()); + element.setAttribute(IPapyrusPaletteConstant.DESCRIPTION, aspectEntryProxy.getEntry().getDescription()); + element.setAttribute(IPapyrusPaletteConstant.REF_TOOL_ID, aspectEntryProxy.getReferencedPaletteID()); + + if (aspectEntryProxy.getImagePath() != null && !aspectEntryProxy.getImagePath().equals("")) { + element.setAttribute(IPapyrusPaletteConstant.ICON_PATH, aspectEntryProxy.getImagePath()); + } + + + // add post action, stereotype list + for (IAspectAction action : ((PaletteAspectToolEntryProxy) containerProxy).getPostActions()) { + Element postActionNode = document.createElement(IPapyrusPaletteConstant.POST_ACTION); + postActionNode.setAttribute(IPapyrusPaletteConstant.ID, action.getFactoryId()); + action.save(postActionNode); + element.appendChild(postActionNode); + } + for (IAspectAction action : ((PaletteAspectToolEntryProxy) containerProxy).getPreActions()) { + Element preActionNode = document.createElement(IPapyrusPaletteConstant.PRE_ACTION); + preActionNode.setAttribute(IPapyrusPaletteConstant.ID, action.getFactoryId()); + action.save(preActionNode); + element.appendChild(preActionNode); + } + } + default: + break; + } + + element.setAttribute(IPapyrusPaletteConstant.ID, containerProxy.getId()); + contentElement.appendChild(element); + + if (children != null) { + for (PaletteEntryProxy proxy : children) { + generateXMLPaletteContainerProxy(document, element, proxy); + } + } + } + + public enum EntryType { + DRAWER, TOOL, STACK, SEPARATOR, ASPECT_TOOL + } + + public class LabelViewerComparator extends ViewerComparator { + + /** + * Creates a new LabelViewerComparator. + */ + public LabelViewerComparator() { + super(); + } + + /** + * {@inheritDoc} + */ + @Override + public int compare(Viewer testViewer, Object e1, Object e2) { + String label1 = ""; + String label2 = ""; + + if (e1 instanceof PaletteEntry) { + label1 = ((PaletteEntry) e1).getLabel(); + } else if (e1 instanceof Stereotype) { + label1 = ((Stereotype) e1).getName(); + } + if (e2 instanceof PaletteEntry) { + label2 = ((PaletteEntry) e2).getLabel(); + } else if (e2 instanceof Stereotype) { + label2 = ((Stereotype) e2).getName(); + } + + if (label1 == null) { + return 1; + } + if (label2 == null) { + return -1; + } + + return label1.compareTo(label2); + } + } + + /** + * Listener for the profile combo. It changes the input of the following viewer. + */ + public class ProfileComboSelectionListener implements SelectionListener, ModifyListener { + + /** + * {@inheritDoc} + */ + @Override + public void widgetDefaultSelected(SelectionEvent e) { + // nothing to do + } + + /** + * {@inheritDoc} + */ + @Override + public void widgetSelected(SelectionEvent e) { + handleSelectionChanged(); + } + + /** + * {@inheritDoc} + */ + @Override + public void modifyText(ModifyEvent e) { + handleSelectionChanged(); + } + + /** + * handles the change selection for the combo + */ + protected void handleSelectionChanged() { + int index = profileCombo.getSelectionIndex(); + if (index < 0 || index >= profileCombo.getItems().length) { + return; + } + String name = profileComboList.get(index); + + Collection<PaletteEntry> standardEntries = getAllVisibleStandardEntries(); + // retrieve the profile or uml standards tools to display + if (UML_TOOLS_LABEL.equals(name)) { + // change content provider + availableToolsViewer.setContentProvider(new UMLToolsTreeContentProvider()); + availableToolsViewer.setInput(standardEntries); + toggleContentProvider.setEnabled(false); + } else { + if (toggleContentProvider != null && !toggleContentProvider.isDisposed()) { + toggleContentProvider.setEnabled(true); + } + // switch content provider + // this is a profile in case of uml2 tools + Profile profile = getAllAppliedProfiles().get(index); + if (toggleContentProvider.getSelection()) { + availableToolsViewer.setContentProvider(new ProfileToolsStereotypeMetaclassTreeContentProvider(profile, standardEntries)); + } else { + availableToolsViewer.setContentProvider(new ProfileToolsMetaclassStereotypeTreeContentProvider(profile, standardEntries)); + } + + // generate tools for given profile + availableToolsViewer.setInput(profile); + } + } + } + + /** + * Content provider for the available tools viewer, when the tools to see are coming from a + * profile + */ + public class ProfileToolsStereotypeMetaclassTreeContentProvider implements ITreeContentProvider { + + /** standard uml tools palette entries */ + final protected Collection<PaletteEntry> standardEntries; + + /** + * Creates a new ProfileToolsStereotypeMetaclassTreeContentProvider. + * + * @param profile + * the profile for which tools are built + * @param standardEntries + * list of standard uml tools palette entries + */ + public ProfileToolsStereotypeMetaclassTreeContentProvider(Profile profile, Collection<PaletteEntry> standardEntries) { + this.standardEntries = standardEntries; + } + + /** + * {@inheritDoc} + */ + @Override + public Object[] getChildren(Object parentElement) { + if (parentElement instanceof Profile) { + return ((Profile) parentElement).getOwnedStereotypes().toArray(); + } else if (parentElement instanceof Stereotype) { + List<PaletteEntry> entries = new ArrayList<PaletteEntry>(); + Stereotype stereotype = (Stereotype) parentElement; + + for (PaletteEntry entry : standardEntries) { + // retrieve the element type created by the tool. + if (entry instanceof CombinedTemplateCreationEntry) { + + EClass toolMetaclass = PaletteUtil.getToolMetaclass((CombinedTemplateCreationEntry) entry); + if (toolMetaclass != null) { + List<Class> metaclasses = stereotype.getAllExtendedMetaclasses(); + for (Class stMetaclass : metaclasses) { + // get Eclass + java.lang.Class<?> metaclassClass = stMetaclass.getClass(); + if (metaclassClass != null) { + EClassifier metaClassifier = UMLPackage.eINSTANCE.getEClassifier(stMetaclass.getName()); + if (((EClass) metaClassifier).isSuperTypeOf(toolMetaclass)) { + // should create the palette entry + Map<String, Object> properties = new HashMap<String, Object>(); + properties.put(IPapyrusPaletteConstant.ASPECT_ACTION_KEY, StereotypeAspectActionProvider.createConfigurationNode(stereotype.getQualifiedName())); + AspectCreationEntry aspectEntry = new AspectCreationEntry(stereotype.getName() + " (" + entry.getLabel() + ")", "Create an element with a stereotype", entry.getId() + "_" + System.currentTimeMillis(), + entry.getSmallIcon(), (CombinedTemplateCreationEntry) entry, properties); + entries.add(aspectEntry); + } + } + + } + } + } + } + return entries.toArray(); + } else { + return new Object[0]; + } + } + + /** + * {@inheritDoc} + */ + @Override + public Object getParent(Object element) { + if (element instanceof Stereotype) { + return ((Stereotype) element).getProfile(); + } + return null; + } + + /** + * {@inheritDoc} + */ + @Override + public boolean hasChildren(Object element) { + if (element instanceof Profile) { + return true; + } else if (element instanceof Stereotype) { + return true; + } + return false; + } + + /** + * {@inheritDoc} + */ + @Override + public Object[] getElements(Object inputElement) { + if (inputElement instanceof Profile) { + List<Stereotype> stereotypes = ((Profile) inputElement).getOwnedStereotypes(); + return stereotypes.toArray(); + } + return new Object[0]; + } + + /** + * {@inheritDoc} + */ + @Override + public void dispose() { + // nothing to do here + } + + /** + * {@inheritDoc} + */ + @Override + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + // nothing to do here + } + + } + + /** + * Content provider for the available tools viewer, when the + */ + public class ProfileToolsMetaclassStereotypeTreeContentProvider implements ITreeContentProvider { + + /** standard uml tools palette entries */ + final protected Collection<PaletteEntry> standardEntries; + + /** profile to display */ + final protected Profile profile; + + /** + * Creates a new ProfileToolsMetaclassStereotypeTreeContentProvider. + * + * @param profile + * the profile for which tools are built + * @param standardEntries + * list of standard uml tools palette entries + */ + public ProfileToolsMetaclassStereotypeTreeContentProvider(Profile profile, Collection<PaletteEntry> standardEntries) { + this.profile = profile; + this.standardEntries = standardEntries; + } + + /** + * {@inheritDoc} + */ + @Override + public Object[] getChildren(Object parentElement) { + if (parentElement instanceof Profile) { + return standardEntries.toArray(); + } else if (parentElement instanceof AspectCreationEntry) { + return new Object[0]; + } else if (parentElement instanceof PaletteEntry) { + List<AspectCreationEntry> entries = new ArrayList<AspectCreationEntry>(); + // display all stereotypes applicable to the type of element created by this tool + if (parentElement instanceof CombinedTemplateCreationEntry) { + CombinedTemplateCreationEntry entry = (CombinedTemplateCreationEntry) parentElement; + EClass toolMetaclass = PaletteUtil.getToolMetaclass(entry); + if (toolMetaclass != null) { + for (Stereotype stereotype : profile.getOwnedStereotypes()) { + List<Class> metaclasses = stereotype.getAllExtendedMetaclasses(); + for (Class stMetaclass : metaclasses) { + // get Eclass + java.lang.Class<?> metaclassClass = stMetaclass.getClass(); + if (metaclassClass != null) { + EClassifier metaClassifier = UMLPackage.eINSTANCE.getEClassifier(stMetaclass.getName()); + if (((EClass) metaClassifier).isSuperTypeOf(toolMetaclass)) { + // should create the palette entry + Map<String, Object> properties = new HashMap<String, Object>(); + properties.put(IPapyrusPaletteConstant.ASPECT_ACTION_KEY, StereotypeAspectActionProvider.createConfigurationNode(stereotype.getQualifiedName())); + AspectCreationEntry aspectEntry = new AspectCreationEntry(stereotype.getName() + " (" + entry.getLabel() + ")", "Create an element with a stereotype", entry.getId() + "_" + System.currentTimeMillis(), + entry.getSmallIcon(), entry, properties); + entries.add(aspectEntry); + } + } + + } + } + } + } + return entries.toArray(); + } else { + return new Object[0]; + } + } + + /** + * {@inheritDoc} + */ + @Override + public Object getParent(Object element) { + if (element instanceof Stereotype) { + return ((Stereotype) element).getProfile(); + } + return null; + } + + /** + * {@inheritDoc} + */ + @Override + public boolean hasChildren(Object element) { + if (element instanceof Profile) { + return true; + } else if (element instanceof AspectCreationEntry) { + return false; + } else if (element instanceof PaletteEntry) { + return true; + } + return false; + } + + /** + * {@inheritDoc} + */ + @Override + public Object[] getElements(Object inputElement) { + if (inputElement instanceof Profile) { + return standardEntries.toArray(); + } + return new Object[0]; + } + + /** + * {@inheritDoc} + */ + @Override + public void dispose() { + // nothing to do here + } + + /** + * {@inheritDoc} + */ + @Override + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + // nothing to do here + } + + } + + /** + * Returns the list of all visible palette entries + * + * @return the list of all visible palette entries + */ + protected Collection<PaletteEntry> getAllVisibleStandardEntries() { + HashSet<PaletteEntry> result = new HashSet<PaletteEntry>(); + for (PaletteEntry entry : PaletteUtil.getAvailableEntriesSet(editorPart, priority).values()) { + // the entry is not just a defineOnly entry but a visible one + if (getRootParent(entry) != null) { + result.add(entry); + } + } + return result; + } + + /** + * Returns the Root element for the palette entry. It searches recursively from parent to parent, until it find the root element + * + * @param entry + * the palette entry for which root element is searched + * @return the root element or <code>null</code> if none was found + */ + protected PaletteRoot getRootParent(PaletteEntry entry) { + PaletteContainer parent = entry.getParent(); + if (parent instanceof PaletteRoot) { + return (PaletteRoot) parent; + } else if (parent != null) { + return getRootParent(parent); + } else { + return null; + } + } + + /** + * Returns the list of required profiles by this local palette definition + * + * @return the profiles required by this palette + */ + public Set<String> getRequiredProfiles() { + return requiredProfiles; + } + + /** + * Item validator + */ + protected abstract class ToolBarItemValidator { + + /** + * Checks if the button should be enable or not + * + * @return <code>true</code> if the button should be enable + */ + public abstract boolean isEnable(); + } + + /** + * validator for the edit element tool item. It does not remove + */ + protected class EditElementToolBarItemValidator extends ToolBarItemValidator { + + /** + * @{inheritDoc + */ + @Override + public boolean isEnable() { + // retrieve selection + if (paletteTreeViewer != null && !paletteTreeViewer.getControl().isDisposed()) { + // retrieve selection. first element should be a drawer + IStructuredSelection selection = (IStructuredSelection) paletteTreeViewer.getSelection(); + if (selection == null) { + return false; + } else { + // look for first element. should be an instance of drawer + return (selection.getFirstElement() instanceof PaletteLocalDrawerProxy); + } + } + return false; + } + } + + /** + * validator for the create separator or stack tool item. Only valid when selection is a {@link PaletteEntryProxy} or a {@link PaletteLocalDrawerProxy} + */ + protected class PaletteEntryProxySelectedValidator extends ToolBarItemValidator { + + /** + * @{inheritDoc + */ + @Override + public boolean isEnable() { + // retrieve selection + if (paletteTreeViewer != null && !paletteTreeViewer.getControl().isDisposed()) { + // retrieve selection. first element should be a drawer + IStructuredSelection selection = (IStructuredSelection) paletteTreeViewer.getSelection(); + if (selection == null) { + return false; + } else { + Object object = selection.getFirstElement(); + return (object instanceof PaletteEntryProxy); + } + } + return false; + } + } + + /** + * Sets the priority of the current edited palette + * + * @param priority + * the priority of the current edited palette + */ + public void setPriority(ProviderPriority priority) { + this.priority = priority; + } + + protected static class LocalSelectionDragSource extends DragSourceAdapter { + private ISelectionProvider selectionSource; + + public LocalSelectionDragSource(ISelectionProvider selectionProvider) { + selectionSource = selectionProvider; + } + + @Override + public void dragStart(DragSourceEvent event) { + super.dragStart(event); + LocalSelectionTransfer.getTransfer().setSelection(selectionSource.getSelection()); + } + + /** + * {@inheritDoc} + */ + @Override + public void dragSetData(DragSourceEvent event) { + super.dragSetData(event); + LocalSelectionTransfer.getTransfer().setSelection(selectionSource.getSelection()); + } + + /** + * {@inheritDoc} + */ + @Override + public void dragFinished(DragSourceEvent event) { + LocalSelectionTransfer.getTransfer().setSelection(null); + super.dragFinished(event); + } + + } +} diff --git a/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/dialog/LocalPaletteInformationPage.java b/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/dialog/LocalPaletteInformationPage.java index 18de885ef37..0fc299a24ce 100644 --- a/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/dialog/LocalPaletteInformationPage.java +++ b/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/dialog/LocalPaletteInformationPage.java @@ -1,486 +1,488 @@ -/*****************************************************************************
- * Copyright (c) 2009 CEA LIST.
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Remi Schnekenburger (CEA LIST) remi.schnekenburger@cea.fr - Initial API and implementation
- *
- *****************************************************************************/
-
-package org.eclipse.papyrus.customization.palette.dialog;
-
-import java.util.Arrays;
-
-import org.eclipse.gmf.runtime.common.core.service.ProviderPriority;
-import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditorWithFlyOutPalette;
-import org.eclipse.jface.dialogs.Dialog;
-import org.eclipse.jface.wizard.IWizardPage;
-import org.eclipse.jface.wizard.WizardPage;
-import org.eclipse.papyrus.uml.diagram.common.Activator;
-import org.eclipse.papyrus.uml.diagram.common.Messages;
-import org.eclipse.papyrus.uml.diagram.common.part.PapyrusPalettePreferences;
-import org.eclipse.papyrus.uml.diagram.common.service.PapyrusPaletteService;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.SelectionAdapter;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Combo;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Event;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Listener;
-import org.eclipse.swt.widgets.Text;
-import org.eclipse.swt.widgets.Widget;
-import org.eclipse.ui.IEditorPart;
-
-/**
- * Wizard page for information about the new local palette definition
- */
-public class LocalPaletteInformationPage extends WizardPage implements Listener {
-
- /** array list of priorities */
- private static String[] priorityList;
-
- /** text area for the name of the palette definition */
- protected Text nameText;
-
- /** text area for the id of the palette definition */
- protected Text idText;
-
- /** text area for the editor id of the palette definition */
- protected Text editorText;
-
- /** combo for the priority of the provider */
- private Combo priorityCombo;
-
- /** parent composite for advanced fields */
- protected Composite advancedComposite;
-
- /** Button to show/hide advanced fields */
- protected Button advancedButton;
-
- /** editor part in which the palette is created */
- protected IEditorPart editorPart;
-
- /** priority value */
- protected ProviderPriority priority;
-
- /** editor ID value */
- protected String editorID;
-
- /** palette ID */
- protected String paletteID;
-
- /** palette name */
- protected String name;
-
- /** path to the icon */
- protected static final String WIZARD_ICON = "/icons/local_desc_wiz.png";
-
- /** validate on opening */
- protected boolean validateOnLaunch = false;
-
- static {
- priorityList = new String[] { ProviderPriority.LOWEST.getName(), ProviderPriority.LOW.getName(), ProviderPriority.MEDIUM.getName(), ProviderPriority.HIGH.getName(), ProviderPriority.HIGHEST.getName() };
- }
-
- /**
- * Creates a new wizard page with the given name, title, and image.
- *
- * @param part
- * the editor part in which the wizard was created
- */
- public LocalPaletteInformationPage(IEditorPart part) {
- super(Messages.Local_Palette_InfoPage_Name, Messages.Local_Palette_InfoPage_Title, Activator.getImageDescriptor(WIZARD_ICON));
- this.editorPart = part;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public IWizardPage getNextPage() {
- LocalPaletteContentPage contentPage = (LocalPaletteContentPage) super.getNextPage();
- if (priority != null) {
- contentPage.setPriority(priority);
- contentPage.profileCombo.deselectAll();
- contentPage.profileCombo.select(contentPage.profileCombo.getItems().length - 1); // select the last one (UML)
- }
- return contentPage;
- }
-
- /**
- * {@inheritDoc}
- */
- public void createControl(Composite parent) {
-
- // initialize dialog units
- initializeDialogUnits(parent);
-
- // Create a new composite as there is the title bar seperator
- // to deal with
- Composite control = new Composite(parent, SWT.NONE);
- GridLayout layout = new GridLayout(2, false);
- control.setLayout(layout);
- control.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
- setControl(control);
-
- createNameControl(control);
-
- createAdvancedControls(control);
-
- // end of the control creation
- Dialog.applyDialogFont(control);
-
- // Show description on opening
- setErrorMessage(null);
- setMessage(null);
- if (validateOnLaunch) {
- setPageComplete(validatePage());
- }
- setControl(control);
- }
-
- /**
- * initializes fields using context information
- */
- public void intializeValues() {
- initName("");
- String editorIDValue = "";
- if (editorPart instanceof DiagramEditorWithFlyOutPalette) {
- editorIDValue = ((DiagramEditorWithFlyOutPalette) editorPart).getContributorId();
- }
- initEditorID(editorIDValue);
- initPaletteID(System.getProperty("user.name") + "_" + System.currentTimeMillis());
- initPriority(ProviderPriority.MEDIUM);
- }
-
- /**
- * initializes fields using existing descriptor
- */
- public void intializeValues(PapyrusPaletteService.LocalProviderDescriptor descriptor) {
- initName(descriptor.getContributionName());
- String editorIDValue = "";
- if (editorPart instanceof DiagramEditorWithFlyOutPalette) {
- editorIDValue = ((DiagramEditorWithFlyOutPalette) editorPart).getContributorId();
- }
- initEditorID(editorIDValue);
- initPaletteID(descriptor.getContributionID());
- initPriority(PapyrusPalettePreferences.getLocalPalettePriority(descriptor.getContributionID()));
- validateOnLaunch = true;
- }
-
- /**
- * Returns the current value of palette name
- *
- * @return the current value of palette name
- */
- public String getPaletteName() {
- return name;
- }
-
- /**
- * Returns the current value of palette ID
- *
- * @return the current value of palette ID
- */
- public String getPaletteID() {
- return paletteID;
- }
-
- /**
- * Returns the current value of editor ID
- *
- * @return the current value of editor ID
- */
- public String getEditorID() {
- return editorID;
- }
-
- /**
- * Returns the current value of editor ID
- *
- * @return the current value of editor ID
- */
- public ProviderPriority getPalettePriority() {
- return priority;
- }
-
- /**
- * inits the name field value
- *
- * @param value
- * value to set
- */
- protected void initName(String value) {
- name = value;
- }
-
- /**
- * inits the priority value
- *
- * @param value
- * value to set
- */
- protected void initPriority(ProviderPriority value) {
- if (value != null) {
- this.priority = value;
- } else {
- // by default, Medium
- this.priority = ProviderPriority.MEDIUM;
- }
- }
-
- /**
- * inits the palette id value
- *
- * @param value
- * value to set
- */
- protected void initPaletteID(String value) {
- paletteID = value;
-
- }
-
- /**
- * inits the editor id value
- *
- * @param value
- * value to set
- */
- protected void initEditorID(String value) {
- editorID = value;
- }
-
- /**
- * Validates the content of the fields in this page
- */
- protected boolean validatePage() {
- boolean valid = true;
- if (advancedComposite != null && !advancedComposite.isDisposed()) {
- if (-1 == priorityCombo.getSelectionIndex()) {
- setErrorMessage(Messages.Local_Palette_Error_Priority);
- valid = false;
- }
- if ("".equals(getEditorID())) {
- setErrorMessage(Messages.Local_Palette_Error_EditorId);
- valid = false;
- }
-
- if ("".equals(getPaletteID())) {
- setErrorMessage(Messages.Local_Palette_Error_PaletteId);
- valid = false;
- }
- }
-
- if ("".equals(getPaletteName())) {
- setErrorMessage(Messages.Local_Palette_Error_Name);
- valid = false;
- }
-
- if (valid) {
- setMessage(null);
- setErrorMessage(null);
- }
- return valid;
- }
-
- /**
- * Creates the widget for advanced options.
- *
- * @param parent
- * the parent composite
- */
- protected void createAdvancedControls(Composite parent) {
- advancedButton = new Button(parent, SWT.PUSH);
- advancedButton.setFont(parent.getFont());
- advancedButton.setText(Messages.Dialog_Advanced_Button_Closed);
- GridData data = setButtonLayoutData(advancedButton);
- data.horizontalAlignment = GridData.BEGINNING;
- data.horizontalSpan = 2;
- advancedButton.setLayoutData(data);
- advancedButton.addSelectionListener(new SelectionAdapter() {
-
- @Override
- public void widgetSelected(SelectionEvent e) {
- handleAdvancedButtonSelect();
- }
- });
- }
-
- public Composite createAdvancedComposite(Composite parent) {
- advancedComposite = new Composite(parent, SWT.NONE);
- advancedComposite.setFont(parent.getFont());
- advancedComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
- GridLayout layout = new GridLayout(2, false);
- layout.marginHeight = 0;
- layout.marginWidth = 0;
- advancedComposite.setLayout(layout);
-
- createIDControl(advancedComposite);
-
- createEditorIDControl(advancedComposite);
-
- createPriorityControl(advancedComposite);
-
- advancedComposite.getParent().layout();
- return advancedComposite;
- }
-
- /**
- * Shows/hides the advanced option widgets.
- */
- protected void handleAdvancedButtonSelect() {
- Composite composite = (Composite) getControl();
-
- if (advancedComposite != null) {
- advancedComposite.dispose();
- advancedComposite = null;
- advancedButton.setText(Messages.Dialog_Advanced_Button_Closed);
- } else {
- createAdvancedComposite(composite);
- advancedButton.setText(Messages.Dialog_Advanced_Button_Opened);
- }
- }
-
- /**
- * creates the control area for the priority
- *
- * @param control
- * the parent composite
- */
- protected void createPriorityControl(Composite control) {
- final Label priorityLabel = new Label(control, SWT.NONE);
- priorityLabel.setText(Messages.Local_Palette_Priority);
- priorityLabel.setToolTipText(Messages.Local_Palette_Priority_Tooltip);
-
- // choice widget among priority values
- priorityCombo = new Combo(control, SWT.READ_ONLY);
- priorityCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
- priorityCombo.setToolTipText(Messages.Local_Palette_Priority_Tooltip);
- priorityCombo.setItems(priorityList);
-
- // initialize, then add the listener...
- initialPopulatePriorityField();
-
- priorityCombo.addListener(SWT.Modify, this);
- }
-
- /**
- * intialize the field using current value of the palette id
- */
- protected void initialPopulatePriorityField() {
- priorityCombo.select(Arrays.asList(priorityList).indexOf(priority.getName()));
- }
-
- /**
- * creates the control area for the id definition
- *
- * @param control
- * the parent composite
- */
- protected void createIDControl(Composite control) {
- final Label idLabel = new Label(control, SWT.NONE);
- idLabel.setText(Messages.Local_Palette_Id);
- idLabel.setToolTipText(Messages.Local_Palette_Id_Tooltip);
-
- idText = new Text(control, SWT.BORDER);
- idText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
- idText.setToolTipText(Messages.Local_Palette_Id_Tooltip);
-
- // initialize, then add the listener...
- initialPopulatePaletteIDField();
-
- idText.addListener(SWT.Modify, this);
- }
-
- /**
- * intialize the field using current value of the palette id
- */
- protected void initialPopulatePaletteIDField() {
- idText.setText(paletteID);
- }
-
- /**
- * creates the control area for the name definition
- *
- * @param control
- * the parent composite
- */
- protected void createNameControl(Composite control) {
- final Label nameLabel = new Label(control, SWT.NONE);
- nameLabel.setText(Messages.Local_Palette_Name);
- nameLabel.setToolTipText(Messages.Local_Palette_Name_Tooltip);
-
- nameText = new Text(control, SWT.BORDER);
- nameText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
- nameText.setToolTipText(Messages.Local_Palette_Name_Tooltip);
-
- // initialize, then add the listener...
- initialPopulateNameField();
-
- nameText.addListener(SWT.Modify, this);
-
- }
-
- /**
- * creates the control area for the name definition
- *
- * @param control
- * the parent composite
- */
- protected void createEditorIDControl(Composite control) {
- final Label editorLabel = new Label(control, SWT.NONE);
- editorLabel.setText(Messages.Local_Palette_Editor_Id);
- editorLabel.setToolTipText(Messages.Local_Palette_Editor_Id_Tooltip);
-
- editorText = new Text(control, SWT.BORDER);
- editorText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
- editorText.setToolTipText(Messages.Local_Palette_Editor_Id_Tooltip);
-
- // initialize, then add the listener...
- initialPopulateEditorIDField();
-
- editorText.addListener(SWT.Modify, this);
- // this editor should propose a list of existing editors = looking in the extension point?
- }
-
- /**
- * intialize the field using current value of the editor id
- */
- protected void initialPopulateEditorIDField() {
- editorText.setText(editorID);
- }
-
- /**
- * initialize name field
- */
- protected void initialPopulateNameField() {
- nameText.setText(name);
- }
-
- /**
- * The <code>WizardNewFileCreationPage</code> implementation of this <code>Listener</code> method handles all events and enablements for controls
- * on this page. Subclasses may extend.
- */
- public void handleEvent(Event event) {
- Widget widget = event.widget;
- if (widget.equals(nameText)) {
- name = nameText.getText();
- } else if (widget.equals(idText)) {
- paletteID = idText.getText();
- } else if (widget.equals(editorText)) {
- editorID = editorText.getText();
- } else if (widget.equals(priorityCombo)) {
- priority = ProviderPriority.parse(priorityCombo.getText());
- }
- setPageComplete(validatePage());
- }
-
-}
+/***************************************************************************** + * Copyright (c) 2009 CEA LIST. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Remi Schnekenburger (CEA LIST) remi.schnekenburger@cea.fr - Initial API and implementation + * + *****************************************************************************/ + +package org.eclipse.papyrus.customization.palette.dialog; + +import java.util.Arrays; + +import org.eclipse.gmf.runtime.common.core.service.ProviderPriority; +import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditorWithFlyOutPalette; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.wizard.IWizardPage; +import org.eclipse.jface.wizard.WizardPage; +import org.eclipse.papyrus.customization.palette.Messages; +import org.eclipse.papyrus.uml.diagram.common.Activator; +import org.eclipse.papyrus.uml.diagram.common.part.PapyrusPalettePreferences; +import org.eclipse.papyrus.uml.diagram.common.service.PapyrusPaletteService; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Combo; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.swt.widgets.Text; +import org.eclipse.swt.widgets.Widget; +import org.eclipse.ui.IEditorPart; + +/** + * Wizard page for information about the new local palette definition + */ +public class LocalPaletteInformationPage extends WizardPage implements Listener { + + /** array list of priorities */ + private static String[] priorityList; + + /** text area for the name of the palette definition */ + protected Text nameText; + + /** text area for the id of the palette definition */ + protected Text idText; + + /** text area for the editor id of the palette definition */ + protected Text editorText; + + /** combo for the priority of the provider */ + private Combo priorityCombo; + + /** parent composite for advanced fields */ + protected Composite advancedComposite; + + /** Button to show/hide advanced fields */ + protected Button advancedButton; + + /** editor part in which the palette is created */ + protected IEditorPart editorPart; + + /** priority value */ + protected ProviderPriority priority; + + /** editor ID value */ + protected String editorID; + + /** palette ID */ + protected String paletteID; + + /** palette name */ + protected String name; + + /** path to the icon */ + protected static final String WIZARD_ICON = "/icons/local_desc_wiz.png"; + + /** validate on opening */ + protected boolean validateOnLaunch = false; + + static { + priorityList = new String[] { ProviderPriority.LOWEST.getName(), ProviderPriority.LOW.getName(), ProviderPriority.MEDIUM.getName(), ProviderPriority.HIGH.getName(), ProviderPriority.HIGHEST.getName() }; + } + + /** + * Creates a new wizard page with the given name, title, and image. + * + * @param part + * the editor part in which the wizard was created + */ + public LocalPaletteInformationPage(IEditorPart part) { + super(Messages.Local_Palette_InfoPage_Name, Messages.Local_Palette_InfoPage_Title, Activator.getImageDescriptor(WIZARD_ICON)); + this.editorPart = part; + } + + /** + * {@inheritDoc} + */ + @Override + public IWizardPage getNextPage() { + LocalPaletteContentPage contentPage = (LocalPaletteContentPage) super.getNextPage(); + if (priority != null) { + contentPage.setPriority(priority); + contentPage.profileCombo.deselectAll(); + contentPage.profileCombo.select(contentPage.profileCombo.getItems().length - 1); // select the last one (UML) + } + return contentPage; + } + + /** + * {@inheritDoc} + */ + @Override + public void createControl(Composite parent) { + + // initialize dialog units + initializeDialogUnits(parent); + + // Create a new composite as there is the title bar seperator + // to deal with + Composite control = new Composite(parent, SWT.NONE); + GridLayout layout = new GridLayout(2, false); + control.setLayout(layout); + control.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + setControl(control); + + createNameControl(control); + + createAdvancedControls(control); + + // end of the control creation + Dialog.applyDialogFont(control); + + // Show description on opening + setErrorMessage(null); + setMessage(null); + if (validateOnLaunch) { + setPageComplete(validatePage()); + } + setControl(control); + } + + /** + * initializes fields using context information + */ + public void intializeValues() { + initName(""); + String editorIDValue = ""; + if (editorPart instanceof DiagramEditorWithFlyOutPalette) { + editorIDValue = ((DiagramEditorWithFlyOutPalette) editorPart).getContributorId(); + } + initEditorID(editorIDValue); + initPaletteID(System.getProperty("user.name") + "_" + System.currentTimeMillis()); + initPriority(ProviderPriority.MEDIUM); + } + + /** + * initializes fields using existing descriptor + */ + public void intializeValues(PapyrusPaletteService.LocalProviderDescriptor descriptor) { + initName(descriptor.getContributionName()); + String editorIDValue = ""; + if (editorPart instanceof DiagramEditorWithFlyOutPalette) { + editorIDValue = ((DiagramEditorWithFlyOutPalette) editorPart).getContributorId(); + } + initEditorID(editorIDValue); + initPaletteID(descriptor.getContributionID()); + initPriority(PapyrusPalettePreferences.getLocalPalettePriority(descriptor.getContributionID())); + validateOnLaunch = true; + } + + /** + * Returns the current value of palette name + * + * @return the current value of palette name + */ + public String getPaletteName() { + return name; + } + + /** + * Returns the current value of palette ID + * + * @return the current value of palette ID + */ + public String getPaletteID() { + return paletteID; + } + + /** + * Returns the current value of editor ID + * + * @return the current value of editor ID + */ + public String getEditorID() { + return editorID; + } + + /** + * Returns the current value of editor ID + * + * @return the current value of editor ID + */ + public ProviderPriority getPalettePriority() { + return priority; + } + + /** + * inits the name field value + * + * @param value + * value to set + */ + protected void initName(String value) { + name = value; + } + + /** + * inits the priority value + * + * @param value + * value to set + */ + protected void initPriority(ProviderPriority value) { + if (value != null) { + this.priority = value; + } else { + // by default, Medium + this.priority = ProviderPriority.MEDIUM; + } + } + + /** + * inits the palette id value + * + * @param value + * value to set + */ + protected void initPaletteID(String value) { + paletteID = value; + + } + + /** + * inits the editor id value + * + * @param value + * value to set + */ + protected void initEditorID(String value) { + editorID = value; + } + + /** + * Validates the content of the fields in this page + */ + protected boolean validatePage() { + boolean valid = true; + if (advancedComposite != null && !advancedComposite.isDisposed()) { + if (-1 == priorityCombo.getSelectionIndex()) { + setErrorMessage(Messages.Local_Palette_Error_Priority); + valid = false; + } + if ("".equals(getEditorID())) { + setErrorMessage(Messages.Local_Palette_Error_EditorId); + valid = false; + } + + if ("".equals(getPaletteID())) { + setErrorMessage(Messages.Local_Palette_Error_PaletteId); + valid = false; + } + } + + if ("".equals(getPaletteName())) { + setErrorMessage(Messages.Local_Palette_Error_Name); + valid = false; + } + + if (valid) { + setMessage(null); + setErrorMessage(null); + } + return valid; + } + + /** + * Creates the widget for advanced options. + * + * @param parent + * the parent composite + */ + protected void createAdvancedControls(Composite parent) { + advancedButton = new Button(parent, SWT.PUSH); + advancedButton.setFont(parent.getFont()); + advancedButton.setText(Messages.Dialog_Advanced_Button_Closed); + GridData data = setButtonLayoutData(advancedButton); + data.horizontalAlignment = GridData.BEGINNING; + data.horizontalSpan = 2; + advancedButton.setLayoutData(data); + advancedButton.addSelectionListener(new SelectionAdapter() { + + @Override + public void widgetSelected(SelectionEvent e) { + handleAdvancedButtonSelect(); + } + }); + } + + public Composite createAdvancedComposite(Composite parent) { + advancedComposite = new Composite(parent, SWT.NONE); + advancedComposite.setFont(parent.getFont()); + advancedComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1)); + GridLayout layout = new GridLayout(2, false); + layout.marginHeight = 0; + layout.marginWidth = 0; + advancedComposite.setLayout(layout); + + createIDControl(advancedComposite); + + createEditorIDControl(advancedComposite); + + createPriorityControl(advancedComposite); + + advancedComposite.getParent().layout(); + return advancedComposite; + } + + /** + * Shows/hides the advanced option widgets. + */ + protected void handleAdvancedButtonSelect() { + Composite composite = (Composite) getControl(); + + if (advancedComposite != null) { + advancedComposite.dispose(); + advancedComposite = null; + advancedButton.setText(Messages.Dialog_Advanced_Button_Closed); + } else { + createAdvancedComposite(composite); + advancedButton.setText(Messages.Dialog_Advanced_Button_Opened); + } + } + + /** + * creates the control area for the priority + * + * @param control + * the parent composite + */ + protected void createPriorityControl(Composite control) { + final Label priorityLabel = new Label(control, SWT.NONE); + priorityLabel.setText(Messages.Local_Palette_Priority); + priorityLabel.setToolTipText(Messages.Local_Palette_Priority_Tooltip); + + // choice widget among priority values + priorityCombo = new Combo(control, SWT.READ_ONLY); + priorityCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + priorityCombo.setToolTipText(Messages.Local_Palette_Priority_Tooltip); + priorityCombo.setItems(priorityList); + + // initialize, then add the listener... + initialPopulatePriorityField(); + + priorityCombo.addListener(SWT.Modify, this); + } + + /** + * intialize the field using current value of the palette id + */ + protected void initialPopulatePriorityField() { + priorityCombo.select(Arrays.asList(priorityList).indexOf(priority.getName())); + } + + /** + * creates the control area for the id definition + * + * @param control + * the parent composite + */ + protected void createIDControl(Composite control) { + final Label idLabel = new Label(control, SWT.NONE); + idLabel.setText(Messages.Local_Palette_Id); + idLabel.setToolTipText(Messages.Local_Palette_Id_Tooltip); + + idText = new Text(control, SWT.BORDER); + idText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + idText.setToolTipText(Messages.Local_Palette_Id_Tooltip); + + // initialize, then add the listener... + initialPopulatePaletteIDField(); + + idText.addListener(SWT.Modify, this); + } + + /** + * intialize the field using current value of the palette id + */ + protected void initialPopulatePaletteIDField() { + idText.setText(paletteID); + } + + /** + * creates the control area for the name definition + * + * @param control + * the parent composite + */ + protected void createNameControl(Composite control) { + final Label nameLabel = new Label(control, SWT.NONE); + nameLabel.setText(Messages.Local_Palette_Name); + nameLabel.setToolTipText(Messages.Local_Palette_Name_Tooltip); + + nameText = new Text(control, SWT.BORDER); + nameText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + nameText.setToolTipText(Messages.Local_Palette_Name_Tooltip); + + // initialize, then add the listener... + initialPopulateNameField(); + + nameText.addListener(SWT.Modify, this); + + } + + /** + * creates the control area for the name definition + * + * @param control + * the parent composite + */ + protected void createEditorIDControl(Composite control) { + final Label editorLabel = new Label(control, SWT.NONE); + editorLabel.setText(Messages.Local_Palette_Editor_Id); + editorLabel.setToolTipText(Messages.Local_Palette_Editor_Id_Tooltip); + + editorText = new Text(control, SWT.BORDER); + editorText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + editorText.setToolTipText(Messages.Local_Palette_Editor_Id_Tooltip); + + // initialize, then add the listener... + initialPopulateEditorIDField(); + + editorText.addListener(SWT.Modify, this); + // this editor should propose a list of existing editors = looking in the extension point? + } + + /** + * intialize the field using current value of the editor id + */ + protected void initialPopulateEditorIDField() { + editorText.setText(editorID); + } + + /** + * initialize name field + */ + protected void initialPopulateNameField() { + nameText.setText(name); + } + + /** + * The <code>WizardNewFileCreationPage</code> implementation of this <code>Listener</code> method handles all events and enablements for controls + * on this page. Subclasses may extend. + */ + @Override + public void handleEvent(Event event) { + Widget widget = event.widget; + if (widget.equals(nameText)) { + name = nameText.getText(); + } else if (widget.equals(idText)) { + paletteID = idText.getText(); + } else if (widget.equals(editorText)) { + editorID = editorText.getText(); + } else if (widget.equals(priorityCombo)) { + priority = ProviderPriority.parse(priorityCombo.getText()); + } + setPageComplete(validatePage()); + } + +} diff --git a/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/dialog/PaletteConfigurationContentPage.java b/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/dialog/PaletteConfigurationContentPage.java new file mode 100644 index 00000000000..499cafe530e --- /dev/null +++ b/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/dialog/PaletteConfigurationContentPage.java @@ -0,0 +1,1498 @@ +/***************************************************************************** + * Copyright (c) 2009, 2014 CEA LIST, Christian W. Damus, and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Remi Schnekenburger (CEA LIST) remi.schnekenburger@cea.fr - Initial API and implementation + * Christian W. Damus - bug 454578 + * Mickael ADAM (ALL4TEC) mickael.adam@all4tec.net - new implemenatation for palette configuration model case + * + *****************************************************************************/ +package org.eclipse.papyrus.customization.palette.dialog; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; + +import org.eclipse.core.runtime.Assert; +import org.eclipse.emf.common.command.AbstractCommand; +import org.eclipse.emf.common.command.Command; +import org.eclipse.emf.common.command.CompoundCommand; +import org.eclipse.emf.common.notify.Notification; +import org.eclipse.emf.common.util.Diagnostic; +import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.common.util.URI; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.ecore.util.Diagnostician; +import org.eclipse.emf.ecore.util.EContentAdapter; +import org.eclipse.emf.ecore.util.EcoreUtil; +import org.eclipse.emf.edit.command.AddCommand; +import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain; +import org.eclipse.emf.edit.ui.celleditor.AdapterFactoryTreeEditor; +import org.eclipse.emf.edit.ui.dnd.EditingDomainViewerDropAdapter; +import org.eclipse.emf.edit.ui.dnd.LocalTransfer; +import org.eclipse.emf.edit.ui.dnd.ViewerDragAdapter; +import org.eclipse.emf.edit.ui.provider.AdapterFactoryContentProvider; +import org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider; +import org.eclipse.gef.palette.PaletteContainer; +import org.eclipse.gef.palette.PaletteDrawer; +import org.eclipse.gef.palette.PaletteEntry; +import org.eclipse.gef.palette.PaletteRoot; +import org.eclipse.gef.palette.PaletteStack; +import org.eclipse.gef.palette.PaletteToolbar; +import org.eclipse.gef.palette.ToolEntry; +import org.eclipse.gmf.runtime.common.core.service.ProviderPriority; +import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditorWithFlyOutPalette; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.util.LocalSelectionTransfer; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.ITreeSelection; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.jface.viewers.TreeSelection; +import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.jface.viewers.ViewerComparator; +import org.eclipse.jface.viewers.ViewerFilter; +import org.eclipse.jface.wizard.WizardPage; +import org.eclipse.osgi.util.NLS; +import org.eclipse.papyrus.customization.palette.Messages; +import org.eclipse.papyrus.customization.palette.provider.PaletteLabelProvider; +import org.eclipse.papyrus.customization.palette.provider.ProfileToolsMetaclassStereotypeTreeContentProvider; +import org.eclipse.papyrus.customization.palette.provider.ProfileToolsStereotypeMetaclassTreeContentProvider; +import org.eclipse.papyrus.customization.palette.provider.UMLToolsTreeContentProvider; +import org.eclipse.papyrus.infra.properties.ui.runtime.DisplayEngine; +import org.eclipse.papyrus.infra.properties.ui.util.PropertiesDisplayHelper; +import org.eclipse.papyrus.uml.diagram.common.Activator; +import org.eclipse.papyrus.uml.diagram.common.part.PaletteUtil; +import org.eclipse.papyrus.uml.diagram.paletteconfiguration.ChildConfiguration; +import org.eclipse.papyrus.uml.diagram.paletteconfiguration.Configuration; +import org.eclipse.papyrus.uml.diagram.paletteconfiguration.DrawerConfiguration; +import org.eclipse.papyrus.uml.diagram.paletteconfiguration.LeafConfiguration; +import org.eclipse.papyrus.uml.diagram.paletteconfiguration.PaletteConfiguration; +import org.eclipse.papyrus.uml.diagram.paletteconfiguration.PaletteconfigurationFactory; +import org.eclipse.papyrus.uml.diagram.paletteconfiguration.SeparatorConfiguration; +import org.eclipse.papyrus.uml.diagram.paletteconfiguration.StackConfiguration; +import org.eclipse.papyrus.uml.diagram.paletteconfiguration.ToolConfiguration; +import org.eclipse.papyrus.uml.diagram.paletteconfiguration.utils.CreatePaletteItemUtil; +import org.eclipse.swt.SWT; +import org.eclipse.swt.dnd.DND; +import org.eclipse.swt.dnd.DropTargetEvent; +import org.eclipse.swt.dnd.FileTransfer; +import org.eclipse.swt.dnd.Transfer; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.events.MouseAdapter; +import org.eclipse.swt.events.MouseEvent; +import org.eclipse.swt.events.MouseListener; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Combo; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.swt.widgets.ToolBar; +import org.eclipse.swt.widgets.ToolItem; +import org.eclipse.swt.widgets.Tree; +import org.eclipse.swt.widgets.TreeItem; +import org.eclipse.ui.IEditorPart; +import org.eclipse.uml2.uml.Package; +import org.eclipse.uml2.uml.Profile; +import org.eclipse.uml2.uml.Stereotype; + +/** + * Wizard page for information about the new local palette definition + */ +public class PaletteConfigurationContentPage extends WizardPage { + + /** icon path for the add button */ + protected static final String ADD_ICON = "/icons/arrow_right.gif"; //$NON-NLS-1$ + + /** icon path for the create drawer button */ + protected static final String CREATE_DRAWERS_ICON = "/icons/new_drawer.gif";//$NON-NLS-1$ + + /** icon path for the create separator button */ + protected static final String CREATE_SEPARATOR_ICON = "/icons/new_separator.gif";//$NON-NLS-1$ + + /** icon path for the create stack button */ + protected static final String CREATE_STACK_ICON = "/icons/new_stack.gif";//$NON-NLS-1$ + + /** icon path for the create stack button */ + protected static final String CREATE_TOOL_ICON = "/icons/new_tool.gif";//$NON-NLS-1$ + + /** icon path for the delete button */ + protected static final String DELETE_ICON = "/icons/delete.gif";//$NON-NLS-1$ + + /** icon path for the remove button */ + protected static final String REMOVE_ICON = "/icons/arrow_left.gif"; //$NON-NLS-1$ + + /** icon path when tools are shown */ + protected static final String SHOWN_TOOLS_ICON = "/icons/tools_shown.gif"; //$NON-NLS-1$ + + /** path to the icon */ + protected static final String WIZARD_ICON = "/icons/local_desc_wiz.png";//$NON-NLS-1$ + + /** icon for the content provider switch button */ + protected String SWITCH_CONTENT_PROVIDER_ICON = "/icons/switch_provider.gif"; //$NON-NLS-1$ + + /** the label for drawer */ + private static final String DRAWER_LABEL = Messages.PaletteConfigurationContentPage_Drawer; + + /** The label for new tool */ + private static final String NEW_TOOL_LABEL = Messages.PaletteConfigurationContentPage_NewTool; + + /** the label for separator */ + private static final String SEPARATOR_LABEL = Messages.PaletteConfigurationContentPage_Separator; + + /** the label for stack */ + private static final String STACK_LABEL = Messages.PaletteConfigurationContentPage_Stack; + + /** label for the standard tools */ + private static final String UML_TOOLS_LABEL = Messages.PaletteConfigurationContentPage_UMLTools; + + /** Validator key for toolbar items */ + private final static String VALIDATOR = "validator"; //$NON-NLS-1$ + + /** the add button */ + private Button addButton; + + /** the remove button */ + private Button removeButton; + + /** the tree viewer for available tools */ + private TreeViewer availableToolsViewer; + + /** combo to select which profile tools should be visible */ + private Combo profileCombo; + + /** list of profiles that can provide tools */ + private List<String> profileComboList = new ArrayList<String>(); + + /** the tree viewer for the edited palette */ + private TreeViewer paletteTreeViewer; + + /** the display engine */ + private DisplayEngine displayEngine; + + /** instance of the filter used to show/hide drawers */ + private final ViewerFilter drawerFilter = new DrawerFilter(); + + /** the editing domain */ + private AdapterFactoryEditingDomain editingDomain; + + /** editor part in which the palette is created */ + private IEditorPart editorPart; + + /** the label provider for the edited palette */ + private PaletteLabelProvider paletteLabelProvider; + + /** priority of the current edited palette */ + private ProviderPriority priority; + + /** the properties composite */ + private Composite propertiesComposite; + + /** tool item in charge of toggling content providers in the available tool viewer */ + protected ToolItem toggleContentProvider; + + /** the toolbar for actions on edited palette */ + private ToolBar toolbar; + + /** instance of the filter used to show/hide tools */ + private final ViewerFilter toolFilter = new ToolFilter(); + + /** enumeration of existing entry types */ + public enum EntryType { + ASPECT_TOOL, DRAWER, SEPARATOR, STACK, TOOL + } + + /** + * Filter for the viewer. Hide/show Drawers + */ + protected class DrawerFilter extends ViewerFilter { + + /** + * {@inheritDoc} + */ + @Override + public boolean select(final Viewer viewer, final Object parentElement, final Object element) { + boolean notDrawer = true; + if (element instanceof PaletteDrawer) { + notDrawer = false; + } + return notDrawer; + } + } + + /** + * A viewer comparator for label of Palette Entry + */ + protected class LabelViewerComparator extends ViewerComparator { + + /** + * Creates a new LabelViewerComparator. + */ + public LabelViewerComparator() { + super(); + } + + /** + * {@inheritDoc} + */ + @Override + public int compare(final Viewer testViewer, final Object e1, final Object e2) { + String label1 = "";//$NON-NLS-1$ + String label2 = "";//$NON-NLS-1$ + + if (e1 instanceof PaletteEntry) { + label1 = ((PaletteEntry) e1).getLabel(); + } else if (e1 instanceof Stereotype) { + label1 = ((Stereotype) e1).getName(); + } + if (e2 instanceof PaletteEntry) { + label2 = ((PaletteEntry) e2).getLabel(); + } else if (e2 instanceof Stereotype) { + label2 = ((Stereotype) e2).getName(); + } + + int comparaison; + if (null == label1 && null == label2) { + comparaison = 0; + } else if (null == label1) { + comparaison = 1; + } else if (null == label2) { + comparaison = -1; + } else { + comparaison = label1.compareTo(label2); + } + return comparaison; + } + } + + /** + * Validator for the create separator or stack tool item. Only valid when selection is a {@link PaletteEntryProxy} or a {@link PaletteLocalDrawerProxy} + */ + protected class PaletteConfigurationEntrySelectedValidator implements ToolBarItemValidator { + + /** + * @{inheritDoc + */ + @Override + public boolean isEnable() { + boolean enable = false; + // retrieve selection + if (null != paletteTreeViewer && !paletteTreeViewer.getControl().isDisposed()) { + // retrieve selection. first element should be a drawer + IStructuredSelection selection = (IStructuredSelection) paletteTreeViewer.getSelection(); + if (null != selection) { + Object object = selection.getFirstElement(); + enable = (object instanceof Configuration); + } + } + return enable; + } + } + + + /** + * validator for the create separator or stack tool item. Only valid when selection is a {@link PaletteEntryProxy} or a {@link PaletteLocalDrawerProxy} + */ + protected class PaletteConfigurationStackLeafSelectedValidator implements ToolBarItemValidator { + + /** + * @{inheritDoc + */ + @Override + public boolean isEnable() { + boolean enable = false; + // retrieve selection + if (paletteTreeViewer != null && !paletteTreeViewer.getControl().isDisposed()) { + // retrieve selection. first element should be a drawer + IStructuredSelection selection = (IStructuredSelection) paletteTreeViewer.getSelection(); + if (null != selection) { + Object object = selection.getFirstElement(); + enable = (object instanceof Configuration && !(((Configuration) object).eContainer() instanceof StackConfiguration)); + } + } + return enable; + } + } + + + + /** + * Listener for the profile combo. It changes the input of the following viewer. + */ + protected class ProfileComboSelectionListener implements SelectionListener, ModifyListener { + + /** + * handles the change selection for the combo + */ + protected void handleSelectionChanged() { + int index = profileCombo.getSelectionIndex(); + if (0 <= index && index < profileCombo.getItems().length) { + String name = profileComboList.get(index); + + Collection<PaletteEntry> standardEntries = getAllVisibleStandardEntries(); + // retrieve the profile or uml standards tools to display + if (UML_TOOLS_LABEL.equals(name)) { + // change content provider + availableToolsViewer.setContentProvider(new UMLToolsTreeContentProvider()); + availableToolsViewer.setInput(standardEntries); + toggleContentProvider.setEnabled(false); + } else { + if (null != toggleContentProvider && !toggleContentProvider.isDisposed()) { + toggleContentProvider.setEnabled(true); + } + // switch content provider + // this is a profile in case of uml2 tools + Profile profile = getAllAppliedProfiles().get(index); + if (toggleContentProvider.getSelection()) { + availableToolsViewer.setContentProvider(new ProfileToolsStereotypeMetaclassTreeContentProvider(profile, standardEntries)); + } else { + availableToolsViewer.setContentProvider(new ProfileToolsMetaclassStereotypeTreeContentProvider(profile, standardEntries)); + } + + // generate tools for given profile + availableToolsViewer.setInput(profile); + } + } + } + + /** + * {@inheritDoc} + */ + @Override + public void modifyText(final ModifyEvent e) { + handleSelectionChanged(); + } + + /** + * {@inheritDoc} + */ + @Override + public void widgetDefaultSelected(final SelectionEvent e) { + // Do nothing + } + + /** + * {@inheritDoc} + */ + @Override + public void widgetSelected(final SelectionEvent e) { + handleSelectionChanged(); + } + } + + + /** + * Item validator interface + */ + interface ToolBarItemValidator { + + /** + * Checks if the button should be enable or not + * + * @return <code>true</code> if the button should be enable + */ + public boolean isEnable(); + } + + /** + * Filter for the viewer. Hide/show Drawers + */ + protected class ToolFilter extends ViewerFilter { + + /** + * {@inheritDoc} + */ + @Override + public boolean select(final Viewer viewer, final Object parentElement, final Object element) { + return !(element instanceof ToolEntry); + } + } + + /** Listener to validate page on change. */ + EContentAdapter adapter = new EContentAdapter() { + /** + * @see org.eclipse.emf.common.notify.impl.AdapterImpl#notifyChanged(org.eclipse.emf.common.notify.Notification) + */ + @Override + public void notifyChanged(Notification msg) { + setPageComplete(validatePage()); + } + }; + + /** the palette configuration model */ + private PaletteConfiguration paletteConfigurationModel; + + /** + * Constructor. + * + * @param editorPart + * @param editingDomain + */ + public PaletteConfigurationContentPage(final IEditorPart editorPart, final AdapterFactoryEditingDomain editingDomain) { + super(Messages.Local_Palette_ContentPage_Name, Messages.Local_Palette_ContentPage_Title, Activator.getImageDescriptor(WIZARD_ICON)); + this.editorPart = editorPart; + this.editingDomain = editingDomain; + paletteConfigurationModel = getPaletteConfigurationModel(); + paletteConfigurationModel.eAdapters().add(adapter); + } + + /** + * Constructor. + * + * @param pageName + */ + protected PaletteConfigurationContentPage(final String pageName) { + super(pageName); + } + + /** + * Add drag support from the available tools viewer + */ + protected void addAvailableToolsDragSupport() { + // transfer types + Transfer[] transfers = new Transfer[] { LocalTransfer.getInstance(), LocalSelectionTransfer.getTransfer(), FileTransfer.getInstance() }; + int dndOperations = DND.DROP_COPY | DND.DROP_MOVE | DND.DROP_LINK; + // drag listener + + availableToolsViewer.addDragSupport(dndOperations, transfers, new ViewerDragAdapter(availableToolsViewer)); + } + + + /** + * Adds drag ability to the palette preview composite + */ + protected void addPalettePreviewDragSupport() { + // transfer types + Transfer[] transfers = new Transfer[] { LocalTransfer.getInstance(), LocalSelectionTransfer.getTransfer(), FileTransfer.getInstance() }; + int dndOperations = DND.DROP_COPY | DND.DROP_MOVE | DND.DROP_LINK; + // drag listener + paletteTreeViewer.addDragSupport(dndOperations, transfers, new ViewerDragAdapter(paletteTreeViewer)); + } + + /** + * Add drop behavior for the palette preview + */ + protected void addPalettePreviewDropSupport() { + // transfer types + Transfer[] transfers = new Transfer[] { LocalTransfer.getInstance(), LocalSelectionTransfer.getTransfer(), FileTransfer.getInstance() }; + int dndOperations = DND.DROP_COPY | DND.DROP_MOVE | DND.DROP_LINK; + EditingDomainViewerDropAdapter listener = new EditingDomainViewerDropAdapter(editingDomain, paletteTreeViewer) { + + /** + * {@inheritDoc} + */ + @Override + public void dragEnter(final DropTargetEvent event) { + super.dragEnter(event); + expandItem(event); + } + + /** + * {@inheritDoc} + */ + @Override + public void drop(final DropTargetEvent event) { + super.drop(event); + expandItem(event); + } + + /** + * Expand the TreeItem from the event + * + * @param event + */ + private void expandItem(final DropTargetEvent event) { + // Expands branch when over it to show children + if (event.item instanceof TreeItem) { + // Get the target Object of the drop + Object target = ((TreeItem) event.item).getData(); + if (target == null) { + target = paletteTreeViewer.getInput(); + } + // Expand tree + paletteTreeViewer.expandToLevel(target, 1); + } + } + + }; + + paletteTreeViewer.addDropSupport(dndOperations, transfers, listener); + } + + /** + * Creates the add button listener + */ + protected MouseListener createAddButtonListener() { + return new MouseAdapter() { + + @Override + public void mouseUp(MouseEvent e) { + // add the element selected on the left to the right tree + // check the selection. + IStructuredSelection selection = (IStructuredSelection) availableToolsViewer.getSelection(); + if (selection == null || selection.size() < 1) { + return; + } + PaletteEntry entry = (PaletteEntry) selection.getFirstElement(); + if (entry == null) { + return; + } + + // find the selection on the right + selection = (IStructuredSelection) paletteTreeViewer.getSelection(); + + Configuration target = (Configuration) selection.getFirstElement(); + + // Create Entry + CompoundCommand command = new CompoundCommand(); + ToolConfiguration node = CreatePaletteItemUtil.createToolConfiguration(entry, editingDomain.getResourceSet()); + if (null != node) { + if (target instanceof PaletteConfiguration) { + // ((PaletteConfiguration) target).getDrawerConfigurations().add((DrawerConfiguration) node); + command.append(new AddCommand(editingDomain, ((PaletteConfiguration) target).getDrawerConfigurations(), (DrawerConfiguration) node)); + } else if (target instanceof DrawerConfiguration) { + // ((DrawerConfiguration) target).getOwnedConfigurations().add((ChildConfiguration) node); + command.append(new AddCommand(editingDomain, ((DrawerConfiguration) target).getOwnedConfigurations(), (ChildConfiguration) node)); + } else if (target instanceof StackConfiguration) { + // ((StackConfiguration) target).getOwnedConfigurations().add((LeafConfiguration) node); + command.append(new AddCommand(editingDomain, ((StackConfiguration) target).getOwnedConfigurations(), (LeafConfiguration) node)); + } + } + command.append(CreatePaletteItemUtil.createElementTypesElement(editingDomain, (ToolEntry) entry, node)); + execute(command); + // Expand tree + paletteTreeViewer.expandToLevel(target, 1); + } + }; + } + + /** + * creates the buttons to add/remove entries from palette entrey and palette preview + */ + protected void createAddRemoveButtons() { + Composite composite = new Composite((Composite) getControl(), SWT.NONE); + GridLayout layout = new GridLayout(1, true); + composite.setLayout(layout); + + GridData data = new GridData(SWT.CENTER, SWT.CENTER, false, true); + composite.setLayoutData(data); + + addButton = new Button(composite, SWT.NONE); + addButton.setImage(Activator.getPluginIconImage(Activator.ID, ADD_ICON)); + addButton.setToolTipText(Messages.PapyrusPaletteCustomizerDialog_AddButtonTooltip); + addButton.addMouseListener(createAddButtonListener()); + addButton.setEnabled(false); + + removeButton = new Button(composite, SWT.NONE); + removeButton.setImage(Activator.getPluginIconImage(Activator.ID, REMOVE_ICON)); + removeButton.setToolTipText(Messages.PapyrusPaletteCustomizerDialog_RemoveButtonTooltip); + removeButton.addMouseListener(createRemoveButtonListener()); + removeButton.setEnabled(false); + } + + /** + * creates the available entries group + */ + protected void createAvailableToolsGroup() { + Composite parent = (Composite) getControl(); + Composite availableToolsComposite = new Composite(parent, SWT.NONE); + GridLayout layout = new GridLayout(2, true); + layout.marginHeight = 0; + layout.marginWidth = 0; + availableToolsComposite.setLayout(layout); + GridData data = new GridData(SWT.FILL, SWT.FILL, true, true); + availableToolsComposite.setLayoutData(data); + + Label label = new Label(availableToolsComposite, SWT.NONE); + label.setText(Messages.Local_Palette_Available_Tools); + data = new GridData(SWT.LEFT, SWT.CENTER, true, false); + label.setLayoutData(data); + + ToolBar toolbar = new ToolBar(availableToolsComposite, SWT.HORIZONTAL); + data = new GridData(SWT.RIGHT, SWT.FILL, false, false); + toolbar.setLayoutData(data); + populateAvailableToolsToolBar(toolbar); + + createProfileCombo(availableToolsComposite); + + Tree tree = new Tree(availableToolsComposite, SWT.SINGLE | SWT.BORDER); + data = new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1); + data.widthHint = 350; + // Make the tree this tall even when there is nothing in it. This will keep the + // dialog from shrinking to an unusually small size. + data.heightHint = 200; + tree.setLayoutData(data); + availableToolsViewer = new TreeViewer(tree); + availableToolsViewer.setContentProvider(new UMLToolsTreeContentProvider()); + paletteLabelProvider = new PaletteLabelProvider(); + availableToolsViewer.setLabelProvider(paletteLabelProvider); + ViewerComparator labelComparator = new LabelViewerComparator(); + availableToolsViewer.setComparator(labelComparator); + // remove the note stack and standard group + availableToolsViewer.addFilter(new ViewerFilter() { + + /** + * {@inheritDoc} + */ + @Override + public boolean select(final Viewer viewer, final Object parentElement, final Object element) { + boolean visible = true; + if (element instanceof PaletteStack && "noteStack".equals(((PaletteStack) element).getId())) {//$NON-NLS-1$ + visible = false; + } else if (element instanceof PaletteToolbar && "standardGroup".equals(((PaletteToolbar) element).getId())) {//$NON-NLS-1$ + visible = false; + } + return visible; + } + }); + availableToolsViewer.addFilter(new DrawerFilter()); + + // add drag support + addAvailableToolsDragSupport(); + + // init availableTools combo on the first elemet + profileCombo.deselectAll(); + profileCombo.select(profileCombo.getItems().length - 1); // select the last one (UML) + } + + + + /** + * Creates a toolbar item which can be checked. + * + * @param toolbar + * the parent toolbar + * @param shownElementsIcon + * path for shown elements icon + * @param listener + * listener for button action + * @param tooltip + * tooltip text for the toolbar item + */ + protected ToolItem createCheckToolBarItem(final ToolBar toolbar, final String shownElementsIcon, final String tooltip, final Listener listener) { + ToolItem item = new ToolItem(toolbar, SWT.CHECK | SWT.BORDER); + item.setImage(Activator.getPluginIconImage(Activator.ID, shownElementsIcon)); + item.setToolTipText(tooltip); + item.addListener(SWT.Selection, listener); + return item; + } + + /** + * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite) + * + * @param parent + */ + @Override + public void createControl(final Composite parent) { + + // initialize dialog units + initializeDialogUnits(parent); + + // Create a new composite as there is the title bar seperator + // to deal with + Composite control = new Composite(parent, SWT.NONE); + GridLayout layout = new GridLayout(3, false); + control.setLayout(layout); + control.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + setControl(control); + + // create Available Tools Group + createAvailableToolsGroup(); + + // create add/remove buttons + createAddRemoveButtons(); + + // Create palette preview + createPalettePreviewGroup(); + + // Create properties view + createPropertiesGroup(); + + // add listeners inter-groups + ISelectionChangedListener listener = createToolsViewerSelectionChangeListener(); + availableToolsViewer.addSelectionChangedListener(listener); + paletteTreeViewer.addSelectionChangedListener(listener); + + // end of the control creation + Dialog.applyDialogFont(control); + + // Show description on opening + setErrorMessage(null); + setMessage(null); + setPageComplete(validatePage()); + } + + /** + * Creates the listener for the new drawer tool item + * + * @return the listener created + */ + protected Listener createNewDrawerListener() { + return new Listener() { + + /** + * {@inheritDoc} + */ + @Override + public void handleEvent(final Event event) { + + EObject palette = editingDomain.getResourceSet().getResources().get(0).getContents().get(0); + if (palette instanceof PaletteConfiguration) { + // Create a void drawer + DrawerConfiguration drawer = PaletteconfigurationFactory.eINSTANCE.createDrawerConfiguration(); + // Set label + drawer.setLabel(DRAWER_LABEL); + // Set the drawer on the palette configuration + EList<DrawerConfiguration> drawerConfigurations = ((PaletteConfiguration) palette).getDrawerConfigurations(); + // Create add command + Command addCommand = new AddCommand(editingDomain, drawerConfigurations, drawer); + // Execute add command + execute(addCommand); + paletteTreeViewer.refresh(); + } + } + }; + } + + /** + * Creates the listener for the new separator tool item + * + * @return the listener created + */ + protected Listener createNewSeparatorListener() { + return new Listener() { + + /** + * {@inheritDoc} + */ + @Override + public void handleEvent(final Event event) { + // retrieve selected element + Object object = ((IStructuredSelection) paletteTreeViewer.getSelection()).getFirstElement(); + // Create a separator + SeparatorConfiguration separator = PaletteconfigurationFactory.eINSTANCE.createSeparatorConfiguration(); + // Set label & Id + separator.setLabel(SEPARATOR_LABEL); + separator.setId(CreatePaletteItemUtil.generateID(SEPARATOR_LABEL)); + Command addCommand = null; + if (object instanceof DrawerConfiguration) { + // Add separator at the end of drawer own configuration + addCommand = new AddCommand(editingDomain, ((DrawerConfiguration) object).getOwnedConfigurations(), separator); + } else if (object instanceof ChildConfiguration) { + // retrieve parent + EList<ChildConfiguration> ownedConfigurations = ((DrawerConfiguration) ((ChildConfiguration) object).eContainer()).getOwnedConfigurations(); + int index = ownedConfigurations.indexOf(object); + // adds the separator + addCommand = new AddCommand(editingDomain, ownedConfigurations, separator, index); + } + // Execute add command + execute(addCommand); + + paletteTreeViewer.expandToLevel(object, 1); + paletteTreeViewer.refresh(); + } + }; + } + + /** + * Creates the listener for the new stack tool item + * + * @return the listener created + */ + protected Listener createNewStackListener() { + return new Listener() { + + /** + * {@inheritDoc} + */ + @Override + public void handleEvent(final Event event) { + // retrieve selected element + Object object = ((IStructuredSelection) paletteTreeViewer.getSelection()).getFirstElement(); + // Create a separator + StackConfiguration stack = PaletteconfigurationFactory.eINSTANCE.createStackConfiguration(); + // Set label & Id + stack.setLabel(STACK_LABEL); + stack.setId(CreatePaletteItemUtil.generateID(STACK_LABEL)); + Command addCommand = null; + if (object instanceof DrawerConfiguration) { + // Add separator at the end of drawer own configuration + addCommand = new AddCommand(editingDomain, ((DrawerConfiguration) object).getOwnedConfigurations(), stack); + } else if (object instanceof ChildConfiguration) { + // retrieve parent + EList<ChildConfiguration> ownedConfigurations = ((DrawerConfiguration) ((ChildConfiguration) object).eContainer()).getOwnedConfigurations(); + int index = ownedConfigurations.indexOf(object); + // adds the stack + addCommand = new AddCommand(editingDomain, ownedConfigurations, stack, index); + } + execute(addCommand); + + paletteTreeViewer.expandToLevel(object, 1); + paletteTreeViewer.refresh(); + } + + }; + } + + /** + * Execute command in the command stack. + */ + protected void execute(final Command command) { + if (null != command && command.canExecute()) { + editingDomain.getCommandStack().execute(command); + } + } + + /** + * Creates the listener for the new tool item + * + * @return the listener created + */ + protected Listener createNewToolListener() { + return new Listener() { + + /** + * {@inheritDoc} + */ + @Override + public void handleEvent(Event event) { + // retrieve selected element + Object object = ((IStructuredSelection) paletteTreeViewer.getSelection()).getFirstElement(); + // Create a separator + ToolConfiguration tool = PaletteconfigurationFactory.eINSTANCE.createToolConfiguration(); + // Set label & Id + tool.setLabel(NEW_TOOL_LABEL); + Command addCommand = null; + if (object instanceof DrawerConfiguration || object instanceof StackConfiguration) { + // Add separator at the end of drawer own configuration + if (object instanceof DrawerConfiguration) { + addCommand = new AddCommand(editingDomain, ((DrawerConfiguration) object).getOwnedConfigurations(), tool); + } else if (object instanceof StackConfiguration) { + addCommand = new AddCommand(editingDomain, ((StackConfiguration) object).getOwnedConfigurations(), tool); + } + } else if (object instanceof ChildConfiguration) { + // retrieve parent + EObject eContainer = ((EObject) object).eContainer(); + // add as sibling of the object + if (eContainer instanceof DrawerConfiguration) { + EList<ChildConfiguration> ownedConfigurations = ((DrawerConfiguration) eContainer).getOwnedConfigurations(); + int index = ownedConfigurations.indexOf(object); + addCommand = new AddCommand(editingDomain, ownedConfigurations, tool, index); + } else if (eContainer instanceof StackConfiguration) { + EList<LeafConfiguration> ownedConfigurations = ((StackConfiguration) eContainer).getOwnedConfigurations(); + int index = ownedConfigurations.indexOf(object); + addCommand = new AddCommand(editingDomain, ownedConfigurations, tool, index); + } + } + execute(addCommand); + paletteTreeViewer.expandToLevel(object, 1); + paletteTreeViewer.refresh(); + } + }; + } + + /** + * creates the palette preview group + */ + protected void createPalettePreviewGroup() { + Composite parent = (Composite) getControl(); + Composite paletteComposite = new Composite(parent, SWT.NONE); + + GridLayout layout = new GridLayout(2, true); + layout.marginHeight = 0; + layout.marginWidth = 0; + paletteComposite.setLayout(layout); + GridData data = new GridData(SWT.FILL, SWT.FILL, true, true); + paletteComposite.setLayoutData(data); + + Label label = new Label(paletteComposite, SWT.NONE); + label.setText(Messages.Local_Palette_Palette_Preview); + data = new GridData(SWT.LEFT, SWT.CENTER, true, false); + label.setLayoutData(data); + + toolbar = new ToolBar(paletteComposite, SWT.HORIZONTAL); + data = new GridData(SWT.RIGHT, SWT.FILL, false, false); + toolbar.setLayoutData(data); + populatePalettePreviewToolBar(toolbar); + + Tree tree = new Tree(paletteComposite, SWT.SINGLE | SWT.BORDER); + data = new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1); + data.widthHint = 350; + // Make the tree this tall even when there is nothing in it. This will keep the + // dialog from shrinking to an unusually small size. + data.heightHint = 200; + tree.setLayoutData(data); + + paletteTreeViewer = new TreeViewer(tree); + + paletteTreeViewer.setContentProvider(new AdapterFactoryContentProvider(editingDomain.getAdapterFactory())); + paletteTreeViewer.setLabelProvider(new AdapterFactoryLabelProvider(editingDomain.getAdapterFactory())); + paletteTreeViewer.setInput(editingDomain.getResourceSet()); + + paletteTreeViewer.setSelection(new StructuredSelection(editingDomain.getResourceSet().getResources().get(0)), true); + + new AdapterFactoryTreeEditor(paletteTreeViewer.getTree(), editingDomain.getAdapterFactory()); + + paletteTreeViewer.addSelectionChangedListener(new ISelectionChangedListener() { + + @Override + public void selectionChanged(SelectionChangedEvent event) { + handlePalettePreviewSelectionChanged(event); + } + }); + + // Refresh button + handlePalettePreviewSelectionChanged(null); + addPalettePreviewDropSupport(); + addPalettePreviewDragSupport(); + } + + /** + * Creates the profile combo + * + * @param availableToolsComposite + * the available tools composite + * @return the created combo + */ + protected Combo createProfileCombo(final Composite availableToolsComposite) { + // retrieve top package, to know which profiles are available + // creates the combo + profileCombo = new Combo(availableToolsComposite, SWT.BORDER | SWT.READ_ONLY); + GridData data = new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1); + profileCombo.setLayoutData(data); + + // retrieve all applied profiles + List<Profile> profiles = getAllAppliedProfiles(); + + int profileNumber = profiles.size(); + for (int i = 0; i < profileNumber; i++) { + String name; + if (profiles.get(i).eIsProxy()) { + name = NLS.bind("<unresolved: {0}>", URI.decode(EcoreUtil.getURI(profiles.get(i)).lastSegment())); //$NON-NLS-1$ + } else { + name = profiles.get(i).getName(); + if (name == null) { + name = NLS.bind("<unnamed: {0}>", URI.decode(EcoreUtil.getURI(profiles.get(i)).lastSegment())); //$NON-NLS-1$ + } + } + profileComboList.add(i, name); + } + profileComboList.add(UML_TOOLS_LABEL); + profileCombo.setItems(profileComboList.toArray(new String[] {})); + + // add selection listener for the combo. selects the "UML tools" item + ProfileComboSelectionListener listener = new ProfileComboSelectionListener(); + profileCombo.addSelectionListener(listener); + profileCombo.addModifyListener(listener); + + return profileCombo; + } + + /** + * create the properties group + */ + protected void createPropertiesGroup() { + Composite parent = (Composite) getControl(); + + Label entryInformationLabel = new Label(parent, SWT.NONE); + entryInformationLabel.setText(Messages.Local_Palette_Entry_Information); + { + GridData data = new GridData(SWT.FILL, SWT.FILL, true, false); + data.horizontalSpan = 3; + entryInformationLabel.setLayoutData(data); + } + + propertiesComposite = new Composite(parent, SWT.NONE); + FillLayout layout = new FillLayout(); + layout.marginHeight = 0; + layout.marginWidth = 0; + propertiesComposite.setLayout(layout); + { + GridData data = new GridData(SWT.FILL, SWT.FILL, true, true); + data.horizontalSpan = 3; + data.heightHint = 240; + propertiesComposite.setLayoutData(data); + } + + } + + /** + * Creates the add button listener. + */ + protected MouseListener createRemoveButtonListener() { + return new MouseAdapter() { + + /** + * {@inheritDoc} + */ + @Override + public void mouseUp(final MouseEvent e) { + deleteSelectedConfiguration(); + } + }; + } + + /** + * Creates the listener for the remove item(s) button. + * + * @return the listener for the remove button + */ + protected Listener createRemoveElementListener() { + return new Listener() { + + /** + * {@inheritDoc} + */ + @Override + public void handleEvent(final Event event) { + deleteSelectedConfiguration(); + } + + }; + } + + /** + * Delete the selection configuration in the paletteTreeViewer. + */ + protected void deleteSelectedConfiguration() { + IStructuredSelection selection = (IStructuredSelection) paletteTreeViewer.getSelection(); + if (null != selection && 1 <= selection.size()) { + Iterator<?> it = selection.iterator(); + while (it.hasNext()) { + Object object = it.next(); + if (object instanceof Configuration) { + Command deleteCommand = new AbstractCommand() { + + @Override + public void redo() { + execute(); + } + + @Override + public void execute() { + EcoreUtil.delete((EObject) object); + } + + @Override + public boolean prepare() { + return true; + } + }; + deleteCommand.canExecute(); + editingDomain.getCommandStack().execute(deleteCommand); + } + } + paletteTreeViewer.refresh(); + // remove the properties view + if (null != displayEngine) { + displayEngine.removeSection(propertiesComposite); + } + } + } + + /** + * creates the tool item for drawers visibility listener + * + * @return the listener for the tool button + */ + protected Listener createShowDrawerListener() { + return new Listener() { + + /** + * {@inheritDoc} + */ + @Override + public void handleEvent(final Event event) { + if (event.widget instanceof ToolItem) { + ToolItem item = ((ToolItem) event.widget); + if (item.getSelection()) { + // elements should be hidden + availableToolsViewer.addFilter(drawerFilter); + item.setSelection(true); + } else { + availableToolsViewer.removeFilter(drawerFilter); + item.setSelection(false); + } + } + } + }; + } + + /** + * creates the tool item for tools visibility listener + * + * @return the listener for the tool button + */ + protected Listener createsShowToolListener() { + return new Listener() { + + /** + * {@inheritDoc} + */ + @Override + public void handleEvent(final Event event) { + if (event.widget instanceof ToolItem) { + ToolItem item = ((ToolItem) event.widget); + if (item.getSelection()) { + // elements should be hidden + availableToolsViewer.addFilter(toolFilter); + item.setSelection(true); + } else { + availableToolsViewer.removeFilter(toolFilter); + item.setSelection(false); + } + } + } + }; + } + + /** + * Creates the listener for the available tools content provider + * + * @return the listener created + */ + protected Listener createSwitchToolsContentProviderListener() { + return new Listener() { + + /** + * {@inheritDoc} + */ + @Override + public void handleEvent(final Event event) { + if (event.widget instanceof ToolItem) { + ToolItem item = ((ToolItem) event.widget); + // retrieve current profile selected in the combo profile + int index = profileCombo.getSelectionIndex(); + Collection<PaletteEntry> standardEntries = getAllVisibleStandardEntries(); + Profile profile = getAllAppliedProfiles().get(index); + + if (item.getSelection()) { + availableToolsViewer.setContentProvider(new ProfileToolsStereotypeMetaclassTreeContentProvider(profile, standardEntries)); + item.setSelection(true); + } else { + + availableToolsViewer.setContentProvider(new ProfileToolsMetaclassStereotypeTreeContentProvider(profile, standardEntries)); + item.setSelection(false); + } + + // generate tools for given profile + availableToolsViewer.setInput(profile); + } + } + }; + } + + /** + * Creates a toolbar item. + * + * @param toolbar + * the parent toolbar + * @param itemIcon + * path for icon + * @param tooltip + * tooltip text for the toolbar item + * @param listener + * listener for tool bar item + */ + protected void createToolBarItem(final ToolBar toolbar, final String itemIcon, final String tooltip, final Listener listener, final ToolBarItemValidator validator) { + ToolItem item = new ToolItem(toolbar, SWT.BORDER); + item.setImage(Activator.getPluginIconImage(Activator.ID, itemIcon)); + item.setToolTipText(tooltip); + item.addListener(SWT.Selection, listener); + item.setData(VALIDATOR, validator); + } + + /** + * selection listener for the tools viewer , to update the state of the add button + * + * @return the new created selection listener + */ + protected ISelectionChangedListener createToolsViewerSelectionChangeListener() { + return new ISelectionChangedListener() { + + /** + * Returns true if the source can be added to the target + * + * @param source + * the source object + * @param target + * the target object + * @return <code>true</code> if the source can be added to the target + */ + protected boolean isAddValidTarget(final Object source, final Object target) { + boolean isAddValidTarget = false; + if (source instanceof PaletteEntry) { + // case1: source is a drawer. + // it can only be added to the root element (no selection) + // case2: source is a palette tool + // it can't be added to the root element + // it can only be added to a container element (drawer or stack) + + if (source instanceof PaletteDrawer) { + isAddValidTarget = null == target; + } else if (source instanceof ToolEntry) { + isAddValidTarget = target instanceof DrawerConfiguration || target instanceof StackConfiguration; + } + } + return isAddValidTarget; + } + + /** + * Returns true if the source can be added to the target + * + * @param source + * the source object + * @return <code>true</code> if the source can be removed (not null and instanceof + * PaletteEntryProxy) + */ + protected boolean isRemoveValidSource(final Object source) { + return source instanceof Configuration; + } + + /** + * {@inheritDoc} + */ + @Override + public void selectionChanged(final SelectionChangedEvent event) { + // get source and target selection + // check source entry can be added to target entry + Object source = ((IStructuredSelection) availableToolsViewer.getSelection()).getFirstElement(); + Object target = ((IStructuredSelection) paletteTreeViewer.getSelection()).getFirstElement(); + + // manage add button + if (isAddValidTarget(source, target)) { + addButton.setEnabled(true); + } else { + addButton.setEnabled(false); + } + + // manage remove button + if (isRemoveValidSource(target)) { + removeButton.setEnabled(true); + } else { + removeButton.setEnabled(false); + } + + } + }; + + } + + /** + * @see org.eclipse.jface.dialogs.DialogPage#dispose() + * + */ + @Override + public void dispose() { + // dispose engine + if (null != displayEngine) { + displayEngine.dispose(); + } + // dispose adapter + paletteConfigurationModel.eAdapters().remove(adapter); + super.dispose(); + } + + /** + * returns the list of applied profile for the nearest package of the top element + * + * @return the list of applied profile for the nearest package of the top element or an empty + * list + */ + protected List<Profile> getAllAppliedProfiles() { + Package topPackage = null; + if (editorPart instanceof DiagramEditorWithFlyOutPalette) { + EObject element = ((DiagramEditorWithFlyOutPalette) editorPart).getDiagram().getElement(); + if (element instanceof org.eclipse.uml2.uml.Element) { + topPackage = ((org.eclipse.uml2.uml.Element) element).getNearestPackage(); + } + } + return null != topPackage ? topPackage.getAllAppliedProfiles() : Collections.emptyList(); + } + + /** + * Returns the list of all visible palette entries + * + * @return the list of all visible palette entries + */ + protected Collection<PaletteEntry> getAllVisibleStandardEntries() { + HashSet<PaletteEntry> result = new HashSet<PaletteEntry>(); + for (PaletteEntry entry : PaletteUtil.getAvailableEntriesSet(editorPart, priority).values()) { + // the entry is not just a defineOnly entry but a visible one + if (getRootParent(entry) != null) { + result.add(entry); + } + } + return result; + } + + /** + * Returns the Root element for the palette entry. It searches recursively from parent to parent, until it find the root element + * + * @param entry + * the palette entry for which root element is searched + * @return the root element or <code>null</code> if none was found + */ + protected PaletteRoot getRootParent(final PaletteEntry entry) { + PaletteRoot paletteRoot = null; + + PaletteContainer parent = entry.getParent(); + if (parent instanceof PaletteRoot) { + paletteRoot = (PaletteRoot) parent; + } else if (null != parent) { + paletteRoot = getRootParent(parent); + } + return paletteRoot; + } + + /** + * handle the selection change event for the palette preview + * + * @param event + * the event that is thrown by the palette viewer + */ + protected void handlePalettePreviewSelectionChanged(final SelectionChangedEvent event) { + // Properties view + if (null != event) { + // retrieve current selection + ITreeSelection selection = (TreeSelection) event.getSelection(); + Object firstSelected = selection.getFirstElement(); + + if (firstSelected instanceof Configuration) { + if (null != displayEngine) { + displayEngine.removeSection(propertiesComposite); + } + displayEngine = PropertiesDisplayHelper.display(firstSelected, propertiesComposite); + propertiesComposite.layout(); + } + } + // update toolbar + if (null != toolbar && !toolbar.isDisposed()) { + for (int i = 0; i < toolbar.getItemCount(); i++) { + ToolItem item = toolbar.getItem(i); + Object validator = item.getData(VALIDATOR); + if (validator instanceof ToolBarItemValidator) { + item.setEnabled(((ToolBarItemValidator) validator).isEnable()); + } + } + } + } + + /** + * Adds elements to the tool bar for available tools viewer + * + * @param toolbar + * the toolbar to populate + */ + protected void populateAvailableToolsToolBar(final ToolBar toolbar) { + toggleContentProvider = createCheckToolBarItem(toolbar, SWITCH_CONTENT_PROVIDER_ICON, Messages.Local_Palette_SwitchToolsContentProvider_Tooltip, createSwitchToolsContentProviderListener()); + toggleContentProvider.setSelection(true); + toggleContentProvider.setEnabled(false); + createCheckToolBarItem(toolbar, SHOWN_TOOLS_ICON, Messages.Local_Palette_ShowTools_Tooltip, createsShowToolListener()); + } + + /** + * populates the preview palette toolbar + * + * @param toolbar + * the toolbar to populate + */ + protected void populatePalettePreviewToolBar(final ToolBar toolbar) { + // create validator + PaletteConfigurationEntrySelectedValidator validator = new PaletteConfigurationEntrySelectedValidator(); + PaletteConfigurationStackLeafSelectedValidator validatorForNotStackChild = new PaletteConfigurationStackLeafSelectedValidator(); + + createToolBarItem(toolbar, DELETE_ICON, Messages.PapyrusPaletteCustomizerDialog_RemoveButtonTooltip, createRemoveElementListener(), validator); + createToolBarItem(toolbar, CREATE_DRAWERS_ICON, Messages.Local_Palette_Create_Drawer_Tooltip, createNewDrawerListener(), null); + createToolBarItem(toolbar, CREATE_SEPARATOR_ICON, Messages.Local_Palette_Create_Separator_Tooltip, createNewSeparatorListener(), validatorForNotStackChild); + createToolBarItem(toolbar, CREATE_TOOL_ICON, Messages.Local_Palette_Create_Tool_Tooltip, createNewToolListener(), validator); + createToolBarItem(toolbar, CREATE_STACK_ICON, Messages.Local_Palette_Create_Stack_Tooltip, createNewStackListener(), validatorForNotStackChild); + } + + /** + * Sets the priority of the current edited palette + * + * @param priority + * the priority of the current edited palette + */ + public void setPriority(final ProviderPriority priority) { + this.priority = priority; + } + + /** + * @return the priority + */ + public ProviderPriority getPriority() { + return priority; + } + + /** The model diagnostician. */ + Diagnostician diagnostician = new Diagnostician() { + + @Override + public String getObjectLabel(final EObject eObject) { + String label = null; + if (eObject instanceof Configuration) { + label = ((Configuration) eObject).getLabel(); + } + if (null == label || label.isEmpty()) { + label = EcoreUtil.getIdentification(eObject); + } + return label; + } + }; + + /** + * Validates the content of the fields in this page. + */ + protected boolean validatePage() { + // TODO Adds OCL validation to Configuration to have error if Id is empty. + Diagnostic validate = diagnostician.validate(paletteConfigurationModel); + boolean valid = Diagnostic.OK == validate.getSeverity(); + + if (!valid) { + setErrorMessage(validate.getChildren().get(0).getMessage()); + } else { + setErrorMessage(null); + } + return valid; + } + + /** + * @return The {@link PaletteConfiguration} model from resource set. + */ + protected PaletteConfiguration getPaletteConfigurationModel() { + PaletteConfiguration paletteModel = null; + EList<Resource> resources = editingDomain.getResourceSet().getResources(); + if (!resources.isEmpty()) { + EList<EObject> contents = resources.get(0).getContents(); + if (!contents.isEmpty()) { + EObject eObject = (EObject) contents.get(0); + if (eObject instanceof PaletteConfiguration) { + paletteModel = (PaletteConfiguration) eObject; + } + } + } + Assert.isNotNull(paletteModel); + return paletteModel; + } + +} diff --git a/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/dialog/PaletteConfigurationInformationPage.java b/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/dialog/PaletteConfigurationInformationPage.java new file mode 100644 index 00000000000..059f556c7f8 --- /dev/null +++ b/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/dialog/PaletteConfigurationInformationPage.java @@ -0,0 +1,108 @@ +/***************************************************************************** + * Copyright (c) 2016 CEA LIST and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Mickael ADAM (ALL4TEC) mickael.adam@all4tec.net - Initial API and Implementation + *****************************************************************************/ + +package org.eclipse.papyrus.customization.palette.dialog; + +import org.eclipse.emf.common.notify.Notification; +import org.eclipse.emf.common.notify.impl.AdapterImpl; +import org.eclipse.jface.wizard.WizardPage; +import org.eclipse.papyrus.infra.properties.ui.runtime.DisplayEngine; +import org.eclipse.papyrus.infra.properties.ui.runtime.PropertiesRuntime; +import org.eclipse.papyrus.infra.properties.ui.util.PropertiesDisplayHelper; +import org.eclipse.papyrus.uml.diagram.paletteconfiguration.PaletteConfiguration; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Layout; + +/** + * {@link WizardPage} for informations of a {@link PaletteConfiguration} Model. + * + */ +public class PaletteConfigurationInformationPage extends WizardPage { + + /** The {@link PaletteConfiguration} model */ + private PaletteConfiguration paletteConfiguration; + + /** The display engine */ + private DisplayEngine displayEngine; + + /** + * Constructor. + */ + protected PaletteConfigurationInformationPage(final String pageName, final PaletteConfiguration paletteConfiguration) { + super(pageName); + this.paletteConfiguration = paletteConfiguration; + + // install adapter + AdapterImpl adapter = new AdapterImpl() { + + /** + * @see org.eclipse.emf.common.notify.impl.AdapterImpl#notifyChanged(org.eclipse.emf.common.notify.Notification) + */ + @Override + public void notifyChanged(final Notification msg) { + setPageComplete(validatePage()); + } + }; + paletteConfiguration.eAdapters().add(adapter); + adapter.setTarget(paletteConfiguration); + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite) + */ + @Override + public void createControl(final Composite parent) { + // initialize dialog units + initializeDialogUnits(parent); + + Composite control = new Composite(parent, SWT.NONE); + Layout layout = new FillLayout(); + control.setLayout(layout); + setControl(control); + + // Create the composite + if (!PropertiesRuntime.getConstraintEngine().getDisplayUnits(paletteConfiguration).isEmpty()) { + displayEngine = PropertiesDisplayHelper.display(paletteConfiguration, control); + } + setPageComplete(validatePage()); + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.jface.dialogs.DialogPage#dispose() + */ + @Override + public void dispose() { + if (null != displayEngine) { + displayEngine.dispose(); + } + super.dispose(); + } + + + /** + * Validate the paletteConfiguration properties. paletteConfiguration must at leazst have a name and an id. + */ + protected boolean validatePage() { + return null != paletteConfiguration + && null != paletteConfiguration.getLabel() + && null != paletteConfiguration.getId() + && !paletteConfiguration.getLabel().isEmpty() + && !paletteConfiguration.getId().isEmpty(); + } + +} diff --git a/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/dialog/PaletteConfigurationWizard.java b/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/dialog/PaletteConfigurationWizard.java new file mode 100644 index 00000000000..3a36a8aa635 --- /dev/null +++ b/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/dialog/PaletteConfigurationWizard.java @@ -0,0 +1,279 @@ +/***************************************************************************** + * Copyright (c) 2016 CEA LIST. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Remi Schnekenburger (CEA LIST) remi.schnekenburger@cea.fr - Initial API and implementation + * Mickael ADAM (ALL4TEC) mickael.adam@all4tec.net - new implementation for palette configuration model case + * + *****************************************************************************/ + +package org.eclipse.papyrus.customization.palette.dialog; + +import java.io.IOException; +import java.util.Collections; +import java.util.HashSet; + +import org.eclipse.emf.common.util.URI; +import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditorWithFlyOutPalette; +import org.eclipse.jface.wizard.WizardPage; +import org.eclipse.papyrus.customization.palette.Messages; +import org.eclipse.papyrus.customization.palette.PaletteConstants; +import org.eclipse.papyrus.customization.palette.PaletteConstants.PaletteModelContextEnum; +import org.eclipse.papyrus.customization.palette.utils.PaletteUtils; +import org.eclipse.papyrus.infra.types.ElementTypeSetConfiguration; +import org.eclipse.papyrus.infra.types.core.registries.ElementTypeSetConfigurationRegistry; +import org.eclipse.papyrus.uml.diagram.common.Activator; +import org.eclipse.papyrus.uml.diagram.common.part.PaletteUtil; +import org.eclipse.papyrus.uml.diagram.common.part.PapyrusPalettePreferences; +import org.eclipse.papyrus.uml.diagram.common.service.PapyrusPaletteService.ProviderDescriptor; +import org.eclipse.papyrus.uml.diagram.paletteconfiguration.PaletteConfiguration; +import org.eclipse.ui.IEditorPart; + +/** + * Wizard to update or create an Palette configuration + */ +public class PaletteConfigurationWizard extends AbstractPaletteConfigurationWizard { + + /** content page */ + protected WizardPage contentPage; + + /** info page */ + protected WizardPage infoPage; + + /** + * Creates a NewLocalPaletteWizard. + * + * @param part + * the editor part where the palette is available + * @param descriptor + * the descriptor to edit + */ + public PaletteConfigurationWizard(final IEditorPart part, final ProviderDescriptor descriptor) { + super(part, descriptor); + } + + /** constructor in case of new palette configuration model */ + public PaletteConfigurationWizard(final IEditorPart part) { + this(part, null); + } + + /** + * {@inheritDoc} + */ + @Override + public void addPages() { + super.addPages(); + + // create pages + infoPage = createPaletteInformationPage(); + contentPage = createPaletteContentPage(); + + // Add pages + addPage(infoPage); + addPage(contentPage); + } + + /** + * Create the content page. + */ + protected WizardPage createPaletteContentPage() { + // second page: describe the paletteContent + WizardPage page = new PaletteConfigurationContentPage(editorPart, editingDomain); + page.setTitle(Messages.PaletteConfigurationWizard_NewPaletteContentPageWizard_Title); + page.setDescription(Messages.PaletteConfigurationWizard_NewPaletteContentPageWizard_Description); + + // init content page + ((PaletteConfigurationContentPage) page).setPriority(priority); + return page; + } + + /** + * Create the information page. + */ + protected WizardPage createPaletteInformationPage() { + WizardPage page = new PaletteConfigurationInformationPage("", (PaletteConfiguration) paletteResource.getContents().get(0));//$NON-NLS-1$ + if (PaletteModelContextEnum.New.equals(paletteContext)) { + page.setTitle(Messages.PaletteConfigurationWizard_NewPaletteInfoPageWizard_Title); + } else { + page.setTitle(Messages.PaletteConfigurationWizard_EditionPaletteInfoPageWizard_Tilte); + } + page.setDescription(Messages.PaletteConfigurationWizard_PaletteInfoPageWizard_Description); + return page; + } + + /** + * {@inheritDoc} + */ + @Override + protected void deployModels() { + + // Loads element types models. + deployElementTypesModels(); + + // loads modified palette model + deployPaletteModel(); + + // Force the update + PaletteUtil.getAvailableEntriesSet(editorPart, priority); + } + + /** + * load palette models on Papyrus preferences. + */ + protected void deployPaletteModel() { + // Get the palette model + PaletteConfiguration paletteModel = (PaletteConfiguration) paletteResource.getContents().get(0); + + // The palette id + String paletteId = paletteModel.getId(); + + // Update palette preferences + switch (paletteContext) { + + case New: + // New model + PapyrusPalettePreferences.addLocalExtendedPalette(paletteId, paletteId, priority, PaletteUtils.getEditorIdValue(editorPart), new HashSet(paletteModel.getRequiredProfiles())); + break; + + case Local: + // Edition of a local extended palette + // Refresh by deletion and re add it. + PapyrusPalettePreferences.deleteLocalExtendedPalette(descriptor.getContributionID()); + PapyrusPalettePreferences.addLocalExtendedPalette(paletteId, paletteId, priority, PaletteUtils.getEditorIdValue(editorPart), new HashSet(paletteModel.getRequiredProfiles())); + break; + + case Plugin: + // Edition of palette redefinition from plugin + // Case of redefinition of read-only palette configuration model + String path = PapyrusPalettePreferences.getPaletteRedefinition(descriptor.getContributionID()); + if (null != path) { + // Register the redefinition + PapyrusPalettePreferences.registerLocalRedefinition(descriptor.getContributionID(), path); // if already exists: removes, then add + } + break; + + case Workspace: + // Workspace palette case + String pathWS = paletteResource.getURI().toPlatformString(false); + // If identifier is changed: need to delete palette + if (null != descriptor && !paletteId.equals(descriptor.getContributionID())) { + PapyrusPalettePreferences.deleteWorkspaceExtendedPalette(descriptor.getContributionID());// Delete it in case of id change + } + PapyrusPalettePreferences.addWorkspaceExtendedPalette(paletteId, paletteId, pathWS, priority, PaletteUtils.getEditorIdValue(editorPart), new HashSet(paletteModel.getRequiredProfiles())); + + break; + + default: + break; + } + + + // toggle visibility to refresh the content + if (editorPart instanceof DiagramEditorWithFlyOutPalette) { + PapyrusPalettePreferences.changePaletteVisibility(paletteId, editorPart, false); + PapyrusPalettePreferences.changePaletteVisibility(paletteId, editorPart, true); + } + + } + + /** + * deploy element types models. + */ + protected void deployElementTypesModels() { + // deploy element types configuration files + if (!elementTypeSemResource.getContents().isEmpty() && !elementTypeUIResource.getContents().isEmpty()) { + ElementTypeSetConfigurationRegistry.getInstance().unload(getClientContext(), ((ElementTypeSetConfiguration) elementTypeSemResource.getContents().get(0)).getIdentifier()); + ElementTypeSetConfigurationRegistry.getInstance().unload(getClientContext(), ((ElementTypeSetConfiguration) elementTypeUIResource.getContents().get(0)).getIdentifier()); + + ElementTypeSetConfigurationRegistry.getInstance().loadElementTypeSetConfiguration(getClientContext(), ((ElementTypeSetConfiguration) elementTypeSemResource.getContents().get(0))); + ElementTypeSetConfigurationRegistry.getInstance().loadElementTypeSetConfiguration(getClientContext(), ((ElementTypeSetConfiguration) elementTypeUIResource.getContents().get(0))); + } + } + + + /** + * {@inheritDoc} + */ + @Override + protected void saveResources() { + // Get the palette model + PaletteConfiguration paletteModel = (PaletteConfiguration) paletteResource.getContents().get(0); + + // The palette id + String paletteId = paletteModel.getId(); + + // Save resources + + // Id is changed => needs to rename files + if (PaletteModelContextEnum.Local.equals(paletteContext) && !paletteId.equals(descriptor.getContributionID())) { + + // needs to change the file name for local extended palette model + String newPalettePath = paletteResource.getURI().toFileString().replace(descriptor.getContributionID(), paletteId); + paletteResource.setURI(URI.createFileURI(newPalettePath)); + + String newElementTypeUIResourcePath = elementTypeUIResource.getURI().toFileString().replace(descriptor.getContributionID(), paletteId); + elementTypeUIResource.setURI(URI.createFileURI(newElementTypeUIResourcePath)); + + String newElementTypeSemResourcePath = elementTypeSemResource.getURI().toFileString().replace(descriptor.getContributionID(), paletteId); + elementTypeSemResource.setURI(URI.createFileURI(newElementTypeSemResourcePath)); + + } else if (PaletteModelContextEnum.New.equals(paletteContext)) { + // set file names for new palette and element type + clearStringBuilder(); + stringBuilder.append(paletteId); + stringBuilder.append(STR_DOT); + stringBuilder.append(PaletteConstants.PALETTECONFIGURATION_EXTENSION); + String newPalettePath = paletteResource.getURI().toFileString().replace(paletteResource.getURI().lastSegment().replace("%20", " "), stringBuilder.toString());//$NON-NLS-1$ //$NON-NLS-2$ + paletteResource.setURI(URI.createFileURI(newPalettePath)); + + clearStringBuilder(); + stringBuilder.append(paletteId); + stringBuilder.append(PaletteConstants.ELEMENTTYPE_UI_IDENTIFIER_POSTFIX); + stringBuilder.append(STR_DOT); + stringBuilder.append(PaletteConstants.ELEMENTTYPE_EXTENSION); + String newElementTypeUIResourcePath = elementTypeUIResource.getURI().toFileString().replace(elementTypeUIResource.getURI().lastSegment().replace("%20", " "), stringBuilder.toString());//$NON-NLS-1$ //$NON-NLS-2$ + elementTypeUIResource.setURI(URI.createFileURI(newElementTypeUIResourcePath)); + + clearStringBuilder(); + stringBuilder.append(paletteId); + stringBuilder.append(PaletteConstants.ELEMENTTYPE_SEMENTIC_IDENTIFIER_POSTFIX); + stringBuilder.append(STR_DOT); + stringBuilder.append(PaletteConstants.ELEMENTTYPE_EXTENSION); + String newElementTypeSemResourcePath = elementTypeSemResource.getURI().toFileString().replace(elementTypeSemResource.getURI().lastSegment().replace("%20", " "), stringBuilder.toString());//$NON-NLS-1$ //$NON-NLS-2$ + elementTypeSemResource.setURI(URI.createFileURI(newElementTypeSemResourcePath)); + } + + // Save if necessary + try { + paletteResource.save(PaletteUtils.saveOptions); + // Checks if model are not void and are useful + if (!((ElementTypeSetConfiguration) elementTypeUIResource.getContents().get(0)).getElementTypeConfigurations().isEmpty()) { + elementTypeUIResource.save(PaletteUtils.saveOptions); + elementTypeSemResource.save(PaletteUtils.saveOptions); + } else { + ElementTypeSetConfigurationRegistry.getInstance().unload(getClientContext(), ((ElementTypeSetConfiguration) elementTypeSemResource.getContents().get(0)).getIdentifier()); + ElementTypeSetConfigurationRegistry.getInstance().unload(getClientContext(), ((ElementTypeSetConfiguration) elementTypeUIResource.getContents().get(0)).getIdentifier()); + elementTypeUIResource.delete(Collections.EMPTY_MAP); + elementTypeSemResource.delete(Collections.EMPTY_MAP); + } + } catch (IOException e) { + Activator.log.error(e); + } + } + + /** + * @return The client context of element types. + * + * TODO: switch it with point of you context if needed. + */ + protected String getClientContext() { + return "org.eclipse.papyrus.infra.services.edit.TypeContext";//$NON-NLS-1$ + } + + +} diff --git a/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/dialog/PaletteEntryProxyInformationComposite.java b/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/dialog/PaletteEntryProxyInformationComposite.java index 430cbe02779..dec022c7af3 100644 --- a/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/dialog/PaletteEntryProxyInformationComposite.java +++ b/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/dialog/PaletteEntryProxyInformationComposite.java @@ -1,349 +1,359 @@ -/*****************************************************************************
- * Copyright (c) 2010 CEA LIST.
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Remi Schnekenburger (CEA LIST) remi.schnekenburger@cea.fr - Initial API and implementation
- *****************************************************************************/
-package org.eclipse.papyrus.customization.palette.dialog;
-
-import java.util.List;
-
-import org.eclipse.emf.ecore.EClass;
-import org.eclipse.gef.palette.CombinedTemplateCreationEntry;
-import org.eclipse.gef.palette.PaletteEntry;
-import org.eclipse.jface.window.Window;
-import org.eclipse.papyrus.customization.palette.dialog.LocalPaletteContentPage.EntryType;
-import org.eclipse.papyrus.uml.diagram.common.Activator;
-import org.eclipse.papyrus.uml.diagram.common.Messages;
-import org.eclipse.papyrus.uml.diagram.common.part.PaletteUtil;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.FocusEvent;
-import org.eclipse.swt.events.FocusListener;
-import org.eclipse.swt.events.MouseEvent;
-import org.eclipse.swt.events.MouseListener;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Text;
-import org.eclipse.uml2.uml.Profile;
-
-
-/**
- * Class in charge of the composite in the {@link LocalPaletteContentPage}
- */
-public class PaletteEntryProxyInformationComposite {
-
- /** current selected entry proxy */
- protected PaletteEntryProxy selectedEntryProxy;
-
- /** proxy name text */
- protected Text nameText;
-
- /** proxy description text */
- protected Text descriptionText;
-
- /** proxy icon text */
- protected Text iconText;
-
- /** referenced proxy text */
- protected Text referencedText;
-
- /** list of applied profiles */
- protected List<Profile> appliedProfiles;
-
- protected Button iconButton;
-
- /**
- * Creates the content of the information composite
- *
- * @param parent
- * the composite where to add created controls
- * @param appliedProfiles
- * the list of applied profiles
- * @return the newly created composite
- */
- public Composite createComposite(final Composite parent, List<Profile> appliedProfiles) {
- this.appliedProfiles = appliedProfiles;
- Composite composite = new Composite(parent, SWT.NONE);
- GridLayout layout = new GridLayout(3, false);
- composite.setLayout(layout);
- GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
- data.widthHint = 260;
- data.horizontalIndent = 10;
- composite.setLayoutData(data);
-
- Label entryInformationLabel = new Label(composite, SWT.NONE);
- entryInformationLabel.setText(Messages.Local_Palette_Entry_Information);
- data = new GridData(SWT.FILL, SWT.FILL, true, false);
- data.horizontalSpan = 3;
- entryInformationLabel.setLayoutData(data);
-
- Label nameLabel = new Label(composite, SWT.NONE);
- nameLabel.setText(Messages.Local_Palette_Entry_Name);
- data = new GridData(SWT.FILL, SWT.FILL, false, false);
- nameLabel.setLayoutData(data);
- nameText = new Text(composite, SWT.LEAD | SWT.BORDER);
- data = new GridData(SWT.FILL, SWT.FILL, true, false);
- nameText.setLayoutData(data);
- nameText.addFocusListener(new NameFocusListener());
- data = new GridData(SWT.FILL, SWT.FILL, true, false);
- data.horizontalSpan = 2;
- nameText.setLayoutData(data);
-
- Label referencedLabel = new Label(composite, SWT.NONE);
- referencedLabel.setText(Messages.Local_Palette_Entry_Reference);
- data = new GridData(SWT.FILL, SWT.BEGINNING, true, false);
- referencedLabel.setLayoutData(data);
- referencedText = new Text(composite, SWT.LEAD | SWT.BORDER | SWT.READ_ONLY);
- data = new GridData(SWT.FILL, SWT.FILL, true, false);
- referencedText.setLayoutData(data);
- data = new GridData(SWT.FILL, SWT.FILL, true, false);
- data.horizontalSpan = 2;
- referencedText.setLayoutData(data);
-
- Label descriptionLabel = new Label(composite, SWT.NONE);
- descriptionLabel.setText(Messages.Local_Palette_Entry_Description);
- data = new GridData(SWT.FILL, SWT.BEGINNING, true, false);
- descriptionLabel.setLayoutData(data);
- descriptionText = new Text(composite, SWT.WRAP | SWT.BORDER);
- data = new GridData(SWT.FILL, SWT.FILL, true, true);
- data.horizontalSpan = 2;
- data.widthHint = 160;
- descriptionText.setLayoutData(data);
- descriptionText.addFocusListener(new DescriptionFocusListener());
-
-
- Label iconLabel = new Label(composite, SWT.NONE);
- iconLabel.setText(Messages.Local_Palette_Entry_Icon);
- data = new GridData(SWT.FILL, SWT.BEGINNING, true, false);
- iconLabel.setLayoutData(data);
- iconText = new Text(composite, SWT.LEAD | SWT.BORDER);
- data = new GridData(SWT.FILL, SWT.FILL, true, false);
- iconText.setLayoutData(data);
- iconText.addFocusListener(new IconFocusListener());
- iconButton = new Button(composite, SWT.NONE);
- iconButton.setText("Select...");
- iconButton.addMouseListener(new MouseListener() {
-
- /**
- * @{inheritDoc
- */
- public void mouseUp(MouseEvent e) {
- BundleIconExplorerDialog dialog = new BundleIconExplorerDialog(parent.getShell(), iconText.getText());
- if (Window.OK == dialog.open()) {
- Object[] values = dialog.getResult();
- if (values.length != 1) {
- Activator.log.error("Waiting one icon path, but found " + values.length, null);
- } else {
- iconText.setText(values[0].toString());
- selectedEntryProxy.getEntry().setSmallIcon(Activator.getImageDescriptor(iconText.getText().trim()));
- selectedEntryProxy.getEntry().setLargeIcon(Activator.getImageDescriptor(iconText.getText().trim()));
- if (selectedEntryProxy instanceof PaletteAspectToolEntryProxy) {
- ((PaletteAspectToolEntryProxy) selectedEntryProxy).setIcon(iconText.getText().trim());
- }
- }
- }
- }
-
- /**
- * @{inheritDoc
- */
- public void mouseDown(MouseEvent e) {
- }
-
- /**
- * @{inheritDoc
- */
- public void mouseDoubleClick(MouseEvent e) {
- }
- });
-
- return composite;
- }
-
- /**
- * Updates the name field in the information area
- */
- protected void updateNameEntryField() {
- EntryType type = selectedEntryProxy.getType();
- switch (type) {
- case STACK:
- case SEPARATOR:
- nameText.setText("");
- nameText.setEnabled(false);
- break;
- case DRAWER:
- case TOOL:
- case ASPECT_TOOL:
- // the fields describing information about entry should be updated
- String name = selectedEntryProxy.getLabel();
- nameText.setText((name != null) ? name : "");
- nameText.setEnabled(true);
- break;
- }
- }
-
- /**
- * Updates the reference field in the information area
- */
- protected void updateReferencedEntryField() {
- if (selectedEntryProxy instanceof PaletteAspectToolEntryProxy) {
- CombinedTemplateCreationEntry entry = ((PaletteAspectToolEntryProxy) selectedEntryProxy).getEntry().getReferencedEntry();
- EClass eClass = PaletteUtil.getToolMetaclass(entry);
- referencedText.setText((eClass != null) ? eClass.getInstanceTypeName() : "");
- } else if (selectedEntryProxy instanceof PaletteEntryProxy) {
- PaletteEntry entry = selectedEntryProxy.getEntry();
- if (entry instanceof CombinedTemplateCreationEntry) {
- EClass eClass = PaletteUtil.getToolMetaclass((CombinedTemplateCreationEntry) entry);
- referencedText.setText((eClass != null) ? eClass.getInstanceTypeName() : "");
- } else {
- referencedText.setText("");
- }
- } else {
- // should never happen
- referencedText.setText("");
- }
- }
-
- /**
- * Updates the description field in the information area
- */
- protected void updateDescriptionEntryField() {
- EntryType type = selectedEntryProxy.getType();
- switch (type) {
- case STACK:
- case SEPARATOR:
- case DRAWER:
- descriptionText.setText("");
- descriptionText.setEnabled(false);
- break;
- case TOOL:
- case ASPECT_TOOL:
- // the fields describing information about entry should be updated
- String name = selectedEntryProxy.getDescription();
- descriptionText.setText((name != null) ? name : "");
- descriptionText.setEnabled(true);
- break;
- }
- }
-
- /**
- * Updates the icon field in the information area
- */
- protected void updateIconEntryField() {
- EntryType type = selectedEntryProxy.getType();
- switch (type) {
- case STACK:
- case SEPARATOR:
- case TOOL:
- iconText.setText("");
- iconText.setEnabled(false);
- iconButton.setEnabled(false);
- break;
- case DRAWER:
- String drawerIcon = selectedEntryProxy.getImagePath();
- iconText.setText((drawerIcon != null) ? drawerIcon : "");
- iconText.setEnabled(false);
- iconButton.setEnabled(false);
- break;
- case ASPECT_TOOL:
- String icon = selectedEntryProxy.getImagePath();
- iconText.setText((icon != null) ? icon : "");
- iconText.setEnabled(true);
- iconButton.setEnabled(true);
- break;
- }
- }
-
-
- /**
- * Sets the new Selected entry
- *
- * @param selectedEntryProxy
- * the selectedEntryProxy to set
- */
- public void setSelectedEntryProxy(PaletteEntryProxy selectedEntryProxy) {
- this.selectedEntryProxy = selectedEntryProxy;
-
- updateNameEntryField();
- updateIconEntryField();
- updateReferencedEntryField();
- updateDescriptionEntryField();
- }
-
- /**
- * focus listener for the name text field
- */
- protected class NameFocusListener implements FocusListener {
-
- /**
- * @{inheritDoc
- */
- public void focusGained(FocusEvent e) {
- }
-
- /**
- * @{inheritDoc
- */
- public void focusLost(FocusEvent e) {
- if (selectedEntryProxy != null) {
- selectedEntryProxy.setLabel(nameText.getText().trim());
- }
- }
-
- }
-
- /**
- * focus listener for the name text field
- */
- protected class DescriptionFocusListener implements FocusListener {
-
- /**
- * @{inheritDoc
- */
- public void focusGained(FocusEvent e) {
- }
-
- /**
- * @{inheritDoc
- */
- public void focusLost(FocusEvent e) {
- if (selectedEntryProxy != null && selectedEntryProxy.getEntry() != null) {
- selectedEntryProxy.setDescription(descriptionText.getText().trim());
- }
- }
- }
-
- /**
- * focus listener for the name text field
- */
- protected class IconFocusListener implements FocusListener {
-
- /**
- * @{inheritDoc
- */
- public void focusGained(FocusEvent e) {
- }
-
- /**
- * @{inheritDoc
- */
- public void focusLost(FocusEvent e) {
- if (selectedEntryProxy != null && iconText.getText() != null && !iconText.getText().equals("")) {
- selectedEntryProxy.getEntry().setSmallIcon(Activator.getImageDescriptor(iconText.getText().trim()));
- selectedEntryProxy.getEntry().setLargeIcon(Activator.getImageDescriptor(iconText.getText().trim()));
- if (selectedEntryProxy instanceof PaletteAspectToolEntryProxy) {
- ((PaletteAspectToolEntryProxy) selectedEntryProxy).setIcon(iconText.getText().trim());
- }
- }
- }
- }
-
-}
+/***************************************************************************** + * Copyright (c) 2010 CEA LIST. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Remi Schnekenburger (CEA LIST) remi.schnekenburger@cea.fr - Initial API and implementation + *****************************************************************************/ +package org.eclipse.papyrus.customization.palette.dialog; + +import java.util.List; + +import org.eclipse.emf.ecore.EClass; +import org.eclipse.gef.palette.CombinedTemplateCreationEntry; +import org.eclipse.gef.palette.PaletteEntry; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.customization.palette.Messages; +import org.eclipse.papyrus.customization.palette.dialog.LocalPaletteContentPage.EntryType; +import org.eclipse.papyrus.infra.widgets.editors.BundleIconExplorerDialog; +import org.eclipse.papyrus.uml.diagram.common.Activator; +import org.eclipse.papyrus.uml.diagram.common.part.PaletteUtil; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.FocusEvent; +import org.eclipse.swt.events.FocusListener; +import org.eclipse.swt.events.MouseEvent; +import org.eclipse.swt.events.MouseListener; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Text; +import org.eclipse.uml2.uml.Profile; + + +/** + * Class in charge of the composite in the {@link LocalPaletteContentPage} + */ +public class PaletteEntryProxyInformationComposite { + + /** current selected entry proxy */ + protected PaletteEntryProxy selectedEntryProxy; + + /** proxy name text */ + protected Text nameText; + + /** proxy description text */ + protected Text descriptionText; + + /** proxy icon text */ + protected Text iconText; + + /** referenced proxy text */ + protected Text referencedText; + + /** list of applied profiles */ + protected List<Profile> appliedProfiles; + + protected Button iconButton; + + /** + * Creates the content of the information composite + * + * @param parent + * the composite where to add created controls + * @param appliedProfiles + * the list of applied profiles + * @return the newly created composite + */ + public Composite createComposite(final Composite parent, List<Profile> appliedProfiles) { + this.appliedProfiles = appliedProfiles; + Composite composite = new Composite(parent, SWT.NONE); + GridLayout layout = new GridLayout(3, false); + composite.setLayout(layout); + GridData data = new GridData(SWT.FILL, SWT.FILL, true, true); + data.widthHint = 260; + data.horizontalIndent = 10; + composite.setLayoutData(data); + + Label entryInformationLabel = new Label(composite, SWT.NONE); + entryInformationLabel.setText(Messages.Local_Palette_Entry_Information); + data = new GridData(SWT.FILL, SWT.FILL, true, false); + data.horizontalSpan = 3; + entryInformationLabel.setLayoutData(data); + + Label nameLabel = new Label(composite, SWT.NONE); + nameLabel.setText(Messages.Local_Palette_Entry_Name); + data = new GridData(SWT.FILL, SWT.FILL, false, false); + nameLabel.setLayoutData(data); + nameText = new Text(composite, SWT.LEAD | SWT.BORDER); + data = new GridData(SWT.FILL, SWT.FILL, true, false); + nameText.setLayoutData(data); + nameText.addFocusListener(new NameFocusListener()); + data = new GridData(SWT.FILL, SWT.FILL, true, false); + data.horizontalSpan = 2; + nameText.setLayoutData(data); + + Label referencedLabel = new Label(composite, SWT.NONE); + referencedLabel.setText(Messages.Local_Palette_Entry_Reference); + data = new GridData(SWT.FILL, SWT.BEGINNING, true, false); + referencedLabel.setLayoutData(data); + referencedText = new Text(composite, SWT.LEAD | SWT.BORDER | SWT.READ_ONLY); + data = new GridData(SWT.FILL, SWT.FILL, true, false); + referencedText.setLayoutData(data); + data = new GridData(SWT.FILL, SWT.FILL, true, false); + data.horizontalSpan = 2; + referencedText.setLayoutData(data); + + Label descriptionLabel = new Label(composite, SWT.NONE); + descriptionLabel.setText(Messages.Local_Palette_Entry_Description); + data = new GridData(SWT.FILL, SWT.BEGINNING, true, false); + descriptionLabel.setLayoutData(data); + descriptionText = new Text(composite, SWT.WRAP | SWT.BORDER); + data = new GridData(SWT.FILL, SWT.FILL, true, true); + data.horizontalSpan = 2; + data.widthHint = 160; + descriptionText.setLayoutData(data); + descriptionText.addFocusListener(new DescriptionFocusListener()); + + + Label iconLabel = new Label(composite, SWT.NONE); + iconLabel.setText(Messages.Local_Palette_Entry_Icon); + data = new GridData(SWT.FILL, SWT.BEGINNING, true, false); + iconLabel.setLayoutData(data); + iconText = new Text(composite, SWT.LEAD | SWT.BORDER); + data = new GridData(SWT.FILL, SWT.FILL, true, false); + iconText.setLayoutData(data); + iconText.addFocusListener(new IconFocusListener()); + iconButton = new Button(composite, SWT.NONE); + iconButton.setText("Select..."); + iconButton.addMouseListener(new MouseListener() { + + /** + * @{inheritDoc + */ + @Override + public void mouseUp(MouseEvent e) { + BundleIconExplorerDialog dialog = new BundleIconExplorerDialog(parent.getShell(), iconText.getText()); + if (Window.OK == dialog.open()) { + Object[] values = dialog.getResult(); + if (values.length != 1) { + Activator.log.error("Waiting one icon path, but found " + values.length, null); + } else { + iconText.setText(values[0].toString()); + selectedEntryProxy.getEntry().setSmallIcon(Activator.getImageDescriptor(iconText.getText().trim())); + selectedEntryProxy.getEntry().setLargeIcon(Activator.getImageDescriptor(iconText.getText().trim())); + if (selectedEntryProxy instanceof PaletteAspectToolEntryProxy) { + ((PaletteAspectToolEntryProxy) selectedEntryProxy).setIcon(iconText.getText().trim()); + } + } + } + } + + /** + * @{inheritDoc + */ + @Override + public void mouseDown(MouseEvent e) { + } + + /** + * @{inheritDoc + */ + @Override + public void mouseDoubleClick(MouseEvent e) { + } + }); + + return composite; + } + + /** + * Updates the name field in the information area + */ + protected void updateNameEntryField() { + EntryType type = selectedEntryProxy.getType(); + switch (type) { + case STACK: + case SEPARATOR: + nameText.setText(""); + nameText.setEnabled(false); + break; + case DRAWER: + case TOOL: + case ASPECT_TOOL: + // the fields describing information about entry should be updated + String name = selectedEntryProxy.getLabel(); + nameText.setText((name != null) ? name : ""); + nameText.setEnabled(true); + break; + } + } + + /** + * Updates the reference field in the information area + */ + protected void updateReferencedEntryField() { + if (selectedEntryProxy instanceof PaletteAspectToolEntryProxy) { + CombinedTemplateCreationEntry entry = ((PaletteAspectToolEntryProxy) selectedEntryProxy).getEntry().getReferencedEntry(); + EClass eClass = PaletteUtil.getToolMetaclass(entry); + referencedText.setText((eClass != null) ? eClass.getInstanceTypeName() : ""); + } else if (selectedEntryProxy instanceof PaletteEntryProxy) { + PaletteEntry entry = selectedEntryProxy.getEntry(); + if (entry instanceof CombinedTemplateCreationEntry) { + EClass eClass = PaletteUtil.getToolMetaclass((CombinedTemplateCreationEntry) entry); + referencedText.setText((eClass != null) ? eClass.getInstanceTypeName() : ""); + } else { + referencedText.setText(""); + } + } else { + // should never happen + referencedText.setText(""); + } + } + + /** + * Updates the description field in the information area + */ + protected void updateDescriptionEntryField() { + EntryType type = selectedEntryProxy.getType(); + switch (type) { + case STACK: + case SEPARATOR: + case DRAWER: + descriptionText.setText(""); + descriptionText.setEnabled(false); + break; + case TOOL: + case ASPECT_TOOL: + // the fields describing information about entry should be updated + String name = selectedEntryProxy.getDescription(); + descriptionText.setText((name != null) ? name : ""); + descriptionText.setEnabled(true); + break; + } + } + + /** + * Updates the icon field in the information area + */ + protected void updateIconEntryField() { + EntryType type = selectedEntryProxy.getType(); + switch (type) { + case STACK: + case SEPARATOR: + case TOOL: + iconText.setText(""); + iconText.setEnabled(false); + iconButton.setEnabled(false); + break; + case DRAWER: + String drawerIcon = selectedEntryProxy.getImagePath(); + iconText.setText((drawerIcon != null) ? drawerIcon : ""); + iconText.setEnabled(false); + iconButton.setEnabled(false); + break; + case ASPECT_TOOL: + String icon = selectedEntryProxy.getImagePath(); + iconText.setText((icon != null) ? icon : ""); + iconText.setEnabled(true); + iconButton.setEnabled(true); + break; + } + } + + + /** + * Sets the new Selected entry + * + * @param selectedEntryProxy + * the selectedEntryProxy to set + */ + public void setSelectedEntryProxy(PaletteEntryProxy selectedEntryProxy) { + this.selectedEntryProxy = selectedEntryProxy; + + updateNameEntryField(); + updateIconEntryField(); + updateReferencedEntryField(); + updateDescriptionEntryField(); + } + + /** + * focus listener for the name text field + */ + protected class NameFocusListener implements FocusListener { + + /** + * @{inheritDoc + */ + @Override + public void focusGained(FocusEvent e) { + } + + /** + * @{inheritDoc + */ + @Override + public void focusLost(FocusEvent e) { + if (selectedEntryProxy != null) { + selectedEntryProxy.setLabel(nameText.getText().trim()); + } + } + + } + + /** + * focus listener for the name text field + */ + protected class DescriptionFocusListener implements FocusListener { + + /** + * @{inheritDoc + */ + @Override + public void focusGained(FocusEvent e) { + } + + /** + * @{inheritDoc + */ + @Override + public void focusLost(FocusEvent e) { + if (selectedEntryProxy != null && selectedEntryProxy.getEntry() != null) { + selectedEntryProxy.setDescription(descriptionText.getText().trim()); + } + } + } + + /** + * focus listener for the name text field + */ + protected class IconFocusListener implements FocusListener { + + /** + * @{inheritDoc + */ + @Override + public void focusGained(FocusEvent e) { + } + + /** + * @{inheritDoc + */ + @Override + public void focusLost(FocusEvent e) { + if (selectedEntryProxy != null && iconText.getText() != null && !iconText.getText().equals("")) { + selectedEntryProxy.getEntry().setSmallIcon(Activator.getImageDescriptor(iconText.getText().trim())); + selectedEntryProxy.getEntry().setLargeIcon(Activator.getImageDescriptor(iconText.getText().trim())); + if (selectedEntryProxy instanceof PaletteAspectToolEntryProxy) { + ((PaletteAspectToolEntryProxy) selectedEntryProxy).setIcon(iconText.getText().trim()); + } + } + } + } + +} diff --git a/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/dialog/PapyrusPaletteCustomizerDialog.java b/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/dialog/PapyrusPaletteCustomizerDialog.java index df38078a3d6..7312b62192e 100644 --- a/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/dialog/PapyrusPaletteCustomizerDialog.java +++ b/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/dialog/PapyrusPaletteCustomizerDialog.java @@ -1,5 +1,5 @@ /***************************************************************************** - * Copyright (c) 2009 CEA LIST. + * Copyright (c) 2016 CEA LIST. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -9,6 +9,7 @@ * Contributors: * Remi Schnekenburger (CEA LIST) remi.schnekenburger@cea.fr - Initial API and implementation * Gabriel Pascual (ALL4TEC) gabriel.pascual@gmail.com - Bug 350134 + * Mickael ADAM (ALL4TEC) mickael.adam@all4tec.net - Bug 482669 * *****************************************************************************/ @@ -23,10 +24,9 @@ import org.eclipse.core.runtime.preferences.IEclipsePreferences; import org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener; import org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent; import org.eclipse.core.runtime.preferences.InstanceScope; -import org.eclipse.gef.palette.PaletteContainer; -import org.eclipse.gef.palette.PaletteEntry; import org.eclipse.gef.palette.PaletteRoot; import org.eclipse.gef.ui.palette.PaletteCustomizer; +import org.eclipse.gmf.runtime.common.core.service.IProvider; import org.eclipse.gmf.runtime.gef.ui.palette.customize.PaletteCustomizerDialogEx; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.dialogs.MessageDialog; @@ -43,21 +43,21 @@ import org.eclipse.jface.viewers.IStructuredContentProvider; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.SelectionChangedEvent; import org.eclipse.jface.viewers.TableViewer; -import org.eclipse.jface.viewers.TreeViewer; import org.eclipse.jface.viewers.Viewer; import org.eclipse.jface.wizard.WizardDialog; +import org.eclipse.papyrus.customization.palette.Messages; import org.eclipse.papyrus.infra.core.sasheditor.editor.ISashWindowsContainer; import org.eclipse.papyrus.uml.diagram.common.Activator; -import org.eclipse.papyrus.uml.diagram.common.Messages; -import org.eclipse.papyrus.uml.diagram.common.part.PaletteUtil; -import org.eclipse.papyrus.uml.diagram.common.part.PapyrusPaletteCustomizer; import org.eclipse.papyrus.uml.diagram.common.part.PapyrusPalettePreferences; +import org.eclipse.papyrus.uml.diagram.common.service.ExtendedPluginPaletteProvider; import org.eclipse.papyrus.uml.diagram.common.service.IPapyrusPaletteConstant; import org.eclipse.papyrus.uml.diagram.common.service.PapyrusPaletteService; import org.eclipse.papyrus.uml.diagram.common.service.PapyrusPaletteService.ExtendedProviderDescriptor; +import org.eclipse.papyrus.uml.diagram.common.service.PapyrusPaletteService.ProviderDescriptor; +import org.eclipse.papyrus.uml.diagram.common.service.PluginPaletteProvider; import org.eclipse.swt.SWT; +import org.eclipse.swt.events.MouseAdapter; import org.eclipse.swt.events.MouseEvent; -import org.eclipse.swt.events.MouseListener; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.graphics.Image; @@ -86,6 +86,9 @@ public class PapyrusPaletteCustomizerDialog extends PaletteCustomizerDialogEx im /** Id for restore button of extended customization palette. */ private static final int RESTORE_DEFAULT_PALETTE_BUTTON_ID = 23; + /** Id for restore button of extended customization palette. */ + private static final int EXPORT_DEFAULT_PALETTE_BUTTON_ID = 24; + /** Id for delete button of local palette. */ private static final int DELETE_PALETTE_BUTTON_ID = 22; @@ -95,28 +98,32 @@ public class PapyrusPaletteCustomizerDialog extends PaletteCustomizerDialogEx im /** Id for new button to create local palette. */ private static final int NEW_LOCAL_PALETTE_BUTTON_ID = 20; + /** Id for new button to create local extended palette. */ + private static final int NEW_EXTENDED_PALETTE_BUTTON_ID = 25; + /** new local palette icon */ - private static final String NEW_LOCAL_DESC_IMAGE = "/icons/local_desc_new.gif"; + private static final String NEW_LOCAL_DESC_IMAGE = "/icons/local_desc_new.gif"; //$NON-NLS-1$ /** delete palette icon */ - private static final String DELETE_LOCAL_DESC_IMAGE = "/icons/local_desc_destroy.gif"; + private static final String DELETE_LOCAL_DESC_IMAGE = "/icons/local_desc_destroy.gif"; //$NON-NLS-1$ /** edit palette icon */ - private static final String EDIT_LOCAL_DESC_IMAGE = "/icons/local_desc_edit.gif"; + private static final String EDIT_LOCAL_DESC_IMAGE = "/icons/local_desc_edit.gif"; //$NON-NLS-1$ + + /** restore palette icon */ + private static final String RESTORE_DEFAULT_DESC_IMAGE = "/icons/obj16/eraser.gif"; //$NON-NLS-1$ - private static final String RESTORE_DEFAULT_DESC_IMAGE = "/icons/obj16/eraser.gif"; + /** restore palette icon */ + private static final String EXPORT_DEFAULT_DESC_IMAGE = "/icons/obj16/Export.gif"; //$NON-NLS-1$ /** path to the local descriptor icon */ - protected final String LOCAL_DESCRIPTOR = "/icons/local_desc.gif"; + protected final String LOCAL_DESCRIPTOR = "/icons/local_desc.gif"; //$NON-NLS-1$ /** path to the plugin descriptor icon */ - protected final String PLUGIN_DESCRIPTOR = "/icons/plugin_desc.gif"; + protected final String PLUGIN_DESCRIPTOR = "/icons/plugin_desc.gif"; //$NON-NLS-1$ /** path to the plugin descriptor icon */ - protected final String EXTENDED_PLUGIN_DESCRIPTOR = "/icons/extended_plugin_desc.gif"; - - /** viewer for the available tools */ - protected TreeViewer availableToolsTreeViewer; + protected final String EXTENDED_PLUGIN_DESCRIPTOR = "/icons/extended_plugin_desc.gif"; //$NON-NLS-1$ /** table viewed by the availablePalettesTreeViewer */ protected Table availablePalettesTable; @@ -167,7 +174,7 @@ public class PapyrusPaletteCustomizerDialog extends PaletteCustomizerDialogEx im * {@inheritDoc} */ @Override - protected Control createDialogArea(Composite parent) { + protected Control createDialogArea(final Composite parent) { // RS: does not call super, as the composite should not be drawn like they are in parent Composite mainComposite = createMainComposite(parent); @@ -179,14 +186,6 @@ public class PapyrusPaletteCustomizerDialog extends PaletteCustomizerDialogEx im // data.right = new FormAttachment(40, 0); availableToolsComposite.setLayoutData(data); - // final Control displayButtons = createDisplayButtons(mainComposite); - // data = new FormData(); - // data.left = new FormAttachment(availableToolsComposite, 0); - // // data.width = 30; - // data.top = new FormAttachment(40, 0); - // data.bottom = new FormAttachment(100, 0); - // displayButtons.setLayoutData(data); - final Label nameLabel = new Label(mainComposite, SWT.NONE); nameLabel.setText(Messages.Palette_Viewer); data = new FormData(); @@ -221,94 +220,66 @@ public class PapyrusPaletteCustomizerDialog extends PaletteCustomizerDialogEx im return mainComposite; } + /** + * the selection changed listener to available tools, which update buttons status + * + * @return the listener + */ protected ISelectionChangedListener createSelectionChangedListener() { return new ISelectionChangedListener() { /** * {@inheritDoc} */ - public void selectionChanged(SelectionChangedEvent event) { + @Override + public void selectionChanged(final SelectionChangedEvent event) { // retrieve element selected Object selectedElement = ((IStructuredSelection) event.getSelection()).getFirstElement(); + // Plug-in contribution palette if (selectedElement instanceof PapyrusPaletteService.ExtendedProviderDescriptor) { - paletteButtonsMap.get(DELETE_PALETTE_BUTTON_ID).setEnabled(false); + IProvider provider = ((PapyrusPaletteService.ExtendedProviderDescriptor) selectedElement).getProvider(); + + // xml definition of palette + if (provider instanceof PluginPaletteProvider) { + paletteButtonsMap.get(DELETE_PALETTE_BUTTON_ID).setEnabled(false); + paletteButtonsMap.get(EDIT_PALETTE_BUTTON_ID).setEnabled(false); + paletteButtonsMap.get(RESTORE_DEFAULT_PALETTE_BUTTON_ID).setEnabled(false); + paletteButtonsMap.get(EXPORT_DEFAULT_PALETTE_BUTTON_ID).setEnabled(false); + } else + // Modelconfiguration model definition + if (provider instanceof ExtendedPluginPaletteProvider) { + paletteButtonsMap.get(DELETE_PALETTE_BUTTON_ID).setEnabled(false); + paletteButtonsMap.get(EDIT_PALETTE_BUTTON_ID).setEnabled(true); + paletteButtonsMap.get(RESTORE_DEFAULT_PALETTE_BUTTON_ID).setEnabled(isRedefined((ExtendedProviderDescriptor) selectedElement)); + paletteButtonsMap.get(EXPORT_DEFAULT_PALETTE_BUTTON_ID).setEnabled(true); + } + + } else + // Local Palette configuration model + if (selectedElement instanceof PapyrusPaletteService.LocalExtendedProviderDescriptor) { + paletteButtonsMap.get(DELETE_PALETTE_BUTTON_ID).setEnabled(true); paletteButtonsMap.get(EDIT_PALETTE_BUTTON_ID).setEnabled(true); - paletteButtonsMap.get(RESTORE_DEFAULT_PALETTE_BUTTON_ID).setEnabled(true); - } else if (selectedElement instanceof PapyrusPaletteService.LocalProviderDescriptor) { + paletteButtonsMap.get(RESTORE_DEFAULT_PALETTE_BUTTON_ID).setEnabled(false); + paletteButtonsMap.get(EXPORT_DEFAULT_PALETTE_BUTTON_ID).setEnabled(true); + } else + // Local XML Palette + if (selectedElement instanceof PapyrusPaletteService.LocalProviderDescriptor) { paletteButtonsMap.get(DELETE_PALETTE_BUTTON_ID).setEnabled(true); paletteButtonsMap.get(EDIT_PALETTE_BUTTON_ID).setEnabled(true); paletteButtonsMap.get(RESTORE_DEFAULT_PALETTE_BUTTON_ID).setEnabled(false); + paletteButtonsMap.get(EXPORT_DEFAULT_PALETTE_BUTTON_ID).setEnabled(false); } else { paletteButtonsMap.get(DELETE_PALETTE_BUTTON_ID).setEnabled(false); paletteButtonsMap.get(EDIT_PALETTE_BUTTON_ID).setEnabled(false); paletteButtonsMap.get(RESTORE_DEFAULT_PALETTE_BUTTON_ID).setEnabled(false); + paletteButtonsMap.get(EXPORT_DEFAULT_PALETTE_BUTTON_ID).setEnabled(false); } - // if(selectedElement instanceof PapyrusPaletteService.LocalProviderDescriptor) { - // deletePaletteButton.setEnabled(true); - // // check if the palette is in good configuration to be edited... - // if(PaletteUtil.areRequiredProfileApplied(getActiveSashPage(), (PapyrusPaletteService.LocalProviderDescriptor)selectedElement)) { - // editPaletteButton.setEnabled(true); - // editPaletteButton.setToolTipText(Messages.PapyrusPaletteCustomizerDialog_EditButtonTooltip_LocalPaletteSelected); - // } else { - // editPaletteButton.setEnabled(false); - // editPaletteButton.setToolTipText(Messages.PapyrusPaletteCustomizerDialog_EditButtonTooltip_MissingProfile); - // } - // } else { - // deletePaletteButton.setEnabled(false); - // editPaletteButton.setEnabled(false); - // editPaletteButton.setToolTipText(Messages.PapyrusPaletteCustomizerDialog_EditButtonTooltip_LocalPaletteNotSelected); - // } } }; } - protected void addEntry(MouseEvent e) { - ISelection selection = availableToolsTreeViewer.getSelection(); - PaletteEntry entry = null; - if (selection instanceof IStructuredSelection) { - Object firstElement = ((IStructuredSelection) selection).getFirstElement(); - if (!(firstElement instanceof PaletteEntry)) { - return; - } else { - entry = ((PaletteEntry) firstElement); - } - } - // sets the active entry, to have the page useful for saving modification - setActiveEntry(entry); - // add entry to the selected container - // retrieve the selection in the palette viewer - PaletteEntry destContainer = getSelectedPaletteEntry(); - ((PapyrusPaletteCustomizer) getCustomizer()).storePaletteState(entry); - if (destContainer instanceof PaletteContainer) { - PaletteContainer oldParent = entry.getParent(); - - // checks if the parent is already changed. If not, must store the standard parent (the - // one given by the factory) - PaletteContainer stdParent = ((PapyrusPaletteCustomizer) getCustomizer()).getChangedParents().get(entry); - if (stdParent == null) { - ((PapyrusPaletteCustomizer) getCustomizer()).getChangedParents().put(entry, entry.getParent()); - } - oldParent.remove(entry); - entry.setParent((PaletteContainer) destContainer); - ((PaletteContainer) destContainer).add(entry); - } else { - // add it to the palette root - PaletteRoot root = (PaletteRoot) PaletteUtil.getRoot(entry); - if (root != null) { - PaletteContainer oldParent = entry.getParent(); - PaletteContainer stdParent = ((PapyrusPaletteCustomizer) getCustomizer()).getChangedParents().get(entry); - if (stdParent == null) { - ((PapyrusPaletteCustomizer) getCustomizer()).getChangedParents().put(entry, stdParent); - } - oldParent.remove(entry); - entry.setParent(root); - root.add(entry); - } - } - } - /** * Creates the available palettes viewer part of the dialog. * @@ -316,11 +287,11 @@ public class PapyrusPaletteCustomizerDialog extends PaletteCustomizerDialogEx im * The Composite within which the viewer has to be created * @return The newly created Control that has the viewer */ - protected Control createAvailablePalettesViewer(Composite container) { + protected Control createAvailablePalettesViewer(final Composite container) { // Create the Composite that will contain the available tools Composite composite = new Composite(container, SWT.NONE); composite.setFont(container.getFont()); - GridLayout layout = new GridLayout(5, false); + GridLayout layout = new GridLayout(6, false); layout.horizontalSpacing = 0; layout.verticalSpacing = 0; layout.marginHeight = 0; @@ -333,10 +304,17 @@ public class PapyrusPaletteCustomizerDialog extends PaletteCustomizerDialogEx im nameLabel.setLayoutData(data); // Create action buttons - createEditionPaletteButton(composite, NEW_LOCAL_PALETTE_BUTTON_ID, Activator.getImage(NEW_LOCAL_DESC_IMAGE), Messages.Dialog_Create_Palette_Tooltip); + createEditionPaletteButton(composite, NEW_EXTENDED_PALETTE_BUTTON_ID, Activator.getImage(NEW_LOCAL_DESC_IMAGE), Messages.Dialog_Create_Palette_Tooltip); createEditionPaletteButton(composite, EDIT_PALETTE_BUTTON_ID, Activator.getImage(EDIT_LOCAL_DESC_IMAGE), Messages.Dialog_Edit_Palette_Tooltip); createEditionPaletteButton(composite, DELETE_PALETTE_BUTTON_ID, Activator.getImage(DELETE_LOCAL_DESC_IMAGE), Messages.Dialog_Delete_Palette_Tooltip); createEditionPaletteButton(composite, RESTORE_DEFAULT_PALETTE_BUTTON_ID, Activator.getImage(RESTORE_DEFAULT_DESC_IMAGE), Messages.Dialog_Restore_Palette_Tooltip); + createEditionPaletteButton(composite, EXPORT_DEFAULT_PALETTE_BUTTON_ID, Activator.getImage(EXPORT_DEFAULT_DESC_IMAGE), Messages.Dialog_Export_Palette_Tooltip); + + // initialize it + paletteButtonsMap.get(DELETE_PALETTE_BUTTON_ID).setEnabled(false); + paletteButtonsMap.get(EDIT_PALETTE_BUTTON_ID).setEnabled(false); + paletteButtonsMap.get(RESTORE_DEFAULT_PALETTE_BUTTON_ID).setEnabled(false); + paletteButtonsMap.get(EXPORT_DEFAULT_PALETTE_BUTTON_ID).setEnabled(false); availablePalettesTable = new Table(composite, SWT.BORDER | SWT.CHECK); availablePalettesTable.setFont(composite.getFont()); @@ -345,7 +323,8 @@ public class PapyrusPaletteCustomizerDialog extends PaletteCustomizerDialogEx im /** * {@inheritDoc} */ - public void widgetSelected(SelectionEvent e) { + @Override + public void widgetSelected(final SelectionEvent e) { if (e.detail == SWT.CHECK) { TableItem item = (TableItem) e.item; // one item was checked => display/hide the given provider @@ -356,12 +335,13 @@ public class PapyrusPaletteCustomizerDialog extends PaletteCustomizerDialogEx im /** * {@inheritDoc} */ - public void widgetDefaultSelected(SelectionEvent e) { + @Override + public void widgetDefaultSelected(final SelectionEvent e) { // does nothing } }); data = new GridData(GridData.FILL_VERTICAL | GridData.HORIZONTAL_ALIGN_FILL); - data.horizontalSpan = 5; + data.horizontalSpan = 6; data.widthHint = 185; // Make the tree this tall even when there is nothing in it. This will keep the // dialog from shrinking to an unusually small size. @@ -376,6 +356,7 @@ public class PapyrusPaletteCustomizerDialog extends PaletteCustomizerDialogEx im availablePalettesTableViewer.setInput(PapyrusPaletteService.getInstance()); availablePalettesTableViewer.addDoubleClickListener(new IDoubleClickListener() { + @Override public void doubleClick(DoubleClickEvent event) { // get selection. if local palette: open the wizard to edit this local palette IStructuredSelection selection = (IStructuredSelection) event.getSelection(); @@ -390,28 +371,24 @@ public class PapyrusPaletteCustomizerDialog extends PaletteCustomizerDialogEx im * Create button to edit palette in table. * * @param parentConposite - * @return + * @return the edition button */ - protected Button createEditionPaletteButton(Composite parentConposite, int id, Image icon, String toolTip) { + protected Button createEditionPaletteButton(final Composite parentConposite, final int id, final Image icon, final String toolTip) { Button button = new Button(parentConposite, SWT.NONE); button.setData(new Integer(id)); button.setImage(icon); button.setToolTipText(toolTip); - button.addMouseListener(new MouseListener() { - - public void mouseDoubleClick(MouseEvent e) { - // Nothing to do - - } + button.addMouseListener(new MouseAdapter() { - public void mouseDown(MouseEvent e) { - // Nothing to do - - } - - public void mouseUp(MouseEvent e) { - buttonPressed(((Integer) e.widget.getData()).intValue()); + @Override + public void mouseUp(final MouseEvent e) { + int buttonId = ((Integer) e.widget.getData()).intValue(); + // If ctrl is pressed use the old editor + if (NEW_EXTENDED_PALETTE_BUTTON_ID == buttonId && (SWT.CTRL == (SWT.CTRL & e.stateMask))) { + buttonId = NEW_LOCAL_PALETTE_BUTTON_ID; + } + buttonPressed(buttonId); } }); @@ -423,37 +400,86 @@ public class PapyrusPaletteCustomizerDialog extends PaletteCustomizerDialogEx im } /** - * @see org.eclipse.gef.ui.palette.customize.PaletteCustomizerDialog#buttonPressed(int) - * - * @param buttonId + * {@inheritDoc} + * + * @param */ @Override - protected void buttonPressed(int buttonId) { + protected void buttonPressed(final int buttonId) { if (paletteButtonsMap.containsKey(buttonId)) { switch (buttonId) { - case NEW_LOCAL_PALETTE_BUTTON_ID: - createNewLocalPalette(); + case NEW_EXTENDED_PALETTE_BUTTON_ID: + createPaletteConfigurationPalette(); break; - case EDIT_PALETTE_BUTTON_ID: + case EDIT_PALETTE_BUTTON_ID: { IStructuredSelection selection = getPalettesTableSelection(); editSelectedPalette(selection); + } break; - case DELETE_PALETTE_BUTTON_ID: - deleteLocalPalette(); + case DELETE_PALETTE_BUTTON_ID: { + IStructuredSelection selection = getPalettesTableSelection(); + deleteSelectedPalette(selection); + } break; case RESTORE_DEFAULT_PALETTE_BUTTON_ID: restoreExtendedPaletteToDefault(); break; + + case EXPORT_DEFAULT_PALETTE_BUTTON_ID: { + IStructuredSelection selection = getPalettesTableSelection(); + exportSelectedPalette(selection); + } + break; default: break; } + } else if (NEW_LOCAL_PALETTE_BUTTON_ID == buttonId) { + createNewLocalPalette(); } else { super.buttonPressed(buttonId); } } /** + * Open wizard to export palette configuration model file to the wanted location + * + * @param selection + * the selected palette + */ + protected void exportSelectedPalette(final IStructuredSelection selection) { + /* + * Two palettes type to export: + * - ExtendedProviderDescriptor : plug-in definition : needs to create local file if not exist + * - LocalExtendedProviderDescriptor : local definition + */ + + Object firstElement = selection.getFirstElement(); + if (firstElement instanceof PapyrusPaletteService.ExtendedProviderDescriptor) { + + if (!isRedefined((ExtendedProviderDescriptor) firstElement)) { + // create a local redefinition of this palette contribution + PapyrusPalettePreferences.createPaletteRedefinition((ExtendedProviderDescriptor) firstElement); + } + exportPalette((PapyrusPaletteService.ProviderDescriptor) firstElement); + + } else if (firstElement instanceof PapyrusPaletteService.LocalExtendedProviderDescriptor) { + exportPalette((PapyrusPaletteService.ProviderDescriptor) firstElement); + } + } + + /** + * export the palette corresponding to the descriptor. The ressource have to exist. + * + * @param descriptor + */ + protected void exportPalette(final PapyrusPaletteService.ProviderDescriptor descriptor) { + ExportPaletteConfigurationWizard wizard = new ExportPaletteConfigurationWizard(getActiveSashPage(), descriptor); + WizardDialog wizardDialog = new WizardDialog(new Shell(), wizard); + wizardDialog.open(); + } + + /** * Get selection in palettes table viewer. * * @return The {@link IStructuredSelection} if there is one, otherwise <code>null</code> @@ -466,8 +492,6 @@ public class PapyrusPaletteCustomizerDialog extends PaletteCustomizerDialogEx im structuredSelection = (IStructuredSelection) selection; } } - - return structuredSelection; } @@ -477,7 +501,7 @@ public class PapyrusPaletteCustomizerDialog extends PaletteCustomizerDialogEx im * @param button */ @Override - protected void setButtonLayoutData(Button button) { + protected void setButtonLayoutData(final Button button) { if (paletteButtonsMap.containsValue(button)) { GridData data = new GridData(SWT.CENTER, SWT.CENTER, false, false); button.setLayoutData(data); @@ -493,6 +517,7 @@ public class PapyrusPaletteCustomizerDialog extends PaletteCustomizerDialogEx im * @param shell * the shell where to display the wizard */ + @Deprecated protected void createNewLocalPalette() { NewLocalPaletteWizard wizard = new NewLocalPaletteWizard(getActiveSashPage(), getCustomizer()); WizardDialog wizardDialog = new WizardDialog(new Shell(), wizard); @@ -500,33 +525,91 @@ public class PapyrusPaletteCustomizerDialog extends PaletteCustomizerDialogEx im } /** + * Launch the wizard for the palette creation + * + * @param shell + * the shell where to display the wizard + */ + protected void createPaletteConfigurationPalette() { + PaletteConfigurationWizard wizard = new PaletteConfigurationWizard(getActiveSashPage()); + WizardDialog wizardDialog = new WizardDialog(new Shell(), wizard); + wizardDialog.open(); + } + + /** * Deletes the current selected local palette */ - protected void deleteLocalPalette() { - IStructuredSelection selection = (IStructuredSelection) availablePalettesTableViewer.getSelection(); - if (selection == null || !(selection.getFirstElement() instanceof PapyrusPaletteService.LocalProviderDescriptor)) { + protected void deleteLocalPalette(final PapyrusPaletteService.LocalProviderDescriptor descriptor) { + if (null == descriptor) { MessageDialog.openError(getShell(), Messages.Dialog_Not_Local_Palette_Title, Messages.Dialog_Not_Local_Palette_Message); } else { - PapyrusPaletteService.LocalProviderDescriptor descriptor = ((PapyrusPaletteService.LocalProviderDescriptor) selection.getFirstElement()); String id = descriptor.getContributionID(); PapyrusPalettePreferences.deleteLocalPalette(id); } } /** - * Reset the current selected extended palette to the initial configurtion in the plugin + * Deletes the current selected local extended palette + */ + protected void deleteLocalExtendedPalette(final PapyrusPaletteService.LocalExtendedProviderDescriptor descriptor) { + if (null == descriptor) { + MessageDialog.openError(getShell(), Messages.Dialog_Not_Local_Palette_Title, Messages.Dialog_Not_Local_Palette_Message); + } else { + String id = descriptor.getContributionID(); + deleteAssociatedRessource(descriptor); + PapyrusPalettePreferences.deleteLocalExtendedPalette(id); + } + } + + /** + * Deletes the current selected local palette + */ + protected void deleteWorkspaceExtendedPalette(final PapyrusPaletteService.LocalProviderDescriptor descriptor) { + if (null == descriptor) { + MessageDialog.openError(getShell(), Messages.Dialog_Not_Extended_Palette_Title, Messages.Dialog_Not_Extended_Palette_Message); + } else { + String id = descriptor.getContributionID(); + PapyrusPalettePreferences.deleteWorkspaceExtendedPalette(id); + } + } + + /** + * Reset the current selected extended palette to the initial configuration in the plugin */ protected void restoreExtendedPaletteToDefault() { IStructuredSelection selection = (IStructuredSelection) availablePalettesTableViewer.getSelection(); - if (selection == null || !(selection.getFirstElement() instanceof PapyrusPaletteService.ExtendedProviderDescriptor)) { + if (null == selection || !(selection.getFirstElement() instanceof PapyrusPaletteService.ExtendedProviderDescriptor)) { MessageDialog.openError(getShell(), Messages.Dialog_Not_Extended_Palette_Title, Messages.Dialog_Not_Extended_Palette_Message); } else { PapyrusPaletteService.ExtendedProviderDescriptor descriptor = ((PapyrusPaletteService.ExtendedProviderDescriptor) selection.getFirstElement()); String id = descriptor.getContributionID(); + + deleteAssociatedRessource(descriptor); + PapyrusPalettePreferences.unregisterLocalRedefinition(id); + + // Refresh element on Palette preview only if is checked + if (availablePalettesTableViewer.getChecked(descriptor)) { + // toggle visibility to refresh the content + changeProviderVisibility(descriptor, false); + changeProviderVisibility(descriptor, true); + } } } + + /** + * Delete associated resource and unloads models. + * + * @param descriptor + * + */ + protected void deleteAssociatedRessource(ProviderDescriptor descriptor) { + PaletteConfigurationWizard wizard = new PaletteConfigurationWizard(getActiveSashPage(), descriptor); + wizard.deleteResource(); + wizard.dispose(); + } + /** * Method to launch edition dialog according to selection. * @@ -534,42 +617,89 @@ public class PapyrusPaletteCustomizerDialog extends PaletteCustomizerDialogEx im * Selection which determine kind of edition */ protected void editSelectedPalette(IStructuredSelection selection) { - if (selection != null) { - if ((selection.getFirstElement() instanceof PapyrusPaletteService.LocalProviderDescriptor)) { + if (null != selection) { + if (selection.getFirstElement() instanceof PapyrusPaletteService.WorkspaceExtendedProviderDescriptor || selection.getFirstElement() instanceof PapyrusPaletteService.LocalExtendedProviderDescriptor) { + editPaletteConfiguration((ProviderDescriptor) selection.getFirstElement()); + } else if (selection.getFirstElement() instanceof PapyrusPaletteService.LocalProviderDescriptor) { editLocalPalette((PapyrusPaletteService.LocalProviderDescriptor) selection.getFirstElement()); } else if (selection.getFirstElement() instanceof PapyrusPaletteService.ExtendedProviderDescriptor) { - editExtendedPalette((PapyrusPaletteService.ExtendedProviderDescriptor) selection.getFirstElement()); + IProvider provider = ((PapyrusPaletteService.ExtendedProviderDescriptor) selection.getFirstElement()).getProvider(); + if (!(provider instanceof PluginPaletteProvider)) { + editExtendedPalette((PapyrusPaletteService.ExtendedProviderDescriptor) selection.getFirstElement()); + } } } + } + + /** + * Method to delete palette according to selection. + * + * @param selection + * Selection which determine kind of delectino + */ + protected void deleteSelectedPalette(final IStructuredSelection selection) { + if (null != selection) { + if (selection.getFirstElement() instanceof PapyrusPaletteService.WorkspaceExtendedProviderDescriptor) { + deleteWorkspaceExtendedPalette((PapyrusPaletteService.LocalProviderDescriptor) selection.getFirstElement()); + } else if (selection.getFirstElement() instanceof PapyrusPaletteService.LocalExtendedProviderDescriptor) { + deleteLocalExtendedPalette((PapyrusPaletteService.LocalExtendedProviderDescriptor) selection.getFirstElement()); + } else if ((selection.getFirstElement() instanceof PapyrusPaletteService.LocalProviderDescriptor)) { + deleteLocalPalette((PapyrusPaletteService.LocalProviderDescriptor) selection.getFirstElement()); + } + availablePalettesTableViewer.refresh(); + } + } + /** + * Open wizard to edit palette configuration model. + * + * @param descriptor + * the provider descriptor of the palette + */ + protected void editPaletteConfiguration(final ProviderDescriptor descriptor) { + PaletteConfigurationWizard wizard = new PaletteConfigurationWizard(getActiveSashPage(), descriptor); + WizardDialog wizardDialog = new WizardDialog(new Shell(), wizard); + wizardDialog.open(); } /** * Edits the current selected local palette + * + * @param descriptor + * the provider descriptor of the palette */ - protected void editLocalPalette(PapyrusPaletteService.LocalProviderDescriptor descriptor) { + protected void editLocalPalette(final PapyrusPaletteService.LocalProviderDescriptor descriptor) { UpdateLocalPaletteWizard wizard = new UpdateLocalPaletteWizard(getActiveSashPage(), descriptor, getCustomizer()); WizardDialog wizardDialog = new WizardDialog(new Shell(), wizard); wizardDialog.open(); } /** - * @param firstElement + * Open wizard to edit palette configuration model for a read-only palette. + * + * @param descriptor + * the provider descriptor of the palette */ - protected void editExtendedPalette(ExtendedProviderDescriptor descriptor) { - // check the file in plugin state area. - String contributionID = descriptor.getContributionID(); - String paletteRedefinition = PapyrusPalettePreferences.getPaletteRedefinition(contributionID); - - if (paletteRedefinition == null) { + protected void editExtendedPalette(final ExtendedProviderDescriptor descriptor) { + if (!isRedefined(descriptor)) { // create a local redefinition of this palette contribution PapyrusPalettePreferences.createPaletteRedefinition(descriptor); } + editPaletteConfiguration(descriptor); + } - - UpdateExtendedPaletteWizard wizard = new UpdateExtendedPaletteWizard(getActiveSashPage(), descriptor, getCustomizer()); - WizardDialog wizardDialog = new WizardDialog(new Shell(), wizard); - wizardDialog.open(); + /** + * Test if a palette redefinition exist for the descriptor. + * + * @param descriptor + * the exttended provider desciptor to test + * @return true if redefined + */ + public Boolean isRedefined(final ExtendedProviderDescriptor descriptor) { + // check the file in plugin state area. + String contributionID = descriptor.getContributionID(); + String paletteRedefinition = PapyrusPalettePreferences.getPaletteRedefinition(contributionID); + return null != paletteRedefinition; } @@ -581,7 +711,7 @@ public class PapyrusPaletteCustomizerDialog extends PaletteCustomizerDialogEx im * @param isChecked * <code>true</code> if the descriptor should be visible */ - protected void changeProviderVisibility(PapyrusPaletteService.ProviderDescriptor descriptor, boolean isChecked) { + protected void changeProviderVisibility(final PapyrusPaletteService.ProviderDescriptor descriptor, final boolean isChecked) { PapyrusPalettePreferences.changePaletteVisibility(descriptor.getContributionID(), getActiveSashPage().getClass().getName(), isChecked); } @@ -592,7 +722,7 @@ public class PapyrusPaletteCustomizerDialog extends PaletteCustomizerDialogEx im * the parent of the createrd composite * @return the newly created Composite */ - protected Composite createMainComposite(Composite parent) { + protected Composite createMainComposite(final Composite parent) { // dialog window // create a composite with standard margins and spacing Composite composite = new Composite(parent, SWT.NONE); @@ -622,13 +752,14 @@ public class PapyrusPaletteCustomizerDialog extends PaletteCustomizerDialogEx im * @param tableViewer * The TableViewer whose ContentProvider this PaletteTreeProvider is */ - public PalettesTableContentProvider(TableViewer tableViewer) { + public PalettesTableContentProvider(final TableViewer tableViewer) { this.viewer = tableViewer; } /** * {@inheritDoc} */ + @Override public void dispose() { paletteService = null; } @@ -636,7 +767,8 @@ public class PapyrusPaletteCustomizerDialog extends PaletteCustomizerDialogEx im /** * {@inheritDoc} */ - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + @Override + public void inputChanged(final Viewer viewer, final Object oldInput, final Object newInput) { if (newInput != null) { paletteService = (PapyrusPaletteService) newInput; } @@ -645,7 +777,8 @@ public class PapyrusPaletteCustomizerDialog extends PaletteCustomizerDialogEx im /** * {@inheritDoc} */ - public Object[] getElements(Object inputElement) { + @Override + public Object[] getElements(final Object inputElement) { if (inputElement instanceof PapyrusPaletteService) { List<PapyrusPaletteService.ProviderDescriptor> providers = ((PapyrusPaletteService) inputElement).getContributingProviders(getActiveSashPage(), getPaletteRoot()); @@ -665,7 +798,7 @@ public class PapyrusPaletteCustomizerDialog extends PaletteCustomizerDialogEx im IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); IEditorPart editorPart = page.getActiveEditor(); assert editorPart != null; - ISashWindowsContainer sashWindowsContainer = (ISashWindowsContainer) editorPart.getAdapter(ISashWindowsContainer.class); + ISashWindowsContainer sashWindowsContainer = editorPart.getAdapter(ISashWindowsContainer.class); if (sashWindowsContainer != null) { return sashWindowsContainer.getActiveEditor(); } @@ -680,17 +813,20 @@ public class PapyrusPaletteCustomizerDialog extends PaletteCustomizerDialogEx im /** * {@inheritDoc} */ - public boolean isChecked(Object element) { + @Override + public boolean isChecked(final Object element) { + boolean checked = false; if (element instanceof PapyrusPaletteService.ProviderDescriptor) { - return !PapyrusPalettePreferences.getHiddenPalettes(getActiveSashPage()).contains(((PapyrusPaletteService.ProviderDescriptor) element).getContributionID()); + checked = !PapyrusPalettePreferences.getHiddenPalettes(getActiveSashPage()).contains(((PapyrusPaletteService.ProviderDescriptor) element).getContributionID()); } - return false; + return checked; } /** * {@inheritDoc} */ - public boolean isGrayed(Object element) { + @Override + public boolean isGrayed(final Object element) { return false; } @@ -707,7 +843,7 @@ public class PapyrusPaletteCustomizerDialog extends PaletteCustomizerDialogEx im * @param viewer * the table viewer where the labels are displayed */ - public PaletteLabelProvider(TableViewer viewer) { + public PaletteLabelProvider(final TableViewer viewer) { } private Map<ImageDescriptor, Image> imageCache = new HashMap<ImageDescriptor, Image>(); @@ -715,7 +851,8 @@ public class PapyrusPaletteCustomizerDialog extends PaletteCustomizerDialogEx im /** * {@inheritDoc} */ - public Image getImage(Object element) { + @Override + public Image getImage(final Object element) { if (element instanceof PapyrusPaletteService.LocalProviderDescriptor) { return Activator.getImage(LOCAL_DESCRIPTOR); } else if (element instanceof PapyrusPaletteService.ExtendedProviderDescriptor) { @@ -730,22 +867,26 @@ public class PapyrusPaletteCustomizerDialog extends PaletteCustomizerDialogEx im /** * {@inheritDoc} */ - public String getText(Object element) { + @Override + public String getText(final Object element) { + String text = null; if (element instanceof PapyrusPaletteService.ProviderDescriptor) { - return ((PapyrusPaletteService.ProviderDescriptor) element).getContributionName(); + text = ((PapyrusPaletteService.ProviderDescriptor) element).getContributionName(); } - return "<undefined>"; + return null != text ? text : "<undefined>";//$NON-NLS-1$ } /** * {@inheritDoc} */ - public void addListener(ILabelProviderListener listener) { + @Override + public void addListener(final ILabelProviderListener listener) { } /** * {@inheritDoc} */ + @Override public void dispose() { Iterator<Image> images = imageCache.values().iterator(); while (images.hasNext()) { @@ -757,14 +898,16 @@ public class PapyrusPaletteCustomizerDialog extends PaletteCustomizerDialogEx im /** * {@inheritDoc} */ - public boolean isLabelProperty(Object element, String property) { + @Override + public boolean isLabelProperty(final Object element, final String property) { return false; } /** * {@inheritDoc} */ - public void removeListener(ILabelProviderListener listener) { + @Override + public void removeListener(final ILabelProviderListener listener) { } } @@ -772,7 +915,8 @@ public class PapyrusPaletteCustomizerDialog extends PaletteCustomizerDialogEx im /** * {@inheritDoc} */ - public void preferenceChange(PreferenceChangeEvent event) { + @Override + public void preferenceChange(final PreferenceChangeEvent event) { String id = event.getKey(); if (IPapyrusPaletteConstant.PALETTE_CUSTOMIZATIONS_ID.equals(id) || IPapyrusPaletteConstant.PALETTE_LOCAL_DEFINITIONS.equals(id)) { // refresh available palette table viewer diff --git a/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/handler/AbstractDeployPaletteConfigurationHandler.java b/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/handler/AbstractDeployPaletteConfigurationHandler.java index 75986a8e3b7..89aa3425d9a 100644 --- a/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/handler/AbstractDeployPaletteConfigurationHandler.java +++ b/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/handler/AbstractDeployPaletteConfigurationHandler.java @@ -1,370 +1,442 @@ -/*****************************************************************************
- * Copyright (c) 2013 CEA LIST.
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Remi Schnekenburger (CEA LIST) - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.customization.palette.handler;
-
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.Set;
-
-import org.eclipse.core.commands.AbstractHandler;
-import org.eclipse.core.commands.ExecutionEvent;
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.MultiStatus;
-import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.gmf.runtime.common.core.service.ProviderPriority;
-import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.jface.dialogs.TrayDialog;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.window.Window;
-import org.eclipse.papyrus.uml.diagram.common.Activator;
-import org.eclipse.papyrus.uml.diagram.common.part.PaletteUtil;
-import org.eclipse.papyrus.uml.diagram.common.part.PapyrusPalettePreferences;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.custom.CCombo;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.swt.widgets.Text;
-import org.eclipse.ui.XMLMemento;
-import org.eclipse.ui.handlers.HandlerUtil;
-import org.eclipse.ui.statushandlers.StatusManager;
-
-/**
- * @author RS211865
- */
-public abstract class AbstractDeployPaletteConfigurationHandler extends AbstractHandler {
-
- public static class UpdateContentDialog extends TrayDialog {
- public String paletteName;
- public ProviderPriority priority;
- public String editorID;
- public String requiredProfiles;
- public String fileName;
- private Text nameText;
- private Text editorText;
- private Text profilesText;
- private CCombo priorityCombo;
-
-
- /**
- * @param shell
- * @param priority
- * @param editorID
- * @param requiredProfiles
- */
- protected UpdateContentDialog(Shell shell, String fileName, String paletteName, ProviderPriority priority, String editorID, Set<String> requiredProfiles) {
- super(shell);
- this.fileName = fileName;
- this.paletteName = paletteName;
- this.priority = priority;
- this.editorID = editorID;
- if (requiredProfiles != null) {
- this.requiredProfiles = PaletteUtil.getSerializedProfileList(requiredProfiles);
- }
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected void configureShell(Shell newShell) {
- super.configureShell(newShell);
- if (newShell != null) {
- newShell.setText("Configure Deployment of the palette");
- newShell.setSize(600, 400);
- }
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected Control createDialogArea(Composite parent) {
- Composite superComposite = (Composite) super.createDialogArea(parent);
- Composite composite = new Composite(superComposite, SWT.NONE);
- composite.setLayout(new GridLayout(2, false));
- composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
-
- // new grid data will all necessary info
- Label nameLabel = new Label(composite, SWT.NONE);
- nameLabel.setText("Name:");
- nameText = new Text(composite, SWT.BORDER);
- if (paletteName == null) {
- paletteName = fileName;
- }
- nameText.setText(paletteName);
- nameText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
-
- Label priorityLabel = new Label(composite, SWT.NONE);
- priorityLabel.setText("Priority:");
- priorityCombo = new CCombo(composite, SWT.BORDER);
- priorityCombo.setEditable(false);
- priorityCombo.setItems(new String[] { ProviderPriority.LOWEST.getName(), ProviderPriority.LOW.getName(), ProviderPriority.MEDIUM.getName(), ProviderPriority.HIGH.getName(), ProviderPriority.HIGHEST.getName() });
- if (ProviderPriority.LOWEST.equals(priority)) {
- priorityCombo.select(0);
- } else if (ProviderPriority.LOW.equals(priority)) {
- priorityCombo.select(1);
- } else if (ProviderPriority.MEDIUM.equals(priority)) {
- priorityCombo.select(2);
- } else if (ProviderPriority.HIGH.equals(priority)) {
- priorityCombo.select(3);
- } else if (ProviderPriority.HIGHEST.equals(priority)) {
- priorityCombo.select(4);
- } else {
- priorityCombo.select(2); // default = medium
- }
- priorityCombo.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
-
- Label editorLabel = new Label(composite, SWT.NONE);
- editorLabel.setText("Editor:");
- editorText = new Text(composite, SWT.BORDER);
- if (editorID == null) {
- // TODO: try to see if a Papyrus editor is currently opened?
- editorID = "";
- }
- editorText.setText(editorID);
- editorText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
-
- // list of profiles
- Label profilesLabel = new Label(composite, SWT.NONE);
- profilesLabel.setText("Profiles:");
- profilesText = new Text(composite, SWT.BORDER);
- if (requiredProfiles != null) {
- profilesText.setText(requiredProfiles);
- }
- profilesText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
-
- return superComposite;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected void okPressed() {
- // updates values
- if (nameText != null && !nameText.isDisposed()) {
- paletteName = nameText.getText();
- }
-
- if (editorText != null && !editorText.isDisposed()) {
- editorID = editorText.getText();
- }
-
- if (priorityCombo != null && !priorityCombo.isDisposed()) {
- priority = ProviderPriority.parse(priorityCombo.getText());
- }
-
- if (profilesText != null && !profilesText.isDisposed()) {
- requiredProfiles = profilesText.getText();
- }
-
- super.okPressed();
- }
-
- }
-
- /**
- * {@inheritDoc}
- */
- public Object execute(ExecutionEvent event) throws ExecutionException {
- ISelection currentSelection = HandlerUtil.getCurrentSelection(event);
- if (!(currentSelection instanceof IStructuredSelection) || currentSelection.isEmpty()) {
- return null;
- }
-
- final IStructuredSelection selection = (IStructuredSelection) currentSelection;
-
- final Shell activeShell = HandlerUtil.getActiveShell(event);
-
-
- doExecute(selection, activeShell, new NullProgressMonitor());
- return null;
-
- }
-
- protected void doExecute(IStructuredSelection selection, Shell activeShell, IProgressMonitor monitor) {
-
- Iterator<?> selectionIterator = selection.iterator();
-
- MultiStatus result = new MultiStatus(Activator.ID, IStatus.OK, "The palette configuration has been successfully deployed and activated", null);
-
- while (selectionIterator.hasNext()) {
- Object selectedElement = selectionIterator.next();
- if (selectedElement instanceof IAdaptable) {
- IFile selectedFile = (IFile) ((IAdaptable) selectedElement).getAdapter(IFile.class);
- if (selectedFile == null) {
- monitor.worked(1);
- result.add(new Status(IStatus.ERROR, Activator.ID, "The selected element is not a file"));
- continue;
- }
-
-
- String fileName = selectedFile.getFullPath().removeFileExtension().lastSegment();
- monitor.subTask("Deploy " + fileName);
- boolean alreadyDeployed = false;
- // retrieve info => open a dialog, filled by current opened editor ?
- ProviderPriority priority = getPriority(fileName);
- if (priority == null) {
- priority = ProviderPriority.MEDIUM;
- } else {
- alreadyDeployed = true;
- }
-
- String editorID = getEditorID(fileName);
- if (editorID != null) {
- alreadyDeployed = true;
- }
-
- String paletteName = getPaletteName(fileName);
- if (paletteName != null) {
- alreadyDeployed = true;
- }
- Set<String> requiredProfiles = getRequiredProfiles(fileName);
- if (requiredProfiles != null && requiredProfiles.size() > 0) {
- alreadyDeployed = true;
- }
- String path = selectedFile.getFullPath().toString();
-
-
- UpdateContentDialog dialog = new UpdateContentDialog(activeShell, fileName, paletteName, priority, editorID, requiredProfiles);
- int returnCode = dialog.open();
- if (Window.OK == returnCode) {
- boolean validUpdate = true;
-
- // update values from the editor
- if (dialog.paletteName != null && dialog.paletteName.length() > 0) {
- paletteName = dialog.paletteName;
- } else {
- validUpdate = false;
- }
-
- if (dialog.priority != null) {
- priority = dialog.priority;
- } else {
- validUpdate = false;
- }
-
- if (dialog.editorID != null && dialog.editorID.length() > 0) {
- editorID = dialog.editorID;
- } else {
- validUpdate = false;
- }
-
- if (dialog.requiredProfiles != null && dialog.requiredProfiles.length() > 0) {
- requiredProfiles = PaletteUtil.getProfileSetFromString(dialog.requiredProfiles);
- } else {
- requiredProfiles = Collections.emptySet();
- }
-
- if (validUpdate) {
- if (alreadyDeployed) {
- // update values and set visible again
- result.add(activatePalette(fileName, paletteName, path, priority, editorID, requiredProfiles));
- } else {
- result.add(deployPalette(fileName, paletteName, path, priority, editorID, requiredProfiles));
- }
- } else {
- result.add(new Status(IStatus.ERROR, Activator.ID, "The palette configuration was not deployed, because dialog content was not valid"));
- }
- } else {
- result.add(new Status(IStatus.ERROR, Activator.ID, "The palette configuration was not deployed, because user did cancel the dialog"));
- }
-
- }
- }
-
- if (result.getChildren().length == 1) {
- if (result.isOK()) {
- MessageDialog.openInformation(activeShell, "Success", result.getMessage());
- } else if (result.getSeverity() < IStatus.ERROR) { // Errors are already logged
- StatusManager.getManager().handle(result, StatusManager.SHOW);
- }
- } else { // Merge the result and specify an appropriate message based on the result
- if (result.isOK()) {
- MessageDialog.openInformation(activeShell, "Success", result.getMessage());
- } else {
- MultiStatus actualResult = new MultiStatus(Activator.ID, result.getCode(), "Some errors occurred during the deployment", result.getException());
- actualResult.merge(result);
- }
- }
- }
-
- /**
- * @param identifier
- * @return
- */
- protected Set<String> getRequiredProfiles(String identifier) {
- return PapyrusPalettePreferences.getRequiredProfiles(identifier, getMemento());
- }
-
- /**
- * @param identifier
- * @return
- */
- protected String getPaletteName(String identifier) {
- return PapyrusPalettePreferences.getPaletteName(identifier, getMemento());
- }
-
- /**
- * @param identifier
- * @return
- */
- protected String getEditorID(String identifier) {
- return PapyrusPalettePreferences.getEditorID(identifier, getMemento());
- }
-
- /**
- * Warning. Can be <code>null</code>!
- *
- * @param identifier
- * @return
- */
- protected ProviderPriority getPriority(String identifier) {
- return PapyrusPalettePreferences.getPalettePriority(identifier, getMemento());
- }
-
- protected abstract XMLMemento getMemento();
-
- /**
- * @param fileName
- * @param paletteName
- * @param path
- * @param priority
- * @param editorID
- * @param requiredProfiles
- * @return
- */
- protected abstract IStatus deployPalette(String fileName, String paletteName, String path, ProviderPriority priority, String editorID, Set<String> requiredProfiles);
-
- /**
- * @param fileName
- * @param paletteName
- * @param path
- * @param priority
- * @param editorID
- * @param requiredProfiles
- * @return
- */
- protected abstract IStatus activatePalette(String fileName, String paletteName, String path, ProviderPriority priority, String editorID, Set<String> requiredProfiles);
-
-}
+/***************************************************************************** + * Copyright (c) 2016 CEA LIST. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Remi Schnekenburger (CEA LIST) - Initial API and implementation + * Mickael ADAM (ALL4TEC) mickael.adam@all4tec.net - Permits to display open diagram editor id + * + *****************************************************************************/ +package org.eclipse.papyrus.customization.palette.handler; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; +import java.util.Set; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.MultiStatus; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.core.runtime.Status; +import org.eclipse.gmf.runtime.common.core.service.ProviderPriority; +import org.eclipse.gmf.runtime.common.ui.services.editor.EditorService; +import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditor; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.dialogs.TrayDialog; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.customization.palette.Messages; +import org.eclipse.papyrus.uml.diagram.common.Activator; +import org.eclipse.papyrus.uml.diagram.common.part.PaletteUtil; +import org.eclipse.papyrus.uml.diagram.common.part.PapyrusPalettePreferences; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.CCombo; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Combo; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.XMLMemento; +import org.eclipse.ui.handlers.HandlerUtil; +import org.eclipse.ui.statushandlers.StatusManager; + +/** + * @author RS211865 + */ +public abstract class AbstractDeployPaletteConfigurationHandler extends AbstractHandler { + + public static class UpdateContentDialog extends TrayDialog { + + /** the palette name */ + public String paletteName; + + /** the provider priority */ + public ProviderPriority priority; + + /** the editor id */ + public String editorID; + + /** list of required profiles */ + public String requiredProfiles; + + /** file name */ + public String fileName; + + /** the name field */ + private Text nameText; + + /** the editor filed as a combo */ + private Combo editorIdCombo; + + /** the profiles text field */ + private Text profilesText; + + /** combo for priority */ + private CCombo priorityCombo; + + + /** + * Constructor. + * + * @param shell + * the shell + * @param priority + * the priority + * @param editorID + * the editor id + * @param requiredProfiles + * the required profiles + */ + protected UpdateContentDialog(final Shell shell, final String fileName, final String paletteName, final ProviderPriority priority, final String editorID, final Set<String> requiredProfiles) { + super(shell); + this.fileName = fileName; + this.paletteName = paletteName; + this.priority = priority; + this.editorID = editorID; + if (requiredProfiles != null) { + this.requiredProfiles = PaletteUtil.getSerializedProfileList(requiredProfiles); + } + } + + /** + * {@inheritDoc} + */ + @Override + protected void configureShell(final Shell newShell) { + super.configureShell(newShell); + if (newShell != null) { + newShell.setText(Messages.AbstractDeployPaletteConfigurationHandler_ConfigureDeploymentOfThePalette); + newShell.setSize(600, 400); + } + } + + /** + * {@inheritDoc} + */ + @Override + protected Control createDialogArea(final Composite parent) { + Composite superComposite = (Composite) super.createDialogArea(parent); + Composite composite = new Composite(superComposite, SWT.NONE); + composite.setLayout(new GridLayout(2, false)); + composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); + + // new grid data will all necessary info + Label nameLabel = new Label(composite, SWT.NONE); + nameLabel.setText(Messages.AbstractDeployPaletteConfigurationHandler_Identifier); + nameText = new Text(composite, SWT.BORDER); + if (paletteName == null) { + paletteName = fileName; + } + nameText.setText(paletteName); + nameText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1)); + + Label priorityLabel = new Label(composite, SWT.NONE); + priorityLabel.setText(Messages.AbstractDeployPaletteConfigurationHandler_Priority); + priorityCombo = new CCombo(composite, SWT.BORDER); + priorityCombo.setEditable(false); + priorityCombo.setItems(new String[] { ProviderPriority.LOWEST.getName(), ProviderPriority.LOW.getName(), ProviderPriority.MEDIUM.getName(), ProviderPriority.HIGH.getName(), ProviderPriority.HIGHEST.getName() }); + if (ProviderPriority.LOWEST.equals(priority)) { + priorityCombo.select(0); + } else if (ProviderPriority.LOW.equals(priority)) { + priorityCombo.select(1); + } else if (ProviderPriority.MEDIUM.equals(priority)) { + priorityCombo.select(2); + } else if (ProviderPriority.HIGH.equals(priority)) { + priorityCombo.select(3); + } else if (ProviderPriority.HIGHEST.equals(priority)) { + priorityCombo.select(4); + } else { + priorityCombo.select(2); // default = medium + } + priorityCombo.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1)); + + Label editorLabel = new Label(composite, SWT.NONE); + editorLabel.setText(Messages.AbstractDeployPaletteConfigurationHandler_Editor); + editorIdCombo = new Combo(composite, SWT.BORDER); + if (editorID == null) { + editorID = ""; //$NON-NLS-1$ + } + editorIdCombo.setItems(findOpenedDiagramEditor().toArray(new String[] {})); + editorIdCombo.setText(editorID); + editorIdCombo.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1)); + + // list of profiles + Label profilesLabel = new Label(composite, SWT.NONE); + profilesLabel.setText(Messages.AbstractDeployPaletteConfigurationHandler_Profiles); + profilesText = new Text(composite, SWT.BORDER); + if (requiredProfiles != null) { + profilesText.setText(requiredProfiles); + } + profilesText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1)); + + return superComposite; + } + + /** + * Get the list of id of opened diagram editor + * + * @return the list of opened diagram editor + */ + public static List<String> findOpenedDiagramEditor() { + + // The list of diagram id + List<String> ids = new ArrayList<String>(); + + // The list of open editor part + List<?> diagramEditors = EditorService.getInstance().getRegisteredEditorParts(); + + // Filter it and fill the list with contribution id of each DiagramEditor + diagramEditors.stream() + .filter(diagram -> diagram instanceof DiagramEditor) + .forEach(diagram -> { + ids.add(((DiagramEditor) diagram).getContributorId()); + }); + + return ids; + } + + /** + * {@inheritDoc} + */ + @Override + protected void okPressed() { + // updates values + if (null != nameText && !nameText.isDisposed()) { + paletteName = nameText.getText(); + } + + if (null != editorIdCombo && !editorIdCombo.isDisposed()) { + editorID = editorIdCombo.getText(); + } + + if (null != priorityCombo && !priorityCombo.isDisposed()) { + priority = ProviderPriority.parse(priorityCombo.getText()); + } + + if (null != profilesText && !profilesText.isDisposed()) { + requiredProfiles = profilesText.getText(); + } + + super.okPressed(); + } + + } + + /** + * {@inheritDoc} + */ + @Override + public Object execute(final ExecutionEvent event) throws ExecutionException { + ISelection currentSelection = HandlerUtil.getCurrentSelection(event); + if (!(currentSelection instanceof IStructuredSelection) || currentSelection.isEmpty()) { + return null; + } + + final IStructuredSelection selection = (IStructuredSelection) currentSelection; + + final Shell activeShell = HandlerUtil.getActiveShell(event); + + + doExecute(selection, activeShell, new NullProgressMonitor()); + return null; + + } + + protected void doExecute(final IStructuredSelection selection, final Shell activeShell, final IProgressMonitor monitor) { + + Iterator<?> selectionIterator = selection.iterator(); + + MultiStatus result = new MultiStatus(Activator.ID, IStatus.OK, Messages.AbstractDeployPaletteConfigurationHandler_ThePaletteConfigurationHasBeenSuccessfullyDeployedAndActivated, null); + + while (selectionIterator.hasNext()) { + Object selectedElement = selectionIterator.next(); + if (selectedElement instanceof IAdaptable) { + IFile selectedFile = ((IAdaptable) selectedElement).getAdapter(IFile.class); + if (selectedFile == null) { + monitor.worked(1); + result.add(new Status(IStatus.ERROR, Activator.ID, Messages.AbstractDeployPaletteConfigurationHandler_TheSelectedElementIsNotAFile)); + continue; + } + + + String fileName = selectedFile.getFullPath().removeFileExtension().lastSegment(); + monitor.subTask(Messages.AbstractDeployPaletteConfigurationHandler_Deploy + fileName); + boolean alreadyDeployed = false; + // retrieve info => open a dialog, filled by current opened editor ? + ProviderPriority priority = getPriority(fileName); + if (null == priority) { + priority = ProviderPriority.MEDIUM; + } else { + alreadyDeployed = true; + } + + String editorID = getEditorID(fileName); + if (null != editorID) { + alreadyDeployed = true; + } + + String paletteName = getPaletteName(fileName); + if (null != paletteName) { + alreadyDeployed = true; + } + Set<String> requiredProfiles = getRequiredProfiles(fileName); + if (requiredProfiles != null && requiredProfiles.size() > 0) { + alreadyDeployed = true; + } + String path = selectedFile.getFullPath().toString(); + + + UpdateContentDialog dialog = new UpdateContentDialog(activeShell, fileName, paletteName, priority, editorID, requiredProfiles); + int returnCode = dialog.open(); + if (Window.OK == returnCode) { + boolean validUpdate = true; + + // update values from the editor + if (dialog.paletteName != null && dialog.paletteName.length() > 0) { + paletteName = dialog.paletteName; + } else { + validUpdate = false; + } + + if (dialog.priority != null) { + priority = dialog.priority; + } else { + validUpdate = false; + } + + if (dialog.editorID != null && dialog.editorID.length() > 0) { + editorID = dialog.editorID; + } else { + validUpdate = false; + } + + if (dialog.requiredProfiles != null && dialog.requiredProfiles.length() > 0) { + requiredProfiles = PaletteUtil.getProfileSetFromString(dialog.requiredProfiles); + } else { + requiredProfiles = Collections.emptySet(); + } + + if (validUpdate) { + if (alreadyDeployed) { + // update values and set visible again + result.add(activatePalette(fileName, paletteName, path, priority, editorID, requiredProfiles)); + } else { + result.add(deployPalette(fileName, paletteName, path, priority, editorID, requiredProfiles)); + } + } else { + result.add(new Status(IStatus.ERROR, Activator.ID, Messages.AbstractDeployPaletteConfigurationHandler_Error_ContentDialogNotValid)); + } + } else { + result.add(new Status(IStatus.ERROR, Activator.ID, Messages.AbstractDeployPaletteConfigurationHandler_Error_UserCancelDialog)); + } + + } + } + + if (result.getChildren().length == 1) { + if (result.isOK()) { + MessageDialog.openInformation(activeShell, Messages.AbstractDeployPaletteConfigurationHandler_Success, result.getMessage()); + } else if (result.getSeverity() < IStatus.ERROR) { // Errors are already logged + StatusManager.getManager().handle(result, StatusManager.SHOW); + } + } else { // Merge the result and specify an appropriate message based on the result + if (result.isOK()) { + MessageDialog.openInformation(activeShell, Messages.AbstractDeployPaletteConfigurationHandler_Success, result.getMessage()); + } else { + MultiStatus actualResult = new MultiStatus(Activator.ID, result.getCode(), Messages.AbstractDeployPaletteConfigurationHandler_Error_SomeErrorsOccured, result.getException()); + actualResult.merge(result); + } + } + } + + /** + * get the Required Profiles + * + * @param identifier + * the identifier + * @return the required profiles + */ + protected Set<String> getRequiredProfiles(final String identifier) { + return PapyrusPalettePreferences.getRequiredProfiles(identifier, getMemento()); + } + + /** + * get the Palette Name + * + * @param identifier + * the identifier + * @return the Palette Name + */ + protected String getPaletteName(final String identifier) { + return PapyrusPalettePreferences.getPaletteName(identifier, getMemento()); + } + + /** + * get the Editor ID + * + * @param identifier + * the identifier + * @return the Editor ID + */ + protected String getEditorID(final String identifier) { + return PapyrusPalettePreferences.getEditorID(identifier, getMemento()); + } + + /** + * get the priority + * + * Warning. Can be <code>null</code>! + * + * @param identifier + * the identifier + * @return the provider priority + */ + protected ProviderPriority getPriority(final String identifier) { + return PapyrusPalettePreferences.getPalettePriority(identifier, getMemento()); + } + + /** get the xml memento */ + protected abstract XMLMemento getMemento(); + + /** + * deploy the Palette + * + * @param fileName + * @param paletteName + * @param path + * @param priority + * @param editorID + * @param requiredProfiles + * @return + */ + protected abstract IStatus deployPalette(final String fileName, final String paletteName, final String path, final ProviderPriority priority, final String editorID, final Set<String> requiredProfiles); + + /** + * activate the Palette + * + * @param fileName + * @param paletteName + * @param path + * @param priority + * @param editorID + * @param requiredProfiles + * @return + */ + protected abstract IStatus activatePalette(final String fileName, final String paletteName, final String path, final ProviderPriority priority, final String editorID, final Set<String> requiredProfiles); + +} diff --git a/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/handler/DeployExtendedPaletteConfigurationHandler.java b/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/handler/DeployExtendedPaletteConfigurationHandler.java index c835025cff3..63e3de2f3d2 100644 --- a/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/handler/DeployExtendedPaletteConfigurationHandler.java +++ b/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/handler/DeployExtendedPaletteConfigurationHandler.java @@ -1,58 +1,58 @@ -/*****************************************************************************
- * Copyright (c) 2014 CEA LIST.
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Remi Schnekenburger (CEA LIST) - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.customization.palette.handler;
-
-import java.util.Set;
-
-import org.eclipse.core.commands.IHandler;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.gmf.runtime.common.core.service.ProviderPriority;
-import org.eclipse.papyrus.uml.diagram.common.Activator;
-import org.eclipse.papyrus.uml.diagram.common.part.PapyrusPalettePreferences;
-import org.eclipse.ui.XMLMemento;
-
-
-/**
- * Handler to deploy new configuration of palette based on a XML file
- */
-public class DeployExtendedPaletteConfigurationHandler extends AbstractDeployPaletteConfigurationHandler implements IHandler {
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected IStatus deployPalette(String fileName, String paletteName, String path, ProviderPriority priority, String editorID, Set<String> requiredProfiles) {
- // just add the palette
- PapyrusPalettePreferences.addWorkspaceExtendedPalette(fileName, paletteName, path, priority, editorID, requiredProfiles);
- return new Status(IStatus.OK, Activator.ID, "The palette configuration has been successfully deployed and activated");
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected IStatus activatePalette(String fileName, String paletteName, String path, ProviderPriority priority, String editorID, Set<String> requiredProfiles) {
- PapyrusPalettePreferences.addWorkspaceExtendedPalette(fileName, paletteName, path, priority, editorID, requiredProfiles);
- PapyrusPalettePreferences.changePaletteVisibility(fileName, editorID, true);
- return new Status(IStatus.OK, Activator.ID, "The palette configuration was already deployed, it has just been activated");
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected XMLMemento getMemento() {
- return PapyrusPalettePreferences.getExistingWorkspaceExtendedPalettes();
- }
+/***************************************************************************** + * Copyright (c) 2014 CEA LIST. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Remi Schnekenburger (CEA LIST) - Initial API and implementation + * + *****************************************************************************/ +package org.eclipse.papyrus.customization.palette.handler; + +import java.util.Set; + +import org.eclipse.core.commands.IHandler; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.gmf.runtime.common.core.service.ProviderPriority; +import org.eclipse.papyrus.uml.diagram.common.Activator; +import org.eclipse.papyrus.uml.diagram.common.part.PapyrusPalettePreferences; +import org.eclipse.ui.XMLMemento; + + +/** + * Handler to deploy new configuration of palette based on a XML file + */ +public class DeployExtendedPaletteConfigurationHandler extends AbstractDeployPaletteConfigurationHandler implements IHandler { + + /** + * {@inheritDoc} + */ + @Override + protected IStatus deployPalette(String fileName, String paletteName, String path, ProviderPriority priority, String editorID, Set<String> requiredProfiles) { + // just add the palette + PapyrusPalettePreferences.addWorkspaceExtendedPalette(paletteName, paletteName, path, priority, editorID, requiredProfiles); + return new Status(IStatus.OK, Activator.ID, "The palette configuration has been successfully deployed and activated"); + } + + /** + * {@inheritDoc} + */ + @Override + protected IStatus activatePalette(String fileName, String paletteName, String path, ProviderPriority priority, String editorID, Set<String> requiredProfiles) { + PapyrusPalettePreferences.addWorkspaceExtendedPalette(paletteName, paletteName, path, priority, editorID, requiredProfiles); + PapyrusPalettePreferences.changePaletteVisibility(fileName, editorID, true); + return new Status(IStatus.OK, Activator.ID, "The palette configuration was already deployed, it has just been activated"); + } + + /** + * {@inheritDoc} + */ + @Override + protected XMLMemento getMemento() { + return PapyrusPalettePreferences.getExistingWorkspaceExtendedPalettes(); + } }
\ No newline at end of file diff --git a/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/messages.properties b/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/messages.properties index 2fa7dfeda63..e41320270a2 100644 --- a/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/messages.properties +++ b/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/messages.properties @@ -1,16 +1,123 @@ -###############################################################################
-# Copyright (c) 2010 CEA LIST.
-#
-# All rights reserved. This program and the accompanying materials
-# are made available under the terms of the Eclipse Public License v1.0
-# which accompanies this distribution, and is available at
-# http://www.eclipse.org/legal/epl-v10.html
-#
-# Contributors:
-# Remi Schnekenburger (CEA LIST) remi.schnekenburger@cea.fr - Initial API and implementation
-###############################################################################
-
-# Explorer dialog messages
-BundleIconExplorerDialog_Message=Please select an icon in the following list
-BundleIconExplorerDialog_Title=Icon selection
-BundleIconExplorerDialog_UnknownFileName=<Unknown>
+############################################################################### +# Copyright (c) 2010 CEA LIST. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Eclipse Public License v1.0 +# which accompanies this distribution, and is available at +# http://www.eclipse.org/legal/epl-v10.html +# +# Contributors: +# Remi Schnekenburger (CEA LIST) remi.schnekenburger@cea.fr - Initial API and implementation +############################################################################### + +# Explorer dialog messages +BundleIconExplorerDialog_Message=Please select an icon in the following list +BundleIconExplorerDialog_Title=Icon selection +BundleIconExplorerDialog_UnknownFileName=<Unknown> + +########### Palette configuration model edition messages ########### +ExportPaletteConfigurationWizard_error_cant_read_file=Impossible to read local definition of the file +ExportPaletteConfigurationWizard_error_file_not_existe=local file does not exists : +ExportPaletteConfigurationWizard_Export_description=Choose where you want to export the selected palette configuration +ExportPaletteConfigurationWizard_ExportWiazrdLabel=Export +ExportPaletteConfigurationWizard_export_palette=Export Palette Configuration +PaletteConfigurationContentPage_CreateAnElementWithAStereotype=Create an element with a stereotype +PaletteConfigurationContentPage_Drawer=Drawer +PaletteConfigurationContentPage_NewTool=NewTool +PaletteConfigurationContentPage_Separator=Separator +PaletteConfigurationContentPage_Stack=Stack +PaletteConfigurationContentPage_UMLTools=UML tools +PaletteConfigurationContentPage_UnknownElement=unknown element +PaletteConfigurationWizard_EditionPaletteInfoPageWizard_Tilte=Edit the Palette +PaletteConfigurationWizard_EditPaletteWizardLabel=Edit Palette +PaletteConfigurationWizard_NewPaletteContentPageWizard_Description=Edit the content of the palette. +PaletteConfigurationWizard_NewPaletteContentPageWizard_Title=Palette Content +PaletteConfigurationWizard_NewPaletteDefaultName=New Palette +PaletteConfigurationWizard_PaletteInfoPageWizard_Description=Enter information of the new palette. +PaletteConfigurationWizard_NewPaletteInfoPageWizard_Title=New Local Palette +PaletteConfigurationWizard_NewPaletteWizardLabel=New Palette +PaletteConfigurationWizard_ImpossibleToReadDefinitionOfTheFile=Impossible to read definition of the file +PaletteConfigurationWizard_FileDontExist=File does not exists : +PapyrusPaletteCustomizerDialog_AddButtonTooltip=Create a new palette +PapyrusPaletteCustomizerDialog_RemoveButtonTooltip=Delete the selected palette + +############# Palette Customisation ################# +PapyrusPaletteCustomizerDialog_AddButtonTooltip=Add the selection to the palette +PapyrusPaletteCustomizerDialog_RemoveButtonTooltip=Remove the selection from the palette +PapyrusPaletteCustomizerDialog_EditButtonTooltip_LocalPaletteSelected=Edit the selected local palette +PapyrusPaletteCustomizerDialog_EditButtonTooltip_LocalPaletteNotSelected=Edit a local palette. Please select a local palette in the available palette viewer. +PapyrusPaletteCustomizerDialog_EditButtonTooltip_MissingProfile=Impossible to edit this local palette because some required profile are not applied. +PapyrusPaletteCustomizerDialog_EditButtonTooltip=Edit the current selected drawer +Available_Palettes=Available palettes +Palette_Viewer=Palette preview +Local_Palette_Name=Name*: +Local_Palette_Name_Tooltip=Enter a name for this palette contribution. This name will be displayed when selecting the visible palettes and the hidden ones. +Local_Palette_Id=Identifier*: +Local_Palette_Id_Tooltip=Enter a unique identifier for this palette contribution. This identifier is used to retrieve this palette among others, which means it should be unique. +Local_Palette_Editor_Id=EditorID*: +Local_Palette_Editor_Id_Tooltip=Sets the id of the editor for which this configuration is provided. +Local_Palette_Priority=Priority*: +Local_Palette_Priority_Tooltip=Sets the palette priority. It determines which palette provider is contributing first.\nThis contribution should have at least a priority higher than predefined tools contributions. +Dialog_Advanced_Button_Closed=Advanced >> +Dialog_Advanced_Button_Opened=<< Advanced +Local_Palette_Error_Priority=One priority should be selected in the list of availables priorities +Local_Palette_Error_Name=Name field shall not be empty +Local_Palette_Error_EditorId=Editor ID field shall not be empty +Local_Palette_Error_PaletteId=Palette ID field shall not be empty +Local_Palette_InfoPage_Name=LocalPaletteInformation +Local_Palette_InfoPage_Title=Local Palette Information +Local_Palette_ContentPage_Name=LocalPaletteContent +Local_Palette_ContentPage_Title=Local Palette Content +Local_Palette_Available_Tools=Available tools +Local_Palette_ShowDrawers_Tooltip=Toggle this button to show/hide the drawers in the list +Local_Palette_ShowTools_Tooltip=Toggle this button to show/hide the tools in the list +Local_Palette_SwitchToolsContentProvider_Tooltip=Toggle this button to change the way tools are shown in the list (Metaclass -> Stereotypes or Metaclass -> Stereotypes) +Local_Palette_Palette_Preview=Palette preview +Local_Palette_Entry_Name=Name: +Local_Palette_Entry_Description=Description: +Local_Palette_Entry_Icon=Icon: +Local_Palette_Entry_Information=Entry information +Local_Palette_Entry_Reference:Extended Tool: + +Aspect_Action_Information_List_Label=Aspect actions + +Dialog_Not_Local_Palette_Title=Bad selection (no item or bad item) +Dialog_Not_Local_Palette_Message=Please select a local palette to be deleted. +Dialog_Not_Extended_Palette_Title=Bad selection (no item or bad item) +Dialog_Not_Extended_Palette_Message=Please select an extended palette to be restored. +Dialog_Delete_Palette_Tooltip=Delete selected local palette definition +Dialog_Create_Palette_Tooltip=Create a new local palette +Dialog_Edit_Palette_Tooltip=Edit selected palette +Dialog_Restore_Palette_Tooltip=Restore default values of selected palette +Dialog_Export_Palette_Tooltip= Export configuration model of selected palette + +Local_Palette_Create_Drawer_Tooltip=Create a new drawer in the palette +Local_Palette_Create_Separator_Tooltip=Create a new separator in the palette +Local_Palette_Create_Tool_Tooltip=Create a new tool in the palette +Local_Palette_Create_Stack_Tooltip=Create a new stack in the palette + +Wizard_Drawer_Page_Name=DrawerWizardPage +Wizard_Drawer_Page_Title=Drawer Information Page +Wizard_Drawer_Error_Name=Name field shall not be empty +Wizard_Drawer_Error_Id=ID field shall not be empty +Wizard_Drawer_Error_Icon=Icon field shall not be empty +Wizard_Drawer_Id=Identifier* +Wizard_Drawer_Id_Tooltip=Enter a unique identifier for this drawer.\nThis identifier is used to retrieve this drawer among others, which means it should be unique. +Wizard_Drawer_Name=Name* +Wizard_Drawer_Name_Tooltip=Enter a name for this drawer. +Wizard_Drawer_Icon_Tooltip=Enter the path to the icon. It can be something like "/icon/drawer.gif" or like "platform:/plugin/org.eclipse.uml2.uml.edit/icons/full/obj16/PackageImport.gif" +Wizard_Drawer_Icon=Icon* + +########### Palette deploy wizard ########### +AbstractDeployPaletteConfigurationHandler_ConfigureDeploymentOfThePalette=Configure deployment of the palette +AbstractDeployPaletteConfigurationHandler_Deploy=Deploy +AbstractDeployPaletteConfigurationHandler_Editor=Editor: +AbstractDeployPaletteConfigurationHandler_Error_UserCancelDialog=The palette configuration was not deployed, because user did cancel the dialog +AbstractDeployPaletteConfigurationHandler_Error_ContentDialogNotValid=The palette configuration was not deployed, because dialog content was not valid +AbstractDeployPaletteConfigurationHandler_Error_SomeErrorsOccured=Some errors occurred during the deployment +AbstractDeployPaletteConfigurationHandler_Identifier=Identifier: +AbstractDeployPaletteConfigurationHandler_Priority=Priority: +AbstractDeployPaletteConfigurationHandler_Profiles=Profiles: +AbstractDeployPaletteConfigurationHandler_Success=Success +AbstractDeployPaletteConfigurationHandler_ThePaletteConfigurationHasBeenSuccessfullyDeployedAndActivated=The palette configuration has been successfully deployed and activated +AbstractDeployPaletteConfigurationHandler_TheSelectedElementIsNotAFile=The selected element is not a file diff --git a/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/provider/PaletteLabelProvider.java b/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/provider/PaletteLabelProvider.java new file mode 100644 index 00000000000..16de72a2579 --- /dev/null +++ b/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/provider/PaletteLabelProvider.java @@ -0,0 +1,100 @@ +/***************************************************************************** + * Copyright (c) 2016 CEA LIST and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Mickael ADAM (ALL4TEC) mickael.adam@all4tec.net - Initial API and Implementation + *****************************************************************************/ +package org.eclipse.papyrus.customization.palette.provider; + +import org.eclipse.gef.palette.PaletteEntry; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.viewers.ILabelProvider; +import org.eclipse.jface.viewers.ILabelProviderListener; +import org.eclipse.papyrus.customization.palette.Messages; +import org.eclipse.papyrus.uml.diagram.common.Activator; +import org.eclipse.swt.graphics.Image; +import org.eclipse.uml2.uml.Stereotype; + +/** + * Label provider for palette tools. + * <P> + * We should be using the Palette label provider from GEF, if it was not with visibility "package"... + * + * @see org.eclipse.gef.ui.palette.customize.PaletteLabelProvider + * </P> + * + */ +public class PaletteLabelProvider implements ILabelProvider { + + /** the icon for stereotypes */ + private static final String ICONS_STEREOTYPE = "/icons/stereotype.gif"; // $NON-NLS-N$ + + /** + * {@inheritDoc} + */ + @Override + public void addListener(final ILabelProviderListener listener) { + // Do nothing + } + + /** + * {@inheritDoc} + */ + @Override + public void dispose() { + // Do nothing + } + + /** + * {@inheritDoc} + */ + @Override + public Image getImage(final Object element) { + Image iconImage = null; + if (element instanceof PaletteEntry) { + ImageDescriptor descriptor = ((PaletteEntry) element).getSmallIcon(); + if (descriptor != null) { + iconImage = Activator.getPluginIconImage(Activator.ID, descriptor); + } + } else if (element instanceof Stereotype) { + iconImage = Activator.getPluginIconImage(Activator.ID, ICONS_STEREOTYPE); + } + return iconImage; + } + + /** + * {@inheritDoc} + */ + @Override + public String getText(final Object element) { + String text = null; + if (element instanceof PaletteEntry) { + text = ((PaletteEntry) element).getLabel(); + } else if (element instanceof Stereotype) { + text = ((Stereotype) element).getName(); + } + return null != text ? text : Messages.PaletteConfigurationContentPage_UnknownElement; + } + + /** + * {@inheritDoc} + */ + @Override + public boolean isLabelProperty(final Object element, final String property) { + return false; + } + + /** + * {@inheritDoc} + */ + @Override + public void removeListener(final ILabelProviderListener listener) { + // Do nothing + } + +}
\ No newline at end of file diff --git a/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/provider/ProfileToolsMetaclassStereotypeTreeContentProvider.java b/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/provider/ProfileToolsMetaclassStereotypeTreeContentProvider.java new file mode 100644 index 00000000000..aaf12d1158c --- /dev/null +++ b/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/provider/ProfileToolsMetaclassStereotypeTreeContentProvider.java @@ -0,0 +1,159 @@ +/***************************************************************************** + * Copyright (c) 2016 CEA LIST and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Mickael ADAM (ALL4TEC) mickael.adam@all4tec.net - Initial API and Implementation + *****************************************************************************/ +package org.eclipse.papyrus.customization.palette.provider; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EClassifier; +import org.eclipse.gef.palette.CombinedTemplateCreationEntry; +import org.eclipse.gef.palette.PaletteEntry; +import org.eclipse.jface.viewers.ITreeContentProvider; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.papyrus.customization.palette.Messages; +import org.eclipse.papyrus.uml.diagram.common.part.PaletteUtil; +import org.eclipse.papyrus.uml.diagram.common.service.AspectCreationEntry; +import org.eclipse.papyrus.uml.diagram.common.service.IPapyrusPaletteConstant; +import org.eclipse.papyrus.uml.diagram.common.service.palette.StereotypeAspectActionProvider; +import org.eclipse.uml2.uml.Class; +import org.eclipse.uml2.uml.Profile; +import org.eclipse.uml2.uml.Stereotype; +import org.eclipse.uml2.uml.UMLPackage; + +/** + * Content provider for the available tools viewer, when the + */ +public class ProfileToolsMetaclassStereotypeTreeContentProvider implements ITreeContentProvider { + + /** profile to display */ + final protected Profile profile; + + /** standard uml tools palette entries */ + final protected Collection<PaletteEntry> standardEntries; + + /** + * Creates a new ProfileToolsMetaclassStereotypeTreeContentProvider. + * + * @param profile + * the profile for which tools are built + * @param standardEntries + * list of standard uml tools palette entries + */ + public ProfileToolsMetaclassStereotypeTreeContentProvider(final Profile profile, final Collection<PaletteEntry> standardEntries) { + this.profile = profile; + this.standardEntries = standardEntries; + } + + /** + * {@inheritDoc} + */ + @Override + public void dispose() { + // nothing to do here + } + + /** + * {@inheritDoc} + */ + @Override + public Object[] getChildren(Object parentElement) { + Object[] children; + if (parentElement instanceof Profile) { + children = standardEntries.toArray(); + + } else if (parentElement instanceof AspectCreationEntry) { + children = new Object[0]; + + } else if (parentElement instanceof PaletteEntry) { + List<AspectCreationEntry> entries = new ArrayList<AspectCreationEntry>(); + // display all stereotypes applicable to the type of element created by this tool + if (parentElement instanceof CombinedTemplateCreationEntry) { + CombinedTemplateCreationEntry entry = (CombinedTemplateCreationEntry) parentElement; + EClass toolMetaclass = PaletteUtil.getToolMetaclass(entry); + if (toolMetaclass != null) { + for (Stereotype stereotype : profile.getOwnedStereotypes()) { + List<Class> metaclasses = stereotype.getAllExtendedMetaclasses(); + for (Class stMetaclass : metaclasses) { + // get Eclass + java.lang.Class<?> metaclassClass = stMetaclass.getClass(); + if (metaclassClass != null) { + EClassifier metaClassifier = UMLPackage.eINSTANCE.getEClassifier(stMetaclass.getName()); + if (((EClass) metaClassifier).isSuperTypeOf(toolMetaclass)) { + // should create the palette entry + Map<String, Object> properties = new HashMap<String, Object>(); + properties.put(IPapyrusPaletteConstant.ASPECT_ACTION_KEY, StereotypeAspectActionProvider.createConfigurationNode(stereotype.getQualifiedName())); + StringBuilder name = new StringBuilder(); + name.append(stereotype.getName()); + name.append(" (");//$NON-NLS-1$ + name.append(entry.getLabel()); + name.append(")");//$NON-NLS-1$ + AspectCreationEntry aspectEntry = new AspectCreationEntry(name.toString(), Messages.PaletteConfigurationContentPage_CreateAnElementWithAStereotype, // $NON-NLS-1$ //$NON-NLS-2$ + entry.getId(), // $NON-NLS-4$ + entry.getSmallIcon(), entry, properties); + entries.add(aspectEntry); + } + } + + } + } + } + } + children = entries.toArray(); + } else { + children = new Object[0]; + } + return children; + } + + /** + * {@inheritDoc} + */ + @Override + public Object[] getElements(final Object inputElement) { + return inputElement instanceof Profile ? standardEntries.toArray() : new Object[0]; + } + + /** + * {@inheritDoc} + */ + @Override + public Object getParent(final Object element) { + return element instanceof Stereotype ? ((Stereotype) element).getProfile() : null; + } + + /** + * {@inheritDoc} + */ + @Override + public boolean hasChildren(final Object element) { + boolean hasChildren = false; + if (element instanceof Profile) { + hasChildren = true; + } else if (element instanceof PaletteEntry) { + hasChildren = true; + } + return hasChildren; + } + + /** + * {@inheritDoc} + */ + @Override + public void inputChanged(final Viewer viewer, final Object oldInput, final Object newInput) { + // Do nothing + } + +}
\ No newline at end of file diff --git a/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/provider/ProfileToolsStereotypeMetaclassTreeContentProvider.java b/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/provider/ProfileToolsStereotypeMetaclassTreeContentProvider.java new file mode 100644 index 00000000000..9768842ab6c --- /dev/null +++ b/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/provider/ProfileToolsStereotypeMetaclassTreeContentProvider.java @@ -0,0 +1,148 @@ +/***************************************************************************** + * Copyright (c) 2016 CEA LIST and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Mickael ADAM (ALL4TEC) mickael.adam@all4tec.net - Initial API and Implementation + *****************************************************************************/ +package org.eclipse.papyrus.customization.palette.provider; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EClassifier; +import org.eclipse.gef.palette.CombinedTemplateCreationEntry; +import org.eclipse.gef.palette.PaletteEntry; +import org.eclipse.jface.viewers.ITreeContentProvider; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.papyrus.customization.palette.Messages; +import org.eclipse.papyrus.uml.diagram.common.part.PaletteUtil; +import org.eclipse.papyrus.uml.diagram.common.service.AspectCreationEntry; +import org.eclipse.papyrus.uml.diagram.common.service.IPapyrusPaletteConstant; +import org.eclipse.papyrus.uml.diagram.common.service.palette.StereotypeAspectActionProvider; +import org.eclipse.uml2.uml.Class; +import org.eclipse.uml2.uml.Profile; +import org.eclipse.uml2.uml.Stereotype; +import org.eclipse.uml2.uml.UMLPackage; + +/** + * Content provider for the available tools viewer, when the tools to see are coming from a + * profile + */ +public class ProfileToolsStereotypeMetaclassTreeContentProvider implements ITreeContentProvider { + + /** standard uml tools palette entries */ + final protected Collection<PaletteEntry> standardEntries; + + /** + * Creates a new ProfileToolsStereotypeMetaclassTreeContentProvider. + * + * @param profile + * the profile for which tools are built + * @param standardEntries + * list of standard uml tools palette entries + */ + public ProfileToolsStereotypeMetaclassTreeContentProvider(final Profile profile, final Collection<PaletteEntry> standardEntries) { + this.standardEntries = standardEntries; + } + + /** + * {@inheritDoc} + */ + @Override + public void dispose() { + // nothing to do here + } + + /** + * {@inheritDoc} + */ + @Override + public Object[] getChildren(final Object parentElement) { + Object[] children; + if (parentElement instanceof Profile) { + children = ((Profile) parentElement).getOwnedStereotypes().toArray(); + } else if (parentElement instanceof Stereotype) { + List<PaletteEntry> entries = new ArrayList<PaletteEntry>(); + Stereotype stereotype = (Stereotype) parentElement; + + for (PaletteEntry entry : standardEntries) { + // retrieve the element type created by the tool. + if (entry instanceof CombinedTemplateCreationEntry) { + + EClass toolMetaclass = PaletteUtil.getToolMetaclass((CombinedTemplateCreationEntry) entry); + if (toolMetaclass != null) { + List<Class> metaclasses = stereotype.getAllExtendedMetaclasses(); + for (Class stMetaclass : metaclasses) { + // get Eclass + java.lang.Class<?> metaclassClass = stMetaclass.getClass(); + if (metaclassClass != null) { + EClassifier metaClassifier = UMLPackage.eINSTANCE.getEClassifier(stMetaclass.getName()); + if (((EClass) metaClassifier).isSuperTypeOf(toolMetaclass)) { + // should create the palette entry + Map<String, Object> properties = new HashMap<String, Object>(); + properties.put(IPapyrusPaletteConstant.ASPECT_ACTION_KEY, StereotypeAspectActionProvider.createConfigurationNode(stereotype.getQualifiedName())); + StringBuilder name = new StringBuilder(); + name.append(stereotype.getName()); + name.append(" (");//$NON-NLS-1$ + name.append(entry.getLabel()); + name.append(")");//$NON-NLS-1$ + AspectCreationEntry aspectEntry = new AspectCreationEntry(name.toString(), Messages.PaletteConfigurationContentPage_CreateAnElementWithAStereotype, + entry.getId(), // $NON-NLS-4$ + entry.getSmallIcon(), (CombinedTemplateCreationEntry) entry, properties); + entries.add(aspectEntry); + } + } + + } + } + } + } + children = entries.toArray(); + } else { + children = new Object[0]; + } + return children; + } + + /** + * {@inheritDoc} + */ + @Override + public Object[] getElements(final Object inputElement) { + return inputElement instanceof Profile ? ((Profile) inputElement).getOwnedStereotypes().toArray() : new Object[0]; + } + + /** + * {@inheritDoc} + */ + @Override + public Object getParent(final Object element) { + return element instanceof Stereotype ? ((Stereotype) element).getProfile() : null; + } + + /** + * {@inheritDoc} + */ + @Override + public boolean hasChildren(final Object element) { + return 0 < getChildren(element).length; + } + + /** + * {@inheritDoc} + */ + @Override + public void inputChanged(final Viewer viewer, final Object oldInput, final Object newInput) { + // nothing to do here + } + +}
\ No newline at end of file diff --git a/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/provider/UMLToolsTreeContentProvider.java b/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/provider/UMLToolsTreeContentProvider.java new file mode 100644 index 00000000000..cdb61e3c01c --- /dev/null +++ b/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/provider/UMLToolsTreeContentProvider.java @@ -0,0 +1,105 @@ +/***************************************************************************** + * Copyright (c) 2016 CEA LIST and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Mickael ADAM (ALL4TEC) mickael.adam@all4tec.net - Initial API and Implementation + *****************************************************************************/ +package org.eclipse.papyrus.customization.palette.provider; + +import java.util.Collection; + +import org.eclipse.gef.palette.PaletteRoot; +import org.eclipse.jface.viewers.ITreeContentProvider; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.papyrus.uml.diagram.common.part.PaletteUtil; + +/** + * Content provider for available tools viewer + */ +public class UMLToolsTreeContentProvider implements ITreeContentProvider { + + /** + * Constructor + * + * @param viewer + * The viewer whose ContentProvider this content provider is + */ + public UMLToolsTreeContentProvider() { + } + + /** + * {@inheritDoc} + */ + @Override + public void dispose() { + // Do nothing + } + + /** + * {@inheritDoc} + */ + @Override + public Object[] getChildren(final Object parentElement) { + Object[] elements = null; + + if (parentElement instanceof Collection<?>) { + elements = ((Collection<?>) parentElement).toArray(); + } else if (parentElement instanceof PaletteRoot) { + // paletteUil.getAllEntries(...) to add drawers + // if so, uncomment the addFilterbutton for drawers in populate tool bar + elements = PaletteUtil.getAllToolEntries(((PaletteRoot) parentElement)).toArray(); + } + + return elements; + } + + /** + * {@inheritDoc} + */ + @Override + public Object[] getElements(final Object inputElement) { + Object[] elements = null; + + if (inputElement instanceof Collection<?>) { + elements = ((Collection<?>) inputElement).toArray(); + } else if (inputElement instanceof PaletteRoot) { + // paletteUil.getAllEntries(...) to add drawers + // if so, uncomment the addFilterbutton for drawers in populate tool bar + elements = PaletteUtil.getAllToolEntries(((PaletteRoot) inputElement)).toArray(); + } + + if (elements == null) { + elements = new Object[0]; + } + return elements; + } + + /** + * {@inheritDoc} + */ + @Override + public Object getParent(final Object element) { + return null; + } + + /** + * {@inheritDoc} + */ + @Override + public boolean hasChildren(final Object element) { + return null != getChildren(element) && 0 < getChildren(element).length; + } + + /** + * {@inheritDoc} + */ + @Override + public void inputChanged(final Viewer viewer, final Object oldInput, final Object newInput) { + // Do nothing + } +}
\ No newline at end of file diff --git a/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/utils/PaletteUtils.java b/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/utils/PaletteUtils.java new file mode 100644 index 00000000000..11de2382d08 --- /dev/null +++ b/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/utils/PaletteUtils.java @@ -0,0 +1,99 @@ +/***************************************************************************** + * Copyright (c) 2016 CEA LIST and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Mickael ADAM (ALL4TEC) mickael.adam@all4tec.net - Initial API and Implementation + *****************************************************************************/ + +package org.eclipse.papyrus.customization.palette.utils; + +import java.io.File; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditorWithFlyOutPalette; +import org.eclipse.papyrus.customization.palette.PaletteConstants.PaletteModelContextEnum; +import org.eclipse.papyrus.uml.diagram.common.service.PapyrusPaletteService; +import org.eclipse.papyrus.uml.diagram.common.service.PapyrusPaletteService.ProviderDescriptor; +import org.eclipse.ui.IEditorPart; + +/** + * Utils for palette customization. + * + */ +public class PaletteUtils { + + /** + * Save options for palette resources. + */ + public static final Map<Object, Object> saveOptions; + static { + Map<Object, Object> options = new HashMap<Object, Object>(); + options.put(Resource.OPTION_LINE_DELIMITER, Resource.OPTION_LINE_DELIMITER_UNSPECIFIED); + saveOptions = Collections.unmodifiableMap(options); + } + + /** + * set the status field which describe in which case of palette model we are. + * + * @param descriptor + */ + public static PaletteModelContextEnum getPaletteModelContext(ProviderDescriptor descriptor) { + PaletteModelContextEnum paletteContext; + // Case 1: WS + if (descriptor instanceof PapyrusPaletteService.WorkspaceExtendedProviderDescriptor) { + paletteContext = PaletteModelContextEnum.Workspace; + } else + // case 2: plugin + if (descriptor instanceof PapyrusPaletteService.ExtendedProviderDescriptor) { + paletteContext = PaletteModelContextEnum.Plugin; + } else + // case 3: local + if (descriptor instanceof PapyrusPaletteService.LocalExtendedProviderDescriptor) { + paletteContext = PaletteModelContextEnum.Local; + } else { + // case 4 : new + paletteContext = PaletteModelContextEnum.New; + } + return paletteContext; + } + + /** + * @param the + * file to test + * @return true if it exist and is readable. + */ + public static boolean notErrorOnFile(File file) { + boolean error = false; + if (null != file) { + if (!file.exists()) { + error = true; + } else if (!file.canRead()) { + error = true; + } + } + + return !error; + } + + /** + * Get the Id value of the current editor + * + * @return the editor id value as a String + */ + public static String getEditorIdValue(IEditorPart editorPart) { + String editorIDValue = ""; //$NON-NLS-1$ + if (editorPart instanceof DiagramEditorWithFlyOutPalette) { + editorIDValue = ((DiagramEditorWithFlyOutPalette) editorPart).getContributorId(); + } + return editorIDValue; + } + +} |