diff options
author | Eike Stepper | 2012-01-14 10:27:01 +0000 |
---|---|---|
committer | Eike Stepper | 2012-01-14 10:27:01 +0000 |
commit | 0266166cb9ff9535c150250073ea1e57b42d2693 (patch) | |
tree | c006a3bc0ba1f6e1d8a2bc032eedc346f71eab0d /plugins/org.eclipse.net4j.util.ui | |
parent | 7416443692cdda72d1f704ea4fc5ececcc669df7 (diff) | |
download | cdo-0266166cb9ff9535c150250073ea1e57b42d2693.tar.gz cdo-0266166cb9ff9535c150250073ea1e57b42d2693.tar.xz cdo-0266166cb9ff9535c150250073ea1e57b42d2693.zip |
Adjusted copyrights to 2012
Diffstat (limited to 'plugins/org.eclipse.net4j.util.ui')
68 files changed, 8843 insertions, 8843 deletions
diff --git a/plugins/org.eclipse.net4j.util.ui/.settings/org.eclipse.jdt.ui.prefs b/plugins/org.eclipse.net4j.util.ui/.settings/org.eclipse.jdt.ui.prefs index aaef0ccba1..6726e7034a 100644 --- a/plugins/org.eclipse.net4j.util.ui/.settings/org.eclipse.jdt.ui.prefs +++ b/plugins/org.eclipse.net4j.util.ui/.settings/org.eclipse.jdt.ui.prefs @@ -1,120 +1,120 @@ -#Thu Feb 04 09:44:24 CET 2010 -cleanup.add_default_serial_version_id=true -cleanup.add_generated_serial_version_id=false -cleanup.add_missing_annotations=true -cleanup.add_missing_deprecated_annotations=true -cleanup.add_missing_methods=false -cleanup.add_missing_nls_tags=false -cleanup.add_missing_override_annotations=true -cleanup.add_missing_override_annotations_interface_methods=true -cleanup.add_serial_version_id=true -cleanup.always_use_blocks=true -cleanup.always_use_parentheses_in_expressions=false -cleanup.always_use_this_for_non_static_field_access=false -cleanup.always_use_this_for_non_static_method_access=false -cleanup.convert_to_enhanced_for_loop=false -cleanup.correct_indentation=true -cleanup.format_source_code=true -cleanup.format_source_code_changes_only=false -cleanup.make_local_variable_final=true -cleanup.make_parameters_final=false -cleanup.make_private_fields_final=true -cleanup.make_type_abstract_if_missing_method=false -cleanup.make_variable_declarations_final=false -cleanup.never_use_blocks=false -cleanup.never_use_parentheses_in_expressions=true -cleanup.organize_imports=true -cleanup.qualify_static_field_accesses_with_declaring_class=false -cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true -cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true -cleanup.qualify_static_member_accesses_with_declaring_class=false -cleanup.qualify_static_method_accesses_with_declaring_class=false -cleanup.remove_private_constructors=true -cleanup.remove_trailing_whitespaces=true -cleanup.remove_trailing_whitespaces_all=true -cleanup.remove_trailing_whitespaces_ignore_empty=false -cleanup.remove_unnecessary_casts=true -cleanup.remove_unnecessary_nls_tags=true -cleanup.remove_unused_imports=true -cleanup.remove_unused_local_variables=false -cleanup.remove_unused_private_fields=true -cleanup.remove_unused_private_members=false -cleanup.remove_unused_private_methods=true -cleanup.remove_unused_private_types=true -cleanup.sort_members=false -cleanup.sort_members_all=false -cleanup.use_blocks=true -cleanup.use_blocks_only_for_return_and_throw=false -cleanup.use_parentheses_in_expressions=true -cleanup.use_this_for_non_static_field_access=true -cleanup.use_this_for_non_static_field_access_only_if_necessary=true -cleanup.use_this_for_non_static_method_access=true -cleanup.use_this_for_non_static_method_access_only_if_necessary=true -cleanup_profile=_EMFT -cleanup_settings_version=2 -eclipse.preferences.version=1 -editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true -formatter_profile=_EMFT -formatter_settings_version=11 -org.eclipse.jdt.ui.exception.name=ex -org.eclipse.jdt.ui.gettersetter.use.is=true -org.eclipse.jdt.ui.ignorelowercasenames=true -org.eclipse.jdt.ui.importorder=org.eclipse.emf.cdo;org.eclipse.emf.internal.cdo;org.eclipse.net4j;org.eclipse.internal.net4j;org.eclipse.emf;org.eclipse;com;org;javax;java; -org.eclipse.jdt.ui.javadoc=true -org.eclipse.jdt.ui.keywordthis=false -org.eclipse.jdt.ui.ondemandthreshold=99 -org.eclipse.jdt.ui.overrideannotation=true -org.eclipse.jdt.ui.staticondemandthreshold=99 -org.eclipse.jdt.ui.text.custom_code_templates=<?xml version\="1.0" encoding\="UTF-8" standalone\="no"?><templates><template autoinsert\="false" context\="gettercomment_context" deleted\="false" description\="Comment for getter method" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.gettercomment" name\="gettercomment"/><template autoinsert\="false" context\="settercomment_context" deleted\="false" description\="Comment for setter method" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.settercomment" name\="settercomment"/><template autoinsert\="false" context\="constructorcomment_context" deleted\="false" description\="Comment for created constructors" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.constructorcomment" name\="constructorcomment"/><template autoinsert\="false" context\="filecomment_context" deleted\="false" description\="Comment for created Java files" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.filecomment" name\="filecomment">/*\r\n * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.\r\n * All rights reserved. This program and the accompanying materials\r\n * are made available under the terms of the Eclipse Public License v1.0\r\n * which accompanies this distribution, and is available at\r\n * http\://www.eclipse.org/legal/epl-v10.html\r\n * \r\n * Contributors\:\r\n * Eike Stepper - initial API and implementation\r\n */</template><template autoinsert\="false" context\="typecomment_context" deleted\="false" description\="Comment for created types" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.typecomment" name\="typecomment">/**\r\n * @author Eike Stepper\r\n */</template><template autoinsert\="false" context\="fieldcomment_context" deleted\="false" description\="Comment for fields" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.fieldcomment" name\="fieldcomment"/><template autoinsert\="false" context\="methodcomment_context" deleted\="false" description\="Comment for non-overriding methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.methodcomment" name\="methodcomment"/><template autoinsert\="false" context\="overridecomment_context" deleted\="false" description\="Comment for overriding methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.overridecomment" name\="overridecomment"/><template autoinsert\="false" context\="delegatecomment_context" deleted\="false" description\="Comment for delegate methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.delegatecomment" name\="delegatecomment"/><template autoinsert\="true" context\="newtype_context" deleted\="false" description\="Newly created files" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.newtype" name\="newtype">${filecomment}\r\n${package_declaration}\r\n\r\n${typecomment}\r\n${type_declaration}</template><template autoinsert\="true" context\="classbody_context" deleted\="false" description\="Code in new class type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.classbody" name\="classbody">\r\n</template><template autoinsert\="true" context\="interfacebody_context" deleted\="false" description\="Code in new interface type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.interfacebody" name\="interfacebody">\r\n</template><template autoinsert\="true" context\="enumbody_context" deleted\="false" description\="Code in new enum type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.enumbody" name\="enumbody">\r\n</template><template autoinsert\="true" context\="annotationbody_context" deleted\="false" description\="Code in new annotation type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.annotationbody" name\="annotationbody">\r\n</template><template autoinsert\="false" context\="catchblock_context" deleted\="false" description\="Code in new catch blocks" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.catchblock" name\="catchblock">${exception_var}.printStackTrace();</template><template autoinsert\="false" context\="methodbody_context" deleted\="false" description\="Code in created method stubs" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.methodbody" name\="methodbody">${body_statement}</template><template autoinsert\="false" context\="constructorbody_context" deleted\="false" description\="Code in created constructor stubs" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.constructorbody" name\="constructorbody">${body_statement}</template><template autoinsert\="true" context\="getterbody_context" deleted\="false" description\="Code in created getters" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.getterbody" name\="getterbody">return ${field};</template><template autoinsert\="true" context\="setterbody_context" deleted\="false" description\="Code in created setters" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.setterbody" name\="setterbody">${field} \= ${param};</template></templates> -sp_cleanup.add_default_serial_version_id=true -sp_cleanup.add_generated_serial_version_id=false -sp_cleanup.add_missing_annotations=true -sp_cleanup.add_missing_deprecated_annotations=true -sp_cleanup.add_missing_methods=false -sp_cleanup.add_missing_nls_tags=false -sp_cleanup.add_missing_override_annotations=true -sp_cleanup.add_missing_override_annotations_interface_methods=false -sp_cleanup.add_serial_version_id=false -sp_cleanup.always_use_blocks=true -sp_cleanup.always_use_parentheses_in_expressions=false -sp_cleanup.always_use_this_for_non_static_field_access=false -sp_cleanup.always_use_this_for_non_static_method_access=false -sp_cleanup.convert_to_enhanced_for_loop=false -sp_cleanup.correct_indentation=true -sp_cleanup.format_source_code=true -sp_cleanup.format_source_code_changes_only=false -sp_cleanup.make_local_variable_final=false -sp_cleanup.make_parameters_final=false -sp_cleanup.make_private_fields_final=true -sp_cleanup.make_type_abstract_if_missing_method=false -sp_cleanup.make_variable_declarations_final=false -sp_cleanup.never_use_blocks=false -sp_cleanup.never_use_parentheses_in_expressions=true -sp_cleanup.on_save_use_additional_actions=true -sp_cleanup.organize_imports=true -sp_cleanup.qualify_static_field_accesses_with_declaring_class=false -sp_cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true -sp_cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true -sp_cleanup.qualify_static_member_accesses_with_declaring_class=false -sp_cleanup.qualify_static_method_accesses_with_declaring_class=false -sp_cleanup.remove_private_constructors=true -sp_cleanup.remove_trailing_whitespaces=true -sp_cleanup.remove_trailing_whitespaces_all=true -sp_cleanup.remove_trailing_whitespaces_ignore_empty=false -sp_cleanup.remove_unnecessary_casts=true -sp_cleanup.remove_unnecessary_nls_tags=true -sp_cleanup.remove_unused_imports=true -sp_cleanup.remove_unused_local_variables=false -sp_cleanup.remove_unused_private_fields=true -sp_cleanup.remove_unused_private_members=false -sp_cleanup.remove_unused_private_methods=true -sp_cleanup.remove_unused_private_types=true -sp_cleanup.sort_members=false -sp_cleanup.sort_members_all=false -sp_cleanup.use_blocks=true -sp_cleanup.use_blocks_only_for_return_and_throw=false -sp_cleanup.use_parentheses_in_expressions=true -sp_cleanup.use_this_for_non_static_field_access=true -sp_cleanup.use_this_for_non_static_field_access_only_if_necessary=true -sp_cleanup.use_this_for_non_static_method_access=true -sp_cleanup.use_this_for_non_static_method_access_only_if_necessary=true +#Thu Feb 04 09:44:24 CET 2010
+cleanup.add_default_serial_version_id=true
+cleanup.add_generated_serial_version_id=false
+cleanup.add_missing_annotations=true
+cleanup.add_missing_deprecated_annotations=true
+cleanup.add_missing_methods=false
+cleanup.add_missing_nls_tags=false
+cleanup.add_missing_override_annotations=true
+cleanup.add_missing_override_annotations_interface_methods=true
+cleanup.add_serial_version_id=true
+cleanup.always_use_blocks=true
+cleanup.always_use_parentheses_in_expressions=false
+cleanup.always_use_this_for_non_static_field_access=false
+cleanup.always_use_this_for_non_static_method_access=false
+cleanup.convert_to_enhanced_for_loop=false
+cleanup.correct_indentation=true
+cleanup.format_source_code=true
+cleanup.format_source_code_changes_only=false
+cleanup.make_local_variable_final=true
+cleanup.make_parameters_final=false
+cleanup.make_private_fields_final=true
+cleanup.make_type_abstract_if_missing_method=false
+cleanup.make_variable_declarations_final=false
+cleanup.never_use_blocks=false
+cleanup.never_use_parentheses_in_expressions=true
+cleanup.organize_imports=true
+cleanup.qualify_static_field_accesses_with_declaring_class=false
+cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true
+cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true
+cleanup.qualify_static_member_accesses_with_declaring_class=false
+cleanup.qualify_static_method_accesses_with_declaring_class=false
+cleanup.remove_private_constructors=true
+cleanup.remove_trailing_whitespaces=true
+cleanup.remove_trailing_whitespaces_all=true
+cleanup.remove_trailing_whitespaces_ignore_empty=false
+cleanup.remove_unnecessary_casts=true
+cleanup.remove_unnecessary_nls_tags=true
+cleanup.remove_unused_imports=true
+cleanup.remove_unused_local_variables=false
+cleanup.remove_unused_private_fields=true
+cleanup.remove_unused_private_members=false
+cleanup.remove_unused_private_methods=true
+cleanup.remove_unused_private_types=true
+cleanup.sort_members=false
+cleanup.sort_members_all=false
+cleanup.use_blocks=true
+cleanup.use_blocks_only_for_return_and_throw=false
+cleanup.use_parentheses_in_expressions=true
+cleanup.use_this_for_non_static_field_access=true
+cleanup.use_this_for_non_static_field_access_only_if_necessary=true
+cleanup.use_this_for_non_static_method_access=true
+cleanup.use_this_for_non_static_method_access_only_if_necessary=true
+cleanup_profile=_EMFT
+cleanup_settings_version=2
+eclipse.preferences.version=1
+editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true
+formatter_profile=_EMFT
+formatter_settings_version=11
+org.eclipse.jdt.ui.exception.name=ex
+org.eclipse.jdt.ui.gettersetter.use.is=true
+org.eclipse.jdt.ui.ignorelowercasenames=true
+org.eclipse.jdt.ui.importorder=org.eclipse.emf.cdo;org.eclipse.emf.internal.cdo;org.eclipse.net4j;org.eclipse.internal.net4j;org.eclipse.emf;org.eclipse;com;org;javax;java;
+org.eclipse.jdt.ui.javadoc=true
+org.eclipse.jdt.ui.keywordthis=false
+org.eclipse.jdt.ui.ondemandthreshold=99
+org.eclipse.jdt.ui.overrideannotation=true
+org.eclipse.jdt.ui.staticondemandthreshold=99
+org.eclipse.jdt.ui.text.custom_code_templates=<?xml version\="1.0" encoding\="UTF-8" standalone\="no"?><templates><template autoinsert\="false" context\="gettercomment_context" deleted\="false" description\="Comment for getter method" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.gettercomment" name\="gettercomment"/><template autoinsert\="false" context\="settercomment_context" deleted\="false" description\="Comment for setter method" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.settercomment" name\="settercomment"/><template autoinsert\="false" context\="constructorcomment_context" deleted\="false" description\="Comment for created constructors" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.constructorcomment" name\="constructorcomment"/><template autoinsert\="false" context\="filecomment_context" deleted\="false" description\="Comment for created Java files" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.filecomment" name\="filecomment">/*\r\n * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.\r\n * All rights reserved. This program and the accompanying materials\r\n * are made available under the terms of the Eclipse Public License v1.0\r\n * which accompanies this distribution, and is available at\r\n * http\://www.eclipse.org/legal/epl-v10.html\r\n * \r\n * Contributors\:\r\n * Eike Stepper - initial API and implementation\r\n */</template><template autoinsert\="false" context\="typecomment_context" deleted\="false" description\="Comment for created types" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.typecomment" name\="typecomment">/**\r\n * @author Eike Stepper\r\n */</template><template autoinsert\="false" context\="fieldcomment_context" deleted\="false" description\="Comment for fields" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.fieldcomment" name\="fieldcomment"/><template autoinsert\="false" context\="methodcomment_context" deleted\="false" description\="Comment for non-overriding methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.methodcomment" name\="methodcomment"/><template autoinsert\="false" context\="overridecomment_context" deleted\="false" description\="Comment for overriding methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.overridecomment" name\="overridecomment"/><template autoinsert\="false" context\="delegatecomment_context" deleted\="false" description\="Comment for delegate methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.delegatecomment" name\="delegatecomment"/><template autoinsert\="true" context\="newtype_context" deleted\="false" description\="Newly created files" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.newtype" name\="newtype">${filecomment}\r\n${package_declaration}\r\n\r\n${typecomment}\r\n${type_declaration}</template><template autoinsert\="true" context\="classbody_context" deleted\="false" description\="Code in new class type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.classbody" name\="classbody">\r\n</template><template autoinsert\="true" context\="interfacebody_context" deleted\="false" description\="Code in new interface type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.interfacebody" name\="interfacebody">\r\n</template><template autoinsert\="true" context\="enumbody_context" deleted\="false" description\="Code in new enum type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.enumbody" name\="enumbody">\r\n</template><template autoinsert\="true" context\="annotationbody_context" deleted\="false" description\="Code in new annotation type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.annotationbody" name\="annotationbody">\r\n</template><template autoinsert\="false" context\="catchblock_context" deleted\="false" description\="Code in new catch blocks" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.catchblock" name\="catchblock">${exception_var}.printStackTrace();</template><template autoinsert\="false" context\="methodbody_context" deleted\="false" description\="Code in created method stubs" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.methodbody" name\="methodbody">${body_statement}</template><template autoinsert\="false" context\="constructorbody_context" deleted\="false" description\="Code in created constructor stubs" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.constructorbody" name\="constructorbody">${body_statement}</template><template autoinsert\="true" context\="getterbody_context" deleted\="false" description\="Code in created getters" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.getterbody" name\="getterbody">return ${field};</template><template autoinsert\="true" context\="setterbody_context" deleted\="false" description\="Code in created setters" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.setterbody" name\="setterbody">${field} \= ${param};</template></templates>
+sp_cleanup.add_default_serial_version_id=true
+sp_cleanup.add_generated_serial_version_id=false
+sp_cleanup.add_missing_annotations=true
+sp_cleanup.add_missing_deprecated_annotations=true
+sp_cleanup.add_missing_methods=false
+sp_cleanup.add_missing_nls_tags=false
+sp_cleanup.add_missing_override_annotations=true
+sp_cleanup.add_missing_override_annotations_interface_methods=false
+sp_cleanup.add_serial_version_id=false
+sp_cleanup.always_use_blocks=true
+sp_cleanup.always_use_parentheses_in_expressions=false
+sp_cleanup.always_use_this_for_non_static_field_access=false
+sp_cleanup.always_use_this_for_non_static_method_access=false
+sp_cleanup.convert_to_enhanced_for_loop=false
+sp_cleanup.correct_indentation=true
+sp_cleanup.format_source_code=true
+sp_cleanup.format_source_code_changes_only=false
+sp_cleanup.make_local_variable_final=false
+sp_cleanup.make_parameters_final=false
+sp_cleanup.make_private_fields_final=true
+sp_cleanup.make_type_abstract_if_missing_method=false
+sp_cleanup.make_variable_declarations_final=false
+sp_cleanup.never_use_blocks=false
+sp_cleanup.never_use_parentheses_in_expressions=true
+sp_cleanup.on_save_use_additional_actions=true
+sp_cleanup.organize_imports=true
+sp_cleanup.qualify_static_field_accesses_with_declaring_class=false
+sp_cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true
+sp_cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true
+sp_cleanup.qualify_static_member_accesses_with_declaring_class=false
+sp_cleanup.qualify_static_method_accesses_with_declaring_class=false
+sp_cleanup.remove_private_constructors=true
+sp_cleanup.remove_trailing_whitespaces=true
+sp_cleanup.remove_trailing_whitespaces_all=true
+sp_cleanup.remove_trailing_whitespaces_ignore_empty=false
+sp_cleanup.remove_unnecessary_casts=true
+sp_cleanup.remove_unnecessary_nls_tags=true
+sp_cleanup.remove_unused_imports=true
+sp_cleanup.remove_unused_local_variables=false
+sp_cleanup.remove_unused_private_fields=true
+sp_cleanup.remove_unused_private_members=false
+sp_cleanup.remove_unused_private_methods=true
+sp_cleanup.remove_unused_private_types=true
+sp_cleanup.sort_members=false
+sp_cleanup.sort_members_all=false
+sp_cleanup.use_blocks=true
+sp_cleanup.use_blocks_only_for_return_and_throw=false
+sp_cleanup.use_parentheses_in_expressions=true
+sp_cleanup.use_this_for_non_static_field_access=true
+sp_cleanup.use_this_for_non_static_field_access_only_if_necessary=true
+sp_cleanup.use_this_for_non_static_method_access=true
+sp_cleanup.use_this_for_non_static_method_access_only_if_necessary=true
diff --git a/plugins/org.eclipse.net4j.util.ui/Snippet1.java b/plugins/org.eclipse.net4j.util.ui/Snippet1.java index 0e92c24953..954296a05b 100644 --- a/plugins/org.eclipse.net4j.util.ui/Snippet1.java +++ b/plugins/org.eclipse.net4j.util.ui/Snippet1.java @@ -1,121 +1,121 @@ -/* - * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) 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: - * Eike Stepper - initial API and implementation - */ -package org.eclipse.net4j.util.ui.container.examples; - -import org.eclipse.net4j.util.container.IPluginContainer; -import org.eclipse.net4j.util.factory.Factory; -import org.eclipse.net4j.util.factory.ProductCreationException; -import org.eclipse.net4j.util.ui.UIUtil; -import org.eclipse.net4j.util.ui.container.ElementWizard; -import org.eclipse.net4j.util.ui.container.ElementWizardComposite; -import org.eclipse.net4j.util.ui.container.ElementWizardFactory; -import org.eclipse.net4j.util.ui.container.IElementWizard; - -import org.eclipse.swt.SWT; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Text; - -/** - * @author Eike Stepper - */ -public class Snippet1 -{ - public static void main(String[] args) - { - IPluginContainer container = IPluginContainer.INSTANCE; - String PG = "test.connectors"; - - container.registerFactory(new Factory(PG, "tcp") - { - public Object create(String description) throws ProductCreationException - { - return null; - } - }); - - container.registerFactory(new Factory(PG, "jvm") - { - public Object create(String description) throws ProductCreationException - { - return null; - } - }); - - container.registerFactory(new Factory(PG, "http") - { - public Object create(String description) throws ProductCreationException - { - return null; - } - }); - - container.registerFactory(new ElementWizardFactory(PG, "http") - { - @Override - public IElementWizard create(String description) throws ProductCreationException - { - return new ElementWizard() - { - @Override - protected void create(Composite parent) - { - addText(parent, "Server:"); - addCombo(parent, "Protocol:", "http", "https"); - addText(parent, "Resource:"); - } - }; - } - }); - - container.registerFactory(new ElementWizardFactory(PG, "tcp") - { - @Override - public IElementWizard create(String description) throws ProductCreationException - { - return new ElementWizard() - { - @Override - protected void create(Composite parent) - { - Label l1 = new Label(parent, SWT.NONE); - l1.setText("Hostname:"); - l1.setLayoutData(UIUtil.createGridData(false, false)); - - Text t1 = new Text(parent, SWT.BORDER); - t1.setLayoutData(UIUtil.createGridData(true, false)); - } - }; - } - }); - - Display display = new Display(); - Shell shell = new Shell(display); - shell.setLayout(new GridLayout(1, false)); - - new ElementWizardComposite.WithCombo(shell, SWT.NONE, PG, "Type:"); - - shell.pack(); - shell.open(); - while (!shell.isDisposed()) - { - if (!display.readAndDispatch()) - { - display.sleep(); - } - } - - display.dispose(); - } -} +/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.util.ui.container.examples;
+
+import org.eclipse.net4j.util.container.IPluginContainer;
+import org.eclipse.net4j.util.factory.Factory;
+import org.eclipse.net4j.util.factory.ProductCreationException;
+import org.eclipse.net4j.util.ui.UIUtil;
+import org.eclipse.net4j.util.ui.container.ElementWizard;
+import org.eclipse.net4j.util.ui.container.ElementWizardComposite;
+import org.eclipse.net4j.util.ui.container.ElementWizardFactory;
+import org.eclipse.net4j.util.ui.container.IElementWizard;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+
+/**
+ * @author Eike Stepper
+ */
+public class Snippet1
+{
+ public static void main(String[] args)
+ {
+ IPluginContainer container = IPluginContainer.INSTANCE;
+ String PG = "test.connectors";
+
+ container.registerFactory(new Factory(PG, "tcp")
+ {
+ public Object create(String description) throws ProductCreationException
+ {
+ return null;
+ }
+ });
+
+ container.registerFactory(new Factory(PG, "jvm")
+ {
+ public Object create(String description) throws ProductCreationException
+ {
+ return null;
+ }
+ });
+
+ container.registerFactory(new Factory(PG, "http")
+ {
+ public Object create(String description) throws ProductCreationException
+ {
+ return null;
+ }
+ });
+
+ container.registerFactory(new ElementWizardFactory(PG, "http")
+ {
+ @Override
+ public IElementWizard create(String description) throws ProductCreationException
+ {
+ return new ElementWizard()
+ {
+ @Override
+ protected void create(Composite parent)
+ {
+ addText(parent, "Server:");
+ addCombo(parent, "Protocol:", "http", "https");
+ addText(parent, "Resource:");
+ }
+ };
+ }
+ });
+
+ container.registerFactory(new ElementWizardFactory(PG, "tcp")
+ {
+ @Override
+ public IElementWizard create(String description) throws ProductCreationException
+ {
+ return new ElementWizard()
+ {
+ @Override
+ protected void create(Composite parent)
+ {
+ Label l1 = new Label(parent, SWT.NONE);
+ l1.setText("Hostname:");
+ l1.setLayoutData(UIUtil.createGridData(false, false));
+
+ Text t1 = new Text(parent, SWT.BORDER);
+ t1.setLayoutData(UIUtil.createGridData(true, false));
+ }
+ };
+ }
+ });
+
+ Display display = new Display();
+ Shell shell = new Shell(display);
+ shell.setLayout(new GridLayout(1, false));
+
+ new ElementWizardComposite.WithCombo(shell, SWT.NONE, PG, "Type:");
+
+ shell.pack();
+ shell.open();
+ while (!shell.isDisposed())
+ {
+ if (!display.readAndDispatch())
+ {
+ display.sleep();
+ }
+ }
+
+ display.dispose();
+ }
+}
diff --git a/plugins/org.eclipse.net4j.util.ui/build.properties b/plugins/org.eclipse.net4j.util.ui/build.properties index 6e3f7711a9..c412fc31d8 100644 --- a/plugins/org.eclipse.net4j.util.ui/build.properties +++ b/plugins/org.eclipse.net4j.util.ui/build.properties @@ -1,24 +1,24 @@ -# Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) 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: -# Eike Stepper - initial API and implementation - -# NLS_MESSAGEFORMAT_VAR - -source.. = src/ -output.. = bin/ -bin.includes = META-INF/,\ - .,\ - .options,\ - about.html,\ - copyright.txt,\ - plugin.properties,\ - plugin.xml -src.includes = about.html,\ - copyright.txt - -doc.project = org.eclipse.net4j.util.doc +# Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
+# Eike Stepper - initial API and implementation
+
+# NLS_MESSAGEFORMAT_VAR
+
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .,\
+ .options,\
+ about.html,\
+ copyright.txt,\
+ plugin.properties,\
+ plugin.xml
+src.includes = about.html,\
+ copyright.txt
+
+doc.project = org.eclipse.net4j.util.doc
diff --git a/plugins/org.eclipse.net4j.util.ui/copyright.txt b/plugins/org.eclipse.net4j.util.ui/copyright.txt index e921242cf0..8f6328980e 100644 --- a/plugins/org.eclipse.net4j.util.ui/copyright.txt +++ b/plugins/org.eclipse.net4j.util.ui/copyright.txt @@ -1,8 +1,8 @@ -Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) 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: +Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
Eike Stepper - initial API and implementation
\ No newline at end of file diff --git a/plugins/org.eclipse.net4j.util.ui/plugin.properties b/plugins/org.eclipse.net4j.util.ui/plugin.properties index e90cde7863..7285e0fd87 100644 --- a/plugins/org.eclipse.net4j.util.ui/plugin.properties +++ b/plugins/org.eclipse.net4j.util.ui/plugin.properties @@ -1,15 +1,15 @@ -# Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) 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: -# Eike Stepper - initial API and implementation - -pluginName = Net4j Utilities UI -providerName = Eclipse Modeling Project - -category.name = Net4j Debug -view.name = Container -view.name.0 = Introspector +# Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
+# Eike Stepper - initial API and implementation
+
+pluginName = Net4j Utilities UI
+providerName = Eclipse Modeling Project
+
+category.name = Net4j Debug
+view.name = Container
+view.name.0 = Introspector
diff --git a/plugins/org.eclipse.net4j.util.ui/plugin.xml b/plugins/org.eclipse.net4j.util.ui/plugin.xml index a9be02b344..131156c697 100644 --- a/plugins/org.eclipse.net4j.util.ui/plugin.xml +++ b/plugins/org.eclipse.net4j.util.ui/plugin.xml @@ -1,45 +1,45 @@ -<?xml version="1.0" encoding="UTF-8"?> -<?eclipse version="3.4"?> -<!-- - Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) 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: - Eike Stepper - initial API and implementation ---> - -<plugin> - - <extension - point="org.eclipse.ui.views"> - <category - id="org.eclipse.net4j.debug" - name="%category.name"> - </category> - <view - category="org.eclipse.net4j.debug" - id="org.eclipse.net4j.util.Net4jContainerView" - class="org.eclipse.net4j.util.internal.ui.views.Net4jContainerView" - name="%view.name" - icon="platform:/plugin/org.eclipse.net4j.ui.shared/icons/full/view16/container.gif"/> - <view - category="org.eclipse.net4j.debug" - id="org.eclipse.net4j.util.Net4jIntrospectorView" - class="org.eclipse.net4j.util.internal.ui.views.Net4jIntrospectorView" - name="%view.name.0" - icon="platform:/plugin/org.eclipse.net4j.ui.shared/icons/full/view16/javabean.gif"/> - </extension> - - <extension - point="org.eclipse.net4j.util.factories"> - <factory - class="org.eclipse.net4j.util.internal.ui.InteractiveCredentialsProviderFactory" - productGroup="org.eclipse.net4j.util.security.credentialsProviders" - type="interactive"> - </factory> - </extension> - -</plugin> +<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.4"?>
+<!--
+ Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
+ Eike Stepper - initial API and implementation
+-->
+
+<plugin>
+
+ <extension
+ point="org.eclipse.ui.views">
+ <category
+ id="org.eclipse.net4j.debug"
+ name="%category.name">
+ </category>
+ <view
+ category="org.eclipse.net4j.debug"
+ id="org.eclipse.net4j.util.Net4jContainerView"
+ class="org.eclipse.net4j.util.internal.ui.views.Net4jContainerView"
+ name="%view.name"
+ icon="platform:/plugin/org.eclipse.net4j.ui.shared/icons/full/view16/container.gif"/>
+ <view
+ category="org.eclipse.net4j.debug"
+ id="org.eclipse.net4j.util.Net4jIntrospectorView"
+ class="org.eclipse.net4j.util.internal.ui.views.Net4jIntrospectorView"
+ name="%view.name.0"
+ icon="platform:/plugin/org.eclipse.net4j.ui.shared/icons/full/view16/javabean.gif"/>
+ </extension>
+
+ <extension
+ point="org.eclipse.net4j.util.factories">
+ <factory
+ class="org.eclipse.net4j.util.internal.ui.InteractiveCredentialsProviderFactory"
+ productGroup="org.eclipse.net4j.util.security.credentialsProviders"
+ type="interactive">
+ </factory>
+ </extension>
+
+</plugin>
diff --git a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/internal/ui/InteractiveCredentialsProviderFactory.java b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/internal/ui/InteractiveCredentialsProviderFactory.java index 5f32faf741..247eb84bde 100644 --- a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/internal/ui/InteractiveCredentialsProviderFactory.java +++ b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/internal/ui/InteractiveCredentialsProviderFactory.java @@ -1,35 +1,35 @@ -/* - * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) 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: - * Eike Stepper - initial API and implementation - */ -package org.eclipse.net4j.util.internal.ui; - -import org.eclipse.net4j.util.factory.ProductCreationException; -import org.eclipse.net4j.util.security.CredentialsProviderFactory; -import org.eclipse.net4j.util.security.IPasswordCredentialsProvider; -import org.eclipse.net4j.util.ui.UIUtil; - -/** - * @author Eike Stepper - */ -public class InteractiveCredentialsProviderFactory extends CredentialsProviderFactory -{ - public static final String TYPE = "interactive"; //$NON-NLS-1$ - - public InteractiveCredentialsProviderFactory() - { - super(TYPE); - } - - @Override - public IPasswordCredentialsProvider create(String description) throws ProductCreationException - { - return UIUtil.createInteractiveCredentialsProvider(); - } -} +/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.util.internal.ui;
+
+import org.eclipse.net4j.util.factory.ProductCreationException;
+import org.eclipse.net4j.util.security.CredentialsProviderFactory;
+import org.eclipse.net4j.util.security.IPasswordCredentialsProvider;
+import org.eclipse.net4j.util.ui.UIUtil;
+
+/**
+ * @author Eike Stepper
+ */
+public class InteractiveCredentialsProviderFactory extends CredentialsProviderFactory
+{
+ public static final String TYPE = "interactive"; //$NON-NLS-1$
+
+ public InteractiveCredentialsProviderFactory()
+ {
+ super(TYPE);
+ }
+
+ @Override
+ public IPasswordCredentialsProvider create(String description) throws ProductCreationException
+ {
+ return UIUtil.createInteractiveCredentialsProvider();
+ }
+}
diff --git a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/internal/ui/actions/IntrospectAction.java b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/internal/ui/actions/IntrospectAction.java index 0d70f224ea..586830b6bf 100644 --- a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/internal/ui/actions/IntrospectAction.java +++ b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/internal/ui/actions/IntrospectAction.java @@ -1,36 +1,36 @@ -/* - * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) 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: - * Eike Stepper - initial API and implementation - */ -package org.eclipse.net4j.util.internal.ui.actions; - -import org.eclipse.net4j.util.internal.ui.messages.Messages; -import org.eclipse.net4j.util.internal.ui.views.Net4jIntrospectorView; -import org.eclipse.net4j.util.ui.actions.SafeAction; - -/** - * @author Eike Stepper - */ -public class IntrospectAction extends SafeAction -{ - private Object object; - - public IntrospectAction(Object object) - { - super(Messages.getString("IntrospectAction_0")); //$NON-NLS-1$ - this.object = object; - } - - @Override - protected void safeRun() throws Exception - { - Net4jIntrospectorView introspector = Net4jIntrospectorView.getInstance(true); - introspector.setObject(object); - } -} +/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.util.internal.ui.actions;
+
+import org.eclipse.net4j.util.internal.ui.messages.Messages;
+import org.eclipse.net4j.util.internal.ui.views.Net4jIntrospectorView;
+import org.eclipse.net4j.util.ui.actions.SafeAction;
+
+/**
+ * @author Eike Stepper
+ */
+public class IntrospectAction extends SafeAction
+{
+ private Object object;
+
+ public IntrospectAction(Object object)
+ {
+ super(Messages.getString("IntrospectAction_0")); //$NON-NLS-1$
+ this.object = object;
+ }
+
+ @Override
+ protected void safeRun() throws Exception
+ {
+ Net4jIntrospectorView introspector = Net4jIntrospectorView.getInstance(true);
+ introspector.setObject(object);
+ }
+}
diff --git a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/internal/ui/bundle/OM.java b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/internal/ui/bundle/OM.java index 97ec28b309..dd11bca876 100644 --- a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/internal/ui/bundle/OM.java +++ b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/internal/ui/bundle/OM.java @@ -1,54 +1,54 @@ -/* - * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) 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: - * Eike Stepper - initial API and implementation - */ -package org.eclipse.net4j.util.internal.ui.bundle; - -import org.eclipse.net4j.util.om.OMBundle; -import org.eclipse.net4j.util.om.OMPlatform; -import org.eclipse.net4j.util.om.log.OMLogger; -import org.eclipse.net4j.util.om.trace.OMTracer; -import org.eclipse.net4j.util.ui.UIActivator; - -import org.eclipse.jface.resource.ImageDescriptor; - -/** - * The <em>Operations & Maintenance</em> class of this bundle. - * - * @author Eike Stepper - */ -public abstract class OM -{ - public static final String BUNDLE_ID = "org.eclipse.net4j.util.ui"; //$NON-NLS-1$ - - public static final OMBundle BUNDLE = OMPlatform.INSTANCE.bundle(BUNDLE_ID, OM.class); - - public static final OMTracer DEBUG = BUNDLE.tracer("debug"); //$NON-NLS-1$ - - public static final OMLogger LOG = BUNDLE.logger(); - - public static ImageDescriptor getImageDescriptor(String imageFilePath) - { - return Activator.imageDescriptorFromPlugin(BUNDLE_ID, imageFilePath); - } - - /** - * @author Eike Stepper - */ - public static final class Activator extends UIActivator - { - public static Activator INSTANCE; - - public Activator() - { - super(BUNDLE); - INSTANCE = this; - } - } -} +/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.util.internal.ui.bundle;
+
+import org.eclipse.net4j.util.om.OMBundle;
+import org.eclipse.net4j.util.om.OMPlatform;
+import org.eclipse.net4j.util.om.log.OMLogger;
+import org.eclipse.net4j.util.om.trace.OMTracer;
+import org.eclipse.net4j.util.ui.UIActivator;
+
+import org.eclipse.jface.resource.ImageDescriptor;
+
+/**
+ * The <em>Operations & Maintenance</em> class of this bundle.
+ *
+ * @author Eike Stepper
+ */
+public abstract class OM
+{
+ public static final String BUNDLE_ID = "org.eclipse.net4j.util.ui"; //$NON-NLS-1$
+
+ public static final OMBundle BUNDLE = OMPlatform.INSTANCE.bundle(BUNDLE_ID, OM.class);
+
+ public static final OMTracer DEBUG = BUNDLE.tracer("debug"); //$NON-NLS-1$
+
+ public static final OMLogger LOG = BUNDLE.logger();
+
+ public static ImageDescriptor getImageDescriptor(String imageFilePath)
+ {
+ return Activator.imageDescriptorFromPlugin(BUNDLE_ID, imageFilePath);
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ public static final class Activator extends UIActivator
+ {
+ public static Activator INSTANCE;
+
+ public Activator()
+ {
+ super(BUNDLE);
+ INSTANCE = this;
+ }
+ }
+}
diff --git a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/internal/ui/messages/Messages.java b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/internal/ui/messages/Messages.java index 5409294be7..3e3f6d7bef 100644 --- a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/internal/ui/messages/Messages.java +++ b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/internal/ui/messages/Messages.java @@ -1,41 +1,41 @@ -/* - * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) 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: - * Victor Roldan Betancort - initial API and implementation - * Eike Stepper - maintenance - */ -package org.eclipse.net4j.util.internal.ui.messages; - -import java.util.MissingResourceException; -import java.util.ResourceBundle; - -/** - * @author Victor Roldan Betancort - */ -public class Messages -{ - private static final String BUNDLE_NAME = "org.eclipse.net4j.util.internal.ui.messages.messages"; //$NON-NLS-1$ - - private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME); - - private Messages() - { - } - - public static String getString(String key) - { - try - { - return RESOURCE_BUNDLE.getString(key); - } - catch (MissingResourceException e) - { - return '!' + key + '!'; - } - } -} +/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
+ * Victor Roldan Betancort - initial API and implementation
+ * Eike Stepper - maintenance
+ */
+package org.eclipse.net4j.util.internal.ui.messages;
+
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+/**
+ * @author Victor Roldan Betancort
+ */
+public class Messages
+{
+ private static final String BUNDLE_NAME = "org.eclipse.net4j.util.internal.ui.messages.messages"; //$NON-NLS-1$
+
+ private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME);
+
+ private Messages()
+ {
+ }
+
+ public static String getString(String key)
+ {
+ try
+ {
+ return RESOURCE_BUNDLE.getString(key);
+ }
+ catch (MissingResourceException e)
+ {
+ return '!' + key + '!';
+ }
+ }
+}
diff --git a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/internal/ui/messages/messages.properties b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/internal/ui/messages/messages.properties index af6ab927fb..fed153b915 100644 --- a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/internal/ui/messages/messages.properties +++ b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/internal/ui/messages/messages.properties @@ -1,58 +1,58 @@ -# ============================================================================== -# Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) 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: -# Victor Roldan Betancort - initial API and implementation -# Eike Stepper - maintenance -# ============================================================================== - -# ============================================================================== -# This properties file contains all strings subject to be shown in the UI. -# ============================================================================== - -ContainerView_1=Refresh -ContainerView_2=Refresh view -CredentialsDialog_1=Enter your user ID and password. -CredentialsDialog_2=User ID: -CredentialsDialog_3=Password: -CredentialsDialog_0=Login -IntrospectAction_0=Introspect -MasterDetailsView_2=Refresh -MasterDetailsView_3=Refresh -Net4jContainerItemProvider_0=Remove -Net4jContainerItemProvider.1=Remove -Net4jIntrospectorView_1= -Net4jIntrospectorView_10=Type -Net4jIntrospectorView_11=Element -Net4jIntrospectorView_12=Type -Net4jIntrospectorView_13=Index -Net4jIntrospectorView_14=Element -Net4jIntrospectorView_15=Type -Net4jIntrospectorView_16=Back -Net4jIntrospectorView_17=Container -Net4jIntrospectorView_18=null -Net4jIntrospectorView_21=null -Net4jIntrospectorView_22= -Net4jIntrospectorView_24=null -Net4jIntrospectorView_25= -Net4jIntrospectorView_27=null -Net4jIntrospectorView_28=null -Net4jIntrospectorView_29= -Net4jIntrospectorView_4=Field -Net4jIntrospectorView_5=Value -Net4jIntrospectorView_6=Declared Type -Net4jIntrospectorView_7=Concrete Type -Net4jIntrospectorView_8=Key -Net4jIntrospectorView_9=Value -SafeAction_0=... -SafeAction_1=See the Error log for details. -SafeActionDelegate_0=See the Error log for details. -SafeActionDelegate_1=Error -SashLayoutAction_0=Vertical -SashLayoutAction_1=Horizontal -SashLayoutAction_2=Layout -TextAndDisable.0=Disabled +# ==============================================================================
+# Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
+# Victor Roldan Betancort - initial API and implementation
+# Eike Stepper - maintenance
+# ==============================================================================
+
+# ==============================================================================
+# This properties file contains all strings subject to be shown in the UI.
+# ==============================================================================
+
+ContainerView_1=Refresh
+ContainerView_2=Refresh view
+CredentialsDialog_1=Enter your user ID and password.
+CredentialsDialog_2=User ID:
+CredentialsDialog_3=Password:
+CredentialsDialog_0=Login
+IntrospectAction_0=Introspect
+MasterDetailsView_2=Refresh
+MasterDetailsView_3=Refresh
+Net4jContainerItemProvider_0=Remove
+Net4jContainerItemProvider.1=Remove
+Net4jIntrospectorView_1=
+Net4jIntrospectorView_10=Type
+Net4jIntrospectorView_11=Element
+Net4jIntrospectorView_12=Type
+Net4jIntrospectorView_13=Index
+Net4jIntrospectorView_14=Element
+Net4jIntrospectorView_15=Type
+Net4jIntrospectorView_16=Back
+Net4jIntrospectorView_17=Container
+Net4jIntrospectorView_18=null
+Net4jIntrospectorView_21=null
+Net4jIntrospectorView_22=
+Net4jIntrospectorView_24=null
+Net4jIntrospectorView_25=
+Net4jIntrospectorView_27=null
+Net4jIntrospectorView_28=null
+Net4jIntrospectorView_29=
+Net4jIntrospectorView_4=Field
+Net4jIntrospectorView_5=Value
+Net4jIntrospectorView_6=Declared Type
+Net4jIntrospectorView_7=Concrete Type
+Net4jIntrospectorView_8=Key
+Net4jIntrospectorView_9=Value
+SafeAction_0=...
+SafeAction_1=See the Error log for details.
+SafeActionDelegate_0=See the Error log for details.
+SafeActionDelegate_1=Error
+SashLayoutAction_0=Vertical
+SashLayoutAction_1=Horizontal
+SashLayoutAction_2=Layout
+TextAndDisable.0=Disabled
diff --git a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/internal/ui/views/Net4jContainerItemProvider.java b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/internal/ui/views/Net4jContainerItemProvider.java index 2db29211f5..58ef335e0e 100644 --- a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/internal/ui/views/Net4jContainerItemProvider.java +++ b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/internal/ui/views/Net4jContainerItemProvider.java @@ -1,79 +1,79 @@ -/* - * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) 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: - * Eike Stepper - initial API and implementation - */ -package org.eclipse.net4j.util.internal.ui.views; - -import org.eclipse.net4j.ui.shared.SharedIcons; -import org.eclipse.net4j.util.container.IContainer; -import org.eclipse.net4j.util.internal.ui.messages.Messages; -import org.eclipse.net4j.util.lifecycle.LifecycleUtil; -import org.eclipse.net4j.util.ui.actions.LongRunningAction; -import org.eclipse.net4j.util.ui.views.ContainerItemProvider; -import org.eclipse.net4j.util.ui.views.ContainerView; -import org.eclipse.net4j.util.ui.views.IElementFilter; - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.jface.action.IMenuManager; -import org.eclipse.jface.viewers.ITreeSelection; -import org.eclipse.swt.graphics.Image; - -import java.util.Iterator; - -/** - * @author Eike Stepper - */ -public class Net4jContainerItemProvider extends ContainerItemProvider<IContainer<Object>> -{ - public Net4jContainerItemProvider() - { - } - - public Net4jContainerItemProvider(IElementFilter rootElementFilter) - { - super(rootElementFilter); - } - - @Override - protected void fillContextMenu(IMenuManager manager, ITreeSelection selection) - { - manager.add(new RemoveAction(selection)); - } - - @Override - public Image getImage(Object obj) - { - return SharedIcons.getImage(SharedIcons.OBJ_BEAN); - } - - /** - * @author Eike Stepper - */ - public class RemoveAction extends LongRunningAction - { - private ITreeSelection selection; - - public RemoveAction(ITreeSelection selection) - { - super( - Messages.getString("Net4jContainerItemProvider_0"), Messages.getString("Net4jContainerItemProvider.1"), ContainerView.getDeleteImageDescriptor()); //$NON-NLS-1$ //$NON-NLS-2$ - this.selection = selection; - } - - @Override - protected void doRun(IProgressMonitor progressMonitor) throws Exception - { - for (Iterator<?> it = selection.iterator(); it.hasNext();) - { - Object object = it.next(); - LifecycleUtil.deactivate(object); - } - } - } -} +/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.util.internal.ui.views;
+
+import org.eclipse.net4j.ui.shared.SharedIcons;
+import org.eclipse.net4j.util.container.IContainer;
+import org.eclipse.net4j.util.internal.ui.messages.Messages;
+import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
+import org.eclipse.net4j.util.ui.actions.LongRunningAction;
+import org.eclipse.net4j.util.ui.views.ContainerItemProvider;
+import org.eclipse.net4j.util.ui.views.ContainerView;
+import org.eclipse.net4j.util.ui.views.IElementFilter;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.viewers.ITreeSelection;
+import org.eclipse.swt.graphics.Image;
+
+import java.util.Iterator;
+
+/**
+ * @author Eike Stepper
+ */
+public class Net4jContainerItemProvider extends ContainerItemProvider<IContainer<Object>>
+{
+ public Net4jContainerItemProvider()
+ {
+ }
+
+ public Net4jContainerItemProvider(IElementFilter rootElementFilter)
+ {
+ super(rootElementFilter);
+ }
+
+ @Override
+ protected void fillContextMenu(IMenuManager manager, ITreeSelection selection)
+ {
+ manager.add(new RemoveAction(selection));
+ }
+
+ @Override
+ public Image getImage(Object obj)
+ {
+ return SharedIcons.getImage(SharedIcons.OBJ_BEAN);
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ public class RemoveAction extends LongRunningAction
+ {
+ private ITreeSelection selection;
+
+ public RemoveAction(ITreeSelection selection)
+ {
+ super(
+ Messages.getString("Net4jContainerItemProvider_0"), Messages.getString("Net4jContainerItemProvider.1"), ContainerView.getDeleteImageDescriptor()); //$NON-NLS-1$ //$NON-NLS-2$
+ this.selection = selection;
+ }
+
+ @Override
+ protected void doRun(IProgressMonitor progressMonitor) throws Exception
+ {
+ for (Iterator<?> it = selection.iterator(); it.hasNext();)
+ {
+ Object object = it.next();
+ LifecycleUtil.deactivate(object);
+ }
+ }
+ }
+}
diff --git a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/internal/ui/views/Net4jContainerView.java b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/internal/ui/views/Net4jContainerView.java index 624267a92a..50d952661a 100644 --- a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/internal/ui/views/Net4jContainerView.java +++ b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/internal/ui/views/Net4jContainerView.java @@ -1,36 +1,36 @@ -/* - * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) 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: - * Eike Stepper - initial API and implementation - */ -package org.eclipse.net4j.util.internal.ui.views; - -import org.eclipse.net4j.util.container.IContainer; -import org.eclipse.net4j.util.container.IManagedContainer; -import org.eclipse.net4j.util.container.IPluginContainer; -import org.eclipse.net4j.util.ui.views.ContainerItemProvider; -import org.eclipse.net4j.util.ui.views.ContainerView; - -public class Net4jContainerView extends ContainerView -{ - public Net4jContainerView() - { - } - - @Override - protected ContainerItemProvider<IContainer<Object>> createContainerItemProvider() - { - return new Net4jContainerItemProvider(); - } - - @Override - protected IManagedContainer getContainer() - { - return IPluginContainer.INSTANCE; - } -} +/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.util.internal.ui.views;
+
+import org.eclipse.net4j.util.container.IContainer;
+import org.eclipse.net4j.util.container.IManagedContainer;
+import org.eclipse.net4j.util.container.IPluginContainer;
+import org.eclipse.net4j.util.ui.views.ContainerItemProvider;
+import org.eclipse.net4j.util.ui.views.ContainerView;
+
+public class Net4jContainerView extends ContainerView
+{
+ public Net4jContainerView()
+ {
+ }
+
+ @Override
+ protected ContainerItemProvider<IContainer<Object>> createContainerItemProvider()
+ {
+ return new Net4jContainerItemProvider();
+ }
+
+ @Override
+ protected IManagedContainer getContainer()
+ {
+ return IPluginContainer.INSTANCE;
+ }
+}
diff --git a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/internal/ui/views/Net4jIntrospectorView.java b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/internal/ui/views/Net4jIntrospectorView.java index 980e01ef17..c668363df1 100644 --- a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/internal/ui/views/Net4jIntrospectorView.java +++ b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/internal/ui/views/Net4jIntrospectorView.java @@ -1,743 +1,743 @@ -/* - * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) 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: - * Eike Stepper - initial API and implementation - */ -package org.eclipse.net4j.util.internal.ui.views; - -import org.eclipse.net4j.ui.shared.SharedIcons; -import org.eclipse.net4j.util.ReflectUtil; -import org.eclipse.net4j.util.WrappedException; -import org.eclipse.net4j.util.collection.Pair; -import org.eclipse.net4j.util.container.IPluginContainer; -import org.eclipse.net4j.util.event.EventUtil; -import org.eclipse.net4j.util.event.IEvent; -import org.eclipse.net4j.util.event.IListener; -import org.eclipse.net4j.util.internal.ui.bundle.OM; -import org.eclipse.net4j.util.internal.ui.messages.Messages; -import org.eclipse.net4j.util.ui.UIUtil; - -import org.eclipse.jface.action.Action; -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.action.IMenuManager; -import org.eclipse.jface.action.IToolBarManager; -import org.eclipse.jface.viewers.DoubleClickEvent; -import org.eclipse.jface.viewers.IDoubleClickListener; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.IStructuredContentProvider; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.ITableLabelProvider; -import org.eclipse.jface.viewers.LabelProvider; -import org.eclipse.jface.viewers.TableViewer; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.jface.viewers.ViewerSorter; -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.StackLayout; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Table; -import org.eclipse.swt.widgets.TableColumn; -import org.eclipse.swt.widgets.Text; -import org.eclipse.ui.IActionBars; -import org.eclipse.ui.ISelectionListener; -import org.eclipse.ui.ISharedImages; -import org.eclipse.ui.IWorkbenchPage; -import org.eclipse.ui.IWorkbenchPart; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.part.ViewPart; - -import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Stack; - -/** - * @author Eike Stepper - */ -public class Net4jIntrospectorView extends ViewPart implements ISelectionListener, IDoubleClickListener, IListener -{ - public static final String VIEW_ID = "org.eclipse.net4j.util.Net4jIntrospectorView"; //$NON-NLS-1$ - - private static final Object[] NO_ELEMENTS = {}; - - private static Net4jIntrospectorView instance; - - private TableViewer currentViewer; - - private TableViewer objectViewer; - - private TableViewer iterableViewer; - - private TableViewer arrayViewer; - - private TableViewer mapViewer; - - private Stack<Object> elements = new Stack<Object>(); - - private Text classLabel; - - private Text objectLabel; - - private IAction backAction = new BackAction(); - - private IAction containerAction = new ContainerAction(); - - private IAction refreshAction = new RefreshAction(); - - private StackLayout stackLayout; - - private Composite stacked; - - public Net4jIntrospectorView() - { - } - - @Override - public void dispose() - { - getSite().getPage().removeSelectionListener(this); - super.dispose(); - } - - public static Net4jIntrospectorView getInstance() - { - return instance; - } - - public static synchronized Net4jIntrospectorView getInstance(boolean show) - { - if (instance == null) - { - try - { - IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); - page.showView(VIEW_ID); - } - catch (Exception ex) - { - throw WrappedException.wrap(ex); - } - } - - return instance; - } - - @Override - public void createPartControl(Composite parent) - { - Color bg = parent.getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND); - Color gray = parent.getDisplay().getSystemColor(SWT.COLOR_DARK_BLUE); - - Composite composite = new Composite(parent, SWT.NONE); - composite.setLayout(UIUtil.createGridLayout(1)); - - Composite c = new Composite(composite, SWT.BORDER); - c.setLayout(UIUtil.createGridLayout(2)); - c.setLayoutData(UIUtil.createGridData(true, false)); - - classLabel = new Text(c, SWT.READ_ONLY); - classLabel.setLayoutData(UIUtil.createGridData(false, false)); - classLabel.setBackground(bg); - classLabel.setForeground(gray); - - objectLabel = new Text(c, SWT.READ_ONLY); - objectLabel.setLayoutData(UIUtil.createGridData(true, false)); - objectLabel.setBackground(bg); - - stackLayout = new StackLayout(); - stacked = new Composite(composite, SWT.NONE); - stacked.setLayoutData(UIUtil.createGridData()); - stacked.setLayout(stackLayout); - - objectViewer = createViewer(stacked); - createObjectColmuns(); - objectViewer.addDoubleClickListener(this); - objectViewer.setContentProvider(new ObjectContentProvider()); - objectViewer.setLabelProvider(new ObjectLabelProvider()); - objectViewer.setSorter(new NameSorter()); - objectViewer.setInput(getViewSite()); - - iterableViewer = createViewer(stacked); - createIterableColmuns(); - iterableViewer.addDoubleClickListener(this); - iterableViewer.setContentProvider(new IterableContentProvider()); - iterableViewer.setLabelProvider(new IterableLabelProvider()); - iterableViewer.setInput(getViewSite()); - - arrayViewer = createViewer(stacked); - createArrayColmuns(); - arrayViewer.addDoubleClickListener(this); - arrayViewer.setContentProvider(new ArrayContentProvider()); - arrayViewer.setLabelProvider(new ArrayLabelProvider()); - arrayViewer.setInput(getViewSite()); - - mapViewer = createViewer(stacked); - createMapColmuns(); - mapViewer.addDoubleClickListener(this); - mapViewer.setContentProvider(new MapContentProvider()); - mapViewer.setLabelProvider(new MapLabelProvider()); - mapViewer.setSorter(new NameSorter()); - mapViewer.setInput(getViewSite()); - - IActionBars bars = getViewSite().getActionBars(); - fillLocalPullDown(bars.getMenuManager()); - fillLocalToolBar(bars.getToolBarManager()); - getSite().getPage().addSelectionListener(this); - setCurrentViewer(objectViewer); - instance = this; - } - - private void setCurrentViewer(TableViewer viewer) - { - currentViewer = viewer; - stackLayout.topControl = currentViewer.getControl(); - stacked.layout(); - } - - private TableViewer createViewer(Composite parent) - { - TableViewer viewer = new TableViewer(parent, SWT.FULL_SELECTION | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL); - viewer.getTable().setLayoutData(UIUtil.createGridData()); - viewer.getTable().setHeaderVisible(true); - viewer.getTable().setLinesVisible(true); - return viewer; - } - - public void refreshViewer() - { - UIUtil.refreshViewer(currentViewer); - } - - public void selectionChanged(IWorkbenchPart part, ISelection sel) - { - if (part == this) - { - return; - } - - if (sel instanceof IStructuredSelection) - { - IStructuredSelection ssel = (IStructuredSelection)sel; - elements.clear(); - setObject(ssel.getFirstElement()); - } - else - { - setObject(null); - } - } - - public void doubleClick(DoubleClickEvent event) - { - ISelection sel = event.getSelection(); - if (sel instanceof IStructuredSelection) - { - IStructuredSelection ssel = (IStructuredSelection)sel; - Object element = ssel.getFirstElement(); - if (currentViewer == objectViewer && element instanceof Pair<?, ?>) - { - @SuppressWarnings("unchecked") - Pair<Field, Object> pair = (Pair<Field, Object>)element; - - Field field = pair.getElement1(); - if (!field.getType().isPrimitive()) - { - setObject(pair.getElement2()); - } - } - else if (currentViewer == mapViewer && element instanceof Map.Entry<?, ?>) - { - Map.Entry<?, ?> entry = (Map.Entry<?, ?>)element; - setObject(entry.getValue()); - } - else if (currentViewer == iterableViewer) - { - setObject(element); - } - else if (currentViewer == arrayViewer && element instanceof Pair<?, ?>) - { - @SuppressWarnings("unchecked") - Pair<Integer, Object> pair = (Pair<Integer, Object>)element; - setObject(pair.getElement2()); - } - } - } - - /** - * Passing the focus request to the viewer's control. - */ - @Override - public void setFocus() - { - try - { - currentViewer.getControl().setFocus(); - } - catch (RuntimeException ignore) - { - } - } - - public void notifyEvent(IEvent event) - { - refreshViewer(); - } - - public void setObject(Object object) - { - EventUtil.removeListener(object, this); - if (object != null) - { - if (!elements.isEmpty()) - { - Object element = elements.peek(); - if (element != object) - { - EventUtil.removeListener(element, this); - elements.push(object); - } - } - else - { - elements.push(object); - } - } - - if (object == null) - { - classLabel.setText(""); //$NON-NLS-1$ - objectLabel.setText(""); //$NON-NLS-1$ - currentViewer = objectViewer; - } - else - { - EventUtil.addListener(object, this); - String className = object.getClass().getName(); - classLabel.setText(className); - - String value = object.toString(); - if (value.startsWith(className + "@")) //$NON-NLS-1$ - { - objectLabel.setText(value.substring(className.length())); - } - else - { - objectLabel.setText(value); - } - } - - classLabel.getParent().layout(); - backAction.setEnabled(elements.size() >= 2); - - if (object instanceof Map<?, ?>) - { - setCurrentViewer(mapViewer); - } - else if (object instanceof Iterable<?>) - { - setCurrentViewer(iterableViewer); - } - else if (object != null && object.getClass().isArray()) - { - setCurrentViewer(arrayViewer); - } - else - { - setCurrentViewer(objectViewer); - } - - refreshViewer(); - } - - private void createObjectColmuns() - { - Table table = objectViewer.getTable(); - String[] columnNames = { - Messages.getString("Net4jIntrospectorView_4"), Messages.getString("Net4jIntrospectorView_5"), Messages.getString("Net4jIntrospectorView_6"), Messages.getString("Net4jIntrospectorView_7") }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ - int[] columnWidths = { 200, 400, 300, 300 }; - createColumns(table, columnNames, columnWidths); - } - - private void createMapColmuns() - { - Table table = mapViewer.getTable(); - String[] columnNames = { - Messages.getString("Net4jIntrospectorView_8"), Messages.getString("Net4jIntrospectorView_9"), Messages.getString("Net4jIntrospectorView_10") }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - int[] columnWidths = { 200, 400, 300 }; - createColumns(table, columnNames, columnWidths); - } - - private void createIterableColmuns() - { - Table table = iterableViewer.getTable(); - String[] columnNames = { - Messages.getString("Net4jIntrospectorView_11"), Messages.getString("Net4jIntrospectorView_12") }; //$NON-NLS-1$ //$NON-NLS-2$ - int[] columnWidths = { 400, 300 }; - createColumns(table, columnNames, columnWidths); - } - - private void createArrayColmuns() - { - Table table = arrayViewer.getTable(); - String[] columnNames = { - Messages.getString("Net4jIntrospectorView_13"), Messages.getString("Net4jIntrospectorView_14"), Messages.getString("Net4jIntrospectorView_15") }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - int[] columnWidths = { 50, 400, 300 }; - createColumns(table, columnNames, columnWidths); - } - - private void createColumns(Table table, String[] columnNames, int[] columnWidths) - { - TableColumn[] columns = new TableColumn[columnNames.length]; - for (int i = 0; i < columns.length; i++) - { - TableColumn column = new TableColumn(table, SWT.LEFT, i); - column.setText(columnNames[i]); - column.setWidth(columnWidths[i]); - column.setMoveable(true); - column.setResizable(true); - } - } - - private void fillLocalPullDown(IMenuManager manager) - { - } - - private void fillLocalToolBar(IToolBarManager manager) - { - manager.add(backAction); - manager.add(containerAction); - manager.add(refreshAction); - } - - /** - * @author Eike Stepper - */ - class BackAction extends Action - { - private BackAction() - { - super(Messages.getString("Net4jIntrospectorView_16")); //$NON-NLS-1$ - ISharedImages sharedImages = PlatformUI.getWorkbench().getSharedImages(); - setImageDescriptor(sharedImages.getImageDescriptor(ISharedImages.IMG_TOOL_BACK)); - setDisabledImageDescriptor(sharedImages.getImageDescriptor(ISharedImages.IMG_TOOL_BACK_DISABLED)); - } - - @Override - public void run() - { - if (!elements.isEmpty()) - { - elements.pop(); - if (!elements.isEmpty()) - { - setObject(elements.peek()); - } - } - } - } - - /** - * @author Eike Stepper - */ - class ContainerAction extends Action - { - private ContainerAction() - { - super(Messages.getString("Net4jIntrospectorView_17")); //$NON-NLS-1$ - setImageDescriptor(SharedIcons.getDescriptor(SharedIcons.VIEW_CONTAINER)); - } - - @Override - public void run() - { - setObject(IPluginContainer.INSTANCE); - } - } - - /** - * @author Eike Stepper - */ - class RefreshAction extends Action - { - private RefreshAction() - { - super("Refresh"); //$NON-NLS-1$ - setImageDescriptor(SharedIcons.getDescriptor(SharedIcons.ETOOL_REFRESH)); - } - - @Override - public void run() - { - refreshViewer(); - } - } - - /** - * @author Eike Stepper - */ - abstract class AbstractContentProvider implements IStructuredContentProvider - { - public void inputChanged(Viewer v, Object oldInput, Object newInput) - { - } - - public void dispose() - { - } - } - - /** - * @author Eike Stepper - */ - abstract class AbstractLabelProvider extends LabelProvider implements ITableLabelProvider - { - @Override - public String getText(Object element) - { - return getColumnText(element, 0); - } - - public Image getColumnImage(Object obj, int index) - { - return null; - } - - @Override - public Image getImage(Object obj) - { - return null; - } - } - - /** - * @author Eike Stepper - */ - class ObjectContentProvider extends AbstractContentProvider - { - public Object[] getElements(Object parent) - { - if (!elements.isEmpty()) - { - try - { - return ReflectUtil.dumpToArray(elements.peek()); - } - catch (RuntimeException ex) - { - OM.LOG.error(ex); - } - } - - return NO_ELEMENTS; - } - } - - /** - * @author Eike Stepper - */ - class ObjectLabelProvider extends AbstractLabelProvider - { - public String getColumnText(Object obj, int index) - { - if (obj instanceof Pair<?, ?>) - { - try - { - @SuppressWarnings("unchecked") - Pair<Field, Object> pair = (Pair<Field, Object>)obj; - - Field field = pair.getElement1(); - Object value = pair.getElement2(); - - switch (index) - { - case 0: - return field.getName(); - case 1: - return value == null ? Messages.getString("Net4jIntrospectorView_18") : value.toString(); //$NON-NLS-1$ - case 2: - return field.getType().getName(); - case 3: - return value == null ? Messages.getString("Net4jIntrospectorView_1") : value.getClass().getName(); //$NON-NLS-1$ - } - } - catch (RuntimeException ex) - { - OM.LOG.error(ex); - } - } - - return ""; //$NON-NLS-1$ - } - } - - /** - * @author Eike Stepper - */ - class IterableContentProvider extends AbstractContentProvider - { - public Object[] getElements(Object parent) - { - if (!elements.isEmpty()) - { - Object element = elements.peek(); - if (element instanceof Iterable<?>) - { - List<Object> result = new ArrayList<Object>(); - for (Object object : (Iterable<?>)element) - { - result.add(object); - } - - return result.toArray(); - } - } - - return NO_ELEMENTS; - } - } - - /** - * @author Eike Stepper - */ - class IterableLabelProvider extends AbstractLabelProvider - { - public String getColumnText(Object obj, int index) - { - switch (index) - { - case 0: - return obj == null ? Messages.getString("Net4jIntrospectorView_21") : obj.toString(); //$NON-NLS-1$ - case 1: - return obj == null ? Messages.getString("Net4jIntrospectorView_22") : obj.getClass().getName(); //$NON-NLS-1$ - } - - return ""; //$NON-NLS-1$ - } - } - - /** - * @author Eike Stepper - */ - class ArrayContentProvider extends AbstractContentProvider - { - @SuppressWarnings("unchecked") - public Object[] getElements(Object parent) - { - if (!elements.isEmpty()) - { - Object element = elements.peek(); - if (element.getClass().isArray()) - { - Object[] array = (Object[])element; - Pair<Integer, Object>[] result = new Pair[array.length]; - for (int i = 0; i < array.length; i++) - { - result[i] = new Pair<Integer, Object>(i, array[i]); - } - - return result; - } - } - - return NO_ELEMENTS; - } - } - - /** - * @author Eike Stepper - */ - class ArrayLabelProvider extends AbstractLabelProvider - { - public String getColumnText(Object obj, int index) - { - if (obj instanceof Pair<?, ?>) - { - try - { - @SuppressWarnings("unchecked") - Pair<Integer, Object> pair = (Pair<Integer, Object>)obj; - - int i = pair.getElement1(); - Object value = pair.getElement2(); - switch (index) - { - case 0: - return String.valueOf(i); - case 1: - return value == null ? Messages.getString("Net4jIntrospectorView_24") : value.toString(); //$NON-NLS-1$ - case 2: - return value == null ? Messages.getString("Net4jIntrospectorView_25") : value.getClass().getName(); //$NON-NLS-1$ - } - } - catch (RuntimeException ex) - { - OM.LOG.error(ex); - } - } - - return ""; //$NON-NLS-1$ - } - } - - /** - * @author Eike Stepper - */ - class MapContentProvider extends AbstractContentProvider - { - public Object[] getElements(Object parent) - { - if (!elements.isEmpty()) - { - Object element = elements.peek(); - if (element instanceof Map<?, ?>) - { - return ((Map<?, ?>)element).entrySet().toArray(); - } - } - - return NO_ELEMENTS; - } - } - - /** - * @author Eike Stepper - */ - class MapLabelProvider extends AbstractLabelProvider - { - public String getColumnText(Object obj, int index) - { - if (obj instanceof Map.Entry<?, ?>) - { - Map.Entry<?, ?> entry = (Map.Entry<?, ?>)obj; - Object key = entry.getKey(); - Object value = entry.getValue(); - switch (index) - { - case 0: - return key == null ? Messages.getString("Net4jIntrospectorView_27") : key.toString(); //$NON-NLS-1$ - case 1: - return value == null ? Messages.getString("Net4jIntrospectorView_28") : value.toString(); //$NON-NLS-1$ - case 2: - return value == null ? Messages.getString("Net4jIntrospectorView_29") : value.getClass().getName(); //$NON-NLS-1$ - } - } - - return ""; //$NON-NLS-1$ - } - } - - /** - * @author Eike Stepper - */ - class NameSorter extends ViewerSorter - { - } -} +/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.util.internal.ui.views;
+
+import org.eclipse.net4j.ui.shared.SharedIcons;
+import org.eclipse.net4j.util.ReflectUtil;
+import org.eclipse.net4j.util.WrappedException;
+import org.eclipse.net4j.util.collection.Pair;
+import org.eclipse.net4j.util.container.IPluginContainer;
+import org.eclipse.net4j.util.event.EventUtil;
+import org.eclipse.net4j.util.event.IEvent;
+import org.eclipse.net4j.util.event.IListener;
+import org.eclipse.net4j.util.internal.ui.bundle.OM;
+import org.eclipse.net4j.util.internal.ui.messages.Messages;
+import org.eclipse.net4j.util.ui.UIUtil;
+
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.action.IToolBarManager;
+import org.eclipse.jface.viewers.DoubleClickEvent;
+import org.eclipse.jface.viewers.IDoubleClickListener;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.ITableLabelProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerSorter;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.StackLayout;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableColumn;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.IActionBars;
+import org.eclipse.ui.ISelectionListener;
+import org.eclipse.ui.ISharedImages;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.part.ViewPart;
+
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Stack;
+
+/**
+ * @author Eike Stepper
+ */
+public class Net4jIntrospectorView extends ViewPart implements ISelectionListener, IDoubleClickListener, IListener
+{
+ public static final String VIEW_ID = "org.eclipse.net4j.util.Net4jIntrospectorView"; //$NON-NLS-1$
+
+ private static final Object[] NO_ELEMENTS = {};
+
+ private static Net4jIntrospectorView instance;
+
+ private TableViewer currentViewer;
+
+ private TableViewer objectViewer;
+
+ private TableViewer iterableViewer;
+
+ private TableViewer arrayViewer;
+
+ private TableViewer mapViewer;
+
+ private Stack<Object> elements = new Stack<Object>();
+
+ private Text classLabel;
+
+ private Text objectLabel;
+
+ private IAction backAction = new BackAction();
+
+ private IAction containerAction = new ContainerAction();
+
+ private IAction refreshAction = new RefreshAction();
+
+ private StackLayout stackLayout;
+
+ private Composite stacked;
+
+ public Net4jIntrospectorView()
+ {
+ }
+
+ @Override
+ public void dispose()
+ {
+ getSite().getPage().removeSelectionListener(this);
+ super.dispose();
+ }
+
+ public static Net4jIntrospectorView getInstance()
+ {
+ return instance;
+ }
+
+ public static synchronized Net4jIntrospectorView getInstance(boolean show)
+ {
+ if (instance == null)
+ {
+ try
+ {
+ IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
+ page.showView(VIEW_ID);
+ }
+ catch (Exception ex)
+ {
+ throw WrappedException.wrap(ex);
+ }
+ }
+
+ return instance;
+ }
+
+ @Override
+ public void createPartControl(Composite parent)
+ {
+ Color bg = parent.getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND);
+ Color gray = parent.getDisplay().getSystemColor(SWT.COLOR_DARK_BLUE);
+
+ Composite composite = new Composite(parent, SWT.NONE);
+ composite.setLayout(UIUtil.createGridLayout(1));
+
+ Composite c = new Composite(composite, SWT.BORDER);
+ c.setLayout(UIUtil.createGridLayout(2));
+ c.setLayoutData(UIUtil.createGridData(true, false));
+
+ classLabel = new Text(c, SWT.READ_ONLY);
+ classLabel.setLayoutData(UIUtil.createGridData(false, false));
+ classLabel.setBackground(bg);
+ classLabel.setForeground(gray);
+
+ objectLabel = new Text(c, SWT.READ_ONLY);
+ objectLabel.setLayoutData(UIUtil.createGridData(true, false));
+ objectLabel.setBackground(bg);
+
+ stackLayout = new StackLayout();
+ stacked = new Composite(composite, SWT.NONE);
+ stacked.setLayoutData(UIUtil.createGridData());
+ stacked.setLayout(stackLayout);
+
+ objectViewer = createViewer(stacked);
+ createObjectColmuns();
+ objectViewer.addDoubleClickListener(this);
+ objectViewer.setContentProvider(new ObjectContentProvider());
+ objectViewer.setLabelProvider(new ObjectLabelProvider());
+ objectViewer.setSorter(new NameSorter());
+ objectViewer.setInput(getViewSite());
+
+ iterableViewer = createViewer(stacked);
+ createIterableColmuns();
+ iterableViewer.addDoubleClickListener(this);
+ iterableViewer.setContentProvider(new IterableContentProvider());
+ iterableViewer.setLabelProvider(new IterableLabelProvider());
+ iterableViewer.setInput(getViewSite());
+
+ arrayViewer = createViewer(stacked);
+ createArrayColmuns();
+ arrayViewer.addDoubleClickListener(this);
+ arrayViewer.setContentProvider(new ArrayContentProvider());
+ arrayViewer.setLabelProvider(new ArrayLabelProvider());
+ arrayViewer.setInput(getViewSite());
+
+ mapViewer = createViewer(stacked);
+ createMapColmuns();
+ mapViewer.addDoubleClickListener(this);
+ mapViewer.setContentProvider(new MapContentProvider());
+ mapViewer.setLabelProvider(new MapLabelProvider());
+ mapViewer.setSorter(new NameSorter());
+ mapViewer.setInput(getViewSite());
+
+ IActionBars bars = getViewSite().getActionBars();
+ fillLocalPullDown(bars.getMenuManager());
+ fillLocalToolBar(bars.getToolBarManager());
+ getSite().getPage().addSelectionListener(this);
+ setCurrentViewer(objectViewer);
+ instance = this;
+ }
+
+ private void setCurrentViewer(TableViewer viewer)
+ {
+ currentViewer = viewer;
+ stackLayout.topControl = currentViewer.getControl();
+ stacked.layout();
+ }
+
+ private TableViewer createViewer(Composite parent)
+ {
+ TableViewer viewer = new TableViewer(parent, SWT.FULL_SELECTION | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
+ viewer.getTable().setLayoutData(UIUtil.createGridData());
+ viewer.getTable().setHeaderVisible(true);
+ viewer.getTable().setLinesVisible(true);
+ return viewer;
+ }
+
+ public void refreshViewer()
+ {
+ UIUtil.refreshViewer(currentViewer);
+ }
+
+ public void selectionChanged(IWorkbenchPart part, ISelection sel)
+ {
+ if (part == this)
+ {
+ return;
+ }
+
+ if (sel instanceof IStructuredSelection)
+ {
+ IStructuredSelection ssel = (IStructuredSelection)sel;
+ elements.clear();
+ setObject(ssel.getFirstElement());
+ }
+ else
+ {
+ setObject(null);
+ }
+ }
+
+ public void doubleClick(DoubleClickEvent event)
+ {
+ ISelection sel = event.getSelection();
+ if (sel instanceof IStructuredSelection)
+ {
+ IStructuredSelection ssel = (IStructuredSelection)sel;
+ Object element = ssel.getFirstElement();
+ if (currentViewer == objectViewer && element instanceof Pair<?, ?>)
+ {
+ @SuppressWarnings("unchecked")
+ Pair<Field, Object> pair = (Pair<Field, Object>)element;
+
+ Field field = pair.getElement1();
+ if (!field.getType().isPrimitive())
+ {
+ setObject(pair.getElement2());
+ }
+ }
+ else if (currentViewer == mapViewer && element instanceof Map.Entry<?, ?>)
+ {
+ Map.Entry<?, ?> entry = (Map.Entry<?, ?>)element;
+ setObject(entry.getValue());
+ }
+ else if (currentViewer == iterableViewer)
+ {
+ setObject(element);
+ }
+ else if (currentViewer == arrayViewer && element instanceof Pair<?, ?>)
+ {
+ @SuppressWarnings("unchecked")
+ Pair<Integer, Object> pair = (Pair<Integer, Object>)element;
+ setObject(pair.getElement2());
+ }
+ }
+ }
+
+ /**
+ * Passing the focus request to the viewer's control.
+ */
+ @Override
+ public void setFocus()
+ {
+ try
+ {
+ currentViewer.getControl().setFocus();
+ }
+ catch (RuntimeException ignore)
+ {
+ }
+ }
+
+ public void notifyEvent(IEvent event)
+ {
+ refreshViewer();
+ }
+
+ public void setObject(Object object)
+ {
+ EventUtil.removeListener(object, this);
+ if (object != null)
+ {
+ if (!elements.isEmpty())
+ {
+ Object element = elements.peek();
+ if (element != object)
+ {
+ EventUtil.removeListener(element, this);
+ elements.push(object);
+ }
+ }
+ else
+ {
+ elements.push(object);
+ }
+ }
+
+ if (object == null)
+ {
+ classLabel.setText(""); //$NON-NLS-1$
+ objectLabel.setText(""); //$NON-NLS-1$
+ currentViewer = objectViewer;
+ }
+ else
+ {
+ EventUtil.addListener(object, this);
+ String className = object.getClass().getName();
+ classLabel.setText(className);
+
+ String value = object.toString();
+ if (value.startsWith(className + "@")) //$NON-NLS-1$
+ {
+ objectLabel.setText(value.substring(className.length()));
+ }
+ else
+ {
+ objectLabel.setText(value);
+ }
+ }
+
+ classLabel.getParent().layout();
+ backAction.setEnabled(elements.size() >= 2);
+
+ if (object instanceof Map<?, ?>)
+ {
+ setCurrentViewer(mapViewer);
+ }
+ else if (object instanceof Iterable<?>)
+ {
+ setCurrentViewer(iterableViewer);
+ }
+ else if (object != null && object.getClass().isArray())
+ {
+ setCurrentViewer(arrayViewer);
+ }
+ else
+ {
+ setCurrentViewer(objectViewer);
+ }
+
+ refreshViewer();
+ }
+
+ private void createObjectColmuns()
+ {
+ Table table = objectViewer.getTable();
+ String[] columnNames = {
+ Messages.getString("Net4jIntrospectorView_4"), Messages.getString("Net4jIntrospectorView_5"), Messages.getString("Net4jIntrospectorView_6"), Messages.getString("Net4jIntrospectorView_7") }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ int[] columnWidths = { 200, 400, 300, 300 };
+ createColumns(table, columnNames, columnWidths);
+ }
+
+ private void createMapColmuns()
+ {
+ Table table = mapViewer.getTable();
+ String[] columnNames = {
+ Messages.getString("Net4jIntrospectorView_8"), Messages.getString("Net4jIntrospectorView_9"), Messages.getString("Net4jIntrospectorView_10") }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ int[] columnWidths = { 200, 400, 300 };
+ createColumns(table, columnNames, columnWidths);
+ }
+
+ private void createIterableColmuns()
+ {
+ Table table = iterableViewer.getTable();
+ String[] columnNames = {
+ Messages.getString("Net4jIntrospectorView_11"), Messages.getString("Net4jIntrospectorView_12") }; //$NON-NLS-1$ //$NON-NLS-2$
+ int[] columnWidths = { 400, 300 };
+ createColumns(table, columnNames, columnWidths);
+ }
+
+ private void createArrayColmuns()
+ {
+ Table table = arrayViewer.getTable();
+ String[] columnNames = {
+ Messages.getString("Net4jIntrospectorView_13"), Messages.getString("Net4jIntrospectorView_14"), Messages.getString("Net4jIntrospectorView_15") }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ int[] columnWidths = { 50, 400, 300 };
+ createColumns(table, columnNames, columnWidths);
+ }
+
+ private void createColumns(Table table, String[] columnNames, int[] columnWidths)
+ {
+ TableColumn[] columns = new TableColumn[columnNames.length];
+ for (int i = 0; i < columns.length; i++)
+ {
+ TableColumn column = new TableColumn(table, SWT.LEFT, i);
+ column.setText(columnNames[i]);
+ column.setWidth(columnWidths[i]);
+ column.setMoveable(true);
+ column.setResizable(true);
+ }
+ }
+
+ private void fillLocalPullDown(IMenuManager manager)
+ {
+ }
+
+ private void fillLocalToolBar(IToolBarManager manager)
+ {
+ manager.add(backAction);
+ manager.add(containerAction);
+ manager.add(refreshAction);
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ class BackAction extends Action
+ {
+ private BackAction()
+ {
+ super(Messages.getString("Net4jIntrospectorView_16")); //$NON-NLS-1$
+ ISharedImages sharedImages = PlatformUI.getWorkbench().getSharedImages();
+ setImageDescriptor(sharedImages.getImageDescriptor(ISharedImages.IMG_TOOL_BACK));
+ setDisabledImageDescriptor(sharedImages.getImageDescriptor(ISharedImages.IMG_TOOL_BACK_DISABLED));
+ }
+
+ @Override
+ public void run()
+ {
+ if (!elements.isEmpty())
+ {
+ elements.pop();
+ if (!elements.isEmpty())
+ {
+ setObject(elements.peek());
+ }
+ }
+ }
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ class ContainerAction extends Action
+ {
+ private ContainerAction()
+ {
+ super(Messages.getString("Net4jIntrospectorView_17")); //$NON-NLS-1$
+ setImageDescriptor(SharedIcons.getDescriptor(SharedIcons.VIEW_CONTAINER));
+ }
+
+ @Override
+ public void run()
+ {
+ setObject(IPluginContainer.INSTANCE);
+ }
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ class RefreshAction extends Action
+ {
+ private RefreshAction()
+ {
+ super("Refresh"); //$NON-NLS-1$
+ setImageDescriptor(SharedIcons.getDescriptor(SharedIcons.ETOOL_REFRESH));
+ }
+
+ @Override
+ public void run()
+ {
+ refreshViewer();
+ }
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ abstract class AbstractContentProvider implements IStructuredContentProvider
+ {
+ public void inputChanged(Viewer v, Object oldInput, Object newInput)
+ {
+ }
+
+ public void dispose()
+ {
+ }
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ abstract class AbstractLabelProvider extends LabelProvider implements ITableLabelProvider
+ {
+ @Override
+ public String getText(Object element)
+ {
+ return getColumnText(element, 0);
+ }
+
+ public Image getColumnImage(Object obj, int index)
+ {
+ return null;
+ }
+
+ @Override
+ public Image getImage(Object obj)
+ {
+ return null;
+ }
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ class ObjectContentProvider extends AbstractContentProvider
+ {
+ public Object[] getElements(Object parent)
+ {
+ if (!elements.isEmpty())
+ {
+ try
+ {
+ return ReflectUtil.dumpToArray(elements.peek());
+ }
+ catch (RuntimeException ex)
+ {
+ OM.LOG.error(ex);
+ }
+ }
+
+ return NO_ELEMENTS;
+ }
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ class ObjectLabelProvider extends AbstractLabelProvider
+ {
+ public String getColumnText(Object obj, int index)
+ {
+ if (obj instanceof Pair<?, ?>)
+ {
+ try
+ {
+ @SuppressWarnings("unchecked")
+ Pair<Field, Object> pair = (Pair<Field, Object>)obj;
+
+ Field field = pair.getElement1();
+ Object value = pair.getElement2();
+
+ switch (index)
+ {
+ case 0:
+ return field.getName();
+ case 1:
+ return value == null ? Messages.getString("Net4jIntrospectorView_18") : value.toString(); //$NON-NLS-1$
+ case 2:
+ return field.getType().getName();
+ case 3:
+ return value == null ? Messages.getString("Net4jIntrospectorView_1") : value.getClass().getName(); //$NON-NLS-1$
+ }
+ }
+ catch (RuntimeException ex)
+ {
+ OM.LOG.error(ex);
+ }
+ }
+
+ return ""; //$NON-NLS-1$
+ }
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ class IterableContentProvider extends AbstractContentProvider
+ {
+ public Object[] getElements(Object parent)
+ {
+ if (!elements.isEmpty())
+ {
+ Object element = elements.peek();
+ if (element instanceof Iterable<?>)
+ {
+ List<Object> result = new ArrayList<Object>();
+ for (Object object : (Iterable<?>)element)
+ {
+ result.add(object);
+ }
+
+ return result.toArray();
+ }
+ }
+
+ return NO_ELEMENTS;
+ }
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ class IterableLabelProvider extends AbstractLabelProvider
+ {
+ public String getColumnText(Object obj, int index)
+ {
+ switch (index)
+ {
+ case 0:
+ return obj == null ? Messages.getString("Net4jIntrospectorView_21") : obj.toString(); //$NON-NLS-1$
+ case 1:
+ return obj == null ? Messages.getString("Net4jIntrospectorView_22") : obj.getClass().getName(); //$NON-NLS-1$
+ }
+
+ return ""; //$NON-NLS-1$
+ }
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ class ArrayContentProvider extends AbstractContentProvider
+ {
+ @SuppressWarnings("unchecked")
+ public Object[] getElements(Object parent)
+ {
+ if (!elements.isEmpty())
+ {
+ Object element = elements.peek();
+ if (element.getClass().isArray())
+ {
+ Object[] array = (Object[])element;
+ Pair<Integer, Object>[] result = new Pair[array.length];
+ for (int i = 0; i < array.length; i++)
+ {
+ result[i] = new Pair<Integer, Object>(i, array[i]);
+ }
+
+ return result;
+ }
+ }
+
+ return NO_ELEMENTS;
+ }
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ class ArrayLabelProvider extends AbstractLabelProvider
+ {
+ public String getColumnText(Object obj, int index)
+ {
+ if (obj instanceof Pair<?, ?>)
+ {
+ try
+ {
+ @SuppressWarnings("unchecked")
+ Pair<Integer, Object> pair = (Pair<Integer, Object>)obj;
+
+ int i = pair.getElement1();
+ Object value = pair.getElement2();
+ switch (index)
+ {
+ case 0:
+ return String.valueOf(i);
+ case 1:
+ return value == null ? Messages.getString("Net4jIntrospectorView_24") : value.toString(); //$NON-NLS-1$
+ case 2:
+ return value == null ? Messages.getString("Net4jIntrospectorView_25") : value.getClass().getName(); //$NON-NLS-1$
+ }
+ }
+ catch (RuntimeException ex)
+ {
+ OM.LOG.error(ex);
+ }
+ }
+
+ return ""; //$NON-NLS-1$
+ }
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ class MapContentProvider extends AbstractContentProvider
+ {
+ public Object[] getElements(Object parent)
+ {
+ if (!elements.isEmpty())
+ {
+ Object element = elements.peek();
+ if (element instanceof Map<?, ?>)
+ {
+ return ((Map<?, ?>)element).entrySet().toArray();
+ }
+ }
+
+ return NO_ELEMENTS;
+ }
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ class MapLabelProvider extends AbstractLabelProvider
+ {
+ public String getColumnText(Object obj, int index)
+ {
+ if (obj instanceof Map.Entry<?, ?>)
+ {
+ Map.Entry<?, ?> entry = (Map.Entry<?, ?>)obj;
+ Object key = entry.getKey();
+ Object value = entry.getValue();
+ switch (index)
+ {
+ case 0:
+ return key == null ? Messages.getString("Net4jIntrospectorView_27") : key.toString(); //$NON-NLS-1$
+ case 1:
+ return value == null ? Messages.getString("Net4jIntrospectorView_28") : value.toString(); //$NON-NLS-1$
+ case 2:
+ return value == null ? Messages.getString("Net4jIntrospectorView_29") : value.getClass().getName(); //$NON-NLS-1$
+ }
+ }
+
+ return ""; //$NON-NLS-1$
+ }
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ class NameSorter extends ViewerSorter
+ {
+ }
+}
diff --git a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/AbstractPropertyAdapterFactory.java b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/AbstractPropertyAdapterFactory.java index 7eb0ad9c02..455fd97d04 100644 --- a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/AbstractPropertyAdapterFactory.java +++ b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/AbstractPropertyAdapterFactory.java @@ -1,56 +1,56 @@ -/* - * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) 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: - * Eike Stepper - initial API and implementation - */ -package org.eclipse.net4j.util.ui; - -import org.eclipse.core.runtime.IAdapterFactory; -import org.eclipse.ui.views.properties.IPropertySource; -import org.eclipse.ui.views.properties.IPropertySourceProvider; - -/** - * @author Eike Stepper - * @since 3.2 - */ -@SuppressWarnings("rawtypes") -public abstract class AbstractPropertyAdapterFactory implements IAdapterFactory -{ - private static final Class[] CLASSES = { IPropertySourceProvider.class }; - - public AbstractPropertyAdapterFactory() - { - } - - public Class[] getAdapterList() - { - return CLASSES; - } - - public Object getAdapter(Object adaptableObject, Class adapterType) - { - if (adapterType == CLASSES[0]) - { - final IPropertySource propertySource = createPropertySource(adaptableObject); - if (propertySource != null) - { - return new IPropertySourceProvider() - { - public IPropertySource getPropertySource(Object object) - { - return propertySource; - } - }; - } - } - - return null; - } - - protected abstract IPropertySource createPropertySource(Object object); -} +/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.util.ui;
+
+import org.eclipse.core.runtime.IAdapterFactory;
+import org.eclipse.ui.views.properties.IPropertySource;
+import org.eclipse.ui.views.properties.IPropertySourceProvider;
+
+/**
+ * @author Eike Stepper
+ * @since 3.2
+ */
+@SuppressWarnings("rawtypes")
+public abstract class AbstractPropertyAdapterFactory implements IAdapterFactory
+{
+ private static final Class[] CLASSES = { IPropertySourceProvider.class };
+
+ public AbstractPropertyAdapterFactory()
+ {
+ }
+
+ public Class[] getAdapterList()
+ {
+ return CLASSES;
+ }
+
+ public Object getAdapter(Object adaptableObject, Class adapterType)
+ {
+ if (adapterType == CLASSES[0])
+ {
+ final IPropertySource propertySource = createPropertySource(adaptableObject);
+ if (propertySource != null)
+ {
+ return new IPropertySourceProvider()
+ {
+ public IPropertySource getPropertySource(Object object)
+ {
+ return propertySource;
+ }
+ };
+ }
+ }
+
+ return null;
+ }
+
+ protected abstract IPropertySource createPropertySource(Object object);
+}
diff --git a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/ComboAutoCompleter.java b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/ComboAutoCompleter.java index 1c642f2928..ce8940908c 100644 --- a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/ComboAutoCompleter.java +++ b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/ComboAutoCompleter.java @@ -1,92 +1,92 @@ -/* - * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) 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: - * Eike Stepper - initial API and implementation - */ -package org.eclipse.net4j.util.ui; - -import org.eclipse.jface.viewers.ComboViewer; -import org.eclipse.jface.viewers.ILabelProvider; -import org.eclipse.jface.viewers.IStructuredContentProvider; -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.swt.events.ModifyEvent; -import org.eclipse.swt.events.ModifyListener; - -/** - * @author Eike Stepper - */ -public class ComboAutoCompleter implements ModifyListener -{ - private ComboViewer viewer; - - public ComboAutoCompleter(ComboViewer viewer) - { - this.viewer = viewer; - } - - public final ComboViewer getViewer() - { - return viewer; - } - - public final void modifyText(ModifyEvent e) - { - String text = getText(); - Object foundElement = findShortestLabel(text); - if (foundElement != null) - { - setSelection(new StructuredSelection(foundElement)); - } - else - { - // setSelection(StructuredSelection.EMPTY); - } - } - - protected void setSelection(StructuredSelection selection) - { - viewer.setSelection(selection); - } - - private Object findShortestLabel(String prefix) - { - Object foundElement = null; - String shortestLabel = null; - ILabelProvider labelProvider = (ILabelProvider)viewer.getLabelProvider(); - IStructuredContentProvider contentProvider = (IStructuredContentProvider)viewer.getContentProvider(); - for (Object element : contentProvider.getElements(viewer.getInput())) - { - String label = labelProvider.getText(element); - if (label.startsWith(prefix)) - { - if (shortestLabel == null || label.length() < shortestLabel.length()) - { - shortestLabel = label; - foundElement = element; - } - } - } - - return foundElement; - } - - private String getText() - { - return viewer.getCombo().getText(); - } - - public static void attach(ComboViewer viewer, ComboAutoCompleter completer) - { - viewer.getCombo().addModifyListener(completer); - } - - public static void attach(ComboViewer viewer) - { - viewer.getCombo().addModifyListener(new ComboAutoCompleter(viewer)); - } -} +/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.util.ui;
+
+import org.eclipse.jface.viewers.ComboViewer;
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+
+/**
+ * @author Eike Stepper
+ */
+public class ComboAutoCompleter implements ModifyListener
+{
+ private ComboViewer viewer;
+
+ public ComboAutoCompleter(ComboViewer viewer)
+ {
+ this.viewer = viewer;
+ }
+
+ public final ComboViewer getViewer()
+ {
+ return viewer;
+ }
+
+ public final void modifyText(ModifyEvent e)
+ {
+ String text = getText();
+ Object foundElement = findShortestLabel(text);
+ if (foundElement != null)
+ {
+ setSelection(new StructuredSelection(foundElement));
+ }
+ else
+ {
+ // setSelection(StructuredSelection.EMPTY);
+ }
+ }
+
+ protected void setSelection(StructuredSelection selection)
+ {
+ viewer.setSelection(selection);
+ }
+
+ private Object findShortestLabel(String prefix)
+ {
+ Object foundElement = null;
+ String shortestLabel = null;
+ ILabelProvider labelProvider = (ILabelProvider)viewer.getLabelProvider();
+ IStructuredContentProvider contentProvider = (IStructuredContentProvider)viewer.getContentProvider();
+ for (Object element : contentProvider.getElements(viewer.getInput()))
+ {
+ String label = labelProvider.getText(element);
+ if (label.startsWith(prefix))
+ {
+ if (shortestLabel == null || label.length() < shortestLabel.length())
+ {
+ shortestLabel = label;
+ foundElement = element;
+ }
+ }
+ }
+
+ return foundElement;
+ }
+
+ private String getText()
+ {
+ return viewer.getCombo().getText();
+ }
+
+ public static void attach(ComboViewer viewer, ComboAutoCompleter completer)
+ {
+ viewer.getCombo().addModifyListener(completer);
+ }
+
+ public static void attach(ComboViewer viewer)
+ {
+ viewer.getCombo().addModifyListener(new ComboAutoCompleter(viewer));
+ }
+}
diff --git a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/DefaultPropertySource.java b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/DefaultPropertySource.java index 8f54adb968..1dde6e1df4 100644 --- a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/DefaultPropertySource.java +++ b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/DefaultPropertySource.java @@ -1,210 +1,210 @@ -/* - * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) 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: - * Eike Stepper - initial API and implementation - */ -package org.eclipse.net4j.util.ui; - -import org.eclipse.net4j.util.properties.IPropertyProvider; -import org.eclipse.net4j.util.properties.Property; - -import org.eclipse.jface.viewers.CellEditor; -import org.eclipse.jface.viewers.ILabelProvider; -import org.eclipse.jface.viewers.LabelProvider; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.ui.views.properties.IPropertyDescriptor; -import org.eclipse.ui.views.properties.IPropertySource; -import org.eclipse.ui.views.properties.PropertyDescriptor; - -import java.util.ArrayList; -import java.util.List; - -/** - * @author Eike Stepper - * @since 3.2 - */ -public class DefaultPropertySource<RECEIVER> implements IPropertySource -{ - private List<IPropertyDescriptor> descriptors = new ArrayList<IPropertyDescriptor>(); - - private RECEIVER receiver; - - public DefaultPropertySource(RECEIVER receiver) - { - this.receiver = receiver; - } - - public DefaultPropertySource(RECEIVER object, IPropertyProvider<RECEIVER> provider) - { - this(object); - addDescriptors(provider); - } - - public RECEIVER getReceiver() - { - return receiver; - } - - public PropertyDescriptor addDescriptor(String category, Object id, String displayName, String description) - { - PropertyDescriptor descriptor = new PropertyDescriptor(id, displayName); - descriptor.setCategory(category); - descriptor.setDescription(description); - - descriptors.add(descriptor); - return descriptor; - } - - public void addDescriptors(IPropertyProvider<RECEIVER> provider) - { - for (Property<RECEIVER> property : provider.getProperties()) - { - if (property.getLabel() != null) - { - descriptors.add(new DelegatingPropertyDescriptor<RECEIVER>(property)); - } - } - } - - public IPropertyDescriptor[] getPropertyDescriptors() - { - return descriptors.toArray(new IPropertyDescriptor[descriptors.size()]); - } - - public IPropertyDescriptor getPropertyDescriptor(Object id) - { - IPropertyDescriptor[] propertyDescriptors = getPropertyDescriptors(); - for (int i = 0; i < propertyDescriptors.length; i++) - { - IPropertyDescriptor propertyDescriptor = propertyDescriptors[i]; - if (propertyDescriptor.getId().equals(id)) - { - return propertyDescriptor; - } - } - - return null; - } - - public Property<RECEIVER> getProperty(Object id) - { - IPropertyDescriptor propertyDescriptor = getPropertyDescriptor(id); - if (propertyDescriptor instanceof DelegatingPropertyDescriptor) - { - @SuppressWarnings("unchecked") - DelegatingPropertyDescriptor<RECEIVER> delegating = (DelegatingPropertyDescriptor<RECEIVER>)propertyDescriptor; - return delegating.getProperty(); - } - - return null; - } - - public Object getPropertyValue(Object id) - { - Property<RECEIVER> property = getProperty(id); - if (property != null) - { - return property.getValue(receiver); - } - - return null; - } - - public boolean isPropertySet(Object id) - { - return true; - } - - public void resetPropertyValue(Object id) - { - } - - public void setPropertyValue(Object id, Object value) - { - } - - public Object getEditableValue() - { - return null; - } - - /** - * @author Eike Stepper - */ - public static final class DelegatingPropertyDescriptor<RECEIVER> implements IPropertyDescriptor - { - private final Property<RECEIVER> property; - - private ILabelProvider labelProvider; - - public DelegatingPropertyDescriptor(Property<RECEIVER> property) - { - this.property = property; - } - - public Property<RECEIVER> getProperty() - { - return property; - } - - public String getCategory() - { - return property.getCategory(); - } - - public String getId() - { - return property.getName(); - } - - public String getDisplayName() - { - return property.getLabel(); - } - - public String getDescription() - { - return property.getDescription(); - } - - public boolean isCompatibleWith(IPropertyDescriptor anotherProperty) - { - return anotherProperty.getCategory().equals(getCategory()) && anotherProperty.getId().equals(getId()); - } - - public ILabelProvider getLabelProvider() - { - if (labelProvider != null) - { - return labelProvider; - } - - return new LabelProvider(); - } - - public void setLabelProvider(ILabelProvider labelProvider) - { - this.labelProvider = labelProvider; - } - - public Object getHelpContextIds() - { - return null; - } - - public String[] getFilterFlags() - { - return null; - } - - public CellEditor createPropertyEditor(Composite parent) - { - return null; - } - } -} +/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.util.ui;
+
+import org.eclipse.net4j.util.properties.IPropertyProvider;
+import org.eclipse.net4j.util.properties.Property;
+
+import org.eclipse.jface.viewers.CellEditor;
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.ui.views.properties.IPropertyDescriptor;
+import org.eclipse.ui.views.properties.IPropertySource;
+import org.eclipse.ui.views.properties.PropertyDescriptor;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author Eike Stepper
+ * @since 3.2
+ */
+public class DefaultPropertySource<RECEIVER> implements IPropertySource
+{
+ private List<IPropertyDescriptor> descriptors = new ArrayList<IPropertyDescriptor>();
+
+ private RECEIVER receiver;
+
+ public DefaultPropertySource(RECEIVER receiver)
+ {
+ this.receiver = receiver;
+ }
+
+ public DefaultPropertySource(RECEIVER object, IPropertyProvider<RECEIVER> provider)
+ {
+ this(object);
+ addDescriptors(provider);
+ }
+
+ public RECEIVER getReceiver()
+ {
+ return receiver;
+ }
+
+ public PropertyDescriptor addDescriptor(String category, Object id, String displayName, String description)
+ {
+ PropertyDescriptor descriptor = new PropertyDescriptor(id, displayName);
+ descriptor.setCategory(category);
+ descriptor.setDescription(description);
+
+ descriptors.add(descriptor);
+ return descriptor;
+ }
+
+ public void addDescriptors(IPropertyProvider<RECEIVER> provider)
+ {
+ for (Property<RECEIVER> property : provider.getProperties())
+ {
+ if (property.getLabel() != null)
+ {
+ descriptors.add(new DelegatingPropertyDescriptor<RECEIVER>(property));
+ }
+ }
+ }
+
+ public IPropertyDescriptor[] getPropertyDescriptors()
+ {
+ return descriptors.toArray(new IPropertyDescriptor[descriptors.size()]);
+ }
+
+ public IPropertyDescriptor getPropertyDescriptor(Object id)
+ {
+ IPropertyDescriptor[] propertyDescriptors = getPropertyDescriptors();
+ for (int i = 0; i < propertyDescriptors.length; i++)
+ {
+ IPropertyDescriptor propertyDescriptor = propertyDescriptors[i];
+ if (propertyDescriptor.getId().equals(id))
+ {
+ return propertyDescriptor;
+ }
+ }
+
+ return null;
+ }
+
+ public Property<RECEIVER> getProperty(Object id)
+ {
+ IPropertyDescriptor propertyDescriptor = getPropertyDescriptor(id);
+ if (propertyDescriptor instanceof DelegatingPropertyDescriptor)
+ {
+ @SuppressWarnings("unchecked")
+ DelegatingPropertyDescriptor<RECEIVER> delegating = (DelegatingPropertyDescriptor<RECEIVER>)propertyDescriptor;
+ return delegating.getProperty();
+ }
+
+ return null;
+ }
+
+ public Object getPropertyValue(Object id)
+ {
+ Property<RECEIVER> property = getProperty(id);
+ if (property != null)
+ {
+ return property.getValue(receiver);
+ }
+
+ return null;
+ }
+
+ public boolean isPropertySet(Object id)
+ {
+ return true;
+ }
+
+ public void resetPropertyValue(Object id)
+ {
+ }
+
+ public void setPropertyValue(Object id, Object value)
+ {
+ }
+
+ public Object getEditableValue()
+ {
+ return null;
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ public static final class DelegatingPropertyDescriptor<RECEIVER> implements IPropertyDescriptor
+ {
+ private final Property<RECEIVER> property;
+
+ private ILabelProvider labelProvider;
+
+ public DelegatingPropertyDescriptor(Property<RECEIVER> property)
+ {
+ this.property = property;
+ }
+
+ public Property<RECEIVER> getProperty()
+ {
+ return property;
+ }
+
+ public String getCategory()
+ {
+ return property.getCategory();
+ }
+
+ public String getId()
+ {
+ return property.getName();
+ }
+
+ public String getDisplayName()
+ {
+ return property.getLabel();
+ }
+
+ public String getDescription()
+ {
+ return property.getDescription();
+ }
+
+ public boolean isCompatibleWith(IPropertyDescriptor anotherProperty)
+ {
+ return anotherProperty.getCategory().equals(getCategory()) && anotherProperty.getId().equals(getId());
+ }
+
+ public ILabelProvider getLabelProvider()
+ {
+ if (labelProvider != null)
+ {
+ return labelProvider;
+ }
+
+ return new LabelProvider();
+ }
+
+ public void setLabelProvider(ILabelProvider labelProvider)
+ {
+ this.labelProvider = labelProvider;
+ }
+
+ public Object getHelpContextIds()
+ {
+ return null;
+ }
+
+ public String[] getFilterFlags()
+ {
+ return null;
+ }
+
+ public CellEditor createPropertyEditor(Composite parent)
+ {
+ return null;
+ }
+ }
+}
diff --git a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/DelegatingContentProvider.java b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/DelegatingContentProvider.java index e1f9b06445..dc54417c3d 100644 --- a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/DelegatingContentProvider.java +++ b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/DelegatingContentProvider.java @@ -1,71 +1,71 @@ -/* - * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) 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: - * Eike Stepper - initial API and implementation - */ -package org.eclipse.net4j.util.ui; - -import org.eclipse.jface.viewers.IStructuredContentProvider; -import org.eclipse.jface.viewers.Viewer; - -/** - * @author Eike Stepper - */ -public class DelegatingContentProvider implements IStructuredContentProvider -{ - public static final String NONE = ""; //$NON-NLS-1$ - - private IStructuredContentProvider delegate; - - private boolean optional; - - public DelegatingContentProvider(IStructuredContentProvider delegate, boolean optional) - { - this.delegate = delegate; - this.optional = optional; - } - - public DelegatingContentProvider(IStructuredContentProvider delegate) - { - this(delegate, false); - } - - public IStructuredContentProvider getDelegate() - { - return delegate; - } - - public boolean isOptional() - { - return optional; - } - - public void dispose() - { - delegate.dispose(); - } - - public Object[] getElements(Object inputElement) - { - Object[] elements = delegate.getElements(inputElement); - if (optional) - { - Object[] newElements = new Object[elements.length + 1]; - newElements[0] = NONE; - System.arraycopy(elements, 0, newElements, 1, elements.length); - elements = newElements; - } - - return elements; - } - - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) - { - delegate.inputChanged(viewer, oldInput, newInput); - } -} +/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.util.ui;
+
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.Viewer;
+
+/**
+ * @author Eike Stepper
+ */
+public class DelegatingContentProvider implements IStructuredContentProvider
+{
+ public static final String NONE = ""; //$NON-NLS-1$
+
+ private IStructuredContentProvider delegate;
+
+ private boolean optional;
+
+ public DelegatingContentProvider(IStructuredContentProvider delegate, boolean optional)
+ {
+ this.delegate = delegate;
+ this.optional = optional;
+ }
+
+ public DelegatingContentProvider(IStructuredContentProvider delegate)
+ {
+ this(delegate, false);
+ }
+
+ public IStructuredContentProvider getDelegate()
+ {
+ return delegate;
+ }
+
+ public boolean isOptional()
+ {
+ return optional;
+ }
+
+ public void dispose()
+ {
+ delegate.dispose();
+ }
+
+ public Object[] getElements(Object inputElement)
+ {
+ Object[] elements = delegate.getElements(inputElement);
+ if (optional)
+ {
+ Object[] newElements = new Object[elements.length + 1];
+ newElements[0] = NONE;
+ System.arraycopy(elements, 0, newElements, 1, elements.length);
+ elements = newElements;
+ }
+
+ return elements;
+ }
+
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput)
+ {
+ delegate.inputChanged(viewer, oldInput, newInput);
+ }
+}
diff --git a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/StaticContentProvider.java b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/StaticContentProvider.java index c58ee98ff2..c5edc8062e 100644 --- a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/StaticContentProvider.java +++ b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/StaticContentProvider.java @@ -1,52 +1,52 @@ -/* - * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) 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: - * Eike Stepper - initial API and implementation - */ -package org.eclipse.net4j.util.ui; - -import java.util.Collection; - -/** - * @author Eike Stepper - */ -public class StaticContentProvider extends StructuredContentProvider<Object> -{ - private Object[] elements; - - public StaticContentProvider(Object[] elements) - { - this.elements = elements; - } - - public StaticContentProvider(Collection<?> elements) - { - this(elements.toArray()); - } - - public StaticContentProvider(Class<Object> enumClass) - { - this(createElements(enumClass)); - } - - public Object[] getElements(Object inputElement) - { - return elements; - } - - private static Object[] createElements(Class<Object> enumClass) - { - Object[] enumConstants = enumClass.getEnumConstants(); - if (enumConstants == null) - { - throw new IllegalArgumentException("Illegal enum: " + enumClass); //$NON-NLS-1$ - } - - return enumConstants; - } -} +/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.util.ui;
+
+import java.util.Collection;
+
+/**
+ * @author Eike Stepper
+ */
+public class StaticContentProvider extends StructuredContentProvider<Object>
+{
+ private Object[] elements;
+
+ public StaticContentProvider(Object[] elements)
+ {
+ this.elements = elements;
+ }
+
+ public StaticContentProvider(Collection<?> elements)
+ {
+ this(elements.toArray());
+ }
+
+ public StaticContentProvider(Class<Object> enumClass)
+ {
+ this(createElements(enumClass));
+ }
+
+ public Object[] getElements(Object inputElement)
+ {
+ return elements;
+ }
+
+ private static Object[] createElements(Class<Object> enumClass)
+ {
+ Object[] enumConstants = enumClass.getEnumConstants();
+ if (enumConstants == null)
+ {
+ throw new IllegalArgumentException("Illegal enum: " + enumClass); //$NON-NLS-1$
+ }
+
+ return enumConstants;
+ }
+}
diff --git a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/StructuredContentProvider.java b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/StructuredContentProvider.java index 3a82778704..43b85bf5f1 100644 --- a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/StructuredContentProvider.java +++ b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/StructuredContentProvider.java @@ -1,260 +1,260 @@ -/* - * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) 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: - * Eike Stepper - initial API and implementation - */ -package org.eclipse.net4j.util.ui; - -import org.eclipse.net4j.util.event.IEvent; -import org.eclipse.net4j.util.event.IListener; -import org.eclipse.net4j.util.internal.ui.bundle.OM; - -import org.eclipse.jface.viewers.IStructuredContentProvider; -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.jface.viewers.StructuredViewer; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.Font; -import org.eclipse.swt.graphics.FontData; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Display; - -/** - * @author Eike Stepper - */ -public abstract class StructuredContentProvider<INPUT> implements IStructuredContentProvider, IListener -{ - private StructuredViewer viewer; - - private INPUT input; - - private Font italicFont; - - public StructuredContentProvider() - { - } - - public void dispose() - { - if (input != null) - { - disconnectInput(input); - input = null; - } - - if (italicFont != null) - { - italicFont.dispose(); - italicFont = null; - } - } - - public INPUT getInput() - { - return input; - } - - public StructuredViewer getViewer() - { - return viewer; - } - - @SuppressWarnings("unchecked") - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) - { - this.viewer = (StructuredViewer)viewer; - if (newInput != input) - { - if (input != null) - { - disconnectInput(input); - } - - try - { - input = (INPUT)newInput; - if (input != null) - { - connectInput(input); - } - } - catch (Exception ex) - { - OM.LOG.error(ex); - input = null; - } - } - } - - protected void connectInput(INPUT input) - { - } - - protected void disconnectInput(INPUT input) - { - } - - public void notifyEvent(IEvent event) - { - refreshViewer(true); - } - - /** - * @since 3.0 - */ - public void refreshViewer(boolean updateLabels) - { - refreshElement(null, updateLabels); - } - - /** - * @since 3.1 - */ - public void refreshElement(final Object element, final boolean updateLabels) - { - try - { - getDisplay().asyncExec(new Runnable() - { - public void run() - { - try - { - refreshSynced(element, updateLabels); - } - catch (RuntimeException ignore) - { - } - } - }); - } - catch (RuntimeException ignore) - { - } - } - - /** - * @since 3.1 - */ - public void refreshSynced(final Object element, final boolean updateLabels) - { - if (element != null && element != input) - { - viewer.refresh(element, updateLabels); - } - else - { - viewer.refresh(updateLabels); - } - } - - /** - * @since 3.1 - */ - public void updateLabels(final Object element) - { - try - { - getDisplay().asyncExec(new Runnable() - { - public void run() - { - try - { - viewer.update(element, null); - } - catch (RuntimeException ignore) - { - } - } - }); - } - catch (RuntimeException ignore) - { - } - } - - /** - * @since 3.1 - */ - public void revealElement(final Object element) - { - try - { - getDisplay().asyncExec(new Runnable() - { - public void run() - { - try - { - viewer.reveal(element); - } - catch (RuntimeException ignore) - { - } - } - }); - } - catch (RuntimeException ignore) - { - } - } - - /** - * @since 3.1 - */ - public void selectElement(final Object element, final boolean reveal) - { - try - { - getDisplay().asyncExec(new Runnable() - { - public void run() - { - try - { - viewer.setSelection(new StructuredSelection(element), reveal); - } - catch (RuntimeException ignore) - { - } - } - }); - } - catch (RuntimeException ignore) - { - } - } - - protected Display getDisplay() - { - Display display = viewer.getControl().getDisplay(); - if (display == null) - { - display = UIUtil.getDisplay(); - } - - return display; - } - - /** - * @since 3.1 - */ - protected synchronized Font getItalicFont() - { - if (italicFont == null && viewer != null) - { - Control control = viewer.getControl(); - FontData data = control.getFont().getFontData()[0]; - - italicFont = new Font(control.getDisplay(), data.getName(), data.getHeight(), data.getStyle() | SWT.ITALIC); - } - - return italicFont; - } -} +/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.util.ui;
+
+import org.eclipse.net4j.util.event.IEvent;
+import org.eclipse.net4j.util.event.IListener;
+import org.eclipse.net4j.util.internal.ui.bundle.OM;
+
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.StructuredViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Font;
+import org.eclipse.swt.graphics.FontData;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
+
+/**
+ * @author Eike Stepper
+ */
+public abstract class StructuredContentProvider<INPUT> implements IStructuredContentProvider, IListener
+{
+ private StructuredViewer viewer;
+
+ private INPUT input;
+
+ private Font italicFont;
+
+ public StructuredContentProvider()
+ {
+ }
+
+ public void dispose()
+ {
+ if (input != null)
+ {
+ disconnectInput(input);
+ input = null;
+ }
+
+ if (italicFont != null)
+ {
+ italicFont.dispose();
+ italicFont = null;
+ }
+ }
+
+ public INPUT getInput()
+ {
+ return input;
+ }
+
+ public StructuredViewer getViewer()
+ {
+ return viewer;
+ }
+
+ @SuppressWarnings("unchecked")
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput)
+ {
+ this.viewer = (StructuredViewer)viewer;
+ if (newInput != input)
+ {
+ if (input != null)
+ {
+ disconnectInput(input);
+ }
+
+ try
+ {
+ input = (INPUT)newInput;
+ if (input != null)
+ {
+ connectInput(input);
+ }
+ }
+ catch (Exception ex)
+ {
+ OM.LOG.error(ex);
+ input = null;
+ }
+ }
+ }
+
+ protected void connectInput(INPUT input)
+ {
+ }
+
+ protected void disconnectInput(INPUT input)
+ {
+ }
+
+ public void notifyEvent(IEvent event)
+ {
+ refreshViewer(true);
+ }
+
+ /**
+ * @since 3.0
+ */
+ public void refreshViewer(boolean updateLabels)
+ {
+ refreshElement(null, updateLabels);
+ }
+
+ /**
+ * @since 3.1
+ */
+ public void refreshElement(final Object element, final boolean updateLabels)
+ {
+ try
+ {
+ getDisplay().asyncExec(new Runnable()
+ {
+ public void run()
+ {
+ try
+ {
+ refreshSynced(element, updateLabels);
+ }
+ catch (RuntimeException ignore)
+ {
+ }
+ }
+ });
+ }
+ catch (RuntimeException ignore)
+ {
+ }
+ }
+
+ /**
+ * @since 3.1
+ */
+ public void refreshSynced(final Object element, final boolean updateLabels)
+ {
+ if (element != null && element != input)
+ {
+ viewer.refresh(element, updateLabels);
+ }
+ else
+ {
+ viewer.refresh(updateLabels);
+ }
+ }
+
+ /**
+ * @since 3.1
+ */
+ public void updateLabels(final Object element)
+ {
+ try
+ {
+ getDisplay().asyncExec(new Runnable()
+ {
+ public void run()
+ {
+ try
+ {
+ viewer.update(element, null);
+ }
+ catch (RuntimeException ignore)
+ {
+ }
+ }
+ });
+ }
+ catch (RuntimeException ignore)
+ {
+ }
+ }
+
+ /**
+ * @since 3.1
+ */
+ public void revealElement(final Object element)
+ {
+ try
+ {
+ getDisplay().asyncExec(new Runnable()
+ {
+ public void run()
+ {
+ try
+ {
+ viewer.reveal(element);
+ }
+ catch (RuntimeException ignore)
+ {
+ }
+ }
+ });
+ }
+ catch (RuntimeException ignore)
+ {
+ }
+ }
+
+ /**
+ * @since 3.1
+ */
+ public void selectElement(final Object element, final boolean reveal)
+ {
+ try
+ {
+ getDisplay().asyncExec(new Runnable()
+ {
+ public void run()
+ {
+ try
+ {
+ viewer.setSelection(new StructuredSelection(element), reveal);
+ }
+ catch (RuntimeException ignore)
+ {
+ }
+ }
+ });
+ }
+ catch (RuntimeException ignore)
+ {
+ }
+ }
+
+ protected Display getDisplay()
+ {
+ Display display = viewer.getControl().getDisplay();
+ if (display == null)
+ {
+ display = UIUtil.getDisplay();
+ }
+
+ return display;
+ }
+
+ /**
+ * @since 3.1
+ */
+ protected synchronized Font getItalicFont()
+ {
+ if (italicFont == null && viewer != null)
+ {
+ Control control = viewer.getControl();
+ FontData data = control.getFont().getFontData()[0];
+
+ italicFont = new Font(control.getDisplay(), data.getName(), data.getHeight(), data.getStyle() | SWT.ITALIC);
+ }
+
+ return italicFont;
+ }
+}
diff --git a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/UIActivator.java b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/UIActivator.java index 6e7c20805b..e7b08bb952 100644 --- a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/UIActivator.java +++ b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/UIActivator.java @@ -1,172 +1,172 @@ -/* - * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) 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: - * Eike Stepper - initial API and implementation - */ -package org.eclipse.net4j.util.ui; - -import org.eclipse.net4j.internal.util.bundle.AbstractBundle; -import org.eclipse.net4j.util.om.OMBundle; -import org.eclipse.net4j.util.om.OSGiActivator; -import org.eclipse.net4j.util.om.OSGiActivator.StateHandler; - -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.ui.plugin.AbstractUIPlugin; - -import org.osgi.framework.BundleContext; - -/** - * @author Eike Stepper - */ -public class UIActivator extends AbstractUIPlugin -{ - private OMBundle omBundle; - - /** - * @since 2.0 - */ - protected BundleContext bundleContext; - - public UIActivator(OMBundle omBundle) - { - this.omBundle = omBundle; - } - - public final OMBundle getOMBundle() - { - return omBundle; - } - - /** - * @since 3.1 - */ - public ImageDescriptor loadImageDescriptor(String path) - { - return imageDescriptorFromPlugin(omBundle.getBundleID(), path); - } - - @Override - public final void start(BundleContext context) throws Exception - { - bundleContext = context; - OSGiActivator.traceStart(context); - if (omBundle == null) - { - throw new IllegalStateException("bundle == null"); //$NON-NLS-1$ - } - - try - { - super.start(context); - setBundleContext(context); - ((AbstractBundle)omBundle).start(); - doStart(); - } - catch (Error error) - { - omBundle.logger().error(error); - throw error; - } - catch (Exception ex) - { - omBundle.logger().error(ex); - throw ex; - } - } - - @Override - public final void stop(BundleContext context) throws Exception - { - OSGiActivator.traceStop(context); - if (omBundle == null) - { - throw new IllegalStateException("bundle == null"); //$NON-NLS-1$ - } - - try - { - doStop(); - ((AbstractBundle)omBundle).stop(); - setBundleContext(null); - super.stop(context); - } - catch (Error error) - { - omBundle.logger().error(error); - throw error; - } - catch (Exception ex) - { - omBundle.logger().error(ex); - throw ex; - } - } - - /** - * @since 2.0 - */ - protected void doStart() throws Exception - { - } - - /** - * @since 2.0 - */ - protected void doStop() throws Exception - { - } - - @SuppressWarnings("deprecation") - private void setBundleContext(BundleContext context) - { - omBundle.setBundleContext(context); - } - - /** - * @author Eike Stepper - * @since 3.1 - */ - public static abstract class WithState extends UIActivator - { - private StateHandler handler = new StateHandler(getOMBundle()) - { - @Override - protected void startWithState(Object state) throws Exception - { - doStartWithState(state); - } - - @Override - protected Object stopWithState() throws Exception - { - return doStopWithState(); - } - }; - - public WithState(OMBundle bundle) - { - super(bundle); - } - - @Override - protected final void doStart() throws Exception - { - handler.start(); - } - - @Override - protected final void doStop() throws Exception - { - handler.stop(); - } - - protected abstract void doStartWithState(Object state) throws Exception; - - protected abstract Object doStopWithState() throws Exception; - } -} +/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.util.ui;
+
+import org.eclipse.net4j.internal.util.bundle.AbstractBundle;
+import org.eclipse.net4j.util.om.OMBundle;
+import org.eclipse.net4j.util.om.OSGiActivator;
+import org.eclipse.net4j.util.om.OSGiActivator.StateHandler;
+
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+
+import org.osgi.framework.BundleContext;
+
+/**
+ * @author Eike Stepper
+ */
+public class UIActivator extends AbstractUIPlugin
+{
+ private OMBundle omBundle;
+
+ /**
+ * @since 2.0
+ */
+ protected BundleContext bundleContext;
+
+ public UIActivator(OMBundle omBundle)
+ {
+ this.omBundle = omBundle;
+ }
+
+ public final OMBundle getOMBundle()
+ {
+ return omBundle;
+ }
+
+ /**
+ * @since 3.1
+ */
+ public ImageDescriptor loadImageDescriptor(String path)
+ {
+ return imageDescriptorFromPlugin(omBundle.getBundleID(), path);
+ }
+
+ @Override
+ public final void start(BundleContext context) throws Exception
+ {
+ bundleContext = context;
+ OSGiActivator.traceStart(context);
+ if (omBundle == null)
+ {
+ throw new IllegalStateException("bundle == null"); //$NON-NLS-1$
+ }
+
+ try
+ {
+ super.start(context);
+ setBundleContext(context);
+ ((AbstractBundle)omBundle).start();
+ doStart();
+ }
+ catch (Error error)
+ {
+ omBundle.logger().error(error);
+ throw error;
+ }
+ catch (Exception ex)
+ {
+ omBundle.logger().error(ex);
+ throw ex;
+ }
+ }
+
+ @Override
+ public final void stop(BundleContext context) throws Exception
+ {
+ OSGiActivator.traceStop(context);
+ if (omBundle == null)
+ {
+ throw new IllegalStateException("bundle == null"); //$NON-NLS-1$
+ }
+
+ try
+ {
+ doStop();
+ ((AbstractBundle)omBundle).stop();
+ setBundleContext(null);
+ super.stop(context);
+ }
+ catch (Error error)
+ {
+ omBundle.logger().error(error);
+ throw error;
+ }
+ catch (Exception ex)
+ {
+ omBundle.logger().error(ex);
+ throw ex;
+ }
+ }
+
+ /**
+ * @since 2.0
+ */
+ protected void doStart() throws Exception
+ {
+ }
+
+ /**
+ * @since 2.0
+ */
+ protected void doStop() throws Exception
+ {
+ }
+
+ @SuppressWarnings("deprecation")
+ private void setBundleContext(BundleContext context)
+ {
+ omBundle.setBundleContext(context);
+ }
+
+ /**
+ * @author Eike Stepper
+ * @since 3.1
+ */
+ public static abstract class WithState extends UIActivator
+ {
+ private StateHandler handler = new StateHandler(getOMBundle())
+ {
+ @Override
+ protected void startWithState(Object state) throws Exception
+ {
+ doStartWithState(state);
+ }
+
+ @Override
+ protected Object stopWithState() throws Exception
+ {
+ return doStopWithState();
+ }
+ };
+
+ public WithState(OMBundle bundle)
+ {
+ super(bundle);
+ }
+
+ @Override
+ protected final void doStart() throws Exception
+ {
+ handler.start();
+ }
+
+ @Override
+ protected final void doStop() throws Exception
+ {
+ handler.stop();
+ }
+
+ protected abstract void doStartWithState(Object state) throws Exception;
+
+ protected abstract Object doStopWithState() throws Exception;
+ }
+}
diff --git a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/UIQueueRunner.java b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/UIQueueRunner.java index eb6685b8bf..6751c309e0 100644 --- a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/UIQueueRunner.java +++ b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/UIQueueRunner.java @@ -1,5 +1,5 @@ /*
- * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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
diff --git a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/UIUtil.java b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/UIUtil.java index 9dc546edbf..d03c0110ec 100644 --- a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/UIUtil.java +++ b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/UIUtil.java @@ -1,441 +1,441 @@ -/* - * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) 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: - * Eike Stepper - initial API and implementation - * Victor Roldan Betancort - maintenance - */ -package org.eclipse.net4j.util.ui; - -import org.eclipse.net4j.util.security.IPasswordCredentialsProvider; -import org.eclipse.net4j.util.ui.security.InteractiveCredentialsProvider; - -import org.eclipse.jface.fieldassist.FieldDecoration; -import org.eclipse.jface.fieldassist.FieldDecorationRegistry; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.swt.SWT; -import org.eclipse.swt.dnd.Clipboard; -import org.eclipse.swt.dnd.TextTransfer; -import org.eclipse.swt.dnd.Transfer; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.Font; -import org.eclipse.swt.graphics.FontData; -import org.eclipse.swt.graphics.Image; -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.Display; -import org.eclipse.swt.widgets.Widget; -import org.eclipse.ui.IViewSite; -import org.eclipse.ui.IWorkbench; -import org.eclipse.ui.IWorkbenchPage; -import org.eclipse.ui.IWorkbenchPart; -import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.PlatformUI; - -import java.util.List; - -/** - * @author Eike Stepper - */ -public final class UIUtil -{ - /** - * @since 3.1 - */ - public static final String ERROR_LOG_ID = "org.eclipse.pde.runtime.LogView"; //$NON-NLS-1$ - - private UIUtil() - { - } - - /** - * @since 3.1 - */ - public static void copyToClipboard(Display display, String text) - { - Clipboard clipboard = null; - - try - { - clipboard = new Clipboard(display); - clipboard.setContents(new Object[] { text }, new Transfer[] { TextTransfer.getInstance() }); - } - finally - { - if (clipboard != null) - { - clipboard.dispose(); - } - } - } - - public static void dispose(Font font) - { - if (font != null) - { - font.dispose(); - } - } - - public static void dispose(Color color) - { - if (color != null) - { - color.dispose(); - } - } - - public static void dispose(Widget widget) - { - if (widget != null) - { - widget.dispose(); - } - } - - public static Font getBoldFont(Control control) - { - FontData[] datas = control.getFont().getFontData().clone(); - datas[0].setStyle(SWT.BOLD); - Display display = control.getShell().getDisplay(); - Font font = new Font(display, datas); - return font; - } - - public static Display getDisplay() - { - Display display = Display.getCurrent(); - if (display == null) - { - try - { - display = PlatformUI.getWorkbench().getDisplay(); - } - catch (RuntimeException ignore) - { - } - } - - if (display == null) - { - display = Display.getDefault(); - } - - if (display == null) - { - display = new Display(); - } - - return display; - } - - /** - * @since 2.0 - */ - public static IWorkbench getWorkbench() - { - IWorkbench workbench = PlatformUI.getWorkbench(); - if (workbench == null) - { - throw new IllegalStateException("No workbench available"); //$NON-NLS-1$ - } - - return workbench; - } - - /** - * @since 2.0 - */ - public static IWorkbenchWindow getActiveWorkbenchWindow() - { - IWorkbenchWindow window = getWorkbench().getActiveWorkbenchWindow(); - if (window == null) - { - throw new IllegalStateException("No active window available"); //$NON-NLS-1$ - } - - return window; - } - - /** - * @since 2.0 - */ - public static IWorkbenchPage getActiveWorkbenchPage() - { - IWorkbenchPage page = getActiveWorkbenchWindow().getActivePage(); - if (page == null) - { - throw new IllegalStateException("No active page available"); //$NON-NLS-1$ - } - - return page; - } - - /** - * @since 2.0 - */ - public static IWorkbenchPart getActiveWorkbenchPart() - { - IWorkbenchPart part = getActiveWorkbenchPage().getActivePart(); - if (part == null) - { - throw new IllegalStateException("No active part available"); //$NON-NLS-1$ - } - - return part; - } - - /** - * @since 3.0 - */ - public static Object getElementIfOne(ISelection selection) - { - if (selection instanceof IStructuredSelection) - { - IStructuredSelection ssel = (IStructuredSelection)selection; - if (ssel.size() == 1) - { - return ssel.getFirstElement(); - } - } - - return null; - } - - /** - * @since 2.0 - */ - public static Object getElement(ISelection selection) - { - if (selection instanceof IStructuredSelection) - { - IStructuredSelection ssel = (IStructuredSelection)selection; - return ssel.getFirstElement(); - } - - return null; - } - - /** - * @since 2.0 - */ - public static <T> T getElement(ISelection selection, Class<T> type) - { - Object element = getElement(selection); - if (element != null && type.isInstance(element)) - { - @SuppressWarnings("unchecked") - T result = (T)element; - return result; - } - - return null; - } - - /** - * @since 2.0 - */ - public static <T> List<T> getElements(ISelection selection, Class<T> type) - { - if (selection instanceof IStructuredSelection) - { - IStructuredSelection ssel = (IStructuredSelection)selection; - - @SuppressWarnings("unchecked") - List<T> result = ssel.toList(); - return result; - } - - return null; - } - - /** - * @since 3.1 - */ - public static int setValidationContext(Control control, ValidationContext context) - { - int count = 0; - if (control instanceof ValidationParticipant) - { - ValidationParticipant participant = (ValidationParticipant)control; - if (participant.getValidationContext() == null) - { - participant.setValidationContext(context); - ++count; - } - } - - if (control instanceof Composite) - { - Composite composite = (Composite)control; - for (Control child : composite.getChildren()) - { - count += setValidationContext(child, context); - } - } - - return count; - } - - public static IPasswordCredentialsProvider createInteractiveCredentialsProvider() - { - return new InteractiveCredentialsProvider(); - } - - public static Composite createGridComposite(Composite parent, int columns) - { - Composite composite = new Composite(parent, SWT.NONE); - composite.setLayout(createGridLayout(columns)); - return composite; - } - - public static GridLayout createGridLayout(int columns) - { - GridLayout layout = new GridLayout(); - layout.numColumns = columns; - layout.marginHeight = 0; - layout.marginWidth = 0; - layout.verticalSpacing = 0; - layout.horizontalSpacing = 0; - return layout; - } - - public static GridData createGridData() - { - return createGridData(true, true); - } - - public static GridData createGridData(boolean grabHorizontal, boolean grabVertical) - { - return new GridData(SWT.FILL, SWT.FILL, grabHorizontal, grabVertical); - } - - /** - * @since 3.0 - */ - public static GridData createEmptyGridData() - { - GridData data = new GridData(); - data.heightHint = 0; - data.widthHint = 0; - data.horizontalSpan = 0; - data.horizontalAlignment = 0; - data.horizontalIndent = 0; - data.verticalAlignment = 0; - data.verticalIndent = 0; - data.verticalSpan = 0; - data.minimumHeight = 0; - data.minimumWidth = 0; - data.grabExcessHorizontalSpace = false; - data.grabExcessVerticalSpace = false; - return data; - } - - public static void addDecorationMargin(Control control) - { - Object data = control.getLayoutData(); - if (data instanceof GridData) - { - GridData gd = (GridData)data; - FieldDecorationRegistry registry = FieldDecorationRegistry.getDefault(); - FieldDecoration dec = registry.getFieldDecoration(FieldDecorationRegistry.DEC_CONTENT_PROPOSAL); - gd.horizontalIndent = dec.getImage().getBounds().width; - } - } - - /** - * Adds indentation to the control. if indent value is < 0, the control indentation is left unchanged. - * - * @since 2.0 - */ - public static void setIndentation(Control control, int horizontalIndent, int verticalIndent) - { - if (control == null) - { - throw new IllegalArgumentException("control == null"); //$NON-NLS-1$ - } - - Object data = control.getLayoutData(); - if (data instanceof GridData) - { - GridData gd = (GridData)data; - if (verticalIndent >= 0) - { - gd.verticalIndent = verticalIndent; - } - - if (horizontalIndent >= 0) - { - gd.horizontalIndent = horizontalIndent; - } - } - } - - /** - * @since 2.0 - */ - public static void refreshViewer(final Viewer viewer) - { - try - { - viewer.getControl().getDisplay().asyncExec(new Runnable() - { - public void run() - { - try - { - viewer.refresh(); - } - catch (RuntimeException ignore) - { - // Do nothing - } - } - }); - } - catch (RuntimeException ignore) - { - // Do nothing - } - } - - /** - * Shows a message in the StatusBar. Image can be omitted by passing a null parameter - * - * @since 2.0 - */ - public static void setStatusBarMessage(final String message, final Image image) - { - getDisplay().syncExec(new Runnable() - { - public void run() - { - try - { - IViewSite site = (IViewSite)PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage() - .getActivePart().getSite(); - if (image == null) - { - site.getActionBars().getStatusLineManager().setMessage(message); - } - else - { - site.getActionBars().getStatusLineManager().setMessage(image, message); - } - } - catch (RuntimeException ignore) - { - // Do nothing - } - } - }); - } -} +/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
+ * Eike Stepper - initial API and implementation
+ * Victor Roldan Betancort - maintenance
+ */
+package org.eclipse.net4j.util.ui;
+
+import org.eclipse.net4j.util.security.IPasswordCredentialsProvider;
+import org.eclipse.net4j.util.ui.security.InteractiveCredentialsProvider;
+
+import org.eclipse.jface.fieldassist.FieldDecoration;
+import org.eclipse.jface.fieldassist.FieldDecorationRegistry;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.dnd.Clipboard;
+import org.eclipse.swt.dnd.TextTransfer;
+import org.eclipse.swt.dnd.Transfer;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Font;
+import org.eclipse.swt.graphics.FontData;
+import org.eclipse.swt.graphics.Image;
+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.Display;
+import org.eclipse.swt.widgets.Widget;
+import org.eclipse.ui.IViewSite;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PlatformUI;
+
+import java.util.List;
+
+/**
+ * @author Eike Stepper
+ */
+public final class UIUtil
+{
+ /**
+ * @since 3.1
+ */
+ public static final String ERROR_LOG_ID = "org.eclipse.pde.runtime.LogView"; //$NON-NLS-1$
+
+ private UIUtil()
+ {
+ }
+
+ /**
+ * @since 3.1
+ */
+ public static void copyToClipboard(Display display, String text)
+ {
+ Clipboard clipboard = null;
+
+ try
+ {
+ clipboard = new Clipboard(display);
+ clipboard.setContents(new Object[] { text }, new Transfer[] { TextTransfer.getInstance() });
+ }
+ finally
+ {
+ if (clipboard != null)
+ {
+ clipboard.dispose();
+ }
+ }
+ }
+
+ public static void dispose(Font font)
+ {
+ if (font != null)
+ {
+ font.dispose();
+ }
+ }
+
+ public static void dispose(Color color)
+ {
+ if (color != null)
+ {
+ color.dispose();
+ }
+ }
+
+ public static void dispose(Widget widget)
+ {
+ if (widget != null)
+ {
+ widget.dispose();
+ }
+ }
+
+ public static Font getBoldFont(Control control)
+ {
+ FontData[] datas = control.getFont().getFontData().clone();
+ datas[0].setStyle(SWT.BOLD);
+ Display display = control.getShell().getDisplay();
+ Font font = new Font(display, datas);
+ return font;
+ }
+
+ public static Display getDisplay()
+ {
+ Display display = Display.getCurrent();
+ if (display == null)
+ {
+ try
+ {
+ display = PlatformUI.getWorkbench().getDisplay();
+ }
+ catch (RuntimeException ignore)
+ {
+ }
+ }
+
+ if (display == null)
+ {
+ display = Display.getDefault();
+ }
+
+ if (display == null)
+ {
+ display = new Display();
+ }
+
+ return display;
+ }
+
+ /**
+ * @since 2.0
+ */
+ public static IWorkbench getWorkbench()
+ {
+ IWorkbench workbench = PlatformUI.getWorkbench();
+ if (workbench == null)
+ {
+ throw new IllegalStateException("No workbench available"); //$NON-NLS-1$
+ }
+
+ return workbench;
+ }
+
+ /**
+ * @since 2.0
+ */
+ public static IWorkbenchWindow getActiveWorkbenchWindow()
+ {
+ IWorkbenchWindow window = getWorkbench().getActiveWorkbenchWindow();
+ if (window == null)
+ {
+ throw new IllegalStateException("No active window available"); //$NON-NLS-1$
+ }
+
+ return window;
+ }
+
+ /**
+ * @since 2.0
+ */
+ public static IWorkbenchPage getActiveWorkbenchPage()
+ {
+ IWorkbenchPage page = getActiveWorkbenchWindow().getActivePage();
+ if (page == null)
+ {
+ throw new IllegalStateException("No active page available"); //$NON-NLS-1$
+ }
+
+ return page;
+ }
+
+ /**
+ * @since 2.0
+ */
+ public static IWorkbenchPart getActiveWorkbenchPart()
+ {
+ IWorkbenchPart part = getActiveWorkbenchPage().getActivePart();
+ if (part == null)
+ {
+ throw new IllegalStateException("No active part available"); //$NON-NLS-1$
+ }
+
+ return part;
+ }
+
+ /**
+ * @since 3.0
+ */
+ public static Object getElementIfOne(ISelection selection)
+ {
+ if (selection instanceof IStructuredSelection)
+ {
+ IStructuredSelection ssel = (IStructuredSelection)selection;
+ if (ssel.size() == 1)
+ {
+ return ssel.getFirstElement();
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * @since 2.0
+ */
+ public static Object getElement(ISelection selection)
+ {
+ if (selection instanceof IStructuredSelection)
+ {
+ IStructuredSelection ssel = (IStructuredSelection)selection;
+ return ssel.getFirstElement();
+ }
+
+ return null;
+ }
+
+ /**
+ * @since 2.0
+ */
+ public static <T> T getElement(ISelection selection, Class<T> type)
+ {
+ Object element = getElement(selection);
+ if (element != null && type.isInstance(element))
+ {
+ @SuppressWarnings("unchecked")
+ T result = (T)element;
+ return result;
+ }
+
+ return null;
+ }
+
+ /**
+ * @since 2.0
+ */
+ public static <T> List<T> getElements(ISelection selection, Class<T> type)
+ {
+ if (selection instanceof IStructuredSelection)
+ {
+ IStructuredSelection ssel = (IStructuredSelection)selection;
+
+ @SuppressWarnings("unchecked")
+ List<T> result = ssel.toList();
+ return result;
+ }
+
+ return null;
+ }
+
+ /**
+ * @since 3.1
+ */
+ public static int setValidationContext(Control control, ValidationContext context)
+ {
+ int count = 0;
+ if (control instanceof ValidationParticipant)
+ {
+ ValidationParticipant participant = (ValidationParticipant)control;
+ if (participant.getValidationContext() == null)
+ {
+ participant.setValidationContext(context);
+ ++count;
+ }
+ }
+
+ if (control instanceof Composite)
+ {
+ Composite composite = (Composite)control;
+ for (Control child : composite.getChildren())
+ {
+ count += setValidationContext(child, context);
+ }
+ }
+
+ return count;
+ }
+
+ public static IPasswordCredentialsProvider createInteractiveCredentialsProvider()
+ {
+ return new InteractiveCredentialsProvider();
+ }
+
+ public static Composite createGridComposite(Composite parent, int columns)
+ {
+ Composite composite = new Composite(parent, SWT.NONE);
+ composite.setLayout(createGridLayout(columns));
+ return composite;
+ }
+
+ public static GridLayout createGridLayout(int columns)
+ {
+ GridLayout layout = new GridLayout();
+ layout.numColumns = columns;
+ layout.marginHeight = 0;
+ layout.marginWidth = 0;
+ layout.verticalSpacing = 0;
+ layout.horizontalSpacing = 0;
+ return layout;
+ }
+
+ public static GridData createGridData()
+ {
+ return createGridData(true, true);
+ }
+
+ public static GridData createGridData(boolean grabHorizontal, boolean grabVertical)
+ {
+ return new GridData(SWT.FILL, SWT.FILL, grabHorizontal, grabVertical);
+ }
+
+ /**
+ * @since 3.0
+ */
+ public static GridData createEmptyGridData()
+ {
+ GridData data = new GridData();
+ data.heightHint = 0;
+ data.widthHint = 0;
+ data.horizontalSpan = 0;
+ data.horizontalAlignment = 0;
+ data.horizontalIndent = 0;
+ data.verticalAlignment = 0;
+ data.verticalIndent = 0;
+ data.verticalSpan = 0;
+ data.minimumHeight = 0;
+ data.minimumWidth = 0;
+ data.grabExcessHorizontalSpace = false;
+ data.grabExcessVerticalSpace = false;
+ return data;
+ }
+
+ public static void addDecorationMargin(Control control)
+ {
+ Object data = control.getLayoutData();
+ if (data instanceof GridData)
+ {
+ GridData gd = (GridData)data;
+ FieldDecorationRegistry registry = FieldDecorationRegistry.getDefault();
+ FieldDecoration dec = registry.getFieldDecoration(FieldDecorationRegistry.DEC_CONTENT_PROPOSAL);
+ gd.horizontalIndent = dec.getImage().getBounds().width;
+ }
+ }
+
+ /**
+ * Adds indentation to the control. if indent value is < 0, the control indentation is left unchanged.
+ *
+ * @since 2.0
+ */
+ public static void setIndentation(Control control, int horizontalIndent, int verticalIndent)
+ {
+ if (control == null)
+ {
+ throw new IllegalArgumentException("control == null"); //$NON-NLS-1$
+ }
+
+ Object data = control.getLayoutData();
+ if (data instanceof GridData)
+ {
+ GridData gd = (GridData)data;
+ if (verticalIndent >= 0)
+ {
+ gd.verticalIndent = verticalIndent;
+ }
+
+ if (horizontalIndent >= 0)
+ {
+ gd.horizontalIndent = horizontalIndent;
+ }
+ }
+ }
+
+ /**
+ * @since 2.0
+ */
+ public static void refreshViewer(final Viewer viewer)
+ {
+ try
+ {
+ viewer.getControl().getDisplay().asyncExec(new Runnable()
+ {
+ public void run()
+ {
+ try
+ {
+ viewer.refresh();
+ }
+ catch (RuntimeException ignore)
+ {
+ // Do nothing
+ }
+ }
+ });
+ }
+ catch (RuntimeException ignore)
+ {
+ // Do nothing
+ }
+ }
+
+ /**
+ * Shows a message in the StatusBar. Image can be omitted by passing a null parameter
+ *
+ * @since 2.0
+ */
+ public static void setStatusBarMessage(final String message, final Image image)
+ {
+ getDisplay().syncExec(new Runnable()
+ {
+ public void run()
+ {
+ try
+ {
+ IViewSite site = (IViewSite)PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
+ .getActivePart().getSite();
+ if (image == null)
+ {
+ site.getActionBars().getStatusLineManager().setMessage(message);
+ }
+ else
+ {
+ site.getActionBars().getStatusLineManager().setMessage(image, message);
+ }
+ }
+ catch (RuntimeException ignore)
+ {
+ // Do nothing
+ }
+ }
+ });
+ }
+}
diff --git a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/ValidationContext.java b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/ValidationContext.java index 1cf857927e..9c1e8ef260 100644 --- a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/ValidationContext.java +++ b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/ValidationContext.java @@ -1,5 +1,5 @@ /*
- * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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
diff --git a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/ValidationParticipant.java b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/ValidationParticipant.java index 4713623d8c..5d54078107 100644 --- a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/ValidationParticipant.java +++ b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/ValidationParticipant.java @@ -1,5 +1,5 @@ /*
- * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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
diff --git a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/actions/LongRunningAction.java b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/actions/LongRunningAction.java index 1200095ff5..6fee421d63 100644 --- a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/actions/LongRunningAction.java +++ b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/actions/LongRunningAction.java @@ -1,218 +1,218 @@ -/* - * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) 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: - * Eike Stepper - initial API and implementation - */ -package org.eclipse.net4j.util.ui.actions; - -import org.eclipse.net4j.util.internal.ui.bundle.OM; - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.OperationCanceledException; -import org.eclipse.core.runtime.Status; -import org.eclipse.core.runtime.jobs.Job; -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.ui.IWorkbenchPage; -import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.PlatformUI; - -/** - * @author Eike Stepper - */ -public abstract class LongRunningAction extends SafeAction -{ - private IWorkbenchPage page; - - private int totalWork; - - public LongRunningAction(IWorkbenchPage page) - { - this.page = page; - } - - public LongRunningAction(IWorkbenchPage page, String text, String toolTipText, ImageDescriptor image) - { - super(text, toolTipText, image); - this.page = page; - } - - public LongRunningAction(IWorkbenchPage page, String text, ImageDescriptor image) - { - super(text, image); - this.page = page; - } - - public LongRunningAction(IWorkbenchPage page, String text, String toolTipText) - { - super(text, toolTipText); - this.page = page; - } - - public LongRunningAction(IWorkbenchPage page, String text, int style) - { - super(text, style); - this.page = page; - } - - public LongRunningAction(IWorkbenchPage page, String text) - { - super(text); - this.page = page; - } - - public LongRunningAction() - { - } - - public LongRunningAction(String text, ImageDescriptor image) - { - super(text, image); - } - - public LongRunningAction(String text, int style) - { - super(text, style); - } - - public LongRunningAction(String text, String toolTipText, ImageDescriptor image) - { - super(text, toolTipText, image); - } - - public LongRunningAction(String text, String toolTipText) - { - super(text, toolTipText); - } - - public LongRunningAction(String text) - { - super(text); - } - - public IWorkbenchPage getPage() - { - if (page != null) - { - return page; - } - - IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); - if (window != null) - { - return window.getActivePage(); - } - - return null; - } - - public void setPage(IWorkbenchPage page) - { - this.page = page; - } - - public IWorkbenchWindow getWorkbenchWindow() - { - if (page != null) - { - return page.getWorkbenchWindow(); - } - - return PlatformUI.getWorkbench().getActiveWorkbenchWindow(); - } - - /** - * @since 2.0 - */ - public Display getDisplay() - { - IWorkbenchWindow workbenchWindow = getWorkbenchWindow(); - if (workbenchWindow != null) - { - return workbenchWindow.getShell().getDisplay(); - } - - return PlatformUI.getWorkbench().getDisplay(); - } - - public Shell getShell() - { - IWorkbenchWindow workbenchWindow = getWorkbenchWindow(); - if (workbenchWindow != null) - { - return workbenchWindow.getShell(); - } - - return new Shell(); - } - - protected final int getTotalWork() - { - return totalWork; - } - - protected final void setTotalWork(int totalWork) - { - this.totalWork = totalWork; - } - - protected final void cancel() - { - totalWork = 0; - } - - @Override - protected final void safeRun() throws Exception - { - totalWork = IProgressMonitor.UNKNOWN; - preRun(); - if (totalWork != 0) - { - new Job(getText()) - { - @Override - protected IStatus run(IProgressMonitor progressMonitor) - { - try - { - doRun(progressMonitor); - return Status.OK_STATUS; - } - catch (Exception ex) - { - return new Status(IStatus.ERROR, OM.BUNDLE_ID, ex.getMessage(), ex); - } - } - }.schedule(); - } - } - - protected void preRun() throws Exception - { - } - - protected String getBundleID() - { - return OM.BUNDLE_ID; - } - - /** - * @since 2.0 - */ - protected abstract void doRun(IProgressMonitor progressMonitor) throws Exception; - - protected final void checkCancelation(IProgressMonitor monitor) - { - if (monitor.isCanceled()) - { - throw new OperationCanceledException(); - } - } -} +/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.util.ui.actions;
+
+import org.eclipse.net4j.util.internal.ui.bundle.OM;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.OperationCanceledException;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PlatformUI;
+
+/**
+ * @author Eike Stepper
+ */
+public abstract class LongRunningAction extends SafeAction
+{
+ private IWorkbenchPage page;
+
+ private int totalWork;
+
+ public LongRunningAction(IWorkbenchPage page)
+ {
+ this.page = page;
+ }
+
+ public LongRunningAction(IWorkbenchPage page, String text, String toolTipText, ImageDescriptor image)
+ {
+ super(text, toolTipText, image);
+ this.page = page;
+ }
+
+ public LongRunningAction(IWorkbenchPage page, String text, ImageDescriptor image)
+ {
+ super(text, image);
+ this.page = page;
+ }
+
+ public LongRunningAction(IWorkbenchPage page, String text, String toolTipText)
+ {
+ super(text, toolTipText);
+ this.page = page;
+ }
+
+ public LongRunningAction(IWorkbenchPage page, String text, int style)
+ {
+ super(text, style);
+ this.page = page;
+ }
+
+ public LongRunningAction(IWorkbenchPage page, String text)
+ {
+ super(text);
+ this.page = page;
+ }
+
+ public LongRunningAction()
+ {
+ }
+
+ public LongRunningAction(String text, ImageDescriptor image)
+ {
+ super(text, image);
+ }
+
+ public LongRunningAction(String text, int style)
+ {
+ super(text, style);
+ }
+
+ public LongRunningAction(String text, String toolTipText, ImageDescriptor image)
+ {
+ super(text, toolTipText, image);
+ }
+
+ public LongRunningAction(String text, String toolTipText)
+ {
+ super(text, toolTipText);
+ }
+
+ public LongRunningAction(String text)
+ {
+ super(text);
+ }
+
+ public IWorkbenchPage getPage()
+ {
+ if (page != null)
+ {
+ return page;
+ }
+
+ IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+ if (window != null)
+ {
+ return window.getActivePage();
+ }
+
+ return null;
+ }
+
+ public void setPage(IWorkbenchPage page)
+ {
+ this.page = page;
+ }
+
+ public IWorkbenchWindow getWorkbenchWindow()
+ {
+ if (page != null)
+ {
+ return page.getWorkbenchWindow();
+ }
+
+ return PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+ }
+
+ /**
+ * @since 2.0
+ */
+ public Display getDisplay()
+ {
+ IWorkbenchWindow workbenchWindow = getWorkbenchWindow();
+ if (workbenchWindow != null)
+ {
+ return workbenchWindow.getShell().getDisplay();
+ }
+
+ return PlatformUI.getWorkbench().getDisplay();
+ }
+
+ public Shell getShell()
+ {
+ IWorkbenchWindow workbenchWindow = getWorkbenchWindow();
+ if (workbenchWindow != null)
+ {
+ return workbenchWindow.getShell();
+ }
+
+ return new Shell();
+ }
+
+ protected final int getTotalWork()
+ {
+ return totalWork;
+ }
+
+ protected final void setTotalWork(int totalWork)
+ {
+ this.totalWork = totalWork;
+ }
+
+ protected final void cancel()
+ {
+ totalWork = 0;
+ }
+
+ @Override
+ protected final void safeRun() throws Exception
+ {
+ totalWork = IProgressMonitor.UNKNOWN;
+ preRun();
+ if (totalWork != 0)
+ {
+ new Job(getText())
+ {
+ @Override
+ protected IStatus run(IProgressMonitor progressMonitor)
+ {
+ try
+ {
+ doRun(progressMonitor);
+ return Status.OK_STATUS;
+ }
+ catch (Exception ex)
+ {
+ return new Status(IStatus.ERROR, OM.BUNDLE_ID, ex.getMessage(), ex);
+ }
+ }
+ }.schedule();
+ }
+ }
+
+ protected void preRun() throws Exception
+ {
+ }
+
+ protected String getBundleID()
+ {
+ return OM.BUNDLE_ID;
+ }
+
+ /**
+ * @since 2.0
+ */
+ protected abstract void doRun(IProgressMonitor progressMonitor) throws Exception;
+
+ protected final void checkCancelation(IProgressMonitor monitor)
+ {
+ if (monitor.isCanceled())
+ {
+ throw new OperationCanceledException();
+ }
+ }
+}
diff --git a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/actions/LongRunningActionDelegate.java b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/actions/LongRunningActionDelegate.java index 8032b20842..80ceec1f8b 100644 --- a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/actions/LongRunningActionDelegate.java +++ b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/actions/LongRunningActionDelegate.java @@ -1,95 +1,95 @@ -/* - * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) 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: - * Eike Stepper - initial API and implementation - */ -package org.eclipse.net4j.util.ui.actions; - -import org.eclipse.net4j.util.internal.ui.bundle.OM; - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.OperationCanceledException; -import org.eclipse.core.runtime.Status; -import org.eclipse.core.runtime.jobs.Job; - -/** - * @author Eike Stepper - */ -public abstract class LongRunningActionDelegate extends SafeActionDelegate -{ - private int totalWork; - - public LongRunningActionDelegate() - { - } - - protected final int getTotalWork() - { - return totalWork; - } - - protected final void setTotalWork(int totalWork) - { - this.totalWork = totalWork; - } - - protected final void cancel() - { - totalWork = 0; - } - - @Override - protected final void safeRun() throws Exception - { - totalWork = IProgressMonitor.UNKNOWN; - preRun(); - if (totalWork != 0) - { - new Job(getText()) - { - @Override - protected IStatus run(IProgressMonitor progressMonitor) - { - try - { - doRun(progressMonitor); - return Status.OK_STATUS; - } - catch (Exception ex) - { - OM.LOG.error(ex); - return new Status(IStatus.ERROR, OM.BUNDLE_ID, ex.getMessage(), ex); - } - } - }.schedule(); - } - } - - protected void preRun() throws Exception - { - } - - protected String getBundleID() - { - return OM.BUNDLE_ID; - } - - /** - * @since 2.0 - */ - protected abstract void doRun(IProgressMonitor progressMonitor) throws Exception; - - protected final void checkCancelation(IProgressMonitor monitor) - { - if (monitor.isCanceled()) - { - throw new OperationCanceledException(); - } - } -} +/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.util.ui.actions;
+
+import org.eclipse.net4j.util.internal.ui.bundle.OM;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.OperationCanceledException;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+
+/**
+ * @author Eike Stepper
+ */
+public abstract class LongRunningActionDelegate extends SafeActionDelegate
+{
+ private int totalWork;
+
+ public LongRunningActionDelegate()
+ {
+ }
+
+ protected final int getTotalWork()
+ {
+ return totalWork;
+ }
+
+ protected final void setTotalWork(int totalWork)
+ {
+ this.totalWork = totalWork;
+ }
+
+ protected final void cancel()
+ {
+ totalWork = 0;
+ }
+
+ @Override
+ protected final void safeRun() throws Exception
+ {
+ totalWork = IProgressMonitor.UNKNOWN;
+ preRun();
+ if (totalWork != 0)
+ {
+ new Job(getText())
+ {
+ @Override
+ protected IStatus run(IProgressMonitor progressMonitor)
+ {
+ try
+ {
+ doRun(progressMonitor);
+ return Status.OK_STATUS;
+ }
+ catch (Exception ex)
+ {
+ OM.LOG.error(ex);
+ return new Status(IStatus.ERROR, OM.BUNDLE_ID, ex.getMessage(), ex);
+ }
+ }
+ }.schedule();
+ }
+ }
+
+ protected void preRun() throws Exception
+ {
+ }
+
+ protected String getBundleID()
+ {
+ return OM.BUNDLE_ID;
+ }
+
+ /**
+ * @since 2.0
+ */
+ protected abstract void doRun(IProgressMonitor progressMonitor) throws Exception;
+
+ protected final void checkCancelation(IProgressMonitor monitor)
+ {
+ if (monitor.isCanceled())
+ {
+ throw new OperationCanceledException();
+ }
+ }
+}
diff --git a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/actions/SafeAction.java b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/actions/SafeAction.java index 72fd9d3b43..c8164bfde9 100644 --- a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/actions/SafeAction.java +++ b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/actions/SafeAction.java @@ -1,73 +1,73 @@ -/* - * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) 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: - * Eike Stepper - initial API and implementation - */ -package org.eclipse.net4j.util.ui.actions; - -import org.eclipse.net4j.util.internal.ui.bundle.OM; -import org.eclipse.net4j.util.internal.ui.messages.Messages; - -import org.eclipse.jface.action.Action; -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jface.resource.ImageDescriptor; - -/** - * @author Eike Stepper - */ -public abstract class SafeAction extends Action -{ - public static final String INTERACTIVE = Messages.getString("SafeAction_0"); //$NON-NLS-1$ - - public SafeAction() - { - } - - public SafeAction(String text, String toolTipText, ImageDescriptor image) - { - super(text, image); - setToolTipText(toolTipText); - } - - public SafeAction(String text, String toolTipText) - { - super(text, null); - setToolTipText(toolTipText); - } - - public SafeAction(String text, ImageDescriptor image) - { - super(text, image); - } - - public SafeAction(String text, int style) - { - super(text, style); - } - - public SafeAction(String text) - { - super(text); - } - - @Override - public final void run() - { - try - { - safeRun(); - } - catch (Exception ex) - { - OM.LOG.error(ex); - MessageDialog.openError(null, getText(), ex.getLocalizedMessage() + "\n" + Messages.getString("SafeAction_1")); //$NON-NLS-1$ //$NON-NLS-2$ - } - } - - protected abstract void safeRun() throws Exception; -} +/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.util.ui.actions;
+
+import org.eclipse.net4j.util.internal.ui.bundle.OM;
+import org.eclipse.net4j.util.internal.ui.messages.Messages;
+
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.resource.ImageDescriptor;
+
+/**
+ * @author Eike Stepper
+ */
+public abstract class SafeAction extends Action
+{
+ public static final String INTERACTIVE = Messages.getString("SafeAction_0"); //$NON-NLS-1$
+
+ public SafeAction()
+ {
+ }
+
+ public SafeAction(String text, String toolTipText, ImageDescriptor image)
+ {
+ super(text, image);
+ setToolTipText(toolTipText);
+ }
+
+ public SafeAction(String text, String toolTipText)
+ {
+ super(text, null);
+ setToolTipText(toolTipText);
+ }
+
+ public SafeAction(String text, ImageDescriptor image)
+ {
+ super(text, image);
+ }
+
+ public SafeAction(String text, int style)
+ {
+ super(text, style);
+ }
+
+ public SafeAction(String text)
+ {
+ super(text);
+ }
+
+ @Override
+ public final void run()
+ {
+ try
+ {
+ safeRun();
+ }
+ catch (Exception ex)
+ {
+ OM.LOG.error(ex);
+ MessageDialog.openError(null, getText(), ex.getLocalizedMessage() + "\n" + Messages.getString("SafeAction_1")); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ }
+
+ protected abstract void safeRun() throws Exception;
+}
diff --git a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/actions/SafeActionDelegate.java b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/actions/SafeActionDelegate.java index 162326151b..a48216b9df 100644 --- a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/actions/SafeActionDelegate.java +++ b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/actions/SafeActionDelegate.java @@ -1,72 +1,72 @@ -/* - * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) 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: - * Eike Stepper - initial API and implementation - */ -package org.eclipse.net4j.util.ui.actions; - -import org.eclipse.net4j.util.internal.ui.bundle.OM; -import org.eclipse.net4j.util.internal.ui.messages.Messages; - -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.ui.IActionDelegate; - -/** - * @author Eike Stepper - */ -public abstract class SafeActionDelegate implements IActionDelegate -{ - private IAction action; - - private ISelection selection; - - public SafeActionDelegate() - { - } - - public IAction getAction() - { - return action; - } - - public ISelection getSelection() - { - return selection; - } - - public void selectionChanged(IAction action, ISelection selection) - { - this.action = action; - this.selection = selection; - } - - public void run(IAction action) - { - this.action = action; - - try - { - safeRun(); - } - catch (Exception ex) - { - OM.LOG.error(ex); - MessageDialog.openError(null, getText(), - ex.getLocalizedMessage() + "\n" + Messages.getString("SafeActionDelegate_0")); //$NON-NLS-1$ //$NON-NLS-2$ - } - } - - protected abstract void safeRun() throws Exception; - - protected String getText() - { - return action == null ? Messages.getString("SafeActionDelegate_1") : action.getText(); //$NON-NLS-1$ - } -} +/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.util.ui.actions;
+
+import org.eclipse.net4j.util.internal.ui.bundle.OM;
+import org.eclipse.net4j.util.internal.ui.messages.Messages;
+
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.ui.IActionDelegate;
+
+/**
+ * @author Eike Stepper
+ */
+public abstract class SafeActionDelegate implements IActionDelegate
+{
+ private IAction action;
+
+ private ISelection selection;
+
+ public SafeActionDelegate()
+ {
+ }
+
+ public IAction getAction()
+ {
+ return action;
+ }
+
+ public ISelection getSelection()
+ {
+ return selection;
+ }
+
+ public void selectionChanged(IAction action, ISelection selection)
+ {
+ this.action = action;
+ this.selection = selection;
+ }
+
+ public void run(IAction action)
+ {
+ this.action = action;
+
+ try
+ {
+ safeRun();
+ }
+ catch (Exception ex)
+ {
+ OM.LOG.error(ex);
+ MessageDialog.openError(null, getText(),
+ ex.getLocalizedMessage() + "\n" + Messages.getString("SafeActionDelegate_0")); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ }
+
+ protected abstract void safeRun() throws Exception;
+
+ protected String getText()
+ {
+ return action == null ? Messages.getString("SafeActionDelegate_1") : action.getText(); //$NON-NLS-1$
+ }
+}
diff --git a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/actions/SashLayoutAction.java b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/actions/SashLayoutAction.java index 61a63c2d6b..3e714e60d4 100644 --- a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/actions/SashLayoutAction.java +++ b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/actions/SashLayoutAction.java @@ -1,125 +1,125 @@ -/* - * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) 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: - * Eike Stepper - initial API and implementation - */ -package org.eclipse.net4j.util.ui.actions; - -import org.eclipse.net4j.util.event.IEvent; -import org.eclipse.net4j.util.event.IListener; -import org.eclipse.net4j.util.internal.ui.messages.Messages; -import org.eclipse.net4j.util.ui.widgets.SashComposite; - -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.action.MenuManager; - -/** - * @author Eike Stepper - */ -public abstract class SashLayoutAction extends SafeAction implements IListener -{ - private SashComposite sashComposite; - - public SashLayoutAction(SashComposite sashComposite, String text) - { - super(text, IAction.AS_RADIO_BUTTON); - this.sashComposite = sashComposite; - notifyEvent(null); - sashComposite.addListener(this); - } - - public SashComposite getSashComposite() - { - return sashComposite; - } - - /** - * @since 2.0 - */ - public void dispose() - { - sashComposite.removeListener(this); - } - - /** - * @author Eike Stepper - */ - public static class Vertical extends SashLayoutAction - { - public Vertical(SashComposite sashComposite) - { - super(sashComposite, Messages.getString("SashLayoutAction_0")); //$NON-NLS-1$ - } - - @Override - protected void safeRun() throws Exception - { - getSashComposite().setVertical(true); - } - - /** - * @since 2.0 - */ - public void notifyEvent(IEvent event) - { - setChecked(getSashComposite().isVertical()); - } - } - - /** - * @author Eike Stepper - */ - public static class Horizontal extends SashLayoutAction - { - public Horizontal(SashComposite sashComposite) - { - super(sashComposite, Messages.getString("SashLayoutAction_1")); //$NON-NLS-1$ - } - - @Override - protected void safeRun() throws Exception - { - getSashComposite().setVertical(false); - } - - /** - * @since 2.0 - */ - public void notifyEvent(IEvent event) - { - setChecked(!getSashComposite().isVertical()); - } - } - - /** - * @author Eike Stepper - */ - public static class LayoutMenu extends MenuManager - { - private SafeAction verticalAction; - - private SafeAction horizontalAction; - - public LayoutMenu(SashComposite sashComposite) - { - super(Messages.getString("SashLayoutAction_2")); //$NON-NLS-1$ - add(verticalAction = new SashLayoutAction.Vertical(sashComposite)); - add(horizontalAction = new SashLayoutAction.Horizontal(sashComposite)); - } - - public SafeAction getVerticalAction() - { - return verticalAction; - } - - public SafeAction getHorizontalAction() - { - return horizontalAction; - } - } -} +/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.util.ui.actions;
+
+import org.eclipse.net4j.util.event.IEvent;
+import org.eclipse.net4j.util.event.IListener;
+import org.eclipse.net4j.util.internal.ui.messages.Messages;
+import org.eclipse.net4j.util.ui.widgets.SashComposite;
+
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.action.MenuManager;
+
+/**
+ * @author Eike Stepper
+ */
+public abstract class SashLayoutAction extends SafeAction implements IListener
+{
+ private SashComposite sashComposite;
+
+ public SashLayoutAction(SashComposite sashComposite, String text)
+ {
+ super(text, IAction.AS_RADIO_BUTTON);
+ this.sashComposite = sashComposite;
+ notifyEvent(null);
+ sashComposite.addListener(this);
+ }
+
+ public SashComposite getSashComposite()
+ {
+ return sashComposite;
+ }
+
+ /**
+ * @since 2.0
+ */
+ public void dispose()
+ {
+ sashComposite.removeListener(this);
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ public static class Vertical extends SashLayoutAction
+ {
+ public Vertical(SashComposite sashComposite)
+ {
+ super(sashComposite, Messages.getString("SashLayoutAction_0")); //$NON-NLS-1$
+ }
+
+ @Override
+ protected void safeRun() throws Exception
+ {
+ getSashComposite().setVertical(true);
+ }
+
+ /**
+ * @since 2.0
+ */
+ public void notifyEvent(IEvent event)
+ {
+ setChecked(getSashComposite().isVertical());
+ }
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ public static class Horizontal extends SashLayoutAction
+ {
+ public Horizontal(SashComposite sashComposite)
+ {
+ super(sashComposite, Messages.getString("SashLayoutAction_1")); //$NON-NLS-1$
+ }
+
+ @Override
+ protected void safeRun() throws Exception
+ {
+ getSashComposite().setVertical(false);
+ }
+
+ /**
+ * @since 2.0
+ */
+ public void notifyEvent(IEvent event)
+ {
+ setChecked(!getSashComposite().isVertical());
+ }
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ public static class LayoutMenu extends MenuManager
+ {
+ private SafeAction verticalAction;
+
+ private SafeAction horizontalAction;
+
+ public LayoutMenu(SashComposite sashComposite)
+ {
+ super(Messages.getString("SashLayoutAction_2")); //$NON-NLS-1$
+ add(verticalAction = new SashLayoutAction.Vertical(sashComposite));
+ add(horizontalAction = new SashLayoutAction.Horizontal(sashComposite));
+ }
+
+ public SafeAction getVerticalAction()
+ {
+ return verticalAction;
+ }
+
+ public SafeAction getHorizontalAction()
+ {
+ return horizontalAction;
+ }
+ }
+}
diff --git a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/actions/package-info.java b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/actions/package-info.java index 96f2ec84c7..338e589a24 100644 --- a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/actions/package-info.java +++ b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/actions/package-info.java @@ -1,5 +1,5 @@ /*
- * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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
diff --git a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/container/ElementWizard.java b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/container/ElementWizard.java index 6582a7853f..f22d098b8b 100644 --- a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/container/ElementWizard.java +++ b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/container/ElementWizard.java @@ -1,139 +1,139 @@ -/* - * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) 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: - * Eike Stepper - initial API and implementation - */ -package org.eclipse.net4j.util.ui.container; - -import org.eclipse.net4j.util.ObjectUtil; -import org.eclipse.net4j.util.container.IManagedContainer; -import org.eclipse.net4j.util.event.Notifier; -import org.eclipse.net4j.util.ui.UIUtil; -import org.eclipse.net4j.util.ui.ValidationContext; - -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Combo; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Text; - -/** - * @author Eike Stepper - * @since 3.1 - */ -public abstract class ElementWizard extends Notifier implements IElementWizard, ValidationContext -{ - private IManagedContainer container; - - private String productGroup; - - private String factoryType; - - private String defaultDescription; - - private String resultDescription; - - private ValidationContext context; - - public ElementWizard() - { - } - - protected IManagedContainer getContainer() - { - return container; - } - - protected String getProductGroup() - { - return productGroup; - } - - protected String getFactoryType() - { - return factoryType; - } - - protected String getDefaultDescription() - { - return defaultDescription; - } - - public String getResultDescription() - { - return resultDescription; - } - - public Object getResultElement() - { - return container.getElement(productGroup, factoryType, resultDescription); - } - - public void create(Composite parent, IManagedContainer container, String productGroup, String factoryType, - String defaultDescription, ValidationContext context) - { - this.container = container; - this.productGroup = productGroup; - this.factoryType = factoryType; - this.defaultDescription = defaultDescription; - this.context = context; - - create(parent); - } - - protected void setResultDescription(String resultDescription) - { - String oldDescription = this.resultDescription; - if (!ObjectUtil.equals(resultDescription, oldDescription)) - { - this.resultDescription = resultDescription; - fireEvent(); - } - } - - public void setValidationError(Object source, String message) - { - if (context != null) - { - context.setValidationError(source, message); - } - } - - protected abstract void create(Composite parent); - - public static Label addLabel(Composite parent, String label) - { - Label control = new Label(parent, SWT.NONE); - control.setText(label); - control.setLayoutData(UIUtil.createGridData(false, false)); - return control; - } - - public static Text addText(Composite parent, String label) - { - addLabel(parent, label); - - Text control = new Text(parent, SWT.BORDER); - control.setLayoutData(UIUtil.createGridData(true, false)); - return control; - } - - public static Combo addCombo(Composite parent, String label, String... choices) - { - addLabel(parent, label); - - Combo control = new Combo(parent, SWT.SINGLE); - control.setLayoutData(UIUtil.createGridData(true, false)); - for (String choice : choices) - { - control.add(choice); - } - - return control; - } -} +/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.util.ui.container;
+
+import org.eclipse.net4j.util.ObjectUtil;
+import org.eclipse.net4j.util.container.IManagedContainer;
+import org.eclipse.net4j.util.event.Notifier;
+import org.eclipse.net4j.util.ui.UIUtil;
+import org.eclipse.net4j.util.ui.ValidationContext;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Text;
+
+/**
+ * @author Eike Stepper
+ * @since 3.1
+ */
+public abstract class ElementWizard extends Notifier implements IElementWizard, ValidationContext
+{
+ private IManagedContainer container;
+
+ private String productGroup;
+
+ private String factoryType;
+
+ private String defaultDescription;
+
+ private String resultDescription;
+
+ private ValidationContext context;
+
+ public ElementWizard()
+ {
+ }
+
+ protected IManagedContainer getContainer()
+ {
+ return container;
+ }
+
+ protected String getProductGroup()
+ {
+ return productGroup;
+ }
+
+ protected String getFactoryType()
+ {
+ return factoryType;
+ }
+
+ protected String getDefaultDescription()
+ {
+ return defaultDescription;
+ }
+
+ public String getResultDescription()
+ {
+ return resultDescription;
+ }
+
+ public Object getResultElement()
+ {
+ return container.getElement(productGroup, factoryType, resultDescription);
+ }
+
+ public void create(Composite parent, IManagedContainer container, String productGroup, String factoryType,
+ String defaultDescription, ValidationContext context)
+ {
+ this.container = container;
+ this.productGroup = productGroup;
+ this.factoryType = factoryType;
+ this.defaultDescription = defaultDescription;
+ this.context = context;
+
+ create(parent);
+ }
+
+ protected void setResultDescription(String resultDescription)
+ {
+ String oldDescription = this.resultDescription;
+ if (!ObjectUtil.equals(resultDescription, oldDescription))
+ {
+ this.resultDescription = resultDescription;
+ fireEvent();
+ }
+ }
+
+ public void setValidationError(Object source, String message)
+ {
+ if (context != null)
+ {
+ context.setValidationError(source, message);
+ }
+ }
+
+ protected abstract void create(Composite parent);
+
+ public static Label addLabel(Composite parent, String label)
+ {
+ Label control = new Label(parent, SWT.NONE);
+ control.setText(label);
+ control.setLayoutData(UIUtil.createGridData(false, false));
+ return control;
+ }
+
+ public static Text addText(Composite parent, String label)
+ {
+ addLabel(parent, label);
+
+ Text control = new Text(parent, SWT.BORDER);
+ control.setLayoutData(UIUtil.createGridData(true, false));
+ return control;
+ }
+
+ public static Combo addCombo(Composite parent, String label, String... choices)
+ {
+ addLabel(parent, label);
+
+ Combo control = new Combo(parent, SWT.SINGLE);
+ control.setLayoutData(UIUtil.createGridData(true, false));
+ for (String choice : choices)
+ {
+ control.add(choice);
+ }
+
+ return control;
+ }
+}
diff --git a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/container/ElementWizardComposite.java b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/container/ElementWizardComposite.java index 907df97e9b..36bf114f58 100644 --- a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/container/ElementWizardComposite.java +++ b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/container/ElementWizardComposite.java @@ -1,413 +1,413 @@ -/* - * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) 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: - * Eike Stepper - initial API and implementation - */ -package org.eclipse.net4j.util.ui.container; - -import org.eclipse.net4j.util.container.FactoryNotFoundException; -import org.eclipse.net4j.util.container.IManagedContainer; -import org.eclipse.net4j.util.container.IPluginContainer; -import org.eclipse.net4j.util.event.IEvent; -import org.eclipse.net4j.util.event.IListener; -import org.eclipse.net4j.util.event.INotifier; -import org.eclipse.net4j.util.event.Notifier; -import org.eclipse.net4j.util.ui.UIUtil; -import org.eclipse.net4j.util.ui.ValidationContext; - -import org.eclipse.swt.SWT; -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.Control; -import org.eclipse.swt.widgets.Label; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -/** - * @author Eike Stepper - * @since 3.1 - */ -public abstract class ElementWizardComposite extends Composite implements IListener -{ - private static final IElementWizard NO_WIZARD = new ElementWizard() - { - @Override - protected void create(Composite parent) - { - // Do nothing - } - }; - - private String productGroup; - - private String label; - - private List<String> factoryTypes; - - private Map<String, String> defaultDescriptions = new HashMap<String, String>(); - - private List<IElementWizard> wizards; - - private Map<IElementWizard, List<Control>> wizardControls = new HashMap<IElementWizard, List<Control>>(); - - private Map<Control, IElementWizard> controlWizards = new HashMap<Control, IElementWizard>(); - - private ValidationContext validationContext; - - private boolean firstLayout = true; - - private Notifier notifier = new Notifier(); - - public ElementWizardComposite(Composite parent, int style, String productGroup, String label) - { - this(parent, style, productGroup, label, null); - } - - /** - * @since 3.2 - */ - public ElementWizardComposite(Composite parent, int style, String productGroup, String label, - ValidationContext validationContext) - { - super(parent, style); - this.productGroup = productGroup; - this.label = label; - - setValidationContext(validationContext); - create(); - } - - public String getProductGroup() - { - return productGroup; - } - - public String getLabel() - { - return label; - } - - public void setValidationContext(ValidationContext validationContext) - { - this.validationContext = validationContext; - } - - public String getDefaultDescription(String factoryType) - { - return defaultDescriptions.get(factoryType); - } - - public void setDefaultDescription(String factoryType, String value) - { - defaultDescriptions.put(factoryType, value); - } - - protected void init() - { - IManagedContainer container = getContainer(); - factoryTypes = new ArrayList<String>(container.getFactoryTypes(getProductGroup())); - Collections.sort(factoryTypes); - - wizards = new ArrayList<IElementWizard>(); - wizardControls.put(NO_WIZARD, new ArrayList<Control>()); - - for (Iterator<String> it = factoryTypes.iterator(); it.hasNext();) - { - String factoryType = it.next(); - - try - { - String description = getDefaultDescription(factoryType); - - IElementWizard wizard = (IElementWizard)container.getElement(ElementWizardFactory.PRODUCT_GROUP, - getProductGroup() + ":" + factoryType, description); - wizards.add(wizard); - wizardControls.put(wizard, new ArrayList<Control>()); - - if (wizard instanceof ElementWizard) - { - ElementWizard impl = (ElementWizard)wizard; - impl.addListener(this); - } - } - catch (FactoryNotFoundException ex) - { - it.remove(); - } - } - } - - /** - * @since 3.2 - */ - public void notifyEvent(IEvent event) - { - notifier.fireEvent(event); - } - - protected List<String> getFactoryTypes() - { - return factoryTypes; - } - - protected void create() - { - init(); - setLayout(new GridLayout(2, false)); - - { - Label label = new Label(this, SWT.NONE); - label.setText(getLabel()); - label.setLayoutData(UIUtil.createGridData(false, false)); - - createFactoryTypeControl(); - harvestControls(NO_WIZARD); - } - - for (int i = 0; i < wizards.size(); i++) - { - String factoryType = factoryTypes.get(i); - IElementWizard wizard = wizards.get(i); - wizard.create(this, getContainer(), productGroup, factoryType, null, validationContext); - harvestControls(wizard); - } - - if (!factoryTypes.isEmpty()) - { - setFactoryType(factoryTypes.get(0)); - } - } - - protected void factoryTypeChanged() - { - String newFactoryType = getFactoryType(); - List<Control> controlsToRefresh = new ArrayList<Control>(); - - for (int i = 0; i < wizards.size(); i++) - { - IElementWizard wizard = wizards.get(i); - - String factoryType = factoryTypes.get(i); - boolean visible = factoryType.equals(newFactoryType); - - for (Control control : wizardControls.get(wizard)) - { - control.setVisible(visible); - - if (!visible) - { - control.moveBelow(null); - } - - controlsToRefresh.add(control); - } - } - - // layout(controlsToRefresh.toArray(new Control[controlsToRefresh.size()])); - // layout(getChildren()); - - layout(); - notifier.fireEvent(); - } - - @Override - public void layout() - { - if (firstLayout) - { - super.layout(); - firstLayout = false; - } - else - { - super.layout(getChildren()); - } - } - - protected void harvestControls(IElementWizard wizard) - { - for (Control child : getChildren()) - { - if (!controlWizards.containsKey(child)) - { - controlWizards.put(child, wizard); - wizardControls.get(wizard).add(child); - } - } - } - - protected IManagedContainer getContainer() - { - return IPluginContainer.INSTANCE; - } - - /** - * @since 3.2 - */ - public final INotifier getNotifier() - { - return notifier; - } - - public String getDescription() - { - String resultType = getFactoryType(); - for (int i = 0; i < wizards.size(); i++) - { - String factoryType = factoryTypes.get(i); - if (resultType.equals(factoryType)) - { - return wizards.get(i).getResultDescription(); - } - } - - return null; - } - - public abstract String getFactoryType(); - - protected abstract void setFactoryType(String factoryType); - - protected abstract void createFactoryTypeControl(); - - /** - * @author Eike Stepper - */ - public static class WithCombo extends ElementWizardComposite implements SelectionListener - { - private Combo combo; - - public WithCombo(Composite parent, int style, String productGroup, String label) - { - super(parent, style, productGroup, label); - } - - public void widgetSelected(SelectionEvent e) - { - factoryTypeChanged(); - } - - public void widgetDefaultSelected(SelectionEvent e) - { - } - - @Override - public String getFactoryType() - { - return combo.getText(); - } - - @Override - protected void setFactoryType(String factoryType) - { - int index = getFactoryTypes().indexOf(factoryType); - if (index == -1) - { - combo.setText(factoryType); - } - else - { - combo.select(index); - } - - factoryTypeChanged(); - } - - @Override - protected void createFactoryTypeControl() - { - combo = new Combo(this, SWT.SINGLE); - for (String factoryType : getFactoryTypes()) - { - combo.add(factoryType); - } - - combo.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false)); - combo.addSelectionListener(this); - } - } - - /** - * @author Eike Stepper - */ - public static class WithRadios extends ElementWizardComposite implements SelectionListener - { - private Composite composite; - - public WithRadios(Composite parent, int style, String productGroup, String label) - { - super(parent, style, productGroup, label); - } - - public void widgetSelected(SelectionEvent e) - { - factoryTypeChanged(); - } - - public void widgetDefaultSelected(SelectionEvent e) - { - } - - @Override - public String getFactoryType() - { - Control[] choices = composite.getChildren(); - - for (int i = 0; i < choices.length; i++) - { - Button choice = (Button)choices[i]; - if (choice.getSelection()) - { - return getFactoryTypes().get(i); - } - } - - return null; - } - - @Override - protected void setFactoryType(String factoryType) - { - List<String> factoryTypes = getFactoryTypes(); - Control[] choices = composite.getChildren(); - - for (int i = 0; i < factoryTypes.size(); i++) - { - Button choice = (Button)choices[i]; - choice.setSelection(factoryTypes.get(i).equals(factoryType)); - } - - factoryTypeChanged(); - } - - @Override - protected void createFactoryTypeControl() - { - composite = new Composite(this, SWT.SINGLE); - composite.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false)); - composite.setLayout(new FillLayout()); - for (String factoryType : getFactoryTypes()) - { - Button choice = new Button(composite, SWT.RADIO); - choice.setText(factoryType); - choice.addSelectionListener(this); - } - } - } -} +/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.util.ui.container;
+
+import org.eclipse.net4j.util.container.FactoryNotFoundException;
+import org.eclipse.net4j.util.container.IManagedContainer;
+import org.eclipse.net4j.util.container.IPluginContainer;
+import org.eclipse.net4j.util.event.IEvent;
+import org.eclipse.net4j.util.event.IListener;
+import org.eclipse.net4j.util.event.INotifier;
+import org.eclipse.net4j.util.event.Notifier;
+import org.eclipse.net4j.util.ui.UIUtil;
+import org.eclipse.net4j.util.ui.ValidationContext;
+
+import org.eclipse.swt.SWT;
+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.Control;
+import org.eclipse.swt.widgets.Label;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author Eike Stepper
+ * @since 3.1
+ */
+public abstract class ElementWizardComposite extends Composite implements IListener
+{
+ private static final IElementWizard NO_WIZARD = new ElementWizard()
+ {
+ @Override
+ protected void create(Composite parent)
+ {
+ // Do nothing
+ }
+ };
+
+ private String productGroup;
+
+ private String label;
+
+ private List<String> factoryTypes;
+
+ private Map<String, String> defaultDescriptions = new HashMap<String, String>();
+
+ private List<IElementWizard> wizards;
+
+ private Map<IElementWizard, List<Control>> wizardControls = new HashMap<IElementWizard, List<Control>>();
+
+ private Map<Control, IElementWizard> controlWizards = new HashMap<Control, IElementWizard>();
+
+ private ValidationContext validationContext;
+
+ private boolean firstLayout = true;
+
+ private Notifier notifier = new Notifier();
+
+ public ElementWizardComposite(Composite parent, int style, String productGroup, String label)
+ {
+ this(parent, style, productGroup, label, null);
+ }
+
+ /**
+ * @since 3.2
+ */
+ public ElementWizardComposite(Composite parent, int style, String productGroup, String label,
+ ValidationContext validationContext)
+ {
+ super(parent, style);
+ this.productGroup = productGroup;
+ this.label = label;
+
+ setValidationContext(validationContext);
+ create();
+ }
+
+ public String getProductGroup()
+ {
+ return productGroup;
+ }
+
+ public String getLabel()
+ {
+ return label;
+ }
+
+ public void setValidationContext(ValidationContext validationContext)
+ {
+ this.validationContext = validationContext;
+ }
+
+ public String getDefaultDescription(String factoryType)
+ {
+ return defaultDescriptions.get(factoryType);
+ }
+
+ public void setDefaultDescription(String factoryType, String value)
+ {
+ defaultDescriptions.put(factoryType, value);
+ }
+
+ protected void init()
+ {
+ IManagedContainer container = getContainer();
+ factoryTypes = new ArrayList<String>(container.getFactoryTypes(getProductGroup()));
+ Collections.sort(factoryTypes);
+
+ wizards = new ArrayList<IElementWizard>();
+ wizardControls.put(NO_WIZARD, new ArrayList<Control>());
+
+ for (Iterator<String> it = factoryTypes.iterator(); it.hasNext();)
+ {
+ String factoryType = it.next();
+
+ try
+ {
+ String description = getDefaultDescription(factoryType);
+
+ IElementWizard wizard = (IElementWizard)container.getElement(ElementWizardFactory.PRODUCT_GROUP,
+ getProductGroup() + ":" + factoryType, description);
+ wizards.add(wizard);
+ wizardControls.put(wizard, new ArrayList<Control>());
+
+ if (wizard instanceof ElementWizard)
+ {
+ ElementWizard impl = (ElementWizard)wizard;
+ impl.addListener(this);
+ }
+ }
+ catch (FactoryNotFoundException ex)
+ {
+ it.remove();
+ }
+ }
+ }
+
+ /**
+ * @since 3.2
+ */
+ public void notifyEvent(IEvent event)
+ {
+ notifier.fireEvent(event);
+ }
+
+ protected List<String> getFactoryTypes()
+ {
+ return factoryTypes;
+ }
+
+ protected void create()
+ {
+ init();
+ setLayout(new GridLayout(2, false));
+
+ {
+ Label label = new Label(this, SWT.NONE);
+ label.setText(getLabel());
+ label.setLayoutData(UIUtil.createGridData(false, false));
+
+ createFactoryTypeControl();
+ harvestControls(NO_WIZARD);
+ }
+
+ for (int i = 0; i < wizards.size(); i++)
+ {
+ String factoryType = factoryTypes.get(i);
+ IElementWizard wizard = wizards.get(i);
+ wizard.create(this, getContainer(), productGroup, factoryType, null, validationContext);
+ harvestControls(wizard);
+ }
+
+ if (!factoryTypes.isEmpty())
+ {
+ setFactoryType(factoryTypes.get(0));
+ }
+ }
+
+ protected void factoryTypeChanged()
+ {
+ String newFactoryType = getFactoryType();
+ List<Control> controlsToRefresh = new ArrayList<Control>();
+
+ for (int i = 0; i < wizards.size(); i++)
+ {
+ IElementWizard wizard = wizards.get(i);
+
+ String factoryType = factoryTypes.get(i);
+ boolean visible = factoryType.equals(newFactoryType);
+
+ for (Control control : wizardControls.get(wizard))
+ {
+ control.setVisible(visible);
+
+ if (!visible)
+ {
+ control.moveBelow(null);
+ }
+
+ controlsToRefresh.add(control);
+ }
+ }
+
+ // layout(controlsToRefresh.toArray(new Control[controlsToRefresh.size()]));
+ // layout(getChildren());
+
+ layout();
+ notifier.fireEvent();
+ }
+
+ @Override
+ public void layout()
+ {
+ if (firstLayout)
+ {
+ super.layout();
+ firstLayout = false;
+ }
+ else
+ {
+ super.layout(getChildren());
+ }
+ }
+
+ protected void harvestControls(IElementWizard wizard)
+ {
+ for (Control child : getChildren())
+ {
+ if (!controlWizards.containsKey(child))
+ {
+ controlWizards.put(child, wizard);
+ wizardControls.get(wizard).add(child);
+ }
+ }
+ }
+
+ protected IManagedContainer getContainer()
+ {
+ return IPluginContainer.INSTANCE;
+ }
+
+ /**
+ * @since 3.2
+ */
+ public final INotifier getNotifier()
+ {
+ return notifier;
+ }
+
+ public String getDescription()
+ {
+ String resultType = getFactoryType();
+ for (int i = 0; i < wizards.size(); i++)
+ {
+ String factoryType = factoryTypes.get(i);
+ if (resultType.equals(factoryType))
+ {
+ return wizards.get(i).getResultDescription();
+ }
+ }
+
+ return null;
+ }
+
+ public abstract String getFactoryType();
+
+ protected abstract void setFactoryType(String factoryType);
+
+ protected abstract void createFactoryTypeControl();
+
+ /**
+ * @author Eike Stepper
+ */
+ public static class WithCombo extends ElementWizardComposite implements SelectionListener
+ {
+ private Combo combo;
+
+ public WithCombo(Composite parent, int style, String productGroup, String label)
+ {
+ super(parent, style, productGroup, label);
+ }
+
+ public void widgetSelected(SelectionEvent e)
+ {
+ factoryTypeChanged();
+ }
+
+ public void widgetDefaultSelected(SelectionEvent e)
+ {
+ }
+
+ @Override
+ public String getFactoryType()
+ {
+ return combo.getText();
+ }
+
+ @Override
+ protected void setFactoryType(String factoryType)
+ {
+ int index = getFactoryTypes().indexOf(factoryType);
+ if (index == -1)
+ {
+ combo.setText(factoryType);
+ }
+ else
+ {
+ combo.select(index);
+ }
+
+ factoryTypeChanged();
+ }
+
+ @Override
+ protected void createFactoryTypeControl()
+ {
+ combo = new Combo(this, SWT.SINGLE);
+ for (String factoryType : getFactoryTypes())
+ {
+ combo.add(factoryType);
+ }
+
+ combo.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false));
+ combo.addSelectionListener(this);
+ }
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ public static class WithRadios extends ElementWizardComposite implements SelectionListener
+ {
+ private Composite composite;
+
+ public WithRadios(Composite parent, int style, String productGroup, String label)
+ {
+ super(parent, style, productGroup, label);
+ }
+
+ public void widgetSelected(SelectionEvent e)
+ {
+ factoryTypeChanged();
+ }
+
+ public void widgetDefaultSelected(SelectionEvent e)
+ {
+ }
+
+ @Override
+ public String getFactoryType()
+ {
+ Control[] choices = composite.getChildren();
+
+ for (int i = 0; i < choices.length; i++)
+ {
+ Button choice = (Button)choices[i];
+ if (choice.getSelection())
+ {
+ return getFactoryTypes().get(i);
+ }
+ }
+
+ return null;
+ }
+
+ @Override
+ protected void setFactoryType(String factoryType)
+ {
+ List<String> factoryTypes = getFactoryTypes();
+ Control[] choices = composite.getChildren();
+
+ for (int i = 0; i < factoryTypes.size(); i++)
+ {
+ Button choice = (Button)choices[i];
+ choice.setSelection(factoryTypes.get(i).equals(factoryType));
+ }
+
+ factoryTypeChanged();
+ }
+
+ @Override
+ protected void createFactoryTypeControl()
+ {
+ composite = new Composite(this, SWT.SINGLE);
+ composite.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false));
+ composite.setLayout(new FillLayout());
+ for (String factoryType : getFactoryTypes())
+ {
+ Button choice = new Button(composite, SWT.RADIO);
+ choice.setText(factoryType);
+ choice.addSelectionListener(this);
+ }
+ }
+ }
+}
diff --git a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/container/ElementWizardFactory.java b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/container/ElementWizardFactory.java index 0727b9d70b..2b89c9c716 100644 --- a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/container/ElementWizardFactory.java +++ b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/container/ElementWizardFactory.java @@ -1,30 +1,30 @@ -/* - * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) 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: - * Eike Stepper - initial API and implementation - */ -package org.eclipse.net4j.util.ui.container; - -import org.eclipse.net4j.util.factory.Factory; -import org.eclipse.net4j.util.factory.ProductCreationException; - -/** - * @author Eike Stepper - * @since 3.1 - */ -public abstract class ElementWizardFactory extends Factory -{ - public static final String PRODUCT_GROUP = "org.eclipse.net4j.util.ui.elementWizards"; //$NON-NLS-1$ - - public ElementWizardFactory(String elementProductGroup, String elementFactoryType) - { - super(PRODUCT_GROUP, elementProductGroup + ":" + elementFactoryType); - } - - public abstract IElementWizard create(String description) throws ProductCreationException; -} +/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.util.ui.container;
+
+import org.eclipse.net4j.util.factory.Factory;
+import org.eclipse.net4j.util.factory.ProductCreationException;
+
+/**
+ * @author Eike Stepper
+ * @since 3.1
+ */
+public abstract class ElementWizardFactory extends Factory
+{
+ public static final String PRODUCT_GROUP = "org.eclipse.net4j.util.ui.elementWizards"; //$NON-NLS-1$
+
+ public ElementWizardFactory(String elementProductGroup, String elementFactoryType)
+ {
+ super(PRODUCT_GROUP, elementProductGroup + ":" + elementFactoryType);
+ }
+
+ public abstract IElementWizard create(String description) throws ProductCreationException;
+}
diff --git a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/container/IElementWizard.java b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/container/IElementWizard.java index f6a5bc4223..1ea464a2ef 100644 --- a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/container/IElementWizard.java +++ b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/container/IElementWizard.java @@ -1,30 +1,30 @@ -/* - * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) 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: - * Eike Stepper - initial API and implementation - */ -package org.eclipse.net4j.util.ui.container; - -import org.eclipse.net4j.util.container.IManagedContainer; -import org.eclipse.net4j.util.ui.ValidationContext; - -import org.eclipse.swt.widgets.Composite; - -/** - * @author Eike Stepper - * @since 3.1 - */ -public interface IElementWizard -{ - public void create(Composite parent, IManagedContainer container, String productGroup, String factoryType, - String defaultDescription, ValidationContext context); - - public String getResultDescription(); - - public Object getResultElement(); -} +/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.util.ui.container;
+
+import org.eclipse.net4j.util.container.IManagedContainer;
+import org.eclipse.net4j.util.ui.ValidationContext;
+
+import org.eclipse.swt.widgets.Composite;
+
+/**
+ * @author Eike Stepper
+ * @since 3.1
+ */
+public interface IElementWizard
+{
+ public void create(Composite parent, IManagedContainer container, String productGroup, String factoryType,
+ String defaultDescription, ValidationContext context);
+
+ public String getResultDescription();
+
+ public Object getResultElement();
+}
diff --git a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/container/package-info.java b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/container/package-info.java index b71ea621d7..6077efde1e 100644 --- a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/container/package-info.java +++ b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/container/package-info.java @@ -1,5 +1,5 @@ /*
- * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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
diff --git a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/dnd/DNDDragListener.java b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/dnd/DNDDragListener.java index 8e7d8f4477..8e4ff27d22 100644 --- a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/dnd/DNDDragListener.java +++ b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/dnd/DNDDragListener.java @@ -1,72 +1,72 @@ -/* - * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) 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: - * Eike Stepper - initial API and implementation - */ -package org.eclipse.net4j.util.ui.dnd; - -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.StructuredViewer; -import org.eclipse.swt.dnd.DragSourceAdapter; -import org.eclipse.swt.dnd.DragSourceEvent; -import org.eclipse.swt.dnd.Transfer; - -/** - * @author Eike Stepper - */ -public abstract class DNDDragListener<TYPE> extends DragSourceAdapter -{ - private Transfer[] transfers; - - private StructuredViewer viewer; - - /** - * @since 3.0 - */ - protected DNDDragListener(Transfer[] transfers, StructuredViewer viewer) - { - this.transfers = transfers; - this.viewer = viewer; - } - - /** - * @since 3.0 - */ - public Transfer[] getTransfers() - { - return transfers; - } - - public StructuredViewer getViewer() - { - return viewer; - } - - @Override - public void dragSetData(DragSourceEvent event) - { - for (Transfer transfer : transfers) - { - if (transfer.isSupportedType(event.dataType)) - { - IStructuredSelection selection = (IStructuredSelection)viewer.getSelection(); - event.data = getObject(selection); - break; - } - } - } - - @Override - public void dragStart(DragSourceEvent event) - { - IStructuredSelection selection = (IStructuredSelection)viewer.getSelection(); - event.doit = !viewer.getSelection().isEmpty() && getObject(selection) != null; - } - - protected abstract TYPE getObject(IStructuredSelection selection); -} +/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.util.ui.dnd;
+
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.StructuredViewer;
+import org.eclipse.swt.dnd.DragSourceAdapter;
+import org.eclipse.swt.dnd.DragSourceEvent;
+import org.eclipse.swt.dnd.Transfer;
+
+/**
+ * @author Eike Stepper
+ */
+public abstract class DNDDragListener<TYPE> extends DragSourceAdapter
+{
+ private Transfer[] transfers;
+
+ private StructuredViewer viewer;
+
+ /**
+ * @since 3.0
+ */
+ protected DNDDragListener(Transfer[] transfers, StructuredViewer viewer)
+ {
+ this.transfers = transfers;
+ this.viewer = viewer;
+ }
+
+ /**
+ * @since 3.0
+ */
+ public Transfer[] getTransfers()
+ {
+ return transfers;
+ }
+
+ public StructuredViewer getViewer()
+ {
+ return viewer;
+ }
+
+ @Override
+ public void dragSetData(DragSourceEvent event)
+ {
+ for (Transfer transfer : transfers)
+ {
+ if (transfer.isSupportedType(event.dataType))
+ {
+ IStructuredSelection selection = (IStructuredSelection)viewer.getSelection();
+ event.data = getObject(selection);
+ break;
+ }
+ }
+ }
+
+ @Override
+ public void dragStart(DragSourceEvent event)
+ {
+ IStructuredSelection selection = (IStructuredSelection)viewer.getSelection();
+ event.doit = !viewer.getSelection().isEmpty() && getObject(selection) != null;
+ }
+
+ protected abstract TYPE getObject(IStructuredSelection selection);
+}
diff --git a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/dnd/DNDDropAdapter.java b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/dnd/DNDDropAdapter.java index 4acb4b3926..0e83f10492 100644 --- a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/dnd/DNDDropAdapter.java +++ b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/dnd/DNDDropAdapter.java @@ -1,114 +1,114 @@ -/* - * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) 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: - * Eike Stepper - initial API and implementation - */ -package org.eclipse.net4j.util.ui.dnd; - -import org.eclipse.jface.viewers.StructuredViewer; -import org.eclipse.jface.viewers.ViewerDropAdapter; -import org.eclipse.swt.dnd.DropTargetEvent; -import org.eclipse.swt.dnd.Transfer; -import org.eclipse.swt.dnd.TransferData; - -/** - * @author Eike Stepper - */ -public abstract class DNDDropAdapter<TYPE> extends ViewerDropAdapter -{ - private Transfer[] transfers; - - /** - * Specifies if dropping between two viewer elements is allowed. - */ - private boolean dropBetweenEnabled; - - /** - * @since 3.0 - */ - protected DNDDropAdapter(Transfer[] transfers, StructuredViewer viewer) - { - super(viewer); - this.transfers = transfers; - } - - /** - * @since 3.0 - */ - public Transfer[] getTransfers() - { - return transfers; - } - - @Override - public StructuredViewer getViewer() - { - return (StructuredViewer)super.getViewer(); - } - - public boolean isDropBetweenEnabled() - { - return dropBetweenEnabled; - } - - public void setDropBetweenEnabled(boolean dropBetweenEnabled) - { - this.dropBetweenEnabled = dropBetweenEnabled; - } - - @Override - protected int determineLocation(DropTargetEvent event) - { - int location = super.determineLocation(event); - if (location == LOCATION_BEFORE || location == LOCATION_AFTER) - { - if (!dropBetweenEnabled) - { - location = LOCATION_ON; - } - } - - return location; - } - - @SuppressWarnings("unchecked") - @Override - public boolean performDrop(Object data) - { - Object target = getCurrentTarget(); - if (target == null) - { - target = getViewer().getInput(); - } - - return performDrop((TYPE)data, target); - } - - @Override - public boolean validateDrop(Object target, int operation, TransferData type) - { - if (target != null && !validateTarget(target, operation)) - { - return false; - } - - for (Transfer transfer : transfers) - { - if (transfer.isSupportedType(type)) - { - return true; - } - } - - return false; - } - - protected abstract boolean validateTarget(Object target, int operation); - - protected abstract boolean performDrop(TYPE data, Object target); -} +/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.util.ui.dnd;
+
+import org.eclipse.jface.viewers.StructuredViewer;
+import org.eclipse.jface.viewers.ViewerDropAdapter;
+import org.eclipse.swt.dnd.DropTargetEvent;
+import org.eclipse.swt.dnd.Transfer;
+import org.eclipse.swt.dnd.TransferData;
+
+/**
+ * @author Eike Stepper
+ */
+public abstract class DNDDropAdapter<TYPE> extends ViewerDropAdapter
+{
+ private Transfer[] transfers;
+
+ /**
+ * Specifies if dropping between two viewer elements is allowed.
+ */
+ private boolean dropBetweenEnabled;
+
+ /**
+ * @since 3.0
+ */
+ protected DNDDropAdapter(Transfer[] transfers, StructuredViewer viewer)
+ {
+ super(viewer);
+ this.transfers = transfers;
+ }
+
+ /**
+ * @since 3.0
+ */
+ public Transfer[] getTransfers()
+ {
+ return transfers;
+ }
+
+ @Override
+ public StructuredViewer getViewer()
+ {
+ return (StructuredViewer)super.getViewer();
+ }
+
+ public boolean isDropBetweenEnabled()
+ {
+ return dropBetweenEnabled;
+ }
+
+ public void setDropBetweenEnabled(boolean dropBetweenEnabled)
+ {
+ this.dropBetweenEnabled = dropBetweenEnabled;
+ }
+
+ @Override
+ protected int determineLocation(DropTargetEvent event)
+ {
+ int location = super.determineLocation(event);
+ if (location == LOCATION_BEFORE || location == LOCATION_AFTER)
+ {
+ if (!dropBetweenEnabled)
+ {
+ location = LOCATION_ON;
+ }
+ }
+
+ return location;
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public boolean performDrop(Object data)
+ {
+ Object target = getCurrentTarget();
+ if (target == null)
+ {
+ target = getViewer().getInput();
+ }
+
+ return performDrop((TYPE)data, target);
+ }
+
+ @Override
+ public boolean validateDrop(Object target, int operation, TransferData type)
+ {
+ if (target != null && !validateTarget(target, operation))
+ {
+ return false;
+ }
+
+ for (Transfer transfer : transfers)
+ {
+ if (transfer.isSupportedType(type))
+ {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ protected abstract boolean validateTarget(Object target, int operation);
+
+ protected abstract boolean performDrop(TYPE data, Object target);
+}
diff --git a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/dnd/DNDTransfer.java b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/dnd/DNDTransfer.java index f8a407b6fd..30603b49f0 100644 --- a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/dnd/DNDTransfer.java +++ b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/dnd/DNDTransfer.java @@ -1,98 +1,98 @@ -/* - * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) 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: - * Eike Stepper - initial API and implementation - */ -package org.eclipse.net4j.util.ui.dnd; - -import org.eclipse.net4j.util.internal.ui.bundle.OM; -import org.eclipse.net4j.util.io.ExtendedDataInputStream; -import org.eclipse.net4j.util.io.ExtendedDataOutputStream; - -import org.eclipse.swt.dnd.ByteArrayTransfer; -import org.eclipse.swt.dnd.TransferData; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; - -/** - * @author Eike Stepper - */ -public abstract class DNDTransfer<TYPE> extends ByteArrayTransfer -{ - private String typeName; - - private int typeID; - - protected DNDTransfer(String typeName) - { - this.typeName = typeName; - typeID = registerType(typeName); - } - - @Override - protected int[] getTypeIds() - { - return new int[] { typeID }; - } - - @Override - protected String[] getTypeNames() - { - return new String[] { typeName }; - } - - @Override - protected void javaToNative(Object object, TransferData transferData) - { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - ExtendedDataOutputStream out = new ExtendedDataOutputStream(baos); - byte[] bytes = null; - - try - { - @SuppressWarnings("unchecked") - TYPE typed = (TYPE)object; - writeObject(out, typed); - out.close(); - bytes = baos.toByteArray(); - } - catch (Exception ex) - { - OM.LOG.error(ex); - } - - if (bytes != null) - { - super.javaToNative(bytes, transferData); - } - } - - @Override - protected Object nativeToJava(TransferData transferData) - { - byte[] bytes = (byte[])super.nativeToJava(transferData); - ByteArrayInputStream bais = new ByteArrayInputStream(bytes); - ExtendedDataInputStream in = new ExtendedDataInputStream(bais); - - try - { - return readObject(in); - } - catch (Exception ex) - { - OM.LOG.error(ex); - return null; - } - } - - protected abstract void writeObject(ExtendedDataOutputStream out, TYPE object) throws IOException; - - protected abstract TYPE readObject(ExtendedDataInputStream in) throws IOException; -} +/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.util.ui.dnd;
+
+import org.eclipse.net4j.util.internal.ui.bundle.OM;
+import org.eclipse.net4j.util.io.ExtendedDataInputStream;
+import org.eclipse.net4j.util.io.ExtendedDataOutputStream;
+
+import org.eclipse.swt.dnd.ByteArrayTransfer;
+import org.eclipse.swt.dnd.TransferData;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+
+/**
+ * @author Eike Stepper
+ */
+public abstract class DNDTransfer<TYPE> extends ByteArrayTransfer
+{
+ private String typeName;
+
+ private int typeID;
+
+ protected DNDTransfer(String typeName)
+ {
+ this.typeName = typeName;
+ typeID = registerType(typeName);
+ }
+
+ @Override
+ protected int[] getTypeIds()
+ {
+ return new int[] { typeID };
+ }
+
+ @Override
+ protected String[] getTypeNames()
+ {
+ return new String[] { typeName };
+ }
+
+ @Override
+ protected void javaToNative(Object object, TransferData transferData)
+ {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ExtendedDataOutputStream out = new ExtendedDataOutputStream(baos);
+ byte[] bytes = null;
+
+ try
+ {
+ @SuppressWarnings("unchecked")
+ TYPE typed = (TYPE)object;
+ writeObject(out, typed);
+ out.close();
+ bytes = baos.toByteArray();
+ }
+ catch (Exception ex)
+ {
+ OM.LOG.error(ex);
+ }
+
+ if (bytes != null)
+ {
+ super.javaToNative(bytes, transferData);
+ }
+ }
+
+ @Override
+ protected Object nativeToJava(TransferData transferData)
+ {
+ byte[] bytes = (byte[])super.nativeToJava(transferData);
+ ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
+ ExtendedDataInputStream in = new ExtendedDataInputStream(bais);
+
+ try
+ {
+ return readObject(in);
+ }
+ catch (Exception ex)
+ {
+ OM.LOG.error(ex);
+ return null;
+ }
+ }
+
+ protected abstract void writeObject(ExtendedDataOutputStream out, TYPE object) throws IOException;
+
+ protected abstract TYPE readObject(ExtendedDataInputStream in) throws IOException;
+}
diff --git a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/dnd/package-info.java b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/dnd/package-info.java index 8f530cb9b6..af02007bcf 100644 --- a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/dnd/package-info.java +++ b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/dnd/package-info.java @@ -1,5 +1,5 @@ /*
- * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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
diff --git a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/package-info.java b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/package-info.java index 62b398dd79..37cd57d8af 100644 --- a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/package-info.java +++ b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/package-info.java @@ -1,5 +1,5 @@ /*
- * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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
diff --git a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/prefs/OMPreferencePage.java b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/prefs/OMPreferencePage.java index 63549b2694..5520e925f9 100644 --- a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/prefs/OMPreferencePage.java +++ b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/prefs/OMPreferencePage.java @@ -1,185 +1,185 @@ -/* - * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) 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: - * Eike Stepper - initial API and implementation - */ -package org.eclipse.net4j.util.ui.prefs; - -import org.eclipse.net4j.util.internal.ui.bundle.OM; -import org.eclipse.net4j.util.om.pref.OMPreferences; - -import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.jface.preference.PreferencePage; -import org.eclipse.swt.custom.CCombo; -import org.eclipse.swt.events.ModifyEvent; -import org.eclipse.swt.events.ModifyListener; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.events.SelectionListener; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Combo; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.DateTime; -import org.eclipse.swt.widgets.List; -import org.eclipse.swt.widgets.Table; -import org.eclipse.swt.widgets.Text; -import org.eclipse.swt.widgets.Tree; -import org.eclipse.ui.IWorkbench; -import org.eclipse.ui.IWorkbenchPreferencePage; - -/** - * @author Eike Stepper - */ -public abstract class OMPreferencePage extends PreferencePage implements IWorkbenchPreferencePage -{ - private IWorkbench workbench; - - private OMPreferenceStore preferenceStore; - - private SelectionListener selectionListener = new SelectionListener() - { - public void widgetDefaultSelected(SelectionEvent e) - { - dialogChanged(); - } - - public void widgetSelected(SelectionEvent e) - { - dialogChanged(); - } - }; - - private ModifyListener modifyListener = new ModifyListener() - { - public void modifyText(ModifyEvent e) - { - dialogChanged(); - } - }; - - public OMPreferencePage(OMPreferences preferences) - { - preferenceStore = new OMPreferenceStore(preferences); - } - - public OMPreferences getPreferences() - { - return preferenceStore.getPreferences(); - } - - public IWorkbench getWorkbench() - { - return workbench; - } - - public void init(IWorkbench workbench) - { - this.workbench = workbench; - } - - @Override - protected IPreferenceStore doGetPreferenceStore() - { - return preferenceStore; - } - - protected final SelectionListener getSelectionListener() - { - return selectionListener; - } - - protected final ModifyListener getModifyListener() - { - return modifyListener; - } - - protected void dialogChanged() - { - } - - @Override - protected final Control createContents(Composite parent) - { - try - { - Control control = createUI(parent); - dialogChanged(); - addListeners(control); - return control; - } - catch (RuntimeException ex) - { - OM.LOG.error(ex); - throw ex; - } - } - - protected void addListeners(Control control) - { - if (control instanceof Text) - { - Text c = (Text)control; - c.addModifyListener(modifyListener); - } - - if (control instanceof Combo) - { - Combo c = (Combo)control; - c.addModifyListener(modifyListener); - c.addSelectionListener(selectionListener); - } - - if (control instanceof CCombo) - { - CCombo c = (CCombo)control; - c.addModifyListener(modifyListener); - c.addSelectionListener(selectionListener); - } - - if (control instanceof List) - { - List c = (List)control; - c.addSelectionListener(selectionListener); - } - - if (control instanceof DateTime) - { - DateTime c = (DateTime)control; - c.addSelectionListener(selectionListener); - } - - if (control instanceof Table) - { - Table c = (Table)control; - c.addSelectionListener(selectionListener); - } - - if (control instanceof Tree) - { - Table c = (Table)control; - c.addSelectionListener(selectionListener); - } - - if (control instanceof Button) - { - Button c = (Button)control; - c.addSelectionListener(selectionListener); - } - - if (control instanceof Composite) - { - Composite c = (Composite)control; - for (Control child : c.getChildren()) - { - addListeners(child); - } - } - } - - protected abstract Control createUI(Composite parent); -} +/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.util.ui.prefs;
+
+import org.eclipse.net4j.util.internal.ui.bundle.OM;
+import org.eclipse.net4j.util.om.pref.OMPreferences;
+
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.preference.PreferencePage;
+import org.eclipse.swt.custom.CCombo;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.DateTime;
+import org.eclipse.swt.widgets.List;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.swt.widgets.Tree;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPreferencePage;
+
+/**
+ * @author Eike Stepper
+ */
+public abstract class OMPreferencePage extends PreferencePage implements IWorkbenchPreferencePage
+{
+ private IWorkbench workbench;
+
+ private OMPreferenceStore preferenceStore;
+
+ private SelectionListener selectionListener = new SelectionListener()
+ {
+ public void widgetDefaultSelected(SelectionEvent e)
+ {
+ dialogChanged();
+ }
+
+ public void widgetSelected(SelectionEvent e)
+ {
+ dialogChanged();
+ }
+ };
+
+ private ModifyListener modifyListener = new ModifyListener()
+ {
+ public void modifyText(ModifyEvent e)
+ {
+ dialogChanged();
+ }
+ };
+
+ public OMPreferencePage(OMPreferences preferences)
+ {
+ preferenceStore = new OMPreferenceStore(preferences);
+ }
+
+ public OMPreferences getPreferences()
+ {
+ return preferenceStore.getPreferences();
+ }
+
+ public IWorkbench getWorkbench()
+ {
+ return workbench;
+ }
+
+ public void init(IWorkbench workbench)
+ {
+ this.workbench = workbench;
+ }
+
+ @Override
+ protected IPreferenceStore doGetPreferenceStore()
+ {
+ return preferenceStore;
+ }
+
+ protected final SelectionListener getSelectionListener()
+ {
+ return selectionListener;
+ }
+
+ protected final ModifyListener getModifyListener()
+ {
+ return modifyListener;
+ }
+
+ protected void dialogChanged()
+ {
+ }
+
+ @Override
+ protected final Control createContents(Composite parent)
+ {
+ try
+ {
+ Control control = createUI(parent);
+ dialogChanged();
+ addListeners(control);
+ return control;
+ }
+ catch (RuntimeException ex)
+ {
+ OM.LOG.error(ex);
+ throw ex;
+ }
+ }
+
+ protected void addListeners(Control control)
+ {
+ if (control instanceof Text)
+ {
+ Text c = (Text)control;
+ c.addModifyListener(modifyListener);
+ }
+
+ if (control instanceof Combo)
+ {
+ Combo c = (Combo)control;
+ c.addModifyListener(modifyListener);
+ c.addSelectionListener(selectionListener);
+ }
+
+ if (control instanceof CCombo)
+ {
+ CCombo c = (CCombo)control;
+ c.addModifyListener(modifyListener);
+ c.addSelectionListener(selectionListener);
+ }
+
+ if (control instanceof List)
+ {
+ List c = (List)control;
+ c.addSelectionListener(selectionListener);
+ }
+
+ if (control instanceof DateTime)
+ {
+ DateTime c = (DateTime)control;
+ c.addSelectionListener(selectionListener);
+ }
+
+ if (control instanceof Table)
+ {
+ Table c = (Table)control;
+ c.addSelectionListener(selectionListener);
+ }
+
+ if (control instanceof Tree)
+ {
+ Table c = (Table)control;
+ c.addSelectionListener(selectionListener);
+ }
+
+ if (control instanceof Button)
+ {
+ Button c = (Button)control;
+ c.addSelectionListener(selectionListener);
+ }
+
+ if (control instanceof Composite)
+ {
+ Composite c = (Composite)control;
+ for (Control child : c.getChildren())
+ {
+ addListeners(child);
+ }
+ }
+ }
+
+ protected abstract Control createUI(Composite parent);
+}
diff --git a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/prefs/OMPreferenceStore.java b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/prefs/OMPreferenceStore.java index b0c3b684e9..6486a7ed3b 100644 --- a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/prefs/OMPreferenceStore.java +++ b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/prefs/OMPreferenceStore.java @@ -1,274 +1,274 @@ -/* - * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) 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: - * Eike Stepper - initial API and implementation - */ -package org.eclipse.net4j.util.ui.prefs; - -import org.eclipse.net4j.util.event.IEvent; -import org.eclipse.net4j.util.event.IListener; -import org.eclipse.net4j.util.internal.ui.bundle.OM; -import org.eclipse.net4j.util.om.pref.OMPreference; -import org.eclipse.net4j.util.om.pref.OMPreferences; -import org.eclipse.net4j.util.om.pref.OMPreferencesChangeEvent; - -import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.jface.util.IPropertyChangeListener; -import org.eclipse.jface.util.PropertyChangeEvent; - -import java.util.ArrayList; -import java.util.List; - -/** - * @author Eike Stepper - */ -public class OMPreferenceStore implements IPreferenceStore -{ - private OMPreferences preferences; - - private List<IPropertyChangeListener> listeners = new ArrayList<IPropertyChangeListener>(0); - - private IListener preferencesListener = new IListener() - { - public void notifyEvent(IEvent event) - { - if (event instanceof OMPreferencesChangeEvent<?>) - { - OMPreferencesChangeEvent<?> e = (OMPreferencesChangeEvent<?>)event; - firePropertyChangeEvent(e.getPreference().getName(), e.getOldValue(), e.getNewValue()); - } - } - }; - - public OMPreferenceStore(OMPreferences preferences) - { - this.preferences = preferences; - preferences.addListener(preferencesListener); - } - - public void dispose() - { - preferences.removeListener(preferencesListener); - } - - public OMPreferences getPreferences() - { - return preferences; - } - - public void addPropertyChangeListener(IPropertyChangeListener listener) - { - synchronized (listeners) - { - if (!listeners.contains(listener)) - { - listeners.add(listener); - } - } - } - - public void removePropertyChangeListener(IPropertyChangeListener listener) - { - synchronized (listeners) - { - listeners.remove(listener); - } - } - - public void firePropertyChangeEvent(String name, Object oldValue, Object newValue) - { - PropertyChangeEvent event = new PropertyChangeEvent(this, name, oldValue, newValue); - for (IPropertyChangeListener listener : getPropertyChangeListenerListeners()) - { - try - { - listener.propertyChange(event); - } - catch (RuntimeException ex) - { - OM.LOG.error(ex); - } - } - } - - public boolean contains(String name) - { - return preferences.contains(name); - } - - public boolean isDefault(String name) - { - return !getPreference(name).isSet(); - } - - public boolean needsSaving() - { - return preferences.isDirty(); - } - - public boolean getDefaultBoolean(String name) - { - return (Boolean)getPreference(name).getDefaultValue(); - } - - public double getDefaultDouble(String name) - { - return (Double)getPreference(name).getDefaultValue(); - } - - public float getDefaultFloat(String name) - { - return (Float)getPreference(name).getDefaultValue(); - } - - public int getDefaultInt(String name) - { - return (Integer)getPreference(name).getDefaultValue(); - } - - public long getDefaultLong(String name) - { - return (Long)getPreference(name).getDefaultValue(); - } - - public String getDefaultString(String name) - { - return (String)getPreference(name).getDefaultValue(); - } - - public void setDefault(String name, boolean value) - { - throw new UnsupportedOperationException(); - } - - public void setDefault(String name, double value) - { - throw new UnsupportedOperationException(); - } - - public void setDefault(String name, float value) - { - throw new UnsupportedOperationException(); - } - - public void setDefault(String name, int value) - { - throw new UnsupportedOperationException(); - } - - public void setDefault(String name, long value) - { - throw new UnsupportedOperationException(); - } - - public void setDefault(String name, String defaultObject) - { - throw new UnsupportedOperationException(); - } - - public void setToDefault(String name) - { - getPreference(name).unSet(); - } - - public boolean getBoolean(String name) - { - return (Boolean)getPreference(name).getValue(); - } - - public double getDouble(String name) - { - return (Double)getPreference(name).getValue(); - } - - public float getFloat(String name) - { - return (Float)getPreference(name).getValue(); - } - - public int getInt(String name) - { - return (Integer)getPreference(name).getValue(); - } - - public long getLong(String name) - { - return (Long)getPreference(name).getValue(); - } - - public String getString(String name) - { - return (String)getPreference(name).getValue(); - } - - public void putValue(String name, String value) - { - throw new UnsupportedOperationException(); - } - - @SuppressWarnings("unchecked") - public void setValue(String name, boolean value) - { - OMPreference<Boolean> pref = (OMPreference<Boolean>)getPreference(name); - pref.setValue(value); - } - - @SuppressWarnings("unchecked") - public void setValue(String name, double value) - { - OMPreference<Double> pref = (OMPreference<Double>)getPreference(name); - pref.setValue(value); - } - - @SuppressWarnings("unchecked") - public void setValue(String name, float value) - { - OMPreference<Float> pref = (OMPreference<Float>)getPreference(name); - pref.setValue(value); - } - - @SuppressWarnings("unchecked") - public void setValue(String name, int value) - { - OMPreference<Integer> pref = (OMPreference<Integer>)getPreference(name); - pref.setValue(value); - } - - @SuppressWarnings("unchecked") - public void setValue(String name, long value) - { - OMPreference<Long> pref = (OMPreference<Long>)getPreference(name); - pref.setValue(value); - } - - @SuppressWarnings("unchecked") - public void setValue(String name, String value) - { - OMPreference<String> pref = (OMPreference<String>)getPreference(name); - pref.setValue(value); - } - - private IPropertyChangeListener[] getPropertyChangeListenerListeners() - { - synchronized (listeners) - { - return listeners.toArray(new IPropertyChangeListener[listeners.size()]); - } - } - - private OMPreference<?> getPreference(String name) - { - OMPreference<?> pref = preferences.get(name); - if (pref == null) - { - throw new IllegalStateException("No preference for " + name); //$NON-NLS-1$ - } - - return pref; - } -} +/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.util.ui.prefs;
+
+import org.eclipse.net4j.util.event.IEvent;
+import org.eclipse.net4j.util.event.IListener;
+import org.eclipse.net4j.util.internal.ui.bundle.OM;
+import org.eclipse.net4j.util.om.pref.OMPreference;
+import org.eclipse.net4j.util.om.pref.OMPreferences;
+import org.eclipse.net4j.util.om.pref.OMPreferencesChangeEvent;
+
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.util.IPropertyChangeListener;
+import org.eclipse.jface.util.PropertyChangeEvent;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author Eike Stepper
+ */
+public class OMPreferenceStore implements IPreferenceStore
+{
+ private OMPreferences preferences;
+
+ private List<IPropertyChangeListener> listeners = new ArrayList<IPropertyChangeListener>(0);
+
+ private IListener preferencesListener = new IListener()
+ {
+ public void notifyEvent(IEvent event)
+ {
+ if (event instanceof OMPreferencesChangeEvent<?>)
+ {
+ OMPreferencesChangeEvent<?> e = (OMPreferencesChangeEvent<?>)event;
+ firePropertyChangeEvent(e.getPreference().getName(), e.getOldValue(), e.getNewValue());
+ }
+ }
+ };
+
+ public OMPreferenceStore(OMPreferences preferences)
+ {
+ this.preferences = preferences;
+ preferences.addListener(preferencesListener);
+ }
+
+ public void dispose()
+ {
+ preferences.removeListener(preferencesListener);
+ }
+
+ public OMPreferences getPreferences()
+ {
+ return preferences;
+ }
+
+ public void addPropertyChangeListener(IPropertyChangeListener listener)
+ {
+ synchronized (listeners)
+ {
+ if (!listeners.contains(listener))
+ {
+ listeners.add(listener);
+ }
+ }
+ }
+
+ public void removePropertyChangeListener(IPropertyChangeListener listener)
+ {
+ synchronized (listeners)
+ {
+ listeners.remove(listener);
+ }
+ }
+
+ public void firePropertyChangeEvent(String name, Object oldValue, Object newValue)
+ {
+ PropertyChangeEvent event = new PropertyChangeEvent(this, name, oldValue, newValue);
+ for (IPropertyChangeListener listener : getPropertyChangeListenerListeners())
+ {
+ try
+ {
+ listener.propertyChange(event);
+ }
+ catch (RuntimeException ex)
+ {
+ OM.LOG.error(ex);
+ }
+ }
+ }
+
+ public boolean contains(String name)
+ {
+ return preferences.contains(name);
+ }
+
+ public boolean isDefault(String name)
+ {
+ return !getPreference(name).isSet();
+ }
+
+ public boolean needsSaving()
+ {
+ return preferences.isDirty();
+ }
+
+ public boolean getDefaultBoolean(String name)
+ {
+ return (Boolean)getPreference(name).getDefaultValue();
+ }
+
+ public double getDefaultDouble(String name)
+ {
+ return (Double)getPreference(name).getDefaultValue();
+ }
+
+ public float getDefaultFloat(String name)
+ {
+ return (Float)getPreference(name).getDefaultValue();
+ }
+
+ public int getDefaultInt(String name)
+ {
+ return (Integer)getPreference(name).getDefaultValue();
+ }
+
+ public long getDefaultLong(String name)
+ {
+ return (Long)getPreference(name).getDefaultValue();
+ }
+
+ public String getDefaultString(String name)
+ {
+ return (String)getPreference(name).getDefaultValue();
+ }
+
+ public void setDefault(String name, boolean value)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public void setDefault(String name, double value)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public void setDefault(String name, float value)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public void setDefault(String name, int value)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public void setDefault(String name, long value)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public void setDefault(String name, String defaultObject)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public void setToDefault(String name)
+ {
+ getPreference(name).unSet();
+ }
+
+ public boolean getBoolean(String name)
+ {
+ return (Boolean)getPreference(name).getValue();
+ }
+
+ public double getDouble(String name)
+ {
+ return (Double)getPreference(name).getValue();
+ }
+
+ public float getFloat(String name)
+ {
+ return (Float)getPreference(name).getValue();
+ }
+
+ public int getInt(String name)
+ {
+ return (Integer)getPreference(name).getValue();
+ }
+
+ public long getLong(String name)
+ {
+ return (Long)getPreference(name).getValue();
+ }
+
+ public String getString(String name)
+ {
+ return (String)getPreference(name).getValue();
+ }
+
+ public void putValue(String name, String value)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ @SuppressWarnings("unchecked")
+ public void setValue(String name, boolean value)
+ {
+ OMPreference<Boolean> pref = (OMPreference<Boolean>)getPreference(name);
+ pref.setValue(value);
+ }
+
+ @SuppressWarnings("unchecked")
+ public void setValue(String name, double value)
+ {
+ OMPreference<Double> pref = (OMPreference<Double>)getPreference(name);
+ pref.setValue(value);
+ }
+
+ @SuppressWarnings("unchecked")
+ public void setValue(String name, float value)
+ {
+ OMPreference<Float> pref = (OMPreference<Float>)getPreference(name);
+ pref.setValue(value);
+ }
+
+ @SuppressWarnings("unchecked")
+ public void setValue(String name, int value)
+ {
+ OMPreference<Integer> pref = (OMPreference<Integer>)getPreference(name);
+ pref.setValue(value);
+ }
+
+ @SuppressWarnings("unchecked")
+ public void setValue(String name, long value)
+ {
+ OMPreference<Long> pref = (OMPreference<Long>)getPreference(name);
+ pref.setValue(value);
+ }
+
+ @SuppressWarnings("unchecked")
+ public void setValue(String name, String value)
+ {
+ OMPreference<String> pref = (OMPreference<String>)getPreference(name);
+ pref.setValue(value);
+ }
+
+ private IPropertyChangeListener[] getPropertyChangeListenerListeners()
+ {
+ synchronized (listeners)
+ {
+ return listeners.toArray(new IPropertyChangeListener[listeners.size()]);
+ }
+ }
+
+ private OMPreference<?> getPreference(String name)
+ {
+ OMPreference<?> pref = preferences.get(name);
+ if (pref == null)
+ {
+ throw new IllegalStateException("No preference for " + name); //$NON-NLS-1$
+ }
+
+ return pref;
+ }
+}
diff --git a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/prefs/package-info.java b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/prefs/package-info.java index 3b41832c93..f33eb88b95 100644 --- a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/prefs/package-info.java +++ b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/prefs/package-info.java @@ -1,5 +1,5 @@ /*
- * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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
diff --git a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/proposals/README.java b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/proposals/README.java index e7a6a97fe7..93ac93e91b 100644 --- a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/proposals/README.java +++ b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/proposals/README.java @@ -1,23 +1,23 @@ -/* - * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) 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: - * Eike Stepper - initial API and implementation - */ -package org.eclipse.net4j.util.ui.proposals; - -/** - * The classes in this package are copied from org.eclipse.ui.texteditor because the class - * org.eclipse.ui.texteditor.RegExContentProposalProvider is not public. - * <p> - * TODO We should ask platform guys to open this API. - * - * @author Eike Stepper - */ -class README -{ -} +/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.util.ui.proposals;
+
+/**
+ * The classes in this package are copied from org.eclipse.ui.texteditor because the class
+ * org.eclipse.ui.texteditor.RegExContentProposalProvider is not public.
+ * <p>
+ * TODO We should ask platform guys to open this API.
+ *
+ * @author Eike Stepper
+ */
+class README
+{
+}
diff --git a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/proposals/package-info.java b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/proposals/package-info.java index 3f337a121d..abeb74b28d 100644 --- a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/proposals/package-info.java +++ b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/proposals/package-info.java @@ -1,5 +1,5 @@ /*
- * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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
diff --git a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/security/CredentialsDialog.java b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/security/CredentialsDialog.java index 3703676643..b104432488 100644 --- a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/security/CredentialsDialog.java +++ b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/security/CredentialsDialog.java @@ -1,76 +1,76 @@ -/* - * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) 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: - * Eike Stepper - initial API and implementation - */ -package org.eclipse.net4j.util.ui.security; - -import org.eclipse.net4j.util.internal.ui.bundle.OM; -import org.eclipse.net4j.util.internal.ui.messages.Messages; -import org.eclipse.net4j.util.security.IPasswordCredentials; -import org.eclipse.net4j.util.security.PasswordCredentials; -import org.eclipse.net4j.util.ui.UIUtil; -import org.eclipse.net4j.util.ui.widgets.BaseDialog; - -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.swt.SWT; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Text; - -/** - * @author Eike Stepper - * @since 2.0 - */ -public class CredentialsDialog extends BaseDialog<Viewer> -{ - private static final String TITLE = Messages.getString("CredentialsDialog_0"); //$NON-NLS-1$ - - private static final String MESSAGE = Messages.getString("CredentialsDialog_1"); //$NON-NLS-1$ - - private Text userIDControl; - - private Text passwordControl; - - private IPasswordCredentials credentials; - - public CredentialsDialog(Shell shell) - { - super(shell, DEFAULT_SHELL_STYLE | SWT.APPLICATION_MODAL, TITLE, MESSAGE, OM.Activator.INSTANCE.getDialogSettings()); - } - - public IPasswordCredentials getCredentials() - { - return credentials; - } - - @Override - protected void createUI(Composite parent) - { - Composite composite = new Composite(parent, SWT.NONE); - composite.setLayout(new GridLayout(2, false)); - composite.setLayoutData(UIUtil.createGridData()); - - new Label(composite, SWT.NONE).setText(Messages.getString("CredentialsDialog_2")); //$NON-NLS-1$ - userIDControl = new Text(composite, SWT.BORDER); - - new Label(composite, SWT.NONE).setText(Messages.getString("CredentialsDialog_3")); //$NON-NLS-1$ - passwordControl = new Text(composite, SWT.BORDER | SWT.PASSWORD); - } - - @Override - protected void okPressed() - { - String userID = userIDControl.getText(); - String password = passwordControl.getText(); - credentials = new PasswordCredentials(userID, password.toCharArray()); - super.okPressed(); - } -} +/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.util.ui.security;
+
+import org.eclipse.net4j.util.internal.ui.bundle.OM;
+import org.eclipse.net4j.util.internal.ui.messages.Messages;
+import org.eclipse.net4j.util.security.IPasswordCredentials;
+import org.eclipse.net4j.util.security.PasswordCredentials;
+import org.eclipse.net4j.util.ui.UIUtil;
+import org.eclipse.net4j.util.ui.widgets.BaseDialog;
+
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+
+/**
+ * @author Eike Stepper
+ * @since 2.0
+ */
+public class CredentialsDialog extends BaseDialog<Viewer>
+{
+ private static final String TITLE = Messages.getString("CredentialsDialog_0"); //$NON-NLS-1$
+
+ private static final String MESSAGE = Messages.getString("CredentialsDialog_1"); //$NON-NLS-1$
+
+ private Text userIDControl;
+
+ private Text passwordControl;
+
+ private IPasswordCredentials credentials;
+
+ public CredentialsDialog(Shell shell)
+ {
+ super(shell, DEFAULT_SHELL_STYLE | SWT.APPLICATION_MODAL, TITLE, MESSAGE, OM.Activator.INSTANCE.getDialogSettings());
+ }
+
+ public IPasswordCredentials getCredentials()
+ {
+ return credentials;
+ }
+
+ @Override
+ protected void createUI(Composite parent)
+ {
+ Composite composite = new Composite(parent, SWT.NONE);
+ composite.setLayout(new GridLayout(2, false));
+ composite.setLayoutData(UIUtil.createGridData());
+
+ new Label(composite, SWT.NONE).setText(Messages.getString("CredentialsDialog_2")); //$NON-NLS-1$
+ userIDControl = new Text(composite, SWT.BORDER);
+
+ new Label(composite, SWT.NONE).setText(Messages.getString("CredentialsDialog_3")); //$NON-NLS-1$
+ passwordControl = new Text(composite, SWT.BORDER | SWT.PASSWORD);
+ }
+
+ @Override
+ protected void okPressed()
+ {
+ String userID = userIDControl.getText();
+ String password = passwordControl.getText();
+ credentials = new PasswordCredentials(userID, password.toCharArray());
+ super.okPressed();
+ }
+}
diff --git a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/security/InteractiveCredentialsProvider.java b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/security/InteractiveCredentialsProvider.java index 8045f0e657..aefafc166e 100644 --- a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/security/InteractiveCredentialsProvider.java +++ b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/security/InteractiveCredentialsProvider.java @@ -1,53 +1,53 @@ -/* - * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) 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: - * Eike Stepper - initial API and implementation - */ -package org.eclipse.net4j.util.ui.security; - -import org.eclipse.net4j.util.security.IPasswordCredentials; -import org.eclipse.net4j.util.security.IPasswordCredentialsProvider; -import org.eclipse.net4j.util.ui.UIUtil; - -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Shell; - -/** - * @author Eike Stepper - * @since 2.0 - */ -public class InteractiveCredentialsProvider implements IPasswordCredentialsProvider -{ - public InteractiveCredentialsProvider() - { - } - - public boolean isInteractive() - { - return true; - } - - public IPasswordCredentials getCredentials() - { - final IPasswordCredentials[] credentials = new IPasswordCredentials[1]; - final Display display = UIUtil.getDisplay(); - display.syncExec(new Runnable() - { - public void run() - { - CredentialsDialog dialog = new CredentialsDialog(new Shell(display)); - if (dialog.open() == CredentialsDialog.OK) - { - credentials[0] = dialog.getCredentials(); - } - } - }); - - return credentials[0]; - } -} +/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.util.ui.security;
+
+import org.eclipse.net4j.util.security.IPasswordCredentials;
+import org.eclipse.net4j.util.security.IPasswordCredentialsProvider;
+import org.eclipse.net4j.util.ui.UIUtil;
+
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+
+/**
+ * @author Eike Stepper
+ * @since 2.0
+ */
+public class InteractiveCredentialsProvider implements IPasswordCredentialsProvider
+{
+ public InteractiveCredentialsProvider()
+ {
+ }
+
+ public boolean isInteractive()
+ {
+ return true;
+ }
+
+ public IPasswordCredentials getCredentials()
+ {
+ final IPasswordCredentials[] credentials = new IPasswordCredentials[1];
+ final Display display = UIUtil.getDisplay();
+ display.syncExec(new Runnable()
+ {
+ public void run()
+ {
+ CredentialsDialog dialog = new CredentialsDialog(new Shell(display));
+ if (dialog.open() == CredentialsDialog.OK)
+ {
+ credentials[0] = dialog.getCredentials();
+ }
+ }
+ });
+
+ return credentials[0];
+ }
+}
diff --git a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/security/package-info.java b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/security/package-info.java index a84eec153d..017139fd4c 100644 --- a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/security/package-info.java +++ b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/security/package-info.java @@ -1,5 +1,5 @@ /*
- * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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
diff --git a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/views/ContainerItemProvider.java b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/views/ContainerItemProvider.java index efbc5f1e13..e68ece4e93 100644 --- a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/views/ContainerItemProvider.java +++ b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/views/ContainerItemProvider.java @@ -1,721 +1,721 @@ -/* - * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) 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: - * Eike Stepper - initial API and implementation - */ -package org.eclipse.net4j.util.ui.views; - -import org.eclipse.net4j.internal.util.bundle.OM; -import org.eclipse.net4j.ui.shared.SharedIcons; -import org.eclipse.net4j.util.container.ContainerEventAdapter; -import org.eclipse.net4j.util.container.IContainer; -import org.eclipse.net4j.util.container.ISlow; -import org.eclipse.net4j.util.event.EventUtil; -import org.eclipse.net4j.util.event.IEvent; -import org.eclipse.net4j.util.event.IListener; -import org.eclipse.net4j.util.lifecycle.LifecycleState; -import org.eclipse.net4j.util.lifecycle.LifecycleUtil; -import org.eclipse.net4j.util.ui.UIUtil; - -import org.eclipse.jface.action.Action; -import org.eclipse.jface.action.IMenuManager; -import org.eclipse.jface.viewers.ITreeSelection; -import org.eclipse.jface.viewers.TreePath; -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.Font; -import org.eclipse.swt.graphics.Image; -import org.eclipse.ui.PartInitException; - -import java.text.MessageFormat; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -/** - * @author Eike Stepper - */ -/** - * @author Eike Stepper - */ -public class ContainerItemProvider<CONTAINER extends IContainer<Object>> extends ItemProvider<CONTAINER> -{ - private Map<Object, Node> nodes = new HashMap<Object, Node>(); - - private Node root; - - private IElementFilter rootElementFilter; - - public ContainerItemProvider() - { - } - - public ContainerItemProvider(IElementFilter rootElementFilter) - { - this.rootElementFilter = rootElementFilter; - } - - public IElementFilter getRootElementFilter() - { - return rootElementFilter; - } - - @Override - public boolean hasChildren(Object element) - { - try - { - Node node = getNode(element); - return !node.getChildren().isEmpty(); - } - catch (Exception ex) - { - return false; - } - } - - public Object[] getChildren(Object element) - { - try - { - Node node = getNode(element); - List<Node> children = node.getChildren(); - for (Iterator<Node> it = children.iterator(); it.hasNext();) - { - Node child = it.next(); - if (child.isDisposed()) - { - it.remove(); - } - else - { - Object childElement = child.getElement(); - LifecycleState lifecycleState = LifecycleUtil.getLifecycleState(childElement); - if (lifecycleState == LifecycleState.INACTIVE || lifecycleState == LifecycleState.DEACTIVATING) - { - handleInactiveElement(it, child); - } - } - } - - Object[] result = new Object[children.size()]; - for (int i = 0; i < result.length; i++) - { - result[i] = children.get(i).getElement(); - } - - return result; - } - catch (RuntimeException ex) - { - return NO_ELEMENTS; - } - } - - public Object getParent(Object element) - { - try - { - Node node = getNode(element); - Node parentNode = node.getParent(); - return parentNode == null ? null : parentNode.getElement(); - } - catch (RuntimeException ex) - { - return null; - } - } - - @Override - public void dispose() - { - super.dispose(); - } - - @Override - protected void connectInput(CONTAINER input) - { - root = createNode(null, input); - if (root != null) - { - addNode(input, root); - } - } - - @Override - protected void disconnectInput(CONTAINER input) - { - root.dispose(); - root = null; - nodes.clear(); - } - - /** - * @since 2.0 - */ - protected void handleInactiveElement(Iterator<Node> it, Node child) - { - it.remove(); - child.dispose(); - } - - protected void elementAdded(Object element, Object parent) - { - } - - protected void elementRemoved(Object element, Object parent) - { - } - - protected Node getRoot() - { - return root; - } - - protected Map<Object, Node> getNodes() - { - return nodes; - } - - protected Node getNode(Object element) - { - Node node = root; - if (element != getInput()) - { - node = nodes.get(element); - } - - if (node == null) - { - throw new IllegalStateException("No node for " + element); //$NON-NLS-1$ - } - - return node; - } - - protected Node createNode(Node parent, Object element) - { - if (element instanceof IContainer<?>) - { - return createContaineNode(parent, element); - } - - return createLeafNode(parent, element); - } - - protected LeafNode createLeafNode(Node parent, Object element) - { - return new LeafNode(parent, element); - } - - @SuppressWarnings("unchecked") - protected ContainerNode createContaineNode(Node parent, Object element) - { - return new ContainerNode(parent, (IContainer<Object>)element); - } - - protected void addNode(Object element, Node node) - { - nodes.put(element, node); - } - - protected Node removeNode(Object element) - { - return nodes.remove(element); - } - - protected boolean filterRootElement(Object element) - { - if (rootElementFilter != null) - { - return rootElementFilter.filter(element); - } - - return true; - } - - /** - * @since 3.1 - */ - protected void executeRunnable(Runnable runnable) - { - Thread thread = new Thread(runnable); - thread.setDaemon(true); - thread.start(); - } - - /** - * @since 3.1 - */ - protected boolean isSlow(IContainer<Object> container) - { - return container instanceof ISlow; - } - - /** - * @since 3.1 - */ - protected String getSlowText(IContainer<Object> container) - { - return "Pending..."; - } - - /** - * @since 3.1 - */ - protected String getErrorText(IContainer<Object> container) - { - return "Error"; - } - - @Override - protected void fillContextMenu(IMenuManager manager, ITreeSelection selection) - { - super.fillContextMenu(manager, selection); - if (selection.size() == 1) - { - Object element = selection.getFirstElement(); - if (element instanceof ContainerItemProvider.ErrorElement) - { - manager.add(new Action("Open Error Log") - { - @Override - public void run() - { - try - { - UIUtil.getActiveWorkbenchPage().showView(UIUtil.ERROR_LOG_ID); - } - catch (PartInitException ex) - { - OM.LOG.error(ex); - } - } - }); - } - } - } - - @Override - public Font getFont(Object obj) - { - if (obj instanceof ContainerItemProvider.LazyElement) - { - return getItalicFont(); - } - - return super.getFont(obj); - } - - @Override - public Color getForeground(Object obj) - { - if (obj instanceof ContainerItemProvider.LazyElement) - { - return getDisplay().getSystemColor(SWT.COLOR_GRAY); - } - - return super.getForeground(obj); - } - - @Override - public Image getImage(Object obj) - { - if (obj instanceof ContainerItemProvider.LazyElement) - { - return SharedIcons.getImage(SharedIcons.OBJ_PENDING); - } - - if (obj instanceof ContainerItemProvider.ErrorElement) - { - return SharedIcons.getImage(SharedIcons.OBJ_ERROR); - } - - return super.getImage(obj); - } - - /** - * @author Eike Stepper - */ - public interface Node - { - public void dispose(); - - public boolean isDisposed(); - - public Object getElement(); - - public Node getParent(); - - public List<Node> getChildren(); - - public TreePath getTreePath(); - } - - /** - * @author Eike Stepper - */ - public abstract class AbstractNode implements Node - { - private Node parent; - - private boolean disposed; - - public AbstractNode(Node parent) - { - this.parent = parent; - } - - public void dispose() - { - if (!disposed) - { - removeNode(getElement()); - parent = null; - disposed = true; - } - } - - public boolean isDisposed() - { - return disposed; - } - - @Override - public String toString() - { - return MessageFormat.format("{0}[{1}]", getClass().getSimpleName(), getElement()); //$NON-NLS-1$ - } - - public final Node getParent() - { - checkNotDisposed(); - return parent; - } - - public TreePath getTreePath() - { - TreePath parentPath = parent == null ? TreePath.EMPTY : parent.getTreePath(); - return parentPath.createChildPath(getElement()); - } - - protected void checkNotDisposed() - { - if (disposed) - { - throw new IllegalStateException("Node is already disposed of"); //$NON-NLS-1$ - } - } - - protected Node addChild(Collection<Node> children, Object element) - { - if (nodes.containsKey(element)) - { - return null; - } - - if (this != root || filterRootElement(element)) - { - Node node = createNode(this, element); - if (node != null) - { - addNode(element, node); - children.add(node); - return node; - } - } - - return null; - } - } - - /** - * @author Eike Stepper - */ - public abstract class AbstractContainerNode extends AbstractNode - { - private List<Node> children; - - protected IListener containerListener = new ContainerEventAdapter<Object>() - { - @Override - protected void onAdded(IContainer<Object> container, Object element) - { - AbstractContainerNode.this.onAdded(container, element); - } - - @Override - protected void onRemoved(IContainer<Object> container, Object element) - { - AbstractContainerNode.this.onRemoved(container, element); - } - - @Override - protected void notifyOtherEvent(IEvent event) - { - updateLabels(event.getSource()); - } - }; - - public AbstractContainerNode(Node parent) - { - super(parent); - } - - @Override - public void dispose() - { - if (!isDisposed()) - { - if (children != null) - { - for (Node child : children) - { - child.dispose(); - } - - children.clear(); - children = null; - containerListener = null; - } - - super.dispose(); - } - } - - public final List<Node> getChildren() - { - checkNotDisposed(); - if (children == null) - { - children = createChildren(); - } - - return children; - } - - @SuppressWarnings("unchecked") - public IContainer<Object> getContainer() - { - return (IContainer<Object>)getElement(); - } - - protected List<Node> createChildren() - { - final List<Node> children = new ArrayList<Node>(); - final IContainer<Object> container = getContainer(); - - if (isSlow(container)) - { - final LazyElement lazyElement = new LazyElement(container); - addChild(children, lazyElement); - - Runnable runnable = new Runnable() - { - public void run() - { - try - { - fillChildren(children, container); - } - catch (Exception ex) - { - OM.LOG.error(ex); - addChild(children, new ErrorElement(container)); - } - finally - { - Node node = removeNode(lazyElement); - children.remove(node); - refreshElement(container, false); - } - } - }; - - executeRunnable(runnable); - } - else - { - fillChildren(children, container); - } - - container.addListener(containerListener); - return children; - } - - /** - * @since 3.1 - */ - protected void fillChildren(List<Node> children, IContainer<Object> container) - { - Object[] elements = container.getElements(); - for (int i = 0; i < elements.length; i++) - { - Object element = elements[i]; - addChild(children, element); - } - } - - protected void onAdded(IContainer<Object> container, Object element) - { - Node node = addChild(getChildren(), element); - if (node != null) - { - refreshElement(container, true); - revealElement(element); - elementAdded(element, container); - } - } - - protected void onRemoved(IContainer<Object> container, Object element) - { - Node node = removeNode(element); - if (node != null) - { - getChildren().remove(node); - elementRemoved(element, container); - - Object rootElement = root.getElement(); - Object refreshElement = container == rootElement ? null : container; - refreshElement(refreshElement, true); - node.dispose(); - } - } - } - - /** - * @author Eike Stepper - */ - public class ContainerNode extends AbstractContainerNode - { - private IContainer<Object> container; - - public ContainerNode(Node parent, IContainer<Object> container) - { - super(parent); - this.container = container; - if (container == null) - { - throw new IllegalArgumentException("container == null"); //$NON-NLS-1$ - } - } - - @Override - public void dispose() - { - if (!isDisposed()) - { - container.removeListener(containerListener); - container = null; - super.dispose(); - } - } - - public Object getElement() - { - return container; - } - } - - /** - * @author Eike Stepper - */ - public class LeafNode extends AbstractNode implements IListener - { - private Object element; - - public LeafNode(Node parent, Object element) - { - super(parent); - this.element = element; - EventUtil.addListener(element, this); - } - - @Override - public void dispose() - { - if (!isDisposed()) - { - EventUtil.removeListener(element, this); - element = null; - super.dispose(); - } - } - - public Object getElement() - { - checkNotDisposed(); - return element; - } - - public List<Node> getChildren() - { - checkNotDisposed(); - return Collections.emptyList(); - } - - public void notifyEvent(IEvent event) - { - updateLabels(event.getSource()); - } - } - - /** - * @author Eike Stepper - * @since 3.1 - */ - public class LazyElement - { - private IContainer<Object> container; - - public LazyElement(IContainer<Object> container) - { - this.container = container; - } - - public IContainer<Object> getContainer() - { - return container; - } - - @Override - public String toString() - { - return getSlowText(container); - } - } - - /** - * @author Eike Stepper - * @since 3.1 - */ - public class ErrorElement - { - private IContainer<Object> container; - - public ErrorElement(IContainer<Object> container) - { - this.container = container; - } - - public IContainer<Object> getContainer() - { - return container; - } - - @Override - public String toString() - { - return getErrorText(container); - } - } -} +/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.util.ui.views;
+
+import org.eclipse.net4j.internal.util.bundle.OM;
+import org.eclipse.net4j.ui.shared.SharedIcons;
+import org.eclipse.net4j.util.container.ContainerEventAdapter;
+import org.eclipse.net4j.util.container.IContainer;
+import org.eclipse.net4j.util.container.ISlow;
+import org.eclipse.net4j.util.event.EventUtil;
+import org.eclipse.net4j.util.event.IEvent;
+import org.eclipse.net4j.util.event.IListener;
+import org.eclipse.net4j.util.lifecycle.LifecycleState;
+import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
+import org.eclipse.net4j.util.ui.UIUtil;
+
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.viewers.ITreeSelection;
+import org.eclipse.jface.viewers.TreePath;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Font;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.ui.PartInitException;
+
+import java.text.MessageFormat;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author Eike Stepper
+ */
+/**
+ * @author Eike Stepper
+ */
+public class ContainerItemProvider<CONTAINER extends IContainer<Object>> extends ItemProvider<CONTAINER>
+{
+ private Map<Object, Node> nodes = new HashMap<Object, Node>();
+
+ private Node root;
+
+ private IElementFilter rootElementFilter;
+
+ public ContainerItemProvider()
+ {
+ }
+
+ public ContainerItemProvider(IElementFilter rootElementFilter)
+ {
+ this.rootElementFilter = rootElementFilter;
+ }
+
+ public IElementFilter getRootElementFilter()
+ {
+ return rootElementFilter;
+ }
+
+ @Override
+ public boolean hasChildren(Object element)
+ {
+ try
+ {
+ Node node = getNode(element);
+ return !node.getChildren().isEmpty();
+ }
+ catch (Exception ex)
+ {
+ return false;
+ }
+ }
+
+ public Object[] getChildren(Object element)
+ {
+ try
+ {
+ Node node = getNode(element);
+ List<Node> children = node.getChildren();
+ for (Iterator<Node> it = children.iterator(); it.hasNext();)
+ {
+ Node child = it.next();
+ if (child.isDisposed())
+ {
+ it.remove();
+ }
+ else
+ {
+ Object childElement = child.getElement();
+ LifecycleState lifecycleState = LifecycleUtil.getLifecycleState(childElement);
+ if (lifecycleState == LifecycleState.INACTIVE || lifecycleState == LifecycleState.DEACTIVATING)
+ {
+ handleInactiveElement(it, child);
+ }
+ }
+ }
+
+ Object[] result = new Object[children.size()];
+ for (int i = 0; i < result.length; i++)
+ {
+ result[i] = children.get(i).getElement();
+ }
+
+ return result;
+ }
+ catch (RuntimeException ex)
+ {
+ return NO_ELEMENTS;
+ }
+ }
+
+ public Object getParent(Object element)
+ {
+ try
+ {
+ Node node = getNode(element);
+ Node parentNode = node.getParent();
+ return parentNode == null ? null : parentNode.getElement();
+ }
+ catch (RuntimeException ex)
+ {
+ return null;
+ }
+ }
+
+ @Override
+ public void dispose()
+ {
+ super.dispose();
+ }
+
+ @Override
+ protected void connectInput(CONTAINER input)
+ {
+ root = createNode(null, input);
+ if (root != null)
+ {
+ addNode(input, root);
+ }
+ }
+
+ @Override
+ protected void disconnectInput(CONTAINER input)
+ {
+ root.dispose();
+ root = null;
+ nodes.clear();
+ }
+
+ /**
+ * @since 2.0
+ */
+ protected void handleInactiveElement(Iterator<Node> it, Node child)
+ {
+ it.remove();
+ child.dispose();
+ }
+
+ protected void elementAdded(Object element, Object parent)
+ {
+ }
+
+ protected void elementRemoved(Object element, Object parent)
+ {
+ }
+
+ protected Node getRoot()
+ {
+ return root;
+ }
+
+ protected Map<Object, Node> getNodes()
+ {
+ return nodes;
+ }
+
+ protected Node getNode(Object element)
+ {
+ Node node = root;
+ if (element != getInput())
+ {
+ node = nodes.get(element);
+ }
+
+ if (node == null)
+ {
+ throw new IllegalStateException("No node for " + element); //$NON-NLS-1$
+ }
+
+ return node;
+ }
+
+ protected Node createNode(Node parent, Object element)
+ {
+ if (element instanceof IContainer<?>)
+ {
+ return createContaineNode(parent, element);
+ }
+
+ return createLeafNode(parent, element);
+ }
+
+ protected LeafNode createLeafNode(Node parent, Object element)
+ {
+ return new LeafNode(parent, element);
+ }
+
+ @SuppressWarnings("unchecked")
+ protected ContainerNode createContaineNode(Node parent, Object element)
+ {
+ return new ContainerNode(parent, (IContainer<Object>)element);
+ }
+
+ protected void addNode(Object element, Node node)
+ {
+ nodes.put(element, node);
+ }
+
+ protected Node removeNode(Object element)
+ {
+ return nodes.remove(element);
+ }
+
+ protected boolean filterRootElement(Object element)
+ {
+ if (rootElementFilter != null)
+ {
+ return rootElementFilter.filter(element);
+ }
+
+ return true;
+ }
+
+ /**
+ * @since 3.1
+ */
+ protected void executeRunnable(Runnable runnable)
+ {
+ Thread thread = new Thread(runnable);
+ thread.setDaemon(true);
+ thread.start();
+ }
+
+ /**
+ * @since 3.1
+ */
+ protected boolean isSlow(IContainer<Object> container)
+ {
+ return container instanceof ISlow;
+ }
+
+ /**
+ * @since 3.1
+ */
+ protected String getSlowText(IContainer<Object> container)
+ {
+ return "Pending...";
+ }
+
+ /**
+ * @since 3.1
+ */
+ protected String getErrorText(IContainer<Object> container)
+ {
+ return "Error";
+ }
+
+ @Override
+ protected void fillContextMenu(IMenuManager manager, ITreeSelection selection)
+ {
+ super.fillContextMenu(manager, selection);
+ if (selection.size() == 1)
+ {
+ Object element = selection.getFirstElement();
+ if (element instanceof ContainerItemProvider.ErrorElement)
+ {
+ manager.add(new Action("Open Error Log")
+ {
+ @Override
+ public void run()
+ {
+ try
+ {
+ UIUtil.getActiveWorkbenchPage().showView(UIUtil.ERROR_LOG_ID);
+ }
+ catch (PartInitException ex)
+ {
+ OM.LOG.error(ex);
+ }
+ }
+ });
+ }
+ }
+ }
+
+ @Override
+ public Font getFont(Object obj)
+ {
+ if (obj instanceof ContainerItemProvider.LazyElement)
+ {
+ return getItalicFont();
+ }
+
+ return super.getFont(obj);
+ }
+
+ @Override
+ public Color getForeground(Object obj)
+ {
+ if (obj instanceof ContainerItemProvider.LazyElement)
+ {
+ return getDisplay().getSystemColor(SWT.COLOR_GRAY);
+ }
+
+ return super.getForeground(obj);
+ }
+
+ @Override
+ public Image getImage(Object obj)
+ {
+ if (obj instanceof ContainerItemProvider.LazyElement)
+ {
+ return SharedIcons.getImage(SharedIcons.OBJ_PENDING);
+ }
+
+ if (obj instanceof ContainerItemProvider.ErrorElement)
+ {
+ return SharedIcons.getImage(SharedIcons.OBJ_ERROR);
+ }
+
+ return super.getImage(obj);
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ public interface Node
+ {
+ public void dispose();
+
+ public boolean isDisposed();
+
+ public Object getElement();
+
+ public Node getParent();
+
+ public List<Node> getChildren();
+
+ public TreePath getTreePath();
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ public abstract class AbstractNode implements Node
+ {
+ private Node parent;
+
+ private boolean disposed;
+
+ public AbstractNode(Node parent)
+ {
+ this.parent = parent;
+ }
+
+ public void dispose()
+ {
+ if (!disposed)
+ {
+ removeNode(getElement());
+ parent = null;
+ disposed = true;
+ }
+ }
+
+ public boolean isDisposed()
+ {
+ return disposed;
+ }
+
+ @Override
+ public String toString()
+ {
+ return MessageFormat.format("{0}[{1}]", getClass().getSimpleName(), getElement()); //$NON-NLS-1$
+ }
+
+ public final Node getParent()
+ {
+ checkNotDisposed();
+ return parent;
+ }
+
+ public TreePath getTreePath()
+ {
+ TreePath parentPath = parent == null ? TreePath.EMPTY : parent.getTreePath();
+ return parentPath.createChildPath(getElement());
+ }
+
+ protected void checkNotDisposed()
+ {
+ if (disposed)
+ {
+ throw new IllegalStateException("Node is already disposed of"); //$NON-NLS-1$
+ }
+ }
+
+ protected Node addChild(Collection<Node> children, Object element)
+ {
+ if (nodes.containsKey(element))
+ {
+ return null;
+ }
+
+ if (this != root || filterRootElement(element))
+ {
+ Node node = createNode(this, element);
+ if (node != null)
+ {
+ addNode(element, node);
+ children.add(node);
+ return node;
+ }
+ }
+
+ return null;
+ }
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ public abstract class AbstractContainerNode extends AbstractNode
+ {
+ private List<Node> children;
+
+ protected IListener containerListener = new ContainerEventAdapter<Object>()
+ {
+ @Override
+ protected void onAdded(IContainer<Object> container, Object element)
+ {
+ AbstractContainerNode.this.onAdded(container, element);
+ }
+
+ @Override
+ protected void onRemoved(IContainer<Object> container, Object element)
+ {
+ AbstractContainerNode.this.onRemoved(container, element);
+ }
+
+ @Override
+ protected void notifyOtherEvent(IEvent event)
+ {
+ updateLabels(event.getSource());
+ }
+ };
+
+ public AbstractContainerNode(Node parent)
+ {
+ super(parent);
+ }
+
+ @Override
+ public void dispose()
+ {
+ if (!isDisposed())
+ {
+ if (children != null)
+ {
+ for (Node child : children)
+ {
+ child.dispose();
+ }
+
+ children.clear();
+ children = null;
+ containerListener = null;
+ }
+
+ super.dispose();
+ }
+ }
+
+ public final List<Node> getChildren()
+ {
+ checkNotDisposed();
+ if (children == null)
+ {
+ children = createChildren();
+ }
+
+ return children;
+ }
+
+ @SuppressWarnings("unchecked")
+ public IContainer<Object> getContainer()
+ {
+ return (IContainer<Object>)getElement();
+ }
+
+ protected List<Node> createChildren()
+ {
+ final List<Node> children = new ArrayList<Node>();
+ final IContainer<Object> container = getContainer();
+
+ if (isSlow(container))
+ {
+ final LazyElement lazyElement = new LazyElement(container);
+ addChild(children, lazyElement);
+
+ Runnable runnable = new Runnable()
+ {
+ public void run()
+ {
+ try
+ {
+ fillChildren(children, container);
+ }
+ catch (Exception ex)
+ {
+ OM.LOG.error(ex);
+ addChild(children, new ErrorElement(container));
+ }
+ finally
+ {
+ Node node = removeNode(lazyElement);
+ children.remove(node);
+ refreshElement(container, false);
+ }
+ }
+ };
+
+ executeRunnable(runnable);
+ }
+ else
+ {
+ fillChildren(children, container);
+ }
+
+ container.addListener(containerListener);
+ return children;
+ }
+
+ /**
+ * @since 3.1
+ */
+ protected void fillChildren(List<Node> children, IContainer<Object> container)
+ {
+ Object[] elements = container.getElements();
+ for (int i = 0; i < elements.length; i++)
+ {
+ Object element = elements[i];
+ addChild(children, element);
+ }
+ }
+
+ protected void onAdded(IContainer<Object> container, Object element)
+ {
+ Node node = addChild(getChildren(), element);
+ if (node != null)
+ {
+ refreshElement(container, true);
+ revealElement(element);
+ elementAdded(element, container);
+ }
+ }
+
+ protected void onRemoved(IContainer<Object> container, Object element)
+ {
+ Node node = removeNode(element);
+ if (node != null)
+ {
+ getChildren().remove(node);
+ elementRemoved(element, container);
+
+ Object rootElement = root.getElement();
+ Object refreshElement = container == rootElement ? null : container;
+ refreshElement(refreshElement, true);
+ node.dispose();
+ }
+ }
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ public class ContainerNode extends AbstractContainerNode
+ {
+ private IContainer<Object> container;
+
+ public ContainerNode(Node parent, IContainer<Object> container)
+ {
+ super(parent);
+ this.container = container;
+ if (container == null)
+ {
+ throw new IllegalArgumentException("container == null"); //$NON-NLS-1$
+ }
+ }
+
+ @Override
+ public void dispose()
+ {
+ if (!isDisposed())
+ {
+ container.removeListener(containerListener);
+ container = null;
+ super.dispose();
+ }
+ }
+
+ public Object getElement()
+ {
+ return container;
+ }
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ public class LeafNode extends AbstractNode implements IListener
+ {
+ private Object element;
+
+ public LeafNode(Node parent, Object element)
+ {
+ super(parent);
+ this.element = element;
+ EventUtil.addListener(element, this);
+ }
+
+ @Override
+ public void dispose()
+ {
+ if (!isDisposed())
+ {
+ EventUtil.removeListener(element, this);
+ element = null;
+ super.dispose();
+ }
+ }
+
+ public Object getElement()
+ {
+ checkNotDisposed();
+ return element;
+ }
+
+ public List<Node> getChildren()
+ {
+ checkNotDisposed();
+ return Collections.emptyList();
+ }
+
+ public void notifyEvent(IEvent event)
+ {
+ updateLabels(event.getSource());
+ }
+ }
+
+ /**
+ * @author Eike Stepper
+ * @since 3.1
+ */
+ public class LazyElement
+ {
+ private IContainer<Object> container;
+
+ public LazyElement(IContainer<Object> container)
+ {
+ this.container = container;
+ }
+
+ public IContainer<Object> getContainer()
+ {
+ return container;
+ }
+
+ @Override
+ public String toString()
+ {
+ return getSlowText(container);
+ }
+ }
+
+ /**
+ * @author Eike Stepper
+ * @since 3.1
+ */
+ public class ErrorElement
+ {
+ private IContainer<Object> container;
+
+ public ErrorElement(IContainer<Object> container)
+ {
+ this.container = container;
+ }
+
+ public IContainer<Object> getContainer()
+ {
+ return container;
+ }
+
+ @Override
+ public String toString()
+ {
+ return getErrorText(container);
+ }
+ }
+}
diff --git a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/views/ContainerNameSorter.java b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/views/ContainerNameSorter.java index fa603c636f..5457a217c2 100644 --- a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/views/ContainerNameSorter.java +++ b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/views/ContainerNameSorter.java @@ -1,17 +1,17 @@ -/* - * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) 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: - * Eike Stepper - initial API and implementation - */ -package org.eclipse.net4j.util.ui.views; - -import org.eclipse.jface.viewers.ViewerSorter; - -public class ContainerNameSorter extends ViewerSorter -{ -} +/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.util.ui.views;
+
+import org.eclipse.jface.viewers.ViewerSorter;
+
+public class ContainerNameSorter extends ViewerSorter
+{
+}
diff --git a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/views/ContainerPathItemProvider.java b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/views/ContainerPathItemProvider.java index d86ea6199c..d067f5f223 100644 --- a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/views/ContainerPathItemProvider.java +++ b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/views/ContainerPathItemProvider.java @@ -1,102 +1,102 @@ -/* - * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) 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: - * Eike Stepper - initial API and implementation - */ -package org.eclipse.net4j.util.ui.views; - -import org.eclipse.net4j.util.container.IContainer; - -import org.eclipse.jface.viewers.ITreePathContentProvider; -import org.eclipse.jface.viewers.TreePath; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -/** - * @author Eike Stepper - */ -@Deprecated -public class ContainerPathItemProvider<CONTAINER extends IContainer<Object>> extends ContainerItemProvider<CONTAINER> - implements ITreePathContentProvider -{ - private Map<Object, List<TreePath>> parents = new HashMap<Object, List<TreePath>>(); - - public ContainerPathItemProvider() - { - } - - public ContainerPathItemProvider(IElementFilter rootElementFilter) - { - super(rootElementFilter); - } - - public boolean hasChildren(TreePath path) - { - return hasChildren((Object)path); - } - - public Object[] getChildren(TreePath path) - { - return getChildren((Object)path); - } - - public TreePath[] getParents(Object element) - { - List<TreePath> paths = parents.get(element); - if (paths != null) - { - return paths.toArray(new TreePath[paths.size()]); - } - - return null; - } - - @Override - protected void addNode(Object element, Node node) - { - super.addNode(node.getTreePath(), node); - TreePath path = getParentPath(node); - List<TreePath> paths = parents.get(element); - if (paths == null) - { - paths = new ArrayList<TreePath>(); - parents.put(element, paths); - } - - paths.add(path); - } - - @Override - protected Node removeNode(Object element) - { - Node node = super.removeNode(element); - TreePath path = getParentPath(node); - List<TreePath> paths = parents.get(element); - if (paths != null) - { - paths.remove(path); - } - - return node; - } - - @Override - protected void disconnectInput(CONTAINER input) - { - super.disconnectInput(input); - } - - protected TreePath getParentPath(Node node) - { - Node parent = node.getParent(); - return parent == null ? TreePath.EMPTY : parent.getTreePath(); - } -} +/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.util.ui.views;
+
+import org.eclipse.net4j.util.container.IContainer;
+
+import org.eclipse.jface.viewers.ITreePathContentProvider;
+import org.eclipse.jface.viewers.TreePath;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author Eike Stepper
+ */
+@Deprecated
+public class ContainerPathItemProvider<CONTAINER extends IContainer<Object>> extends ContainerItemProvider<CONTAINER>
+ implements ITreePathContentProvider
+{
+ private Map<Object, List<TreePath>> parents = new HashMap<Object, List<TreePath>>();
+
+ public ContainerPathItemProvider()
+ {
+ }
+
+ public ContainerPathItemProvider(IElementFilter rootElementFilter)
+ {
+ super(rootElementFilter);
+ }
+
+ public boolean hasChildren(TreePath path)
+ {
+ return hasChildren((Object)path);
+ }
+
+ public Object[] getChildren(TreePath path)
+ {
+ return getChildren((Object)path);
+ }
+
+ public TreePath[] getParents(Object element)
+ {
+ List<TreePath> paths = parents.get(element);
+ if (paths != null)
+ {
+ return paths.toArray(new TreePath[paths.size()]);
+ }
+
+ return null;
+ }
+
+ @Override
+ protected void addNode(Object element, Node node)
+ {
+ super.addNode(node.getTreePath(), node);
+ TreePath path = getParentPath(node);
+ List<TreePath> paths = parents.get(element);
+ if (paths == null)
+ {
+ paths = new ArrayList<TreePath>();
+ parents.put(element, paths);
+ }
+
+ paths.add(path);
+ }
+
+ @Override
+ protected Node removeNode(Object element)
+ {
+ Node node = super.removeNode(element);
+ TreePath path = getParentPath(node);
+ List<TreePath> paths = parents.get(element);
+ if (paths != null)
+ {
+ paths.remove(path);
+ }
+
+ return node;
+ }
+
+ @Override
+ protected void disconnectInput(CONTAINER input)
+ {
+ super.disconnectInput(input);
+ }
+
+ protected TreePath getParentPath(Node node)
+ {
+ Node parent = node.getParent();
+ return parent == null ? TreePath.EMPTY : parent.getTreePath();
+ }
+}
diff --git a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/views/ContainerView.java b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/views/ContainerView.java index 85a2a27e52..3e31e64e10 100644 --- a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/views/ContainerView.java +++ b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/views/ContainerView.java @@ -1,694 +1,694 @@ -/* - * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) 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: - * Eike Stepper - initial API and implementation - */ -package org.eclipse.net4j.util.ui.views; - -import org.eclipse.net4j.ui.shared.SharedIcons; -import org.eclipse.net4j.util.container.IContainer; -import org.eclipse.net4j.util.event.IListener; -import org.eclipse.net4j.util.internal.ui.actions.IntrospectAction; -import org.eclipse.net4j.util.internal.ui.bundle.OM; -import org.eclipse.net4j.util.internal.ui.messages.Messages; -import org.eclipse.net4j.util.ui.UIUtil; -import org.eclipse.net4j.util.ui.actions.SafeAction; - -import org.eclipse.jface.action.Action; -import org.eclipse.jface.action.IMenuListener; -import org.eclipse.jface.action.IMenuManager; -import org.eclipse.jface.action.IToolBarManager; -import org.eclipse.jface.action.MenuManager; -import org.eclipse.jface.action.Separator; -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.jface.viewers.DecoratingLabelProvider; -import org.eclipse.jface.viewers.DoubleClickEvent; -import org.eclipse.jface.viewers.IBaseLabelProvider; -import org.eclipse.jface.viewers.IContentProvider; -import org.eclipse.jface.viewers.IDoubleClickListener; -import org.eclipse.jface.viewers.ILabelDecorator; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.ISelectionChangedListener; -import org.eclipse.jface.viewers.ISelectionProvider; -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.swt.SWT; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.Font; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Menu; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.ui.IActionBars; -import org.eclipse.ui.IWorkbenchActionConstants; -import org.eclipse.ui.PartInitException; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.part.ISetSelectionTarget; -import org.eclipse.ui.part.ViewPart; - -public abstract class ContainerView extends ViewPart implements ISelectionProvider, ISetSelectionTarget -{ - private Shell shell; - - private ContainerItemProvider<IContainer<Object>> itemProvider; - - private TreeViewer viewer; - - private ISelectionChangedListener selectionListener = new ISelectionChangedListener() - { - public void selectionChanged(SelectionChangedEvent event) - { - ITreeSelection selection = (ITreeSelection)event.getSelection(); - IActionBars bars = getViewSite().getActionBars(); - ContainerView.this.selectionChanged(bars, selection); - } - }; - - private Action refreshAction = new RefreshAction(); - - public ContainerView() - { - } - - public Shell getShell() - { - return shell; - } - - public TreeViewer getViewer() - { - return viewer; - } - - @Override - public void setFocus() - { - viewer.getControl().setFocus(); - } - - public void resetInput() - { - Runnable runnable = new Runnable() - { - public void run() - { - try - { - IContainer<?> container = getContainer(); - viewer.setInput(container); - } - catch (RuntimeException ignore) - { - } - } - }; - - try - { - Display display = getDisplay(); - if (display.getThread() == Thread.currentThread()) - { - runnable.run(); - } - else - { - display.asyncExec(runnable); - } - } - catch (RuntimeException ignore) - { - } - } - - /** - * @since 3.0 - */ - public ISelection getSelection() - { - if (viewer != null) - { - return viewer.getSelection(); - } - - return StructuredSelection.EMPTY; - } - - /** - * @since 3.0 - */ - public void setSelection(ISelection selection) - { - if (viewer != null) - { - viewer.setSelection(selection); - } - } - - /** - * @since 3.0 - */ - public void addSelectionChangedListener(ISelectionChangedListener listener) - { - if (viewer != null) - { - viewer.addSelectionChangedListener(listener); - } - } - - /** - * @since 3.0 - */ - public void removeSelectionChangedListener(ISelectionChangedListener listener) - { - if (viewer != null) - { - viewer.removeSelectionChangedListener(listener); - } - } - - public void selectReveal(ISelection selection) - { - if (viewer != null) - { - viewer.setSelection(selection, true); - } - } - - @Override - public final void createPartControl(Composite parent) - { - shell = parent.getShell(); - Composite composite = UIUtil.createGridComposite(parent, 1); - - Control control = createUI(composite); - control.setLayoutData(UIUtil.createGridData()); - - hookContextMenu(); - hookDoubleClick(); - contributeToActionBars(); - createdUI(); - } - - protected Control createUI(Composite parent) - { - viewer = new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL); - initViewer(); - - viewer.addSelectionChangedListener(selectionListener); - getSite().setSelectionProvider(this); - return viewer.getControl(); - } - - /** - * @since 3.1 - */ - protected void createdUI() - { - } - - /** - * @since 3.1 - */ - protected void initViewer() - { - itemProvider = createContainerItemProvider(); - viewer.setContentProvider(createContentProvider()); - viewer.setLabelProvider(createLabelProvider()); - viewer.setSorter(new ContainerNameSorter()); - resetInput(); - } - - /** - * @since 3.0 - */ - protected IContentProvider createContentProvider() - { - return itemProvider; - } - - /** - * @since 3.0 - */ - protected IBaseLabelProvider createLabelProvider() - { - ILabelDecorator labelDecorator = createLabelDecorator(); - return new DecoratingLabelProvider(itemProvider, labelDecorator); - } - - /** - * @since 3.0 - */ - protected ILabelDecorator createLabelDecorator() - { - return PlatformUI.getWorkbench().getDecoratorManager().getLabelDecorator(); - } - - protected ContainerItemProvider<IContainer<Object>> createContainerItemProvider() - { - return new ContainerItemProvider<IContainer<Object>>(getRootElementFilter()) - { - @Override - public Image getImage(Object obj) - { - Image image = getElementImage(obj); - if (image == null) - { - image = super.getImage(obj); - } - - return image; - } - - @Override - public String getText(Object obj) - { - String text = getElementText(obj); - if (text == null) - { - text = super.getText(obj); - } - - return text; - } - - @Override - public Color getForeground(Object obj) - { - Color color = getElementForeground(obj); - if (color == null) - { - color = super.getForeground(obj); - } - - return color; - } - - @Override - public Color getBackground(Object obj) - { - Color color = getElementBackground(obj); - if (color == null) - { - color = super.getBackground(obj); - } - - return color; - } - - @Override - public Font getFont(Object obj) - { - Font font = getElementFont(obj); - if (font == null) - { - font = super.getFont(obj); - } - - return font; - } - }; - } - - protected String getElementText(Object element) - { - return null; - } - - protected Image getElementImage(Object element) - { - return null; - } - - /** - * @since 3.0 - */ - protected Color getElementForeground(Object element) - { - return null; - } - - /** - * @since 3.0 - */ - protected Color getElementBackground(Object element) - { - return null; - } - - /** - * @since 3.0 - */ - protected Font getElementFont(Object element) - { - return null; - } - - protected IElementFilter getRootElementFilter() - { - return null; - } - - protected abstract IContainer<?> getContainer(); - - protected void hookDoubleClick() - { - viewer.addDoubleClickListener(new IDoubleClickListener() - { - public void doubleClick(DoubleClickEvent event) - { - ITreeSelection selection = (ITreeSelection)viewer.getSelection(); - Object object = selection.getFirstElement(); - doubleClicked(object); - } - }); - } - - protected void hookContextMenu() - { - MenuManager menuMgr = new MenuManager("#PopupMenu"); //$NON-NLS-1$ - menuMgr.setRemoveAllWhenShown(true); - menuMgr.addMenuListener(new IMenuListener() - { - public void menuAboutToShow(IMenuManager manager) - { - ITreeSelection selection = (ITreeSelection)viewer.getSelection(); - fillContextMenu(manager, selection); - } - }); - - Menu menu = menuMgr.createContextMenu(viewer.getControl()); - viewer.getControl().setMenu(menu); - getSite().registerContextMenu(menuMgr, viewer); - } - - protected void contributeToActionBars() - { - IActionBars bars = getViewSite().getActionBars(); - fillLocalPullDown(bars.getMenuManager()); - fillLocalToolBar(bars.getToolBarManager()); - } - - protected void fillLocalPullDown(IMenuManager manager) - { - manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS)); - manager.add(refreshAction); - manager.add(new IntrospectAction(getViewer())); - } - - protected void fillLocalToolBar(IToolBarManager manager) - { - manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS)); - } - - protected void fillContextMenu(IMenuManager manager, ITreeSelection selection) - { - manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS)); - itemProvider.fillContextMenu(manager, selection); - } - - protected void selectionChanged(IActionBars bars, ITreeSelection selection) - { - } - - protected void doubleClicked(Object object) - { - if (object instanceof ContainerItemProvider.ErrorElement) - { - try - { - UIUtil.getActiveWorkbenchPage().showView(UIUtil.ERROR_LOG_ID); - } - catch (PartInitException ex) - { - OM.LOG.error(ex); - } - } - else if (object != null && viewer.isExpandable(object)) - { - if (viewer.getExpandedState(object)) - { - viewer.collapseToLevel(object, TreeViewer.ALL_LEVELS); - } - else - { - viewer.expandToLevel(object, 1); - } - } - } - - /** - * @since 3.1 - */ - protected void refreshPressed() - { - itemProvider.dispose(); - initViewer(); - } - - protected void closeView() - { - try - { - getDisplay().syncExec(new Runnable() - { - public void run() - { - try - { - getSite().getPage().hideView(ContainerView.this); - ContainerView.this.dispose(); - } - catch (Exception ignore) - { - } - } - }); - } - catch (Exception ignore) - { - } - } - - protected void showMessage(String message) - { - showMessage(MessageType.INFORMATION, message); - } - - protected boolean showMessage(MessageType type, String message) - { - switch (type) - { - case INFORMATION: - MessageDialog.openInformation(viewer.getControl().getShell(), getTitle(), message); - return true; - - case ERROR: - MessageDialog.openError(viewer.getControl().getShell(), getTitle(), message); - return true; - - case WARNING: - MessageDialog.openWarning(viewer.getControl().getShell(), getTitle(), message); - return true; - - case CONFIRM: - return MessageDialog.openConfirm(viewer.getControl().getShell(), getTitle(), message); - - case QUESTION: - return MessageDialog.openQuestion(viewer.getControl().getShell(), getTitle(), message); - - default: - return true; - } - } - - /** - * @since 3.1 - */ - protected Action getRefreshAction() - { - return refreshAction; - } - - protected Display getDisplay() - { - Display display = viewer.getControl().getDisplay(); - if (display == null) - { - display = UIUtil.getDisplay(); - } - - return display; - } - - public void refreshViewer(boolean updateLabels) - { - refreshElement(null, updateLabels); - } - - public void refreshElement(final Object element, final boolean updateLabels) - { - try - { - getDisplay().asyncExec(new Runnable() - { - public void run() - { - try - { - if (element != null) - { - viewer.refresh(element, updateLabels); - } - else - { - viewer.refresh(updateLabels); - } - } - catch (RuntimeException ignore) - { - } - } - }); - } - catch (RuntimeException ignore) - { - } - } - - public void updateLabels(final Object element) - { - try - { - getDisplay().asyncExec(new Runnable() - { - public void run() - { - try - { - viewer.update(element, null); - } - catch (RuntimeException ignore) - { - } - } - }); - } - catch (RuntimeException ignore) - { - } - } - - public void revealElement(final Object element) - { - try - { - getDisplay().asyncExec(new Runnable() - { - public void run() - { - try - { - viewer.reveal(element); - } - catch (RuntimeException ignore) - { - } - } - }); - } - catch (RuntimeException ignore) - { - } - } - - public static ImageDescriptor getAddImageDescriptor() - { - return SharedIcons.getDescriptor(SharedIcons.TOOL_ADD); - } - - public static ImageDescriptor getDeleteImageDescriptor() - { - return SharedIcons.getDescriptor(SharedIcons.TOOL_DELETE); - } - - public static ImageDescriptor getRefreshImageDescriptor() - { - return SharedIcons.getDescriptor(SharedIcons.TOOL_REFRESH); - } - - protected static enum MessageType - { - INFORMATION, ERROR, WARNING, CONFIRM, QUESTION - } - - /** - * @author Eike Stepper - */ - private final class RefreshAction extends SafeAction - { - private RefreshAction() - { - super(Messages.getString("ContainerView_1"), Messages.getString("ContainerView_2"), getRefreshImageDescriptor()); //$NON-NLS-1$ //$NON-NLS-2$ - } - - @Override - protected void safeRun() throws Exception - { - refreshPressed(); - } - } - - /** - * @author Eike Stepper - * @since 3.0 - */ - public static class Default<CONTAINER extends IContainer<?>> extends ContainerView - { - private CONTAINER container; - - public Default() - { - } - - protected IListener getContainerListener() - { - return null; - } - - @Override - protected CONTAINER getContainer() - { - return container; - } - - public void setContainer(CONTAINER container) - { - if (this.container != container) - { - IListener containerListener = getContainerListener(); - if (containerListener != null && this.container != null) - { - this.container.removeListener(containerListener); - } - - this.container = container; - if (containerListener != null && this.container != null) - { - this.container.addListener(containerListener); - } - - resetInput(); - } - } - } -} +/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.util.ui.views;
+
+import org.eclipse.net4j.ui.shared.SharedIcons;
+import org.eclipse.net4j.util.container.IContainer;
+import org.eclipse.net4j.util.event.IListener;
+import org.eclipse.net4j.util.internal.ui.actions.IntrospectAction;
+import org.eclipse.net4j.util.internal.ui.bundle.OM;
+import org.eclipse.net4j.util.internal.ui.messages.Messages;
+import org.eclipse.net4j.util.ui.UIUtil;
+import org.eclipse.net4j.util.ui.actions.SafeAction;
+
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IMenuListener;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.action.IToolBarManager;
+import org.eclipse.jface.action.MenuManager;
+import org.eclipse.jface.action.Separator;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.viewers.DecoratingLabelProvider;
+import org.eclipse.jface.viewers.DoubleClickEvent;
+import org.eclipse.jface.viewers.IBaseLabelProvider;
+import org.eclipse.jface.viewers.IContentProvider;
+import org.eclipse.jface.viewers.IDoubleClickListener;
+import org.eclipse.jface.viewers.ILabelDecorator;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.ISelectionProvider;
+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.swt.SWT;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Font;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Menu;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IActionBars;
+import org.eclipse.ui.IWorkbenchActionConstants;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.part.ISetSelectionTarget;
+import org.eclipse.ui.part.ViewPart;
+
+public abstract class ContainerView extends ViewPart implements ISelectionProvider, ISetSelectionTarget
+{
+ private Shell shell;
+
+ private ContainerItemProvider<IContainer<Object>> itemProvider;
+
+ private TreeViewer viewer;
+
+ private ISelectionChangedListener selectionListener = new ISelectionChangedListener()
+ {
+ public void selectionChanged(SelectionChangedEvent event)
+ {
+ ITreeSelection selection = (ITreeSelection)event.getSelection();
+ IActionBars bars = getViewSite().getActionBars();
+ ContainerView.this.selectionChanged(bars, selection);
+ }
+ };
+
+ private Action refreshAction = new RefreshAction();
+
+ public ContainerView()
+ {
+ }
+
+ public Shell getShell()
+ {
+ return shell;
+ }
+
+ public TreeViewer getViewer()
+ {
+ return viewer;
+ }
+
+ @Override
+ public void setFocus()
+ {
+ viewer.getControl().setFocus();
+ }
+
+ public void resetInput()
+ {
+ Runnable runnable = new Runnable()
+ {
+ public void run()
+ {
+ try
+ {
+ IContainer<?> container = getContainer();
+ viewer.setInput(container);
+ }
+ catch (RuntimeException ignore)
+ {
+ }
+ }
+ };
+
+ try
+ {
+ Display display = getDisplay();
+ if (display.getThread() == Thread.currentThread())
+ {
+ runnable.run();
+ }
+ else
+ {
+ display.asyncExec(runnable);
+ }
+ }
+ catch (RuntimeException ignore)
+ {
+ }
+ }
+
+ /**
+ * @since 3.0
+ */
+ public ISelection getSelection()
+ {
+ if (viewer != null)
+ {
+ return viewer.getSelection();
+ }
+
+ return StructuredSelection.EMPTY;
+ }
+
+ /**
+ * @since 3.0
+ */
+ public void setSelection(ISelection selection)
+ {
+ if (viewer != null)
+ {
+ viewer.setSelection(selection);
+ }
+ }
+
+ /**
+ * @since 3.0
+ */
+ public void addSelectionChangedListener(ISelectionChangedListener listener)
+ {
+ if (viewer != null)
+ {
+ viewer.addSelectionChangedListener(listener);
+ }
+ }
+
+ /**
+ * @since 3.0
+ */
+ public void removeSelectionChangedListener(ISelectionChangedListener listener)
+ {
+ if (viewer != null)
+ {
+ viewer.removeSelectionChangedListener(listener);
+ }
+ }
+
+ public void selectReveal(ISelection selection)
+ {
+ if (viewer != null)
+ {
+ viewer.setSelection(selection, true);
+ }
+ }
+
+ @Override
+ public final void createPartControl(Composite parent)
+ {
+ shell = parent.getShell();
+ Composite composite = UIUtil.createGridComposite(parent, 1);
+
+ Control control = createUI(composite);
+ control.setLayoutData(UIUtil.createGridData());
+
+ hookContextMenu();
+ hookDoubleClick();
+ contributeToActionBars();
+ createdUI();
+ }
+
+ protected Control createUI(Composite parent)
+ {
+ viewer = new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
+ initViewer();
+
+ viewer.addSelectionChangedListener(selectionListener);
+ getSite().setSelectionProvider(this);
+ return viewer.getControl();
+ }
+
+ /**
+ * @since 3.1
+ */
+ protected void createdUI()
+ {
+ }
+
+ /**
+ * @since 3.1
+ */
+ protected void initViewer()
+ {
+ itemProvider = createContainerItemProvider();
+ viewer.setContentProvider(createContentProvider());
+ viewer.setLabelProvider(createLabelProvider());
+ viewer.setSorter(new ContainerNameSorter());
+ resetInput();
+ }
+
+ /**
+ * @since 3.0
+ */
+ protected IContentProvider createContentProvider()
+ {
+ return itemProvider;
+ }
+
+ /**
+ * @since 3.0
+ */
+ protected IBaseLabelProvider createLabelProvider()
+ {
+ ILabelDecorator labelDecorator = createLabelDecorator();
+ return new DecoratingLabelProvider(itemProvider, labelDecorator);
+ }
+
+ /**
+ * @since 3.0
+ */
+ protected ILabelDecorator createLabelDecorator()
+ {
+ return PlatformUI.getWorkbench().getDecoratorManager().getLabelDecorator();
+ }
+
+ protected ContainerItemProvider<IContainer<Object>> createContainerItemProvider()
+ {
+ return new ContainerItemProvider<IContainer<Object>>(getRootElementFilter())
+ {
+ @Override
+ public Image getImage(Object obj)
+ {
+ Image image = getElementImage(obj);
+ if (image == null)
+ {
+ image = super.getImage(obj);
+ }
+
+ return image;
+ }
+
+ @Override
+ public String getText(Object obj)
+ {
+ String text = getElementText(obj);
+ if (text == null)
+ {
+ text = super.getText(obj);
+ }
+
+ return text;
+ }
+
+ @Override
+ public Color getForeground(Object obj)
+ {
+ Color color = getElementForeground(obj);
+ if (color == null)
+ {
+ color = super.getForeground(obj);
+ }
+
+ return color;
+ }
+
+ @Override
+ public Color getBackground(Object obj)
+ {
+ Color color = getElementBackground(obj);
+ if (color == null)
+ {
+ color = super.getBackground(obj);
+ }
+
+ return color;
+ }
+
+ @Override
+ public Font getFont(Object obj)
+ {
+ Font font = getElementFont(obj);
+ if (font == null)
+ {
+ font = super.getFont(obj);
+ }
+
+ return font;
+ }
+ };
+ }
+
+ protected String getElementText(Object element)
+ {
+ return null;
+ }
+
+ protected Image getElementImage(Object element)
+ {
+ return null;
+ }
+
+ /**
+ * @since 3.0
+ */
+ protected Color getElementForeground(Object element)
+ {
+ return null;
+ }
+
+ /**
+ * @since 3.0
+ */
+ protected Color getElementBackground(Object element)
+ {
+ return null;
+ }
+
+ /**
+ * @since 3.0
+ */
+ protected Font getElementFont(Object element)
+ {
+ return null;
+ }
+
+ protected IElementFilter getRootElementFilter()
+ {
+ return null;
+ }
+
+ protected abstract IContainer<?> getContainer();
+
+ protected void hookDoubleClick()
+ {
+ viewer.addDoubleClickListener(new IDoubleClickListener()
+ {
+ public void doubleClick(DoubleClickEvent event)
+ {
+ ITreeSelection selection = (ITreeSelection)viewer.getSelection();
+ Object object = selection.getFirstElement();
+ doubleClicked(object);
+ }
+ });
+ }
+
+ protected void hookContextMenu()
+ {
+ MenuManager menuMgr = new MenuManager("#PopupMenu"); //$NON-NLS-1$
+ menuMgr.setRemoveAllWhenShown(true);
+ menuMgr.addMenuListener(new IMenuListener()
+ {
+ public void menuAboutToShow(IMenuManager manager)
+ {
+ ITreeSelection selection = (ITreeSelection)viewer.getSelection();
+ fillContextMenu(manager, selection);
+ }
+ });
+
+ Menu menu = menuMgr.createContextMenu(viewer.getControl());
+ viewer.getControl().setMenu(menu);
+ getSite().registerContextMenu(menuMgr, viewer);
+ }
+
+ protected void contributeToActionBars()
+ {
+ IActionBars bars = getViewSite().getActionBars();
+ fillLocalPullDown(bars.getMenuManager());
+ fillLocalToolBar(bars.getToolBarManager());
+ }
+
+ protected void fillLocalPullDown(IMenuManager manager)
+ {
+ manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
+ manager.add(refreshAction);
+ manager.add(new IntrospectAction(getViewer()));
+ }
+
+ protected void fillLocalToolBar(IToolBarManager manager)
+ {
+ manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
+ }
+
+ protected void fillContextMenu(IMenuManager manager, ITreeSelection selection)
+ {
+ manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
+ itemProvider.fillContextMenu(manager, selection);
+ }
+
+ protected void selectionChanged(IActionBars bars, ITreeSelection selection)
+ {
+ }
+
+ protected void doubleClicked(Object object)
+ {
+ if (object instanceof ContainerItemProvider.ErrorElement)
+ {
+ try
+ {
+ UIUtil.getActiveWorkbenchPage().showView(UIUtil.ERROR_LOG_ID);
+ }
+ catch (PartInitException ex)
+ {
+ OM.LOG.error(ex);
+ }
+ }
+ else if (object != null && viewer.isExpandable(object))
+ {
+ if (viewer.getExpandedState(object))
+ {
+ viewer.collapseToLevel(object, TreeViewer.ALL_LEVELS);
+ }
+ else
+ {
+ viewer.expandToLevel(object, 1);
+ }
+ }
+ }
+
+ /**
+ * @since 3.1
+ */
+ protected void refreshPressed()
+ {
+ itemProvider.dispose();
+ initViewer();
+ }
+
+ protected void closeView()
+ {
+ try
+ {
+ getDisplay().syncExec(new Runnable()
+ {
+ public void run()
+ {
+ try
+ {
+ getSite().getPage().hideView(ContainerView.this);
+ ContainerView.this.dispose();
+ }
+ catch (Exception ignore)
+ {
+ }
+ }
+ });
+ }
+ catch (Exception ignore)
+ {
+ }
+ }
+
+ protected void showMessage(String message)
+ {
+ showMessage(MessageType.INFORMATION, message);
+ }
+
+ protected boolean showMessage(MessageType type, String message)
+ {
+ switch (type)
+ {
+ case INFORMATION:
+ MessageDialog.openInformation(viewer.getControl().getShell(), getTitle(), message);
+ return true;
+
+ case ERROR:
+ MessageDialog.openError(viewer.getControl().getShell(), getTitle(), message);
+ return true;
+
+ case WARNING:
+ MessageDialog.openWarning(viewer.getControl().getShell(), getTitle(), message);
+ return true;
+
+ case CONFIRM:
+ return MessageDialog.openConfirm(viewer.getControl().getShell(), getTitle(), message);
+
+ case QUESTION:
+ return MessageDialog.openQuestion(viewer.getControl().getShell(), getTitle(), message);
+
+ default:
+ return true;
+ }
+ }
+
+ /**
+ * @since 3.1
+ */
+ protected Action getRefreshAction()
+ {
+ return refreshAction;
+ }
+
+ protected Display getDisplay()
+ {
+ Display display = viewer.getControl().getDisplay();
+ if (display == null)
+ {
+ display = UIUtil.getDisplay();
+ }
+
+ return display;
+ }
+
+ public void refreshViewer(boolean updateLabels)
+ {
+ refreshElement(null, updateLabels);
+ }
+
+ public void refreshElement(final Object element, final boolean updateLabels)
+ {
+ try
+ {
+ getDisplay().asyncExec(new Runnable()
+ {
+ public void run()
+ {
+ try
+ {
+ if (element != null)
+ {
+ viewer.refresh(element, updateLabels);
+ }
+ else
+ {
+ viewer.refresh(updateLabels);
+ }
+ }
+ catch (RuntimeException ignore)
+ {
+ }
+ }
+ });
+ }
+ catch (RuntimeException ignore)
+ {
+ }
+ }
+
+ public void updateLabels(final Object element)
+ {
+ try
+ {
+ getDisplay().asyncExec(new Runnable()
+ {
+ public void run()
+ {
+ try
+ {
+ viewer.update(element, null);
+ }
+ catch (RuntimeException ignore)
+ {
+ }
+ }
+ });
+ }
+ catch (RuntimeException ignore)
+ {
+ }
+ }
+
+ public void revealElement(final Object element)
+ {
+ try
+ {
+ getDisplay().asyncExec(new Runnable()
+ {
+ public void run()
+ {
+ try
+ {
+ viewer.reveal(element);
+ }
+ catch (RuntimeException ignore)
+ {
+ }
+ }
+ });
+ }
+ catch (RuntimeException ignore)
+ {
+ }
+ }
+
+ public static ImageDescriptor getAddImageDescriptor()
+ {
+ return SharedIcons.getDescriptor(SharedIcons.TOOL_ADD);
+ }
+
+ public static ImageDescriptor getDeleteImageDescriptor()
+ {
+ return SharedIcons.getDescriptor(SharedIcons.TOOL_DELETE);
+ }
+
+ public static ImageDescriptor getRefreshImageDescriptor()
+ {
+ return SharedIcons.getDescriptor(SharedIcons.TOOL_REFRESH);
+ }
+
+ protected static enum MessageType
+ {
+ INFORMATION, ERROR, WARNING, CONFIRM, QUESTION
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ private final class RefreshAction extends SafeAction
+ {
+ private RefreshAction()
+ {
+ super(Messages.getString("ContainerView_1"), Messages.getString("ContainerView_2"), getRefreshImageDescriptor()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ @Override
+ protected void safeRun() throws Exception
+ {
+ refreshPressed();
+ }
+ }
+
+ /**
+ * @author Eike Stepper
+ * @since 3.0
+ */
+ public static class Default<CONTAINER extends IContainer<?>> extends ContainerView
+ {
+ private CONTAINER container;
+
+ public Default()
+ {
+ }
+
+ protected IListener getContainerListener()
+ {
+ return null;
+ }
+
+ @Override
+ protected CONTAINER getContainer()
+ {
+ return container;
+ }
+
+ public void setContainer(CONTAINER container)
+ {
+ if (this.container != container)
+ {
+ IListener containerListener = getContainerListener();
+ if (containerListener != null && this.container != null)
+ {
+ this.container.removeListener(containerListener);
+ }
+
+ this.container = container;
+ if (containerListener != null && this.container != null)
+ {
+ this.container.addListener(containerListener);
+ }
+
+ resetInput();
+ }
+ }
+ }
+}
diff --git a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/views/IElementFilter.java b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/views/IElementFilter.java index 64d0f6b838..6cf5f8b4d5 100644 --- a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/views/IElementFilter.java +++ b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/views/IElementFilter.java @@ -1,19 +1,19 @@ -/* - * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) 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: - * Eike Stepper - initial API and implementation - */ -package org.eclipse.net4j.util.ui.views; - -/** - * @author Eike Stepper - */ -public interface IElementFilter -{ - public boolean filter(Object element); -} +/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.util.ui.views;
+
+/**
+ * @author Eike Stepper
+ */
+public interface IElementFilter
+{
+ public boolean filter(Object element);
+}
diff --git a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/views/ItemProvider.java b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/views/ItemProvider.java index acca0ff2bf..f64847164d 100644 --- a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/views/ItemProvider.java +++ b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/views/ItemProvider.java @@ -1,157 +1,157 @@ -/* - * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) 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: - * Eike Stepper - initial API and implementation - */ -package org.eclipse.net4j.util.ui.views; - -import org.eclipse.net4j.util.internal.ui.bundle.OM; -import org.eclipse.net4j.util.lifecycle.LifecycleUtil; -import org.eclipse.net4j.util.ui.StructuredContentProvider; - -import org.eclipse.jface.action.IMenuManager; -import org.eclipse.jface.viewers.IColorProvider; -import org.eclipse.jface.viewers.IFontProvider; -import org.eclipse.jface.viewers.ILabelProvider; -import org.eclipse.jface.viewers.ILabelProviderListener; -import org.eclipse.jface.viewers.ITreeContentProvider; -import org.eclipse.jface.viewers.ITreeSelection; -import org.eclipse.jface.viewers.LabelProviderChangedEvent; -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.Font; -import org.eclipse.swt.graphics.Image; -import org.eclipse.ui.ISharedImages; -import org.eclipse.ui.PlatformUI; - -import java.util.ArrayList; -import java.util.List; - -public abstract class ItemProvider<INPUT> extends StructuredContentProvider<INPUT> implements ITreeContentProvider, - ILabelProvider, IColorProvider, IFontProvider -{ - public static final Object[] NO_ELEMENTS = {}; - - private List<ILabelProviderListener> listeners = new ArrayList<ILabelProviderListener>(0); - - public ItemProvider() - { - } - - public final Object[] getElements(Object parent) - { - return getChildren(parent); - } - - public boolean hasChildren(Object parent) - { - return getChildren(parent).length != 0; - } - - public String getText(Object obj) - { - return obj.toString(); - } - - public Image getImage(Object obj) - { - String imageKey = ISharedImages.IMG_OBJ_ELEMENT; - return PlatformUI.getWorkbench().getSharedImages().getImage(imageKey); - } - - public Color getBackground(Object element) - { - return null; - } - - public Color getForeground(Object element) - { - if (!LifecycleUtil.isActive(element)) - { - return getDisplay().getSystemColor(SWT.COLOR_GRAY); - } - - return null; - } - - public Font getFont(Object element) - { - return null; - } - - public boolean isLabelProperty(Object element, String property) - { - return true; - } - - public ILabelProviderListener[] getListeners() - { - synchronized (listeners) - { - return listeners.toArray(new ILabelProviderListener[listeners.size()]); - } - } - - public void addListener(ILabelProviderListener listener) - { - synchronized (listeners) - { - listeners.add(listener); - } - } - - public void removeListener(ILabelProviderListener listener) - { - synchronized (listeners) - { - listeners.remove(listener); - } - } - - protected void fillContextMenu(IMenuManager manager, ITreeSelection selection) - { - } - - protected void fireLabelProviderChanged() - { - fireLabelProviderChanged(new LabelProviderChangedEvent(this)); - } - - protected void fireLabelProviderChanged(Object element) - { - fireLabelProviderChanged(new LabelProviderChangedEvent(this, element)); - } - - protected void fireLabelProviderChanged(Object[] elements) - { - fireLabelProviderChanged(new LabelProviderChangedEvent(this, elements)); - } - - /** - * Fires a label provider changed event to all registered listeners Only listeners registered at the time this method - * is called are notified. - * - * @param event - * a label provider changed event - * @see ILabelProviderListener#labelProviderChanged - */ - private void fireLabelProviderChanged(LabelProviderChangedEvent event) - { - for (ILabelProviderListener listener : getListeners()) - { - try - { - listener.labelProviderChanged(event); - } - catch (Exception ex) - { - OM.LOG.error(ex); - } - } - } -} +/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.util.ui.views;
+
+import org.eclipse.net4j.util.internal.ui.bundle.OM;
+import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
+import org.eclipse.net4j.util.ui.StructuredContentProvider;
+
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.viewers.IColorProvider;
+import org.eclipse.jface.viewers.IFontProvider;
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.jface.viewers.ILabelProviderListener;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.ITreeSelection;
+import org.eclipse.jface.viewers.LabelProviderChangedEvent;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Font;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.ui.ISharedImages;
+import org.eclipse.ui.PlatformUI;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public abstract class ItemProvider<INPUT> extends StructuredContentProvider<INPUT> implements ITreeContentProvider,
+ ILabelProvider, IColorProvider, IFontProvider
+{
+ public static final Object[] NO_ELEMENTS = {};
+
+ private List<ILabelProviderListener> listeners = new ArrayList<ILabelProviderListener>(0);
+
+ public ItemProvider()
+ {
+ }
+
+ public final Object[] getElements(Object parent)
+ {
+ return getChildren(parent);
+ }
+
+ public boolean hasChildren(Object parent)
+ {
+ return getChildren(parent).length != 0;
+ }
+
+ public String getText(Object obj)
+ {
+ return obj.toString();
+ }
+
+ public Image getImage(Object obj)
+ {
+ String imageKey = ISharedImages.IMG_OBJ_ELEMENT;
+ return PlatformUI.getWorkbench().getSharedImages().getImage(imageKey);
+ }
+
+ public Color getBackground(Object element)
+ {
+ return null;
+ }
+
+ public Color getForeground(Object element)
+ {
+ if (!LifecycleUtil.isActive(element))
+ {
+ return getDisplay().getSystemColor(SWT.COLOR_GRAY);
+ }
+
+ return null;
+ }
+
+ public Font getFont(Object element)
+ {
+ return null;
+ }
+
+ public boolean isLabelProperty(Object element, String property)
+ {
+ return true;
+ }
+
+ public ILabelProviderListener[] getListeners()
+ {
+ synchronized (listeners)
+ {
+ return listeners.toArray(new ILabelProviderListener[listeners.size()]);
+ }
+ }
+
+ public void addListener(ILabelProviderListener listener)
+ {
+ synchronized (listeners)
+ {
+ listeners.add(listener);
+ }
+ }
+
+ public void removeListener(ILabelProviderListener listener)
+ {
+ synchronized (listeners)
+ {
+ listeners.remove(listener);
+ }
+ }
+
+ protected void fillContextMenu(IMenuManager manager, ITreeSelection selection)
+ {
+ }
+
+ protected void fireLabelProviderChanged()
+ {
+ fireLabelProviderChanged(new LabelProviderChangedEvent(this));
+ }
+
+ protected void fireLabelProviderChanged(Object element)
+ {
+ fireLabelProviderChanged(new LabelProviderChangedEvent(this, element));
+ }
+
+ protected void fireLabelProviderChanged(Object[] elements)
+ {
+ fireLabelProviderChanged(new LabelProviderChangedEvent(this, elements));
+ }
+
+ /**
+ * Fires a label provider changed event to all registered listeners Only listeners registered at the time this method
+ * is called are notified.
+ *
+ * @param event
+ * a label provider changed event
+ * @see ILabelProviderListener#labelProviderChanged
+ */
+ private void fireLabelProviderChanged(LabelProviderChangedEvent event)
+ {
+ for (ILabelProviderListener listener : getListeners())
+ {
+ try
+ {
+ listener.labelProviderChanged(event);
+ }
+ catch (Exception ex)
+ {
+ OM.LOG.error(ex);
+ }
+ }
+ }
+}
diff --git a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/views/MasterDetailsView.java b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/views/MasterDetailsView.java index 637156ef8c..3aede367d5 100644 --- a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/views/MasterDetailsView.java +++ b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/views/MasterDetailsView.java @@ -1,318 +1,318 @@ -/* - * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) 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: - * Eike Stepper - initial API and implementation - */ -package org.eclipse.net4j.util.ui.views; - -import org.eclipse.net4j.util.ObjectUtil; -import org.eclipse.net4j.util.internal.ui.bundle.OM; -import org.eclipse.net4j.util.internal.ui.messages.Messages; -import org.eclipse.net4j.util.ui.UIUtil; -import org.eclipse.net4j.util.ui.actions.SafeAction; -import org.eclipse.net4j.util.ui.actions.SashLayoutAction; -import org.eclipse.net4j.util.ui.widgets.CoolBarComposite; -import org.eclipse.net4j.util.ui.widgets.SashComposite; - -import org.eclipse.jface.action.IContributionManager; -import org.eclipse.jface.action.IMenuManager; -import org.eclipse.jface.action.Separator; -import org.eclipse.jface.viewers.ISelectionChangedListener; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.SelectionChangedEvent; -import org.eclipse.jface.viewers.StructuredViewer; -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.CTabFolder; -import org.eclipse.swt.custom.CTabItem; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; - -/** - * @author Eike Stepper - * @since 2.0 - */ -public abstract class MasterDetailsView extends MultiViewersView -{ - private StructuredViewer master; - - private CTabFolder detailsFolder; - - private Object currentMasterElement = new Object(); - - private String[] detailTitles; - - private CTabItem[] detailItems; - - private StructuredViewer[] details; - - private int currentDetailIndex; - - private SashComposite sash; - - public MasterDetailsView() - { - } - - public StructuredViewer getMaster() - { - return master; - } - - public StructuredViewer[] getDetails() - { - return details; - } - - public String[] getDetailTitles() - { - return detailTitles; - } - - public Object getCurrentMasterElement() - { - return currentMasterElement; - } - - public int getCurrentDetailIndex() - { - return currentDetailIndex; - } - - public String getCurrentDetailTitle() - { - if (detailTitles == null || currentDetailIndex == -1) - { - return null; - } - - return detailTitles[currentDetailIndex]; - } - - @Override - protected Control createUI(Composite parent) - { - sash = new SashComposite(parent, SWT.NONE, 10, 50, true) - { - @Override - protected Control createControl1(Composite parent) - { - master = createMaster(parent); - return master.getControl(); - } - - @Override - protected Control createControl2(Composite parent) - { - return new CoolBarComposite(parent, SWT.NONE) - { - @Override - protected Control createUI(Composite parent) - { - // Styles: CLOSE, TOP, BOTTOM, FLAT, BORDER, SINGLE, MULTI - detailsFolder = new CTabFolder(parent, SWT.BOTTOM | SWT.FLAT); - detailsFolder.setLayoutData(UIUtil.createGridData()); - adjustDetails(null); - detailsFolder.addSelectionListener(new SelectionAdapter() - { - @Override - public void widgetSelected(SelectionEvent e) - { - String title = detailsFolder.getSelection().getText(); - int detailIndex = indexOf(detailItems, title); - if (detailIndex != currentDetailIndex) - { - currentDetailIndex = detailIndex; - updateCoolBar(); - } - } - }); - - return detailsFolder; - } - - @Override - protected void fillCoolBar(IContributionManager manager) - { - MasterDetailsView.this.fillCoolBar(manager); - manager.add(new RefreshAction()); - } - }; - } - }; - - sash.setVertical(true); - setCurrentViewer(master); - master.addSelectionChangedListener(new ISelectionChangedListener() - { - public void selectionChanged(SelectionChangedEvent event) - { - try - { - masterSelectionChanged(event); - } - catch (Error ex) - { - OM.LOG.error(ex); - throw ex; - } - catch (RuntimeException ex) - { - OM.LOG.error(ex); - throw ex; - } - } - }); - - return sash; - } - - @Override - protected void fillLocalPullDown(IMenuManager manager) - { - super.fillLocalPullDown(manager); - manager.add(new Separator("group1")); //$NON-NLS-1$ - manager.add(new SashLayoutAction.LayoutMenu(sash)); - manager.add(new Separator("group2")); //$NON-NLS-1$ - manager.add(new RefreshAction()); - } - - protected void masterSelectionChanged(SelectionChangedEvent event) - { - IStructuredSelection selection = (IStructuredSelection)master.getSelection(); - Object masterElement = selection.getFirstElement(); - adjustDetails(masterElement); - } - - protected void adjustDetails(Object masterElement) - { - if (ObjectUtil.equals(masterElement, currentMasterElement)) - { - return; - } - - // Temporarily remember old values - String oldDetailTitle = detailItems == null || currentDetailIndex < 0 ? null : detailItems[currentDetailIndex] - .getText(); - StructuredViewer[] oldDetails = details; - CTabItem[] oldDetailItems = detailItems; - - // Initialize new values - detailTitles = getDetailTitles(masterElement); - details = new StructuredViewer[detailTitles.length]; - detailItems = new CTabItem[detailTitles.length]; - - for (int i = 0; i < detailTitles.length; i++) - { - String title = detailTitles[i]; - int oldIndex = indexOf(oldDetailItems, title); - if (oldIndex != -1) - { - details[i] = oldDetails[oldIndex]; - oldDetailItems[oldIndex].setControl(null); - oldDetailItems[oldIndex].dispose(); - oldDetailItems[oldIndex] = null; - } - else - { - details[i] = createDetail(detailsFolder, title); - } - - detailItems[i] = new CTabItem(detailsFolder, SWT.NONE, i); - detailItems[i].setText(title); - detailItems[i].setControl(details[i].getControl()); - } - - // Cleanup - if (oldDetailItems != null) - { - for (CTabItem item : oldDetailItems) - { - if (item != null) - { - item.dispose(); - } - } - } - - currentMasterElement = masterElement; - for (StructuredViewer viewer : details) - { - setDetailInput(viewer, masterElement); - } - - currentDetailIndex = indexOf(detailItems, oldDetailTitle); - if (currentDetailIndex == -1 && details.length > 0) - { - currentDetailIndex = 0; - } - - if (currentDetailIndex != -1) - { - detailsFolder.setSelection(currentDetailIndex); - } - } - - protected void setDetailInput(StructuredViewer viewer, Object input) - { - if (input != viewer.getInput()) - { - viewer.setInput(input); - } - } - - protected void fillCoolBar(IContributionManager manager) - { - } - - protected abstract StructuredViewer createMaster(Composite parent); - - protected abstract StructuredViewer createDetail(Composite parent, String title); - - protected abstract String[] getDetailTitles(Object masterElement); - - public static int indexOf(CTabItem[] items, String title) - { - if (items != null) - { - for (int i = 0; i < items.length; i++) - { - CTabItem item = items[i]; - if (item != null && ObjectUtil.equals(item.getText(), title)) - { - return i; - } - } - } - - return -1; - } - - /** - * @author Eike Stepper - */ - protected final class RefreshAction extends SafeAction - { - public RefreshAction() - { - super( - Messages.getString("MasterDetailsView_2"), Messages.getString("MasterDetailsView_3"), OM.getImageDescriptor("icons/full/etool16/refresh.gif")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - } - - @Override - protected void safeRun() throws Exception - { - StructuredViewer viewer = getCurrentViewer(); - if (viewer != null) - { - viewer.refresh(); - } - } - } -} +/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.util.ui.views;
+
+import org.eclipse.net4j.util.ObjectUtil;
+import org.eclipse.net4j.util.internal.ui.bundle.OM;
+import org.eclipse.net4j.util.internal.ui.messages.Messages;
+import org.eclipse.net4j.util.ui.UIUtil;
+import org.eclipse.net4j.util.ui.actions.SafeAction;
+import org.eclipse.net4j.util.ui.actions.SashLayoutAction;
+import org.eclipse.net4j.util.ui.widgets.CoolBarComposite;
+import org.eclipse.net4j.util.ui.widgets.SashComposite;
+
+import org.eclipse.jface.action.IContributionManager;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.action.Separator;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.StructuredViewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.CTabFolder;
+import org.eclipse.swt.custom.CTabItem;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+
+/**
+ * @author Eike Stepper
+ * @since 2.0
+ */
+public abstract class MasterDetailsView extends MultiViewersView
+{
+ private StructuredViewer master;
+
+ private CTabFolder detailsFolder;
+
+ private Object currentMasterElement = new Object();
+
+ private String[] detailTitles;
+
+ private CTabItem[] detailItems;
+
+ private StructuredViewer[] details;
+
+ private int currentDetailIndex;
+
+ private SashComposite sash;
+
+ public MasterDetailsView()
+ {
+ }
+
+ public StructuredViewer getMaster()
+ {
+ return master;
+ }
+
+ public StructuredViewer[] getDetails()
+ {
+ return details;
+ }
+
+ public String[] getDetailTitles()
+ {
+ return detailTitles;
+ }
+
+ public Object getCurrentMasterElement()
+ {
+ return currentMasterElement;
+ }
+
+ public int getCurrentDetailIndex()
+ {
+ return currentDetailIndex;
+ }
+
+ public String getCurrentDetailTitle()
+ {
+ if (detailTitles == null || currentDetailIndex == -1)
+ {
+ return null;
+ }
+
+ return detailTitles[currentDetailIndex];
+ }
+
+ @Override
+ protected Control createUI(Composite parent)
+ {
+ sash = new SashComposite(parent, SWT.NONE, 10, 50, true)
+ {
+ @Override
+ protected Control createControl1(Composite parent)
+ {
+ master = createMaster(parent);
+ return master.getControl();
+ }
+
+ @Override
+ protected Control createControl2(Composite parent)
+ {
+ return new CoolBarComposite(parent, SWT.NONE)
+ {
+ @Override
+ protected Control createUI(Composite parent)
+ {
+ // Styles: CLOSE, TOP, BOTTOM, FLAT, BORDER, SINGLE, MULTI
+ detailsFolder = new CTabFolder(parent, SWT.BOTTOM | SWT.FLAT);
+ detailsFolder.setLayoutData(UIUtil.createGridData());
+ adjustDetails(null);
+ detailsFolder.addSelectionListener(new SelectionAdapter()
+ {
+ @Override
+ public void widgetSelected(SelectionEvent e)
+ {
+ String title = detailsFolder.getSelection().getText();
+ int detailIndex = indexOf(detailItems, title);
+ if (detailIndex != currentDetailIndex)
+ {
+ currentDetailIndex = detailIndex;
+ updateCoolBar();
+ }
+ }
+ });
+
+ return detailsFolder;
+ }
+
+ @Override
+ protected void fillCoolBar(IContributionManager manager)
+ {
+ MasterDetailsView.this.fillCoolBar(manager);
+ manager.add(new RefreshAction());
+ }
+ };
+ }
+ };
+
+ sash.setVertical(true);
+ setCurrentViewer(master);
+ master.addSelectionChangedListener(new ISelectionChangedListener()
+ {
+ public void selectionChanged(SelectionChangedEvent event)
+ {
+ try
+ {
+ masterSelectionChanged(event);
+ }
+ catch (Error ex)
+ {
+ OM.LOG.error(ex);
+ throw ex;
+ }
+ catch (RuntimeException ex)
+ {
+ OM.LOG.error(ex);
+ throw ex;
+ }
+ }
+ });
+
+ return sash;
+ }
+
+ @Override
+ protected void fillLocalPullDown(IMenuManager manager)
+ {
+ super.fillLocalPullDown(manager);
+ manager.add(new Separator("group1")); //$NON-NLS-1$
+ manager.add(new SashLayoutAction.LayoutMenu(sash));
+ manager.add(new Separator("group2")); //$NON-NLS-1$
+ manager.add(new RefreshAction());
+ }
+
+ protected void masterSelectionChanged(SelectionChangedEvent event)
+ {
+ IStructuredSelection selection = (IStructuredSelection)master.getSelection();
+ Object masterElement = selection.getFirstElement();
+ adjustDetails(masterElement);
+ }
+
+ protected void adjustDetails(Object masterElement)
+ {
+ if (ObjectUtil.equals(masterElement, currentMasterElement))
+ {
+ return;
+ }
+
+ // Temporarily remember old values
+ String oldDetailTitle = detailItems == null || currentDetailIndex < 0 ? null : detailItems[currentDetailIndex]
+ .getText();
+ StructuredViewer[] oldDetails = details;
+ CTabItem[] oldDetailItems = detailItems;
+
+ // Initialize new values
+ detailTitles = getDetailTitles(masterElement);
+ details = new StructuredViewer[detailTitles.length];
+ detailItems = new CTabItem[detailTitles.length];
+
+ for (int i = 0; i < detailTitles.length; i++)
+ {
+ String title = detailTitles[i];
+ int oldIndex = indexOf(oldDetailItems, title);
+ if (oldIndex != -1)
+ {
+ details[i] = oldDetails[oldIndex];
+ oldDetailItems[oldIndex].setControl(null);
+ oldDetailItems[oldIndex].dispose();
+ oldDetailItems[oldIndex] = null;
+ }
+ else
+ {
+ details[i] = createDetail(detailsFolder, title);
+ }
+
+ detailItems[i] = new CTabItem(detailsFolder, SWT.NONE, i);
+ detailItems[i].setText(title);
+ detailItems[i].setControl(details[i].getControl());
+ }
+
+ // Cleanup
+ if (oldDetailItems != null)
+ {
+ for (CTabItem item : oldDetailItems)
+ {
+ if (item != null)
+ {
+ item.dispose();
+ }
+ }
+ }
+
+ currentMasterElement = masterElement;
+ for (StructuredViewer viewer : details)
+ {
+ setDetailInput(viewer, masterElement);
+ }
+
+ currentDetailIndex = indexOf(detailItems, oldDetailTitle);
+ if (currentDetailIndex == -1 && details.length > 0)
+ {
+ currentDetailIndex = 0;
+ }
+
+ if (currentDetailIndex != -1)
+ {
+ detailsFolder.setSelection(currentDetailIndex);
+ }
+ }
+
+ protected void setDetailInput(StructuredViewer viewer, Object input)
+ {
+ if (input != viewer.getInput())
+ {
+ viewer.setInput(input);
+ }
+ }
+
+ protected void fillCoolBar(IContributionManager manager)
+ {
+ }
+
+ protected abstract StructuredViewer createMaster(Composite parent);
+
+ protected abstract StructuredViewer createDetail(Composite parent, String title);
+
+ protected abstract String[] getDetailTitles(Object masterElement);
+
+ public static int indexOf(CTabItem[] items, String title)
+ {
+ if (items != null)
+ {
+ for (int i = 0; i < items.length; i++)
+ {
+ CTabItem item = items[i];
+ if (item != null && ObjectUtil.equals(item.getText(), title))
+ {
+ return i;
+ }
+ }
+ }
+
+ return -1;
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ protected final class RefreshAction extends SafeAction
+ {
+ public RefreshAction()
+ {
+ super(
+ Messages.getString("MasterDetailsView_2"), Messages.getString("MasterDetailsView_3"), OM.getImageDescriptor("icons/full/etool16/refresh.gif")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ @Override
+ protected void safeRun() throws Exception
+ {
+ StructuredViewer viewer = getCurrentViewer();
+ if (viewer != null)
+ {
+ viewer.refresh();
+ }
+ }
+ }
+}
diff --git a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/views/MultiViewersView.java b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/views/MultiViewersView.java index bb96f31ec2..5622242233 100644 --- a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/views/MultiViewersView.java +++ b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/views/MultiViewersView.java @@ -1,350 +1,350 @@ -/* - * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) 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: - * Eike Stepper - initial API and implementation - */ -package org.eclipse.net4j.util.ui.views; - -import org.eclipse.net4j.util.internal.ui.bundle.OM; -import org.eclipse.net4j.util.ui.UIUtil; - -import org.eclipse.jface.action.IMenuListener; -import org.eclipse.jface.action.IMenuManager; -import org.eclipse.jface.action.IToolBarManager; -import org.eclipse.jface.action.MenuManager; -import org.eclipse.jface.action.Separator; -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jface.viewers.DoubleClickEvent; -import org.eclipse.jface.viewers.IDoubleClickListener; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.StructuredViewer; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Menu; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.ui.IActionBars; -import org.eclipse.ui.IWorkbenchActionConstants; -import org.eclipse.ui.part.ISetSelectionTarget; -import org.eclipse.ui.part.ViewPart; - -/** - * @author Eike Stepper - * @since 2.0 - */ -public abstract class MultiViewersView extends ViewPart implements ISetSelectionTarget -{ - private Shell shell; - - private StructuredViewer currentViewer; - - public MultiViewersView() - { - } - - public Shell getShell() - { - return shell; - } - - public StructuredViewer getCurrentViewer() - { - return currentViewer; - } - - public void setCurrentViewer(StructuredViewer viewer) - { - currentViewer = viewer; - getSite().setSelectionProvider(currentViewer); - hookContextMenu(currentViewer); - } - - @Override - public void setFocus() - { - StructuredViewer viewer = getCurrentViewer(); - if (viewer != null) - { - viewer.getControl().setFocus(); - } - } - - public void refreshViewer(boolean updateLabels) - { - refreshElement(null, updateLabels); - } - - public void refreshElement(final Object element, final boolean updateLabels) - { - try - { - final StructuredViewer viewer = getCurrentViewer(); - if (viewer != null) - { - getDisplay().asyncExec(new Runnable() - { - public void run() - { - try - { - if (element != null) - { - viewer.refresh(element, updateLabels); - } - else - { - viewer.refresh(updateLabels); - } - } - catch (RuntimeException ignore) - { - } - } - }); - } - } - catch (RuntimeException ignore) - { - } - } - - public void updateLabels(final Object element) - { - try - { - final StructuredViewer viewer = getCurrentViewer(); - if (viewer != null) - { - getDisplay().asyncExec(new Runnable() - { - public void run() - { - try - { - viewer.update(element, null); - } - catch (RuntimeException ignore) - { - } - } - }); - } - } - catch (RuntimeException ignore) - { - } - } - - public void revealElement(final Object element) - { - try - { - final StructuredViewer viewer = getCurrentViewer(); - if (viewer != null) - { - getDisplay().asyncExec(new Runnable() - { - public void run() - { - try - { - viewer.reveal(element); - } - catch (RuntimeException ignore) - { - } - } - }); - } - } - catch (RuntimeException ignore) - { - } - } - - public void selectReveal(ISelection selection) - { - StructuredViewer viewer = getCurrentViewer(); - if (viewer != null) - { - viewer.setSelection(selection, true); - } - } - - public void closeView() - { - try - { - getSite().getShell().getDisplay().syncExec(new Runnable() - { - public void run() - { - try - { - getSite().getPage().hideView(MultiViewersView.this); - MultiViewersView.this.dispose(); - } - catch (Exception ignore) - { - } - } - }); - } - catch (Exception ignore) - { - } - } - - @Override - public final void createPartControl(Composite parent) - { - try - { - shell = parent.getShell(); - Composite composite = UIUtil.createGridComposite(parent, 1); - - Control control = createUI(composite); - control.setLayoutData(UIUtil.createGridData()); - - hookDoubleClick(); - contributeToActionBars(); - } - catch (Error ex) - { - OM.LOG.error(ex); - throw ex; - } - catch (RuntimeException ex) - { - OM.LOG.error(ex); - throw ex; - } - } - - protected abstract Control createUI(Composite parent); - - protected void doubleClicked(Object object) - { - } - - protected void fillContextMenu(IMenuManager manager, StructuredViewer viewer, IStructuredSelection selection) - { - } - - protected void fillLocalPullDown(IMenuManager manager) - { - manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS)); - } - - protected void fillLocalToolBar(IToolBarManager manager) - { - manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS)); - } - - protected final void showMessage(String message) - { - showMessage(MessageType.INFORMATION, message); - } - - protected final boolean showMessage(MessageType type, String message) - { - switch (type) - { - case INFORMATION: - MessageDialog.openInformation(getShell(), getTitle(), message); - return true; - - case ERROR: - MessageDialog.openError(getShell(), getTitle(), message); - return true; - - case WARNING: - MessageDialog.openWarning(getShell(), getTitle(), message); - return true; - - case CONFIRM: - return MessageDialog.openConfirm(getShell(), getTitle(), message); - - case QUESTION: - return MessageDialog.openQuestion(getShell(), getTitle(), message); - - default: - return true; - } - } - - protected final Display getDisplay() - { - Display display = null; - final StructuredViewer viewer = getCurrentViewer(); - if (viewer != null) - { - display = viewer.getControl().getDisplay(); - } - - if (display == null) - { - display = UIUtil.getDisplay(); - } - - return display; - } - - private void hookDoubleClick() - { - final StructuredViewer viewer = getCurrentViewer(); - if (viewer != null) - { - viewer.addDoubleClickListener(new IDoubleClickListener() - { - public void doubleClick(DoubleClickEvent event) - { - IStructuredSelection selection = (IStructuredSelection)viewer.getSelection(); - Object object = selection.getFirstElement(); - doubleClicked(object); - } - }); - } - } - - private void hookContextMenu(final StructuredViewer viewer) - { - MenuManager menuMgr = new MenuManager("#PopupMenu"); //$NON-NLS-1$ - menuMgr.setRemoveAllWhenShown(true); - menuMgr.addMenuListener(new IMenuListener() - { - public void menuAboutToShow(IMenuManager manager) - { - final StructuredViewer viewer = getCurrentViewer(); - if (viewer != null) - { - IStructuredSelection selection = (IStructuredSelection)viewer.getSelection(); - fillContextMenu(manager, viewer, selection); - } - } - }); - - Control control = viewer.getControl(); - Menu menu = menuMgr.createContextMenu(control); - viewer.getControl().setMenu(menu); - getSite().registerContextMenu(menuMgr, viewer); - } - - private void contributeToActionBars() - { - IActionBars bars = getViewSite().getActionBars(); - fillLocalPullDown(bars.getMenuManager()); - fillLocalToolBar(bars.getToolBarManager()); - } - - protected static enum MessageType - { - INFORMATION, ERROR, WARNING, CONFIRM, QUESTION - } -} +/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.util.ui.views;
+
+import org.eclipse.net4j.util.internal.ui.bundle.OM;
+import org.eclipse.net4j.util.ui.UIUtil;
+
+import org.eclipse.jface.action.IMenuListener;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.action.IToolBarManager;
+import org.eclipse.jface.action.MenuManager;
+import org.eclipse.jface.action.Separator;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.viewers.DoubleClickEvent;
+import org.eclipse.jface.viewers.IDoubleClickListener;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.StructuredViewer;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Menu;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IActionBars;
+import org.eclipse.ui.IWorkbenchActionConstants;
+import org.eclipse.ui.part.ISetSelectionTarget;
+import org.eclipse.ui.part.ViewPart;
+
+/**
+ * @author Eike Stepper
+ * @since 2.0
+ */
+public abstract class MultiViewersView extends ViewPart implements ISetSelectionTarget
+{
+ private Shell shell;
+
+ private StructuredViewer currentViewer;
+
+ public MultiViewersView()
+ {
+ }
+
+ public Shell getShell()
+ {
+ return shell;
+ }
+
+ public StructuredViewer getCurrentViewer()
+ {
+ return currentViewer;
+ }
+
+ public void setCurrentViewer(StructuredViewer viewer)
+ {
+ currentViewer = viewer;
+ getSite().setSelectionProvider(currentViewer);
+ hookContextMenu(currentViewer);
+ }
+
+ @Override
+ public void setFocus()
+ {
+ StructuredViewer viewer = getCurrentViewer();
+ if (viewer != null)
+ {
+ viewer.getControl().setFocus();
+ }
+ }
+
+ public void refreshViewer(boolean updateLabels)
+ {
+ refreshElement(null, updateLabels);
+ }
+
+ public void refreshElement(final Object element, final boolean updateLabels)
+ {
+ try
+ {
+ final StructuredViewer viewer = getCurrentViewer();
+ if (viewer != null)
+ {
+ getDisplay().asyncExec(new Runnable()
+ {
+ public void run()
+ {
+ try
+ {
+ if (element != null)
+ {
+ viewer.refresh(element, updateLabels);
+ }
+ else
+ {
+ viewer.refresh(updateLabels);
+ }
+ }
+ catch (RuntimeException ignore)
+ {
+ }
+ }
+ });
+ }
+ }
+ catch (RuntimeException ignore)
+ {
+ }
+ }
+
+ public void updateLabels(final Object element)
+ {
+ try
+ {
+ final StructuredViewer viewer = getCurrentViewer();
+ if (viewer != null)
+ {
+ getDisplay().asyncExec(new Runnable()
+ {
+ public void run()
+ {
+ try
+ {
+ viewer.update(element, null);
+ }
+ catch (RuntimeException ignore)
+ {
+ }
+ }
+ });
+ }
+ }
+ catch (RuntimeException ignore)
+ {
+ }
+ }
+
+ public void revealElement(final Object element)
+ {
+ try
+ {
+ final StructuredViewer viewer = getCurrentViewer();
+ if (viewer != null)
+ {
+ getDisplay().asyncExec(new Runnable()
+ {
+ public void run()
+ {
+ try
+ {
+ viewer.reveal(element);
+ }
+ catch (RuntimeException ignore)
+ {
+ }
+ }
+ });
+ }
+ }
+ catch (RuntimeException ignore)
+ {
+ }
+ }
+
+ public void selectReveal(ISelection selection)
+ {
+ StructuredViewer viewer = getCurrentViewer();
+ if (viewer != null)
+ {
+ viewer.setSelection(selection, true);
+ }
+ }
+
+ public void closeView()
+ {
+ try
+ {
+ getSite().getShell().getDisplay().syncExec(new Runnable()
+ {
+ public void run()
+ {
+ try
+ {
+ getSite().getPage().hideView(MultiViewersView.this);
+ MultiViewersView.this.dispose();
+ }
+ catch (Exception ignore)
+ {
+ }
+ }
+ });
+ }
+ catch (Exception ignore)
+ {
+ }
+ }
+
+ @Override
+ public final void createPartControl(Composite parent)
+ {
+ try
+ {
+ shell = parent.getShell();
+ Composite composite = UIUtil.createGridComposite(parent, 1);
+
+ Control control = createUI(composite);
+ control.setLayoutData(UIUtil.createGridData());
+
+ hookDoubleClick();
+ contributeToActionBars();
+ }
+ catch (Error ex)
+ {
+ OM.LOG.error(ex);
+ throw ex;
+ }
+ catch (RuntimeException ex)
+ {
+ OM.LOG.error(ex);
+ throw ex;
+ }
+ }
+
+ protected abstract Control createUI(Composite parent);
+
+ protected void doubleClicked(Object object)
+ {
+ }
+
+ protected void fillContextMenu(IMenuManager manager, StructuredViewer viewer, IStructuredSelection selection)
+ {
+ }
+
+ protected void fillLocalPullDown(IMenuManager manager)
+ {
+ manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
+ }
+
+ protected void fillLocalToolBar(IToolBarManager manager)
+ {
+ manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
+ }
+
+ protected final void showMessage(String message)
+ {
+ showMessage(MessageType.INFORMATION, message);
+ }
+
+ protected final boolean showMessage(MessageType type, String message)
+ {
+ switch (type)
+ {
+ case INFORMATION:
+ MessageDialog.openInformation(getShell(), getTitle(), message);
+ return true;
+
+ case ERROR:
+ MessageDialog.openError(getShell(), getTitle(), message);
+ return true;
+
+ case WARNING:
+ MessageDialog.openWarning(getShell(), getTitle(), message);
+ return true;
+
+ case CONFIRM:
+ return MessageDialog.openConfirm(getShell(), getTitle(), message);
+
+ case QUESTION:
+ return MessageDialog.openQuestion(getShell(), getTitle(), message);
+
+ default:
+ return true;
+ }
+ }
+
+ protected final Display getDisplay()
+ {
+ Display display = null;
+ final StructuredViewer viewer = getCurrentViewer();
+ if (viewer != null)
+ {
+ display = viewer.getControl().getDisplay();
+ }
+
+ if (display == null)
+ {
+ display = UIUtil.getDisplay();
+ }
+
+ return display;
+ }
+
+ private void hookDoubleClick()
+ {
+ final StructuredViewer viewer = getCurrentViewer();
+ if (viewer != null)
+ {
+ viewer.addDoubleClickListener(new IDoubleClickListener()
+ {
+ public void doubleClick(DoubleClickEvent event)
+ {
+ IStructuredSelection selection = (IStructuredSelection)viewer.getSelection();
+ Object object = selection.getFirstElement();
+ doubleClicked(object);
+ }
+ });
+ }
+ }
+
+ private void hookContextMenu(final StructuredViewer viewer)
+ {
+ MenuManager menuMgr = new MenuManager("#PopupMenu"); //$NON-NLS-1$
+ menuMgr.setRemoveAllWhenShown(true);
+ menuMgr.addMenuListener(new IMenuListener()
+ {
+ public void menuAboutToShow(IMenuManager manager)
+ {
+ final StructuredViewer viewer = getCurrentViewer();
+ if (viewer != null)
+ {
+ IStructuredSelection selection = (IStructuredSelection)viewer.getSelection();
+ fillContextMenu(manager, viewer, selection);
+ }
+ }
+ });
+
+ Control control = viewer.getControl();
+ Menu menu = menuMgr.createContextMenu(control);
+ viewer.getControl().setMenu(menu);
+ getSite().registerContextMenu(menuMgr, viewer);
+ }
+
+ private void contributeToActionBars()
+ {
+ IActionBars bars = getViewSite().getActionBars();
+ fillLocalPullDown(bars.getMenuManager());
+ fillLocalToolBar(bars.getToolBarManager());
+ }
+
+ protected static enum MessageType
+ {
+ INFORMATION, ERROR, WARNING, CONFIRM, QUESTION
+ }
+}
diff --git a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/views/package-info.java b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/views/package-info.java index 82d89a5064..c5b72c8af6 100644 --- a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/views/package-info.java +++ b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/views/package-info.java @@ -1,5 +1,5 @@ /*
- * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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
diff --git a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/widgets/BaseDialog.java b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/widgets/BaseDialog.java index a42c465033..3ee0977674 100644 --- a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/widgets/BaseDialog.java +++ b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/widgets/BaseDialog.java @@ -1,145 +1,145 @@ -/* - * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) 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: - * Eike Stepper - initial API and implementation - */ -package org.eclipse.net4j.util.ui.widgets; - -import org.eclipse.jface.action.IMenuListener; -import org.eclipse.jface.action.IMenuManager; -import org.eclipse.jface.action.MenuManager; -import org.eclipse.jface.dialogs.IDialogSettings; -import org.eclipse.jface.dialogs.TitleAreaDialog; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Menu; -import org.eclipse.swt.widgets.Shell; - -/** - * @author Eike Stepper - */ -public abstract class BaseDialog<VIEWER extends Viewer> extends TitleAreaDialog -{ - public static final int DEFAULT_SHELL_STYLE = SWT.SHELL_TRIM; - - private String title; - - private String message; - - private IDialogSettings settings; - - private VIEWER currentViewer; - - private MenuManager contextMenu; - - public BaseDialog(Shell parentShell, int shellStyle, String title, String message, IDialogSettings settings) - { - super(parentShell); - setShellStyle(shellStyle); - this.title = title; - this.message = message; - this.settings = settings; - } - - public BaseDialog(Shell parentShell, String title, String message, IDialogSettings settings) - { - this(parentShell, DEFAULT_SHELL_STYLE, title, message, settings); - } - - @Override - protected void configureShell(Shell newShell) - { - super.configureShell(newShell); - newShell.setText(title); - } - - @Override - protected Control createDialogArea(Composite parent) - { - Composite composite = (Composite)super.createDialogArea(parent); - setTitle(title); - setMessage(message); - - contextMenu = new MenuManager("#PopupMenu"); //$NON-NLS-1$ - contextMenu.setRemoveAllWhenShown(true); - contextMenu.addMenuListener(new IMenuListener() - { - public void menuAboutToShow(IMenuManager manager) - { - VIEWER viewer = getCurrentViewer(); - if (viewer != null) - { - fillContextMenu(manager, viewer); - } - } - }); - - createUI(composite); - return composite; - } - - protected abstract void createUI(Composite parent); - - public VIEWER getCurrentViewer() - { - return currentViewer; - } - - public void setCurrentViewer(VIEWER currentViewer) - { - if (this.currentViewer != null) - { - Control control = this.currentViewer.getControl(); - control.setMenu(null); - } - - this.currentViewer = currentViewer; - if (this.currentViewer != null) - { - Control control = this.currentViewer.getControl(); - Menu menu = contextMenu.createContextMenu(control); - control.setMenu(menu); - } - } - - protected void hookContextMenu() - { - contextMenu = new MenuManager("#PopupMenu"); //$NON-NLS-1$ - contextMenu.setRemoveAllWhenShown(true); - contextMenu.addMenuListener(new IMenuListener() - { - public void menuAboutToShow(IMenuManager manager) - { - fillContextMenu(manager, getCurrentViewer()); - } - }); - } - - protected void fillContextMenu(IMenuManager manager, VIEWER viewer) - { - } - - @Override - protected IDialogSettings getDialogBoundsSettings() - { - if (settings == null) - { - return null; - } - - IDialogSettings section = settings.getSection(title); - if (section == null) - { - section = settings.addNewSection(title); - } - - return section; - } -} +/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.util.ui.widgets;
+
+import org.eclipse.jface.action.IMenuListener;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.action.MenuManager;
+import org.eclipse.jface.dialogs.IDialogSettings;
+import org.eclipse.jface.dialogs.TitleAreaDialog;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Menu;
+import org.eclipse.swt.widgets.Shell;
+
+/**
+ * @author Eike Stepper
+ */
+public abstract class BaseDialog<VIEWER extends Viewer> extends TitleAreaDialog
+{
+ public static final int DEFAULT_SHELL_STYLE = SWT.SHELL_TRIM;
+
+ private String title;
+
+ private String message;
+
+ private IDialogSettings settings;
+
+ private VIEWER currentViewer;
+
+ private MenuManager contextMenu;
+
+ public BaseDialog(Shell parentShell, int shellStyle, String title, String message, IDialogSettings settings)
+ {
+ super(parentShell);
+ setShellStyle(shellStyle);
+ this.title = title;
+ this.message = message;
+ this.settings = settings;
+ }
+
+ public BaseDialog(Shell parentShell, String title, String message, IDialogSettings settings)
+ {
+ this(parentShell, DEFAULT_SHELL_STYLE, title, message, settings);
+ }
+
+ @Override
+ protected void configureShell(Shell newShell)
+ {
+ super.configureShell(newShell);
+ newShell.setText(title);
+ }
+
+ @Override
+ protected Control createDialogArea(Composite parent)
+ {
+ Composite composite = (Composite)super.createDialogArea(parent);
+ setTitle(title);
+ setMessage(message);
+
+ contextMenu = new MenuManager("#PopupMenu"); //$NON-NLS-1$
+ contextMenu.setRemoveAllWhenShown(true);
+ contextMenu.addMenuListener(new IMenuListener()
+ {
+ public void menuAboutToShow(IMenuManager manager)
+ {
+ VIEWER viewer = getCurrentViewer();
+ if (viewer != null)
+ {
+ fillContextMenu(manager, viewer);
+ }
+ }
+ });
+
+ createUI(composite);
+ return composite;
+ }
+
+ protected abstract void createUI(Composite parent);
+
+ public VIEWER getCurrentViewer()
+ {
+ return currentViewer;
+ }
+
+ public void setCurrentViewer(VIEWER currentViewer)
+ {
+ if (this.currentViewer != null)
+ {
+ Control control = this.currentViewer.getControl();
+ control.setMenu(null);
+ }
+
+ this.currentViewer = currentViewer;
+ if (this.currentViewer != null)
+ {
+ Control control = this.currentViewer.getControl();
+ Menu menu = contextMenu.createContextMenu(control);
+ control.setMenu(menu);
+ }
+ }
+
+ protected void hookContextMenu()
+ {
+ contextMenu = new MenuManager("#PopupMenu"); //$NON-NLS-1$
+ contextMenu.setRemoveAllWhenShown(true);
+ contextMenu.addMenuListener(new IMenuListener()
+ {
+ public void menuAboutToShow(IMenuManager manager)
+ {
+ fillContextMenu(manager, getCurrentViewer());
+ }
+ });
+ }
+
+ protected void fillContextMenu(IMenuManager manager, VIEWER viewer)
+ {
+ }
+
+ @Override
+ protected IDialogSettings getDialogBoundsSettings()
+ {
+ if (settings == null)
+ {
+ return null;
+ }
+
+ IDialogSettings section = settings.getSection(title);
+ if (section == null)
+ {
+ section = settings.addNewSection(title);
+ }
+
+ return section;
+ }
+}
diff --git a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/widgets/CoolBarComposite.java b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/widgets/CoolBarComposite.java index a13f0af1c1..2530fbe450 100644 --- a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/widgets/CoolBarComposite.java +++ b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/widgets/CoolBarComposite.java @@ -1,204 +1,204 @@ -/* - * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) 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: - * Eike Stepper - initial API and implementation - */ -package org.eclipse.net4j.util.ui.widgets; - -import org.eclipse.net4j.util.ui.UIUtil; - -import org.eclipse.jface.action.CoolBarManager; -import org.eclipse.jface.action.IContributionManager; -import org.eclipse.jface.action.ToolBarManager; -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.graphics.Rectangle; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.CoolBar; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Layout; - -/** - * @author Eike Stepper - * @since 2.0 - */ -public abstract class CoolBarComposite extends Composite -{ - private CoolBarManager coolBarManager; - - private Control clientControl; - - private Label separator; - - private ToolBarManager toolBarManager; - - public CoolBarComposite(Composite parent, int style) - { - super(parent, style); - setLayout(new CoolBarLayout()); - - toolBarManager = new ToolBarManager(SWT.FLAT | SWT.RIGHT | SWT.WRAP | SWT.HORIZONTAL); - fillCoolBar(toolBarManager); - - coolBarManager = new CoolBarManager(SWT.FLAT | SWT.HORIZONTAL); - coolBarManager.add(toolBarManager); - coolBarManager.setLockLayout(true); - coolBarManager.createControl(this); - coolBarManager.update(true); - - separator = new Label(this, SWT.SEPARATOR | SWT.HORIZONTAL); - separator.setLayoutData(UIUtil.createGridData(true, false)); - - Composite composite = new Composite(this, SWT.NONE); - composite.setLayout(UIUtil.createGridLayout(1)); - - clientControl = createUI(composite); - clientControl.setLayoutData(UIUtil.createGridData()); - } - - @Override - public void dispose() - { - coolBarManager.dispose(); - super.dispose(); - } - - public Control getClientControl() - { - return clientControl; - } - - public void updateCoolBar() - { - toolBarManager.removeAll(); - fillCoolBar(toolBarManager); - coolBarManager.update(true); - } - - protected abstract Control createUI(Composite parent); - - protected CoolBar getCoolBarControl() - { - if (coolBarManager != null) - { - return coolBarManager.getControl(); - } - - return null; - } - - protected void fillCoolBar(IContributionManager manager) - { - } - - /** - * @author Eike Stepper - * @see org.eclipse.jface.window.ApplicationWindow.ApplicationWindowLayout - */ - public class CoolBarLayout extends Layout - { - static final int BAR_SIZE = 23; - - private static final int SEPARATOR_SIZE = 1; - - @Override - protected Point computeSize(Composite composite, int wHint, int hHint, boolean flushCache) - { - if (wHint != SWT.DEFAULT && hHint != SWT.DEFAULT) - { - return new Point(wHint, hHint); - } - - boolean coolBarChildrenExist = coolBarChildrenExist(); - Point result = new Point(0, 0); - Control[] ws = composite.getChildren(); - for (int i = 0; i < ws.length; i++) - { - Control w = ws[i]; - boolean hide = false; - if (w == getCoolBarControl()) - { - if (!coolBarChildrenExist) - { - hide = true; - result.y += BAR_SIZE; - } - } - else if (w == separator) - { - if (!coolBarChildrenExist) - { - hide = true; - result.y += SEPARATOR_SIZE; - } - } - else if (i > 0) - { - hide = false; - } - - if (!hide) - { - Point e = w.computeSize(wHint, hHint, flushCache); - result.x = Math.max(result.x, e.x); - result.y += e.y; - } - } - - if (wHint != SWT.DEFAULT) - { - result.x = wHint; - } - - if (hHint != SWT.DEFAULT) - { - result.y = hHint; - } - - return result; - } - - @Override - protected void layout(Composite composite, boolean flushCache) - { - boolean coolBarChildrenExist = coolBarChildrenExist(); - Rectangle clientArea = composite.getClientArea(); - Control[] ws = composite.getChildren(); - for (int i = 0; i < ws.length; i++) - { - Control w = ws[i]; - if (w == getCoolBarControl() || w == separator) - { - if (coolBarChildrenExist) - { - Point e = w.computeSize(clientArea.width, SWT.DEFAULT, flushCache); - w.setBounds(clientArea.x, clientArea.y, clientArea.width, e.y); - clientArea.y += e.y; - clientArea.height -= e.y; - } - } - else - { - w.setBounds(clientArea.x, clientArea.y, clientArea.width, clientArea.height); - } - } - } - - protected boolean coolBarChildrenExist() - { - CoolBar coolBarControl = getCoolBarControl(); - if (coolBarControl != null) - { - return coolBarControl.getItemCount() > 0; - } - - return false; - } - } -} +/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.util.ui.widgets;
+
+import org.eclipse.net4j.util.ui.UIUtil;
+
+import org.eclipse.jface.action.CoolBarManager;
+import org.eclipse.jface.action.IContributionManager;
+import org.eclipse.jface.action.ToolBarManager;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.CoolBar;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Layout;
+
+/**
+ * @author Eike Stepper
+ * @since 2.0
+ */
+public abstract class CoolBarComposite extends Composite
+{
+ private CoolBarManager coolBarManager;
+
+ private Control clientControl;
+
+ private Label separator;
+
+ private ToolBarManager toolBarManager;
+
+ public CoolBarComposite(Composite parent, int style)
+ {
+ super(parent, style);
+ setLayout(new CoolBarLayout());
+
+ toolBarManager = new ToolBarManager(SWT.FLAT | SWT.RIGHT | SWT.WRAP | SWT.HORIZONTAL);
+ fillCoolBar(toolBarManager);
+
+ coolBarManager = new CoolBarManager(SWT.FLAT | SWT.HORIZONTAL);
+ coolBarManager.add(toolBarManager);
+ coolBarManager.setLockLayout(true);
+ coolBarManager.createControl(this);
+ coolBarManager.update(true);
+
+ separator = new Label(this, SWT.SEPARATOR | SWT.HORIZONTAL);
+ separator.setLayoutData(UIUtil.createGridData(true, false));
+
+ Composite composite = new Composite(this, SWT.NONE);
+ composite.setLayout(UIUtil.createGridLayout(1));
+
+ clientControl = createUI(composite);
+ clientControl.setLayoutData(UIUtil.createGridData());
+ }
+
+ @Override
+ public void dispose()
+ {
+ coolBarManager.dispose();
+ super.dispose();
+ }
+
+ public Control getClientControl()
+ {
+ return clientControl;
+ }
+
+ public void updateCoolBar()
+ {
+ toolBarManager.removeAll();
+ fillCoolBar(toolBarManager);
+ coolBarManager.update(true);
+ }
+
+ protected abstract Control createUI(Composite parent);
+
+ protected CoolBar getCoolBarControl()
+ {
+ if (coolBarManager != null)
+ {
+ return coolBarManager.getControl();
+ }
+
+ return null;
+ }
+
+ protected void fillCoolBar(IContributionManager manager)
+ {
+ }
+
+ /**
+ * @author Eike Stepper
+ * @see org.eclipse.jface.window.ApplicationWindow.ApplicationWindowLayout
+ */
+ public class CoolBarLayout extends Layout
+ {
+ static final int BAR_SIZE = 23;
+
+ private static final int SEPARATOR_SIZE = 1;
+
+ @Override
+ protected Point computeSize(Composite composite, int wHint, int hHint, boolean flushCache)
+ {
+ if (wHint != SWT.DEFAULT && hHint != SWT.DEFAULT)
+ {
+ return new Point(wHint, hHint);
+ }
+
+ boolean coolBarChildrenExist = coolBarChildrenExist();
+ Point result = new Point(0, 0);
+ Control[] ws = composite.getChildren();
+ for (int i = 0; i < ws.length; i++)
+ {
+ Control w = ws[i];
+ boolean hide = false;
+ if (w == getCoolBarControl())
+ {
+ if (!coolBarChildrenExist)
+ {
+ hide = true;
+ result.y += BAR_SIZE;
+ }
+ }
+ else if (w == separator)
+ {
+ if (!coolBarChildrenExist)
+ {
+ hide = true;
+ result.y += SEPARATOR_SIZE;
+ }
+ }
+ else if (i > 0)
+ {
+ hide = false;
+ }
+
+ if (!hide)
+ {
+ Point e = w.computeSize(wHint, hHint, flushCache);
+ result.x = Math.max(result.x, e.x);
+ result.y += e.y;
+ }
+ }
+
+ if (wHint != SWT.DEFAULT)
+ {
+ result.x = wHint;
+ }
+
+ if (hHint != SWT.DEFAULT)
+ {
+ result.y = hHint;
+ }
+
+ return result;
+ }
+
+ @Override
+ protected void layout(Composite composite, boolean flushCache)
+ {
+ boolean coolBarChildrenExist = coolBarChildrenExist();
+ Rectangle clientArea = composite.getClientArea();
+ Control[] ws = composite.getChildren();
+ for (int i = 0; i < ws.length; i++)
+ {
+ Control w = ws[i];
+ if (w == getCoolBarControl() || w == separator)
+ {
+ if (coolBarChildrenExist)
+ {
+ Point e = w.computeSize(clientArea.width, SWT.DEFAULT, flushCache);
+ w.setBounds(clientArea.x, clientArea.y, clientArea.width, e.y);
+ clientArea.y += e.y;
+ clientArea.height -= e.y;
+ }
+ }
+ else
+ {
+ w.setBounds(clientArea.x, clientArea.y, clientArea.width, clientArea.height);
+ }
+ }
+ }
+
+ protected boolean coolBarChildrenExist()
+ {
+ CoolBar coolBarControl = getCoolBarControl();
+ if (coolBarControl != null)
+ {
+ return coolBarControl.getItemCount() > 0;
+ }
+
+ return false;
+ }
+ }
+}
diff --git a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/widgets/HistoryText.java b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/widgets/HistoryText.java index bc2aa31ac7..6cf3911401 100644 --- a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/widgets/HistoryText.java +++ b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/widgets/HistoryText.java @@ -1,212 +1,212 @@ -/* - * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) 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: - * Eike Stepper - initial API and implementation - */ -package org.eclipse.net4j.util.ui.widgets; - -import org.eclipse.net4j.util.ReflectUtil; -import org.eclipse.net4j.util.StringUtil; -import org.eclipse.net4j.util.collection.IHistory; -import org.eclipse.net4j.util.collection.IHistoryChangeEvent; -import org.eclipse.net4j.util.collection.IHistoryElement; -import org.eclipse.net4j.util.event.IEvent; -import org.eclipse.net4j.util.event.IListener; -import org.eclipse.net4j.util.internal.ui.bundle.OM; -import org.eclipse.net4j.util.ui.UIUtil; - -import org.eclipse.swt.custom.CCombo; -import org.eclipse.swt.events.DisposeEvent; -import org.eclipse.swt.events.DisposeListener; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Listener; -import org.eclipse.swt.widgets.Text; - -import java.lang.reflect.Method; - -/** - * @author Eike Stepper - */ -public class HistoryText -{ - private IHistory<String> history; - - private CCombo combo; - - private Method droppedMethod; - - private IListener historyListener = new IListener() - { - public void notifyEvent(IEvent event) - { - if (event instanceof IHistoryChangeEvent) - { - historyChanged(); - } - } - }; - - public HistoryText(Composite parent, int style, IHistory<String> history) - { - this.history = history; - history.addListener(historyListener); - - combo = new CCombo(parent, style); - combo.setLayoutData(UIUtil.createGridData()); - combo.addDisposeListener(new DisposeListener() - { - public void widgetDisposed(DisposeEvent e) - { - HistoryText.this.history.removeListener(historyListener); - } - }); - - // TODO Can't get traversal working when keyListener is added ;-( - // combo.addKeyListener(new KeyAdapter() - // { - // @Override - // public void keyPressed(KeyEvent event) - // { - // if (event.character == SWT.DEL && event.stateMask == 0 && isDropped()) - // { - // int index = combo.getSelectionIndex(); - // if (index != -1) - // { - // HistoryText.this.history.remove(index); - // } - // } - // } - // }); - - try - { - droppedMethod = combo.getClass().getDeclaredMethod("isDropped", ReflectUtil.NO_PARAMETERS); //$NON-NLS-1$ - droppedMethod.setAccessible(true); - } - catch (Exception ex) - { - OM.LOG.error(ex); - } - - historyChanged(); - } - - public IHistory<String> getHistory() - { - return history; - } - - public CCombo getCombo() - { - return combo; - } - - public void append(String string) - { - combo.setText(combo.getText() + string); - } - - public int getCharCount() - { - return combo.getText().length(); - } - - public int getLineCount() - { - return StringUtil.occurrences(combo.getText(), getLineDelimiter()) + 1; - } - - public String getLineDelimiter() - { - return Text.DELIMITER; - } - - public int getLineHeight() - { - return combo.getTextHeight(); - } - - public String getText(boolean addHistory) - { - String text = combo.getText(); - if (addHistory) - { - history.add(text); - } - - return text; - } - - public String getText() - { - return getText(false); - } - - public void setText(String string) - { - combo.setText(string); - } - - public boolean setFocus() - { - return combo.setFocus(); - } - - public boolean isDropped() - { - if (droppedMethod != null) - { - try - { - return (Boolean)droppedMethod.invoke(combo, ReflectUtil.NO_ARGUMENTS); - } - catch (Exception ex) - { - OM.LOG.error(ex); - } - } - - return false; - } - - protected void historyChanged() - { - if (combo.isDisposed()) - { - return; - } - - combo.removeAll(); - for (IHistoryElement<String> element : history) - { - combo.add(element.getData()); - } - - String mostRecent = history.getMostRecent(); - if (mostRecent != null) - { - setText(mostRecent); - } - } - - /** - * @since 3.0 - */ - public void addListener(int evenType, Listener listener) - { - combo.addListener(evenType, listener); - } - - /** - * @since 3.0 - */ - public void removeListener(int evenType, Listener listener) - { - combo.removeListener(evenType, listener); - } -} +/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.util.ui.widgets;
+
+import org.eclipse.net4j.util.ReflectUtil;
+import org.eclipse.net4j.util.StringUtil;
+import org.eclipse.net4j.util.collection.IHistory;
+import org.eclipse.net4j.util.collection.IHistoryChangeEvent;
+import org.eclipse.net4j.util.collection.IHistoryElement;
+import org.eclipse.net4j.util.event.IEvent;
+import org.eclipse.net4j.util.event.IListener;
+import org.eclipse.net4j.util.internal.ui.bundle.OM;
+import org.eclipse.net4j.util.ui.UIUtil;
+
+import org.eclipse.swt.custom.CCombo;
+import org.eclipse.swt.events.DisposeEvent;
+import org.eclipse.swt.events.DisposeListener;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Text;
+
+import java.lang.reflect.Method;
+
+/**
+ * @author Eike Stepper
+ */
+public class HistoryText
+{
+ private IHistory<String> history;
+
+ private CCombo combo;
+
+ private Method droppedMethod;
+
+ private IListener historyListener = new IListener()
+ {
+ public void notifyEvent(IEvent event)
+ {
+ if (event instanceof IHistoryChangeEvent)
+ {
+ historyChanged();
+ }
+ }
+ };
+
+ public HistoryText(Composite parent, int style, IHistory<String> history)
+ {
+ this.history = history;
+ history.addListener(historyListener);
+
+ combo = new CCombo(parent, style);
+ combo.setLayoutData(UIUtil.createGridData());
+ combo.addDisposeListener(new DisposeListener()
+ {
+ public void widgetDisposed(DisposeEvent e)
+ {
+ HistoryText.this.history.removeListener(historyListener);
+ }
+ });
+
+ // TODO Can't get traversal working when keyListener is added ;-(
+ // combo.addKeyListener(new KeyAdapter()
+ // {
+ // @Override
+ // public void keyPressed(KeyEvent event)
+ // {
+ // if (event.character == SWT.DEL && event.stateMask == 0 && isDropped())
+ // {
+ // int index = combo.getSelectionIndex();
+ // if (index != -1)
+ // {
+ // HistoryText.this.history.remove(index);
+ // }
+ // }
+ // }
+ // });
+
+ try
+ {
+ droppedMethod = combo.getClass().getDeclaredMethod("isDropped", ReflectUtil.NO_PARAMETERS); //$NON-NLS-1$
+ droppedMethod.setAccessible(true);
+ }
+ catch (Exception ex)
+ {
+ OM.LOG.error(ex);
+ }
+
+ historyChanged();
+ }
+
+ public IHistory<String> getHistory()
+ {
+ return history;
+ }
+
+ public CCombo getCombo()
+ {
+ return combo;
+ }
+
+ public void append(String string)
+ {
+ combo.setText(combo.getText() + string);
+ }
+
+ public int getCharCount()
+ {
+ return combo.getText().length();
+ }
+
+ public int getLineCount()
+ {
+ return StringUtil.occurrences(combo.getText(), getLineDelimiter()) + 1;
+ }
+
+ public String getLineDelimiter()
+ {
+ return Text.DELIMITER;
+ }
+
+ public int getLineHeight()
+ {
+ return combo.getTextHeight();
+ }
+
+ public String getText(boolean addHistory)
+ {
+ String text = combo.getText();
+ if (addHistory)
+ {
+ history.add(text);
+ }
+
+ return text;
+ }
+
+ public String getText()
+ {
+ return getText(false);
+ }
+
+ public void setText(String string)
+ {
+ combo.setText(string);
+ }
+
+ public boolean setFocus()
+ {
+ return combo.setFocus();
+ }
+
+ public boolean isDropped()
+ {
+ if (droppedMethod != null)
+ {
+ try
+ {
+ return (Boolean)droppedMethod.invoke(combo, ReflectUtil.NO_ARGUMENTS);
+ }
+ catch (Exception ex)
+ {
+ OM.LOG.error(ex);
+ }
+ }
+
+ return false;
+ }
+
+ protected void historyChanged()
+ {
+ if (combo.isDisposed())
+ {
+ return;
+ }
+
+ combo.removeAll();
+ for (IHistoryElement<String> element : history)
+ {
+ combo.add(element.getData());
+ }
+
+ String mostRecent = history.getMostRecent();
+ if (mostRecent != null)
+ {
+ setText(mostRecent);
+ }
+ }
+
+ /**
+ * @since 3.0
+ */
+ public void addListener(int evenType, Listener listener)
+ {
+ combo.addListener(evenType, listener);
+ }
+
+ /**
+ * @since 3.0
+ */
+ public void removeListener(int evenType, Listener listener)
+ {
+ combo.removeListener(evenType, listener);
+ }
+}
diff --git a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/widgets/HistoryTextDialog.java b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/widgets/HistoryTextDialog.java index 62f902d5b5..fa9b756261 100644 --- a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/widgets/HistoryTextDialog.java +++ b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/widgets/HistoryTextDialog.java @@ -1,139 +1,139 @@ -/* - * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) 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: - * Eike Stepper - initial API and implementation - */ -package org.eclipse.net4j.util.ui.widgets; - -import org.eclipse.net4j.util.collection.IHistory; - -import org.eclipse.jface.dialogs.IDialogConstants; -import org.eclipse.jface.dialogs.IInputValidator; -import org.eclipse.jface.dialogs.InputDialog; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.FocusAdapter; -import org.eclipse.swt.events.FocusEvent; -import org.eclipse.swt.events.ModifyEvent; -import org.eclipse.swt.events.ModifyListener; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Text; - -/** - * TODO extend BaseDialog - * - * @author Eike Stepper - */ -public class HistoryTextDialog extends InputDialog -{ - private static final String EMPTY = ""; //$NON-NLS-1$ - - private IHistory<String> history; - - private String value = EMPTY; - - private HistoryText historyText; - - public HistoryTextDialog(Shell parentShell, String dialogTitle, String dialogMessage, IHistory<String> history, - IInputValidator validator) - { - super(parentShell, dialogTitle, dialogMessage, history.getMostRecent(), validator); - this.history = history; - value = super.getValue(); - } - - public IHistory<String> getHistory() - { - return history; - } - - public HistoryText getHistoryText() - { - return historyText; - } - - @Override - public String getValue() - { - return value; - } - - @Override - protected Control createDialogArea(Composite parent) - { - Composite composite = (Composite)super.createDialogArea(parent); - Text text = getText(); - text.setVisible(false); - text.setEnabled(false); - - historyText = new HistoryText(composite, SWT.BORDER, history); - historyText.getCombo().moveAbove(text); - historyText.getCombo().setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL)); - historyText.getCombo().addModifyListener(new ModifyListener() - { - public void modifyText(ModifyEvent e) - { - validateInput(); - } - }); - - text.addFocusListener(new FocusAdapter() - { - @Override - public void focusGained(FocusEvent e) - { - historyText.setFocus(); - } - }); - - composite.getShell().layout(true); - return composite; - } - - @Override - protected void buttonPressed(int buttonId) - { - if (IDialogConstants.OK_ID == buttonId) - { - value = historyText.getText(); - okPressed(); - } - else if (IDialogConstants.CANCEL_ID == buttonId) - { - value = null; - cancelPressed(); - } - } - - @Override - protected void createButtonsForButtonBar(Composite parent) - { - super.createButtonsForButtonBar(parent); - historyText.setFocus(); - if (value != null) - { - historyText.setText(value); - } - } - - @Override - protected void validateInput() - { - String errorMessage = null; - if (getValidator() != null) - { - errorMessage = getValidator().isValid(historyText.getText()); - } - - // Bug 16256: important not to treat "" (blank error) the same as null - // (no error) - setErrorMessage(errorMessage); - } -} +/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.util.ui.widgets;
+
+import org.eclipse.net4j.util.collection.IHistory;
+
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.IInputValidator;
+import org.eclipse.jface.dialogs.InputDialog;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.FocusAdapter;
+import org.eclipse.swt.events.FocusEvent;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+
+/**
+ * TODO extend BaseDialog
+ *
+ * @author Eike Stepper
+ */
+public class HistoryTextDialog extends InputDialog
+{
+ private static final String EMPTY = ""; //$NON-NLS-1$
+
+ private IHistory<String> history;
+
+ private String value = EMPTY;
+
+ private HistoryText historyText;
+
+ public HistoryTextDialog(Shell parentShell, String dialogTitle, String dialogMessage, IHistory<String> history,
+ IInputValidator validator)
+ {
+ super(parentShell, dialogTitle, dialogMessage, history.getMostRecent(), validator);
+ this.history = history;
+ value = super.getValue();
+ }
+
+ public IHistory<String> getHistory()
+ {
+ return history;
+ }
+
+ public HistoryText getHistoryText()
+ {
+ return historyText;
+ }
+
+ @Override
+ public String getValue()
+ {
+ return value;
+ }
+
+ @Override
+ protected Control createDialogArea(Composite parent)
+ {
+ Composite composite = (Composite)super.createDialogArea(parent);
+ Text text = getText();
+ text.setVisible(false);
+ text.setEnabled(false);
+
+ historyText = new HistoryText(composite, SWT.BORDER, history);
+ historyText.getCombo().moveAbove(text);
+ historyText.getCombo().setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL));
+ historyText.getCombo().addModifyListener(new ModifyListener()
+ {
+ public void modifyText(ModifyEvent e)
+ {
+ validateInput();
+ }
+ });
+
+ text.addFocusListener(new FocusAdapter()
+ {
+ @Override
+ public void focusGained(FocusEvent e)
+ {
+ historyText.setFocus();
+ }
+ });
+
+ composite.getShell().layout(true);
+ return composite;
+ }
+
+ @Override
+ protected void buttonPressed(int buttonId)
+ {
+ if (IDialogConstants.OK_ID == buttonId)
+ {
+ value = historyText.getText();
+ okPressed();
+ }
+ else if (IDialogConstants.CANCEL_ID == buttonId)
+ {
+ value = null;
+ cancelPressed();
+ }
+ }
+
+ @Override
+ protected void createButtonsForButtonBar(Composite parent)
+ {
+ super.createButtonsForButtonBar(parent);
+ historyText.setFocus();
+ if (value != null)
+ {
+ historyText.setText(value);
+ }
+ }
+
+ @Override
+ protected void validateInput()
+ {
+ String errorMessage = null;
+ if (getValidator() != null)
+ {
+ errorMessage = getValidator().isValid(historyText.getText());
+ }
+
+ // Bug 16256: important not to treat "" (blank error) the same as null
+ // (no error)
+ setErrorMessage(errorMessage);
+ }
+}
diff --git a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/widgets/LogDialog.java b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/widgets/LogDialog.java index ad4a25cdf2..3a2cddb8b4 100644 --- a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/widgets/LogDialog.java +++ b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/widgets/LogDialog.java @@ -1,153 +1,153 @@ -/* - * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) 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: - * Eike Stepper - initial API and implementation - */ -package org.eclipse.net4j.util.ui.widgets; - -import org.eclipse.net4j.util.io.IOUtil; -import org.eclipse.net4j.util.ui.UIUtil; - -import org.eclipse.jface.dialogs.IDialogConstants; -import org.eclipse.jface.dialogs.IDialogSettings; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.StyleRange; -import org.eclipse.swt.custom.StyledText; -import org.eclipse.swt.graphics.Font; -import org.eclipse.swt.graphics.TextStyle; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Shell; - -import java.util.ArrayList; -import java.util.List; - -/** - * @author Eike Stepper - */ -public class LogDialog extends BaseDialog<Viewer> -{ - private StringBuilder log = new StringBuilder(); - - private StyledText text; - - private TextStyle textStyle; - - private List<StyleRange> styleRanges = new ArrayList<StyleRange>(); - - private StyleRange currentStyleRange = new StyleRange(); - - private StyleRange lastStyleRange; - - private Font font; - - public LogDialog(Shell parentShell, int shellStyle, String title, String message, IDialogSettings settings) - { - super(parentShell, shellStyle, title, message, settings); - } - - public LogDialog(Shell parentShell, String title, String message, IDialogSettings settings) - { - this(parentShell, DEFAULT_SHELL_STYLE, title, message, settings); - } - - public TextStyle getTextStyle() - { - return textStyle; - } - - public void setTextStyle(TextStyle textStyle) - { - if (textStyle == null) - { - throw new IllegalArgumentException("textStyle == null"); //$NON-NLS-1$ - } - - if (textStyle.equals(this.textStyle)) - { - return; - } - - lastStyleRange = currentStyleRange; - this.textStyle = textStyle; - - currentStyleRange = new StyleRange(); - currentStyleRange.start = log.length(); - currentStyleRange.rise = textStyle.rise; - currentStyleRange.background = textStyle.background; - currentStyleRange.font = textStyle.font; - currentStyleRange.foreground = textStyle.foreground; - currentStyleRange.metrics = textStyle.metrics; - currentStyleRange.strikeout = textStyle.strikeout; - currentStyleRange.underline = textStyle.underline; - } - - public void append(String text) - { - checkStyleRange(); - log.append(text); - currentStyleRange.length += text.length(); - } - - public void append(Throwable t) - { - checkStyleRange(); - String text = IOUtil.toString(t); - log.append(text); - currentStyleRange.length += text.length(); - } - - @Override - public boolean close() - { - font.dispose(); - return super.close(); - } - - @Override - protected void createUI(Composite parent) - { - GridLayout grid = new GridLayout(); - grid.marginTop = 6; - grid.marginLeft = 6; - grid.marginRight = 6; - grid.marginBottom = 6; - - Composite composite = new Composite(parent, SWT.NONE); - composite.setLayout(grid); - composite.setLayoutData(UIUtil.createGridData()); - - font = new Font(getShell().getDisplay(), "Courier New", 9, SWT.NORMAL); //$NON-NLS-1$ - checkStyleRange(); - lastStyleRange = currentStyleRange; - checkStyleRange(); - - text = new StyledText(composite, SWT.MULTI | SWT.READ_ONLY | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); - text.setLayoutData(UIUtil.createGridData()); - text.setText(log.toString()); - text.setStyleRanges(styleRanges.toArray(new StyleRange[styleRanges.size()])); - text.setBackground(getShell().getDisplay().getSystemColor(SWT.COLOR_WHITE)); - text.setFont(font); - } - - @Override - protected void createButtonsForButtonBar(Composite parent) - { - createButton(parent, IDialogConstants.OK_ID, IDialogConstants.CLOSE_LABEL, true); - } - - private void checkStyleRange() - { - if (lastStyleRange != null) - { - styleRanges.add(lastStyleRange); - lastStyleRange = null; - } - } -} +/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.util.ui.widgets;
+
+import org.eclipse.net4j.util.io.IOUtil;
+import org.eclipse.net4j.util.ui.UIUtil;
+
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.IDialogSettings;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.StyleRange;
+import org.eclipse.swt.custom.StyledText;
+import org.eclipse.swt.graphics.Font;
+import org.eclipse.swt.graphics.TextStyle;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Shell;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author Eike Stepper
+ */
+public class LogDialog extends BaseDialog<Viewer>
+{
+ private StringBuilder log = new StringBuilder();
+
+ private StyledText text;
+
+ private TextStyle textStyle;
+
+ private List<StyleRange> styleRanges = new ArrayList<StyleRange>();
+
+ private StyleRange currentStyleRange = new StyleRange();
+
+ private StyleRange lastStyleRange;
+
+ private Font font;
+
+ public LogDialog(Shell parentShell, int shellStyle, String title, String message, IDialogSettings settings)
+ {
+ super(parentShell, shellStyle, title, message, settings);
+ }
+
+ public LogDialog(Shell parentShell, String title, String message, IDialogSettings settings)
+ {
+ this(parentShell, DEFAULT_SHELL_STYLE, title, message, settings);
+ }
+
+ public TextStyle getTextStyle()
+ {
+ return textStyle;
+ }
+
+ public void setTextStyle(TextStyle textStyle)
+ {
+ if (textStyle == null)
+ {
+ throw new IllegalArgumentException("textStyle == null"); //$NON-NLS-1$
+ }
+
+ if (textStyle.equals(this.textStyle))
+ {
+ return;
+ }
+
+ lastStyleRange = currentStyleRange;
+ this.textStyle = textStyle;
+
+ currentStyleRange = new StyleRange();
+ currentStyleRange.start = log.length();
+ currentStyleRange.rise = textStyle.rise;
+ currentStyleRange.background = textStyle.background;
+ currentStyleRange.font = textStyle.font;
+ currentStyleRange.foreground = textStyle.foreground;
+ currentStyleRange.metrics = textStyle.metrics;
+ currentStyleRange.strikeout = textStyle.strikeout;
+ currentStyleRange.underline = textStyle.underline;
+ }
+
+ public void append(String text)
+ {
+ checkStyleRange();
+ log.append(text);
+ currentStyleRange.length += text.length();
+ }
+
+ public void append(Throwable t)
+ {
+ checkStyleRange();
+ String text = IOUtil.toString(t);
+ log.append(text);
+ currentStyleRange.length += text.length();
+ }
+
+ @Override
+ public boolean close()
+ {
+ font.dispose();
+ return super.close();
+ }
+
+ @Override
+ protected void createUI(Composite parent)
+ {
+ GridLayout grid = new GridLayout();
+ grid.marginTop = 6;
+ grid.marginLeft = 6;
+ grid.marginRight = 6;
+ grid.marginBottom = 6;
+
+ Composite composite = new Composite(parent, SWT.NONE);
+ composite.setLayout(grid);
+ composite.setLayoutData(UIUtil.createGridData());
+
+ font = new Font(getShell().getDisplay(), "Courier New", 9, SWT.NORMAL); //$NON-NLS-1$
+ checkStyleRange();
+ lastStyleRange = currentStyleRange;
+ checkStyleRange();
+
+ text = new StyledText(composite, SWT.MULTI | SWT.READ_ONLY | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
+ text.setLayoutData(UIUtil.createGridData());
+ text.setText(log.toString());
+ text.setStyleRanges(styleRanges.toArray(new StyleRange[styleRanges.size()]));
+ text.setBackground(getShell().getDisplay().getSystemColor(SWT.COLOR_WHITE));
+ text.setFont(font);
+ }
+
+ @Override
+ protected void createButtonsForButtonBar(Composite parent)
+ {
+ createButton(parent, IDialogConstants.OK_ID, IDialogConstants.CLOSE_LABEL, true);
+ }
+
+ private void checkStyleRange()
+ {
+ if (lastStyleRange != null)
+ {
+ styleRanges.add(lastStyleRange);
+ lastStyleRange = null;
+ }
+ }
+}
diff --git a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/widgets/OneBorderComposite.java b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/widgets/OneBorderComposite.java index a1ddf35b3a..4010a4a315 100644 --- a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/widgets/OneBorderComposite.java +++ b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/widgets/OneBorderComposite.java @@ -1,173 +1,173 @@ -/* - * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) 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: - * Eike Stepper - initial API and implementation - */ -package org.eclipse.net4j.util.ui.widgets; - -import org.eclipse.net4j.util.ui.UIUtil; - -import org.eclipse.swt.SWT; -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; - -/** - * @author Eike Stepper - * @since 2.0 - */ -public abstract class OneBorderComposite extends Composite -{ - private static final int POSITION_MASK = SWT.LEFT | SWT.RIGHT | SWT.TOP | SWT.BOTTOM; - - private int borderPosition; - - private Control border; - - private Control clientControl; - - private GridLayout layout; - - private GridData borderData; - - private GridData clientControlData; - - public OneBorderComposite(Composite parent) - { - super(parent, SWT.NONE); - layout = UIUtil.createGridLayout(1); - setLayout(layout); - - clientControlData = UIUtil.createGridData(); - clientControl = createUI(this); - clientControl.setLayoutData(clientControlData); - } - - public OneBorderComposite(Composite parent, int borderPosition) - { - this(parent); - setBorderPosition(borderPosition); - } - - public Control getClientControl() - { - return clientControl; - } - - public int getBorderPosition() - { - return borderPosition; - } - - public void setBorderPosition(int borderPosition) - { - borderPosition = borderPosition & POSITION_MASK; - if (Integer.bitCount(borderPosition) != 1) - { - throw new IllegalArgumentException("borderPosition: " + borderPosition); //$NON-NLS-1$ - } - - if (this.borderPosition != borderPosition) - { - this.borderPosition = borderPosition; - switch (borderPosition) - { - case SWT.LEFT: - setBorder(true, true); - break; - - case SWT.RIGHT: - setBorder(true, false); - break; - - case SWT.TOP: - setBorder(false, true); - break; - - case SWT.BOTTOM: - setBorder(false, false); - break; - - default: - return; - } - - layout(); - } - } - - public void swapBorderPosition() - { - switch (borderPosition) - { - case SWT.LEFT: - setBorderPosition(SWT.TOP); - break; - - case SWT.RIGHT: - setBorderPosition(SWT.BOTTOM); - break; - - case SWT.TOP: - setBorderPosition(SWT.LEFT); - break; - - case SWT.BOTTOM: - setBorderPosition(SWT.RIGHT); - break; - } - } - - @Override - public String toString() - { - switch (borderPosition) - { - case SWT.LEFT: - return "LEFT"; //$NON-NLS-1$ - - case SWT.RIGHT: - return "RIGHT"; //$NON-NLS-1$ - - case SWT.TOP: - return "TOP"; //$NON-NLS-1$ - - case SWT.BOTTOM: - return "BOTTOM"; //$NON-NLS-1$ - } - - return super.toString(); - } - - protected abstract Control createUI(Composite parent); - - private void setBorder(boolean vertical, boolean beginning) - { - if (border != null) - { - border.dispose(); - } - - layout.numColumns = vertical ? 2 : 1; - borderData = UIUtil.createGridData(); - borderData.widthHint = vertical ? 1 : SWT.DEFAULT; - borderData.heightHint = vertical ? SWT.DEFAULT : 1; - borderData.grabExcessHorizontalSpace = !vertical; - borderData.grabExcessVerticalSpace = vertical; - - int orientation = vertical ? SWT.VERTICAL : SWT.HORIZONTAL; - border = new Label(this, SWT.SEPARATOR | orientation); - border.setLayoutData(borderData); - if (beginning) - { - border.moveAbove(null); - } - } -} +/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.util.ui.widgets;
+
+import org.eclipse.net4j.util.ui.UIUtil;
+
+import org.eclipse.swt.SWT;
+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;
+
+/**
+ * @author Eike Stepper
+ * @since 2.0
+ */
+public abstract class OneBorderComposite extends Composite
+{
+ private static final int POSITION_MASK = SWT.LEFT | SWT.RIGHT | SWT.TOP | SWT.BOTTOM;
+
+ private int borderPosition;
+
+ private Control border;
+
+ private Control clientControl;
+
+ private GridLayout layout;
+
+ private GridData borderData;
+
+ private GridData clientControlData;
+
+ public OneBorderComposite(Composite parent)
+ {
+ super(parent, SWT.NONE);
+ layout = UIUtil.createGridLayout(1);
+ setLayout(layout);
+
+ clientControlData = UIUtil.createGridData();
+ clientControl = createUI(this);
+ clientControl.setLayoutData(clientControlData);
+ }
+
+ public OneBorderComposite(Composite parent, int borderPosition)
+ {
+ this(parent);
+ setBorderPosition(borderPosition);
+ }
+
+ public Control getClientControl()
+ {
+ return clientControl;
+ }
+
+ public int getBorderPosition()
+ {
+ return borderPosition;
+ }
+
+ public void setBorderPosition(int borderPosition)
+ {
+ borderPosition = borderPosition & POSITION_MASK;
+ if (Integer.bitCount(borderPosition) != 1)
+ {
+ throw new IllegalArgumentException("borderPosition: " + borderPosition); //$NON-NLS-1$
+ }
+
+ if (this.borderPosition != borderPosition)
+ {
+ this.borderPosition = borderPosition;
+ switch (borderPosition)
+ {
+ case SWT.LEFT:
+ setBorder(true, true);
+ break;
+
+ case SWT.RIGHT:
+ setBorder(true, false);
+ break;
+
+ case SWT.TOP:
+ setBorder(false, true);
+ break;
+
+ case SWT.BOTTOM:
+ setBorder(false, false);
+ break;
+
+ default:
+ return;
+ }
+
+ layout();
+ }
+ }
+
+ public void swapBorderPosition()
+ {
+ switch (borderPosition)
+ {
+ case SWT.LEFT:
+ setBorderPosition(SWT.TOP);
+ break;
+
+ case SWT.RIGHT:
+ setBorderPosition(SWT.BOTTOM);
+ break;
+
+ case SWT.TOP:
+ setBorderPosition(SWT.LEFT);
+ break;
+
+ case SWT.BOTTOM:
+ setBorderPosition(SWT.RIGHT);
+ break;
+ }
+ }
+
+ @Override
+ public String toString()
+ {
+ switch (borderPosition)
+ {
+ case SWT.LEFT:
+ return "LEFT"; //$NON-NLS-1$
+
+ case SWT.RIGHT:
+ return "RIGHT"; //$NON-NLS-1$
+
+ case SWT.TOP:
+ return "TOP"; //$NON-NLS-1$
+
+ case SWT.BOTTOM:
+ return "BOTTOM"; //$NON-NLS-1$
+ }
+
+ return super.toString();
+ }
+
+ protected abstract Control createUI(Composite parent);
+
+ private void setBorder(boolean vertical, boolean beginning)
+ {
+ if (border != null)
+ {
+ border.dispose();
+ }
+
+ layout.numColumns = vertical ? 2 : 1;
+ borderData = UIUtil.createGridData();
+ borderData.widthHint = vertical ? 1 : SWT.DEFAULT;
+ borderData.heightHint = vertical ? SWT.DEFAULT : 1;
+ borderData.grabExcessHorizontalSpace = !vertical;
+ borderData.grabExcessVerticalSpace = vertical;
+
+ int orientation = vertical ? SWT.VERTICAL : SWT.HORIZONTAL;
+ border = new Label(this, SWT.SEPARATOR | orientation);
+ border.setLayoutData(borderData);
+ if (beginning)
+ {
+ border.moveAbove(null);
+ }
+ }
+}
diff --git a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/widgets/PreferenceButton.java b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/widgets/PreferenceButton.java index 308563060e..3a3ac8b390 100644 --- a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/widgets/PreferenceButton.java +++ b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/widgets/PreferenceButton.java @@ -1,129 +1,129 @@ -/* - * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) 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: - * Eike Stepper - initial API and implementation - */ -package org.eclipse.net4j.util.ui.widgets; - -import org.eclipse.net4j.util.om.pref.OMPreference; - -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Listener; - -/** - * @author Eike Stepper - */ -public class PreferenceButton -{ - private OMPreference<Boolean> preference; - - private Button button; - - public PreferenceButton(Composite parent, int style, String text, final OMPreference<Boolean> preference) - { - this.preference = preference; - - button = new Button(parent, style); - button.setText(text); - button.setSelection(preference.getValue()); - button.addSelectionListener(new SelectionAdapter() - { - @Override - public void widgetSelected(SelectionEvent e) - { - preference.setValue(button.getSelection()); - } - }); - } - - public OMPreference<Boolean> getPreference() - { - return preference; - } - - public Button getButton() - { - return button; - } - - public int getAlignment() - { - return button.getAlignment(); - } - - public Image getImage() - { - return button.getImage(); - } - - public boolean getSelection(boolean setPreference) - { - boolean selection = button.getSelection(); - if (setPreference) - { - preference.setValue(selection); - } - - return selection; - } - - public boolean getSelection() - { - return getSelection(false); - } - - public String getText() - { - return button.getText(); - } - - public void setAlignment(int alignment) - { - button.setAlignment(alignment); - } - - public void setImage(Image image) - { - button.setImage(image); - } - - public void setSelection(boolean selected) - { - button.setSelection(selected); - } - - public void setText(String string) - { - button.setText(string); - } - - public boolean setFocus() - { - return button.setFocus(); - } - - /** - * @since 3.0 - */ - public void addListener(int evenType, Listener listener) - { - button.addListener(evenType, listener); - } - - /** - * @since 3.0 - */ - public void removeListener(int evenType, Listener listener) - { - button.removeListener(evenType, listener); - } -} +/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.util.ui.widgets;
+
+import org.eclipse.net4j.util.om.pref.OMPreference;
+
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Listener;
+
+/**
+ * @author Eike Stepper
+ */
+public class PreferenceButton
+{
+ private OMPreference<Boolean> preference;
+
+ private Button button;
+
+ public PreferenceButton(Composite parent, int style, String text, final OMPreference<Boolean> preference)
+ {
+ this.preference = preference;
+
+ button = new Button(parent, style);
+ button.setText(text);
+ button.setSelection(preference.getValue());
+ button.addSelectionListener(new SelectionAdapter()
+ {
+ @Override
+ public void widgetSelected(SelectionEvent e)
+ {
+ preference.setValue(button.getSelection());
+ }
+ });
+ }
+
+ public OMPreference<Boolean> getPreference()
+ {
+ return preference;
+ }
+
+ public Button getButton()
+ {
+ return button;
+ }
+
+ public int getAlignment()
+ {
+ return button.getAlignment();
+ }
+
+ public Image getImage()
+ {
+ return button.getImage();
+ }
+
+ public boolean getSelection(boolean setPreference)
+ {
+ boolean selection = button.getSelection();
+ if (setPreference)
+ {
+ preference.setValue(selection);
+ }
+
+ return selection;
+ }
+
+ public boolean getSelection()
+ {
+ return getSelection(false);
+ }
+
+ public String getText()
+ {
+ return button.getText();
+ }
+
+ public void setAlignment(int alignment)
+ {
+ button.setAlignment(alignment);
+ }
+
+ public void setImage(Image image)
+ {
+ button.setImage(image);
+ }
+
+ public void setSelection(boolean selected)
+ {
+ button.setSelection(selected);
+ }
+
+ public void setText(String string)
+ {
+ button.setText(string);
+ }
+
+ public boolean setFocus()
+ {
+ return button.setFocus();
+ }
+
+ /**
+ * @since 3.0
+ */
+ public void addListener(int evenType, Listener listener)
+ {
+ button.addListener(evenType, listener);
+ }
+
+ /**
+ * @since 3.0
+ */
+ public void removeListener(int evenType, Listener listener)
+ {
+ button.removeListener(evenType, listener);
+ }
+}
diff --git a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/widgets/SashComposite.java b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/widgets/SashComposite.java index 056e3e351c..b48c103f30 100644 --- a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/widgets/SashComposite.java +++ b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/widgets/SashComposite.java @@ -1,314 +1,314 @@ -/* - * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) 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: - * Eike Stepper - initial API and implementation - */ -package org.eclipse.net4j.util.ui.widgets; - -import org.eclipse.net4j.util.event.IListener; -import org.eclipse.net4j.util.event.INotifier; -import org.eclipse.net4j.util.event.Notifier; - -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.Rectangle; -import org.eclipse.swt.layout.FormAttachment; -import org.eclipse.swt.layout.FormData; -import org.eclipse.swt.layout.FormLayout; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Event; -import org.eclipse.swt.widgets.Listener; -import org.eclipse.swt.widgets.Sash; - -/** - * @author Eike Stepper - */ -public abstract class SashComposite extends Composite implements INotifier -{ - private final SashListener sashListener = new SashListener(); - - private final Notifier notifier = new Notifier(); - - private int limit; - - private int percent; - - private boolean borders; - - private boolean vertical; - - private Sash sash; - - private Control control1; - - private Control control2; - - private FormData sashData; - - private FormData control1Data; - - private FormData control2Data; - - public SashComposite(Composite parent, int style, int limit, int percent) - { - this(parent, style, limit, percent, false); - } - - public SashComposite(Composite parent, int style, int limit, int percent, boolean borders) - { - super(parent, style); - setLayout(new FormLayout()); - this.limit = limit; - this.percent = percent; - this.borders = borders; - - control1Data = new FormData(); - control1 = borders ? new OneBorderComposite(this) - { - @Override - protected Control createUI(Composite parent) - { - return createControl1(parent); - } - } : createControl1(this); - - control1.setLayoutData(control1Data); - - sashData = new FormData(); - sash = createSash(this); - sash.setLayoutData(sashData); - - control2Data = new FormData(); - control2 = borders ? new OneBorderComposite(this) - { - @Override - protected Control createUI(Composite parent) - { - return createControl2(parent); - } - } : createControl2(this); - - control2.setLayoutData(control2Data); - - init(); - } - - /** - * @since 2.0 - */ - @Override - public void dispose() - { - sash.removeListener(SWT.Selection, sashListener); - super.dispose(); - } - - /** - * @since 2.0 - */ - public void addListener(IListener listener) - { - notifier.addListener(listener); - } - - /** - * @since 2.0 - */ - public IListener[] getListeners() - { - return notifier.getListeners(); - } - - /** - * @since 2.0 - */ - public boolean hasListeners() - { - return notifier.hasListeners(); - } - - /** - * @since 2.0 - */ - public void removeListener(IListener listener) - { - notifier.removeListener(listener); - } - - public boolean isVertical() - { - return vertical; - } - - public void setVertical(boolean vertical) - { - if (this.vertical != vertical) - { - this.vertical = vertical; - - Sash newSash = createSash(this); - newSash.moveBelow(control1); - newSash.setLayoutData(sash.getLayoutData()); - - sash.removeListener(SWT.Selection, sashListener); - sash.setLayoutData(null); - sash.dispose(); - sash = newSash; - - init(); - layout(); - IListener[] listeners = notifier.getListeners(); - if (listeners != null) - { - notifier.fireEvent(new OrientationChangedEvent(vertical), listeners); - } - } - } - - public Sash getSash() - { - return sash; - } - - public Control getControl1() - { - return borders ? ((OneBorderComposite)control1).getClientControl() : control1; - } - - public Control getControl2() - { - return borders ? ((OneBorderComposite)control2).getClientControl() : control2; - } - - protected void init() - { - if (borders) - { - ((OneBorderComposite)control1).setBorderPosition(SWT.RIGHT); - ((OneBorderComposite)control2).setBorderPosition(SWT.LEFT); - } - - control1Data.left = new FormAttachment(0, 0); - control1Data.right = new FormAttachment(sash, 0); - control1Data.top = new FormAttachment(0, 0); - control1Data.bottom = new FormAttachment(100, 0); - - sashData.left = new FormAttachment(percent, 0); - sashData.right = null; - sashData.top = new FormAttachment(0, 0); - sashData.bottom = new FormAttachment(100, 0); - - control2Data.left = new FormAttachment(sash, 0); - control2Data.right = new FormAttachment(100, 0); - control2Data.top = new FormAttachment(0, 0); - control2Data.bottom = new FormAttachment(100, 0); - - if (vertical) - { - swap(); - } - } - - protected void swap() - { - if (borders) - { - ((OneBorderComposite)control1).swapBorderPosition(); - ((OneBorderComposite)control2).swapBorderPosition(); - } - - swap(control1Data); - swap(sashData); - swap(control2Data); - } - - protected void swap(FormData formData) - { - FormAttachment tmp1 = formData.left; - formData.left = formData.top; - formData.top = tmp1; - - FormAttachment tmp2 = formData.right; - formData.right = formData.bottom; - formData.bottom = tmp2; - } - - protected Sash createSash(Composite parent) - { - Sash sash = new Sash(parent, vertical ? SWT.HORIZONTAL : SWT.VERTICAL); - sash.addListener(SWT.Selection, sashListener); - return sash; - } - - protected abstract Control createControl1(Composite parent); - - protected abstract Control createControl2(Composite parent); - - /** - * @author Eike Stepper - * @since 2.0 - */ - public class OrientationChangedEvent extends org.eclipse.net4j.util.event.Event - { - private static final long serialVersionUID = 1L; - - private boolean vertical; - - public OrientationChangedEvent(boolean vertical) - { - super(SashComposite.this); - } - - @Override - public SashComposite getSource() - { - return (SashComposite)super.getSource(); - } - - public boolean isVertical() - { - return vertical; - } - } - - /** - * @author Eike Stepper - */ - private final class SashListener implements Listener - { - public SashListener() - { - } - - public void handleEvent(Event e) - { - Rectangle sashRect = sash.getBounds(); - Rectangle shellRect = getClientArea(); - if (!vertical) - { - int right = shellRect.width - sashRect.width - limit; - e.x = Math.max(Math.min(e.x, right), limit); - if (e.x != sashRect.x) - { - sashData.left = new FormAttachment(0, e.x); - layout(); - } - } - else - { - int bottom = shellRect.height - sashRect.height - limit; - e.y = Math.max(Math.min(e.y, bottom), limit); - if (e.y != sashRect.y) - { - sashData.top = new FormAttachment(0, e.y); - layout(); - } - } - } - } -} +/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.util.ui.widgets;
+
+import org.eclipse.net4j.util.event.IListener;
+import org.eclipse.net4j.util.event.INotifier;
+import org.eclipse.net4j.util.event.Notifier;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.layout.FormAttachment;
+import org.eclipse.swt.layout.FormData;
+import org.eclipse.swt.layout.FormLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Sash;
+
+/**
+ * @author Eike Stepper
+ */
+public abstract class SashComposite extends Composite implements INotifier
+{
+ private final SashListener sashListener = new SashListener();
+
+ private final Notifier notifier = new Notifier();
+
+ private int limit;
+
+ private int percent;
+
+ private boolean borders;
+
+ private boolean vertical;
+
+ private Sash sash;
+
+ private Control control1;
+
+ private Control control2;
+
+ private FormData sashData;
+
+ private FormData control1Data;
+
+ private FormData control2Data;
+
+ public SashComposite(Composite parent, int style, int limit, int percent)
+ {
+ this(parent, style, limit, percent, false);
+ }
+
+ public SashComposite(Composite parent, int style, int limit, int percent, boolean borders)
+ {
+ super(parent, style);
+ setLayout(new FormLayout());
+ this.limit = limit;
+ this.percent = percent;
+ this.borders = borders;
+
+ control1Data = new FormData();
+ control1 = borders ? new OneBorderComposite(this)
+ {
+ @Override
+ protected Control createUI(Composite parent)
+ {
+ return createControl1(parent);
+ }
+ } : createControl1(this);
+
+ control1.setLayoutData(control1Data);
+
+ sashData = new FormData();
+ sash = createSash(this);
+ sash.setLayoutData(sashData);
+
+ control2Data = new FormData();
+ control2 = borders ? new OneBorderComposite(this)
+ {
+ @Override
+ protected Control createUI(Composite parent)
+ {
+ return createControl2(parent);
+ }
+ } : createControl2(this);
+
+ control2.setLayoutData(control2Data);
+
+ init();
+ }
+
+ /**
+ * @since 2.0
+ */
+ @Override
+ public void dispose()
+ {
+ sash.removeListener(SWT.Selection, sashListener);
+ super.dispose();
+ }
+
+ /**
+ * @since 2.0
+ */
+ public void addListener(IListener listener)
+ {
+ notifier.addListener(listener);
+ }
+
+ /**
+ * @since 2.0
+ */
+ public IListener[] getListeners()
+ {
+ return notifier.getListeners();
+ }
+
+ /**
+ * @since 2.0
+ */
+ public boolean hasListeners()
+ {
+ return notifier.hasListeners();
+ }
+
+ /**
+ * @since 2.0
+ */
+ public void removeListener(IListener listener)
+ {
+ notifier.removeListener(listener);
+ }
+
+ public boolean isVertical()
+ {
+ return vertical;
+ }
+
+ public void setVertical(boolean vertical)
+ {
+ if (this.vertical != vertical)
+ {
+ this.vertical = vertical;
+
+ Sash newSash = createSash(this);
+ newSash.moveBelow(control1);
+ newSash.setLayoutData(sash.getLayoutData());
+
+ sash.removeListener(SWT.Selection, sashListener);
+ sash.setLayoutData(null);
+ sash.dispose();
+ sash = newSash;
+
+ init();
+ layout();
+ IListener[] listeners = notifier.getListeners();
+ if (listeners != null)
+ {
+ notifier.fireEvent(new OrientationChangedEvent(vertical), listeners);
+ }
+ }
+ }
+
+ public Sash getSash()
+ {
+ return sash;
+ }
+
+ public Control getControl1()
+ {
+ return borders ? ((OneBorderComposite)control1).getClientControl() : control1;
+ }
+
+ public Control getControl2()
+ {
+ return borders ? ((OneBorderComposite)control2).getClientControl() : control2;
+ }
+
+ protected void init()
+ {
+ if (borders)
+ {
+ ((OneBorderComposite)control1).setBorderPosition(SWT.RIGHT);
+ ((OneBorderComposite)control2).setBorderPosition(SWT.LEFT);
+ }
+
+ control1Data.left = new FormAttachment(0, 0);
+ control1Data.right = new FormAttachment(sash, 0);
+ control1Data.top = new FormAttachment(0, 0);
+ control1Data.bottom = new FormAttachment(100, 0);
+
+ sashData.left = new FormAttachment(percent, 0);
+ sashData.right = null;
+ sashData.top = new FormAttachment(0, 0);
+ sashData.bottom = new FormAttachment(100, 0);
+
+ control2Data.left = new FormAttachment(sash, 0);
+ control2Data.right = new FormAttachment(100, 0);
+ control2Data.top = new FormAttachment(0, 0);
+ control2Data.bottom = new FormAttachment(100, 0);
+
+ if (vertical)
+ {
+ swap();
+ }
+ }
+
+ protected void swap()
+ {
+ if (borders)
+ {
+ ((OneBorderComposite)control1).swapBorderPosition();
+ ((OneBorderComposite)control2).swapBorderPosition();
+ }
+
+ swap(control1Data);
+ swap(sashData);
+ swap(control2Data);
+ }
+
+ protected void swap(FormData formData)
+ {
+ FormAttachment tmp1 = formData.left;
+ formData.left = formData.top;
+ formData.top = tmp1;
+
+ FormAttachment tmp2 = formData.right;
+ formData.right = formData.bottom;
+ formData.bottom = tmp2;
+ }
+
+ protected Sash createSash(Composite parent)
+ {
+ Sash sash = new Sash(parent, vertical ? SWT.HORIZONTAL : SWT.VERTICAL);
+ sash.addListener(SWT.Selection, sashListener);
+ return sash;
+ }
+
+ protected abstract Control createControl1(Composite parent);
+
+ protected abstract Control createControl2(Composite parent);
+
+ /**
+ * @author Eike Stepper
+ * @since 2.0
+ */
+ public class OrientationChangedEvent extends org.eclipse.net4j.util.event.Event
+ {
+ private static final long serialVersionUID = 1L;
+
+ private boolean vertical;
+
+ public OrientationChangedEvent(boolean vertical)
+ {
+ super(SashComposite.this);
+ }
+
+ @Override
+ public SashComposite getSource()
+ {
+ return (SashComposite)super.getSource();
+ }
+
+ public boolean isVertical()
+ {
+ return vertical;
+ }
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ private final class SashListener implements Listener
+ {
+ public SashListener()
+ {
+ }
+
+ public void handleEvent(Event e)
+ {
+ Rectangle sashRect = sash.getBounds();
+ Rectangle shellRect = getClientArea();
+ if (!vertical)
+ {
+ int right = shellRect.width - sashRect.width - limit;
+ e.x = Math.max(Math.min(e.x, right), limit);
+ if (e.x != sashRect.x)
+ {
+ sashData.left = new FormAttachment(0, e.x);
+ layout();
+ }
+ }
+ else
+ {
+ int bottom = shellRect.height - sashRect.height - limit;
+ e.y = Math.max(Math.min(e.y, bottom), limit);
+ if (e.y != sashRect.y)
+ {
+ sashData.top = new FormAttachment(0, e.y);
+ layout();
+ }
+ }
+ }
+ }
+}
diff --git a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/widgets/TextAndDisable.java b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/widgets/TextAndDisable.java index 8f1b2b44f7..2a964cd570 100644 --- a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/widgets/TextAndDisable.java +++ b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/widgets/TextAndDisable.java @@ -1,126 +1,126 @@ -/* - * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) 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: - * Eike Stepper - initial API and implementation - */ -package org.eclipse.net4j.util.ui.widgets; - -import org.eclipse.net4j.util.ObjectUtil; -import org.eclipse.net4j.util.internal.ui.messages.Messages; -import org.eclipse.net4j.util.ui.UIUtil; - -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.ModifyEvent; -import org.eclipse.swt.events.ModifyListener; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.events.SelectionListener; -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.Text; - -public class TextAndDisable extends Composite implements SelectionListener, ModifyListener -{ - private Text text; - - private Button disabled; - - private String disabledValue; - - public TextAndDisable(Composite parent, int textStyle, String disabledValue) - { - super(parent, SWT.NONE); - this.disabledValue = disabledValue; - - GridLayout grid = new GridLayout(2, false); - grid.marginHeight = 0; - grid.marginWidth = 0; - setLayout(grid); - - text = createText(textStyle); - text.setLayoutData(createTextLayoutData()); - text.addModifyListener(this); - - disabled = createButton(); - disabled.setText(Messages.getString("TextAndDisable.0")); //$NON-NLS-1$ - disabled.addSelectionListener(this); - disabled.setLayoutData(UIUtil.createGridData(false, false)); - } - - public Text getText() - { - return text; - } - - public Button getButton() - { - return disabled; - } - - public boolean isDisabled() - { - return disabled.getSelection(); - } - - public void setDisabled(boolean disabled) - { - this.disabled.setSelection(disabled); - widgetSelected(null); - } - - public String getValue() - { - return text.getText(); - } - - public void setValue(String value) - { - text.setText(value); - setDisabled(ObjectUtil.equals(value, disabledValue)); - } - - public void widgetDefaultSelected(SelectionEvent e) - { - widgetSelected(e); - } - - public void widgetSelected(SelectionEvent e) - { - if (isDisabled()) - { - text.setText(disabledValue); - text.setEnabled(false); - } - else - { - text.setEnabled(true); - } - } - - public void modifyText(ModifyEvent e) - { - } - - protected Text createText(int textStyle) - { - return new Text(this, textStyle); - } - - protected GridData createTextLayoutData() - { - GridData gd = new GridData(); - gd.widthHint = 32; - return gd; - } - - protected Button createButton() - { - return new Button(this, SWT.CHECK); - } -} +/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.util.ui.widgets;
+
+import org.eclipse.net4j.util.ObjectUtil;
+import org.eclipse.net4j.util.internal.ui.messages.Messages;
+import org.eclipse.net4j.util.ui.UIUtil;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+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.Text;
+
+public class TextAndDisable extends Composite implements SelectionListener, ModifyListener
+{
+ private Text text;
+
+ private Button disabled;
+
+ private String disabledValue;
+
+ public TextAndDisable(Composite parent, int textStyle, String disabledValue)
+ {
+ super(parent, SWT.NONE);
+ this.disabledValue = disabledValue;
+
+ GridLayout grid = new GridLayout(2, false);
+ grid.marginHeight = 0;
+ grid.marginWidth = 0;
+ setLayout(grid);
+
+ text = createText(textStyle);
+ text.setLayoutData(createTextLayoutData());
+ text.addModifyListener(this);
+
+ disabled = createButton();
+ disabled.setText(Messages.getString("TextAndDisable.0")); //$NON-NLS-1$
+ disabled.addSelectionListener(this);
+ disabled.setLayoutData(UIUtil.createGridData(false, false));
+ }
+
+ public Text getText()
+ {
+ return text;
+ }
+
+ public Button getButton()
+ {
+ return disabled;
+ }
+
+ public boolean isDisabled()
+ {
+ return disabled.getSelection();
+ }
+
+ public void setDisabled(boolean disabled)
+ {
+ this.disabled.setSelection(disabled);
+ widgetSelected(null);
+ }
+
+ public String getValue()
+ {
+ return text.getText();
+ }
+
+ public void setValue(String value)
+ {
+ text.setText(value);
+ setDisabled(ObjectUtil.equals(value, disabledValue));
+ }
+
+ public void widgetDefaultSelected(SelectionEvent e)
+ {
+ widgetSelected(e);
+ }
+
+ public void widgetSelected(SelectionEvent e)
+ {
+ if (isDisabled())
+ {
+ text.setText(disabledValue);
+ text.setEnabled(false);
+ }
+ else
+ {
+ text.setEnabled(true);
+ }
+ }
+
+ public void modifyText(ModifyEvent e)
+ {
+ }
+
+ protected Text createText(int textStyle)
+ {
+ return new Text(this, textStyle);
+ }
+
+ protected GridData createTextLayoutData()
+ {
+ GridData gd = new GridData();
+ gd.widthHint = 32;
+ return gd;
+ }
+
+ protected Button createButton()
+ {
+ return new Button(this, SWT.CHECK);
+ }
+}
diff --git a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/widgets/package-info.java b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/widgets/package-info.java index 20df41f3a4..d18c863971 100644 --- a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/widgets/package-info.java +++ b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/widgets/package-info.java @@ -1,5 +1,5 @@ /*
- * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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
|